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