abookdel.c
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:1k
源码类别:

WEB邮件程序

开发平台:

C/C++

  1. #include "config.h"
  2. #include "ldapaddressbook.h"
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. int ldapabook_del(const char *filename, const char *tempname,
  8. const char *delname)
  9. {
  10. /* This is cheating, but we won't really have many abooks, come on... */
  11. struct ldapabook *a=ldapabook_read(filename), *b;
  12. FILE *fp;
  13. if (!a) return (0);
  14. if ((fp=fopen(tempname, "w")) == 0)
  15. {
  16. ldapabook_free(a);
  17. return (-1);
  18. }
  19. for (b=a; b; b=b->next)
  20. {
  21. if (strcmp(b->name, delname) == 0) continue;
  22. fprintf(fp, "%st%st%st%st%st%sn", b->name, b->host,
  23. b->port, b->suffix, b->binddn, b->bindpw);
  24. }
  25. ldapabook_free(a);
  26. if (fflush(fp) || fclose(fp))
  27. {
  28. fclose(fp);
  29. unlink(tempname);
  30. return (-1);
  31. }
  32. if (rename(tempname, filename))
  33. {
  34. unlink(tempname);
  35. return (-1);
  36. }
  37. return (0);
  38. }