home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / pc-mail-nfs / mtime.c < prev    next >
C/C++ Source or Header  |  1989-11-26  |  2KB  |  94 lines

  1. /*++
  2. /* NAME
  3. /*    mtime 3
  4. /* SUMMARY
  5. /*    maintain modification times of files
  6. /* PROJECT
  7. /*    pc-mail
  8. /* PACKAGE
  9. /*    nfs
  10. /* SYNOPSIS
  11. /*    #include "mtime.h"
  12. /*
  13. /*    MTIME *mtime(path)
  14. /*    char *path;
  15. /* DESCRIPTION
  16. /*    mtime() maintains a table of modification times of files.
  17. /*    If a new file name is given, a modification time of 0 is
  18. /*    assumed (the UNIX equivalent of "a very long time ago").
  19. /*
  20. /*    If, for whatever reason, no memory can be allocated to update the
  21. /*    symbol table, a dummy entry is returned with modification time of 0.
  22. /* DIAGNOSTICS
  23. /*    Diagnostics are logged with the syslog(3) facility. The program
  24. /*    tries to continue to run as long as possible.
  25. /* BUGS
  26. /*    The dummy entry is stored in static memory; its value may be
  27. /*    overwritten an any time.
  28. /* AUTHOR(S)
  29. /*    Wietse Z. Venema
  30. /*    Eindhoven University of Technology
  31. /*    Department of Mathematics and Computer Science
  32. /*    Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
  33. /* CREATION DATE
  34. /*    Sun Oct 29 15:48:01 MET 1989
  35. /* LAST MODIFICATION DATE
  36. /*    10/29/89 22:29:56
  37. /* VERSION/RELEASE
  38. /*    1.1
  39. /*--*/
  40.  
  41. #ifndef lint
  42. static char sccsid[] = "@(#) mtime.c 1.1 10/29/89 22:29:56";
  43.  
  44. #endif
  45.  
  46. #ifdef SYSLOG
  47. #include <syslog.h>
  48. #else
  49. #include "syslog.h"
  50. #endif
  51.  
  52. #include "mtime.h"
  53.  
  54. extern char *malloc();
  55. extern char *strcpy();
  56.  
  57. MTIME  *mtime_tree;            /* head of symbol table */
  58.  
  59. /* findtime - actual symbol-table access routine */
  60.  
  61. MTIME  *findtime(path, tree)
  62. register char *path;
  63. register MTIME *tree;
  64. {
  65.     register int direct;
  66.     static MTIME dummy;
  67.  
  68.     /*
  69.      * We use a trivial binary-tree storage scheme. If we cannot get memory
  70.      * for whatever reason, produce a dummy result. This means we will always
  71.      * believe that a file has changed. My first excercise in "graceful
  72.      * degradation".
  73.      */
  74.  
  75.     if (tree == 0) {                /* new file */
  76.     if ((tree = (MTIME *) malloc(sizeof(MTIME))) == 0
  77.         || (tree->path = malloc(strlen(path) + 1)) == 0) {
  78.         syslog(LOG_WARNING, "memory allocation failed");
  79.         dummy.time = 0;
  80.         tree = &dummy;
  81.     } else {
  82.         (void) strcpy(tree->path, path);
  83.         tree->time = 0;
  84.         tree->left = tree->rite = 0;
  85.     }
  86.     } else if ((direct = strcmp(path, tree->path)) < 0) {
  87.     tree->left = findtime(path, tree->left);
  88.     } else if (direct > 0) {
  89.     tree->rite = findtime(path, tree->rite);
  90.     }
  91.     return (tree);
  92. }
  93.  
  94.