home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / pcmail / daemon / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  3.2 KB  |  158 lines

  1. /*++
  2. /* NAME
  3. /*    util 3
  4. /* SUMMARY
  5. /*    wrappers around standard library functions
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    nfs
  10. /* SYNOPSIS
  11. /*    #include <stdio.h>
  12. /*    #include <pwd.h>
  13. /*    #include <directory_access_stuff.h>
  14. /*
  15. /*    FILE *u_fopen(uinfo,path,mode)
  16. /*    struct passwd *uinfo;
  17. /*    char *path;
  18. /*    char *mode;
  19. /*
  20. /*    int u_link(uinfo, old, new)
  21. /*    struct passwd *uinfo;
  22. /*    char *old;
  23. /*    char *new;
  24. /*
  25. /*    int u_unlink(uinfo, path)
  26. /*    struct passwd *uinfo;
  27. /*    char *path;
  28. /*
  29. /*    DIR *e_opendir(path)
  30. /*    char *path;
  31. /*
  32. /*    int e_chdir(path)
  33. /*    char *path;
  34. /*
  35. /*    int e_fork()
  36. /* DESCRIPTION
  37. /*    These functions are wrappers around some standard library functions.
  38. /*    In case of problems, they append an entry to the system log (with
  39. /*    priority LOG_WARNING). The \fIuinfo\fR argument specifies the owner
  40. /*    of the mail subdirectory in which the problem occurred.
  41. /* SEE ALSO
  42. /*    syslog(3)
  43. /* DIAGNOSTICS
  44. /*    Diagnostics are logged via the syslog package; error return values
  45. /*    are identical to those of the underlying library functions.
  46. /* AUTHOR(S)
  47. /*    Wietse Z. Venema
  48. /*    Eindhoven University of Technology
  49. /*    Department of Mathematics and Computer Science
  50. /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  51. /* CREATION DATE
  52. /*    Sun Oct 29 16:21:02 MET 1989
  53. /* LAST MODIFICATION
  54. /*    12/4/89 23:22:13
  55. /* VERSION/RELEASE
  56. /*    1.2
  57. /*--*/
  58.  
  59. #ifndef lint
  60. static char sccsid[] = "@(#) util.c 1.2 12/4/89 23:22:13";
  61.  
  62. #endif
  63.  
  64. #include <stdio.h>
  65. #include <pwd.h>
  66.  
  67. #ifdef SYSV
  68. #include <ndir.h>
  69. #else
  70. #include <sys/types.h>
  71. #include <sys/dir.h>
  72. #endif
  73.  
  74. #ifdef SYSLOG
  75. #include <syslog.h>
  76. #else
  77. #include "syslog.h"
  78. #endif
  79.  
  80. #include "util.h"            /* consistency check */
  81.  
  82. /* u_fopen - open file in user directory, log any errors */
  83.  
  84. FILE   *u_fopen(uinfo, file, mode)
  85. struct passwd *uinfo;
  86. char   *file;
  87. char   *mode;
  88. {
  89.     register FILE *fp;
  90.  
  91.     if ((fp = fopen(file, mode)) == 0)
  92.     syslog(LOG_WARNING, "cannot open %s/%s: %m", uinfo->pw_name, file);
  93.     return (fp);
  94. }
  95.  
  96. /* u_unlink - unlink file in user directory, log any errors */
  97.  
  98. int     u_unlink(uinfo, file)
  99. struct passwd *uinfo;
  100. char   *file;
  101. {
  102.     register int stat;
  103.  
  104.     if (stat = unlink(file))
  105.     syslog(LOG_WARNING, "cannot unlink %s/%s: %m", uinfo->pw_name, file);
  106.     return (stat);
  107. }
  108.  
  109. /* u_link - link file in user directory, log any errors */
  110.  
  111. int     u_link(uinfo, old, new)
  112. struct passwd *uinfo;
  113. char   *old;
  114. char   *new;
  115. {
  116.     register int stat;
  117.  
  118.     if (stat = link(old, new))
  119.     syslog(LOG_WARNING, "cannot link %s/%s: %m", uinfo->pw_name, new);
  120.     return (stat);
  121. }
  122.  
  123. /* e_opendir - open directory, log any errors */
  124.  
  125. DIR    *e_opendir(path)
  126. char   *path;
  127. {
  128.     register DIR *dd;
  129.  
  130.     if ((dd = opendir(path)) == 0)
  131.     syslog(LOG_WARNING, "cannot open directory %s: %m", path);
  132.     return (dd);
  133. }
  134.  
  135. /* e_chdir - change directory, log any errors */
  136.  
  137. int     e_chdir(path)
  138. char   *path;
  139. {
  140.     register int ret;
  141.  
  142.     if (ret = chdir(path))
  143.     syslog(LOG_WARNING, "cannot chdir to directory %s: %m", path);
  144.     return (ret);
  145. }
  146.  
  147. /* e_fork - do a fork(), log any errors */
  148.  
  149. int     e_fork()
  150. {
  151.     register int stat;
  152.  
  153.     if ((stat = fork()) == -1)
  154.     syslog(LOG_WARNING, "fork() failed: %m");
  155.     return (stat);
  156. }
  157.  
  158.