"Fossies" - the Fresh Open Source Software Archive 
Member "courier-1.2.2/libs/ldapaddressbook/abookdel.c" (20 Jan 2022, 856 Bytes) of package /linux/misc/courier-1.2.2.tar.bz2:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "abookdel.c" see the
Fossies "Dox" file reference documentation.
1 /*
2 ** Copyright 2006, Double Precision Inc.
3 **
4 ** See COPYING for distribution information.
5 */
6
7 #include "config.h"
8 #include "ldapaddressbook.h"
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 int ldapabook_del(const char *filename, const char *tempname,
16 const char *delname)
17 {
18 /* This is cheating, but we won't really have many abooks, come on... */
19 struct ldapabook *a=ldapabook_read(filename), *b;
20
21 FILE *fp;
22
23 if (!a) return (0);
24
25 if ((fp=fopen(tempname, "w")) == 0)
26 {
27 ldapabook_free(a);
28 return (-1);
29 }
30
31 for (b=a; b; b=b->next)
32 {
33 if (strcmp(b->name, delname) == 0) continue;
34
35 ldapabook_writerec(b, fp);
36 }
37 ldapabook_free(a);
38
39 if (fflush(fp) || fclose(fp))
40 {
41 fclose(fp);
42 unlink(tempname);
43 return (-1);
44 }
45
46 if (rename(tempname, filename))
47 {
48 unlink(tempname);
49 return (-1);
50 }
51
52 return (0);
53 }