home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libfake / dbz.c < prev    next >
C/C++ Source or Header  |  1995-04-27  |  2KB  |  85 lines

  1. /*
  2.  * fakes for using dbm (or old dbz) as if it were dbz
  3.  */
  4. #include <stdio.h>
  5. #include <sys/types.h>
  6. #include <dbz.h>
  7.  
  8. /* the simple stuff */
  9. dbzfresh(a,b,c,d,e) char *a; long b; { return(dbzagain(a,a)); }
  10. long dbzsize(a) long a; { return(a); }
  11. dbzincore(n) int n; { return(0); }
  12. dbzwritethrough(n) int n; { return(0); }
  13. long dbztagmask(n) long n; { return(0); }
  14. dbzdebug(n) int n; { return(0); }
  15. long dbztrim(a) long a; { return(a); }
  16. int dbzsync() { return(0); }
  17.  
  18. /*
  19.  - dbzagain - like dbminit but creates files
  20.  */
  21. int
  22. dbzagain(a, b)
  23. char *a;
  24. char *b;
  25. {
  26.     char dirname[200];
  27.     char pagname[200];
  28.     FILE *p;
  29.     FILE *d;
  30.  
  31.     sprintf(dirname, "%s.dir", a);
  32.     sprintf(pagname, "%s.pag", a);
  33.     p = fopen(dirname, "w");
  34.     d = fopen(pagname, "w");
  35.     if (p != NULL)
  36.         (void) fclose(p);
  37.     if (d != NULL)
  38.         (void) fclose(d);
  39.     if (p == NULL || d == NULL)
  40.         return(-1);
  41.  
  42.     return(dbminit(a));
  43. }
  44.  
  45. /*
  46.  - dbzfetch - fetch() with case mapping built in
  47.  *
  48.  * Uses C News rfc822ize().  Assumes keys are strings.
  49.  */
  50. datum
  51. dbzfetch(key)
  52. datum key;
  53. {
  54.     char buffer[DBZMAXKEY + 1];
  55.     datum mappedkey;
  56.  
  57.     (void) strcpy(buffer, key.dptr);
  58.     (void) rfc822ize(buffer);
  59.     mappedkey.dptr = buffer;
  60.     mappedkey.dsize = key.dsize;
  61.  
  62.     return(fetch(mappedkey));
  63. }
  64.  
  65. /*
  66.  - dbzstore - store() with case mapping built in
  67.  *
  68.  * Uses C News rfc822ize().  Assumes keys are strings.
  69.  */
  70. int
  71. dbzstore(key, data)
  72. datum key;
  73. datum data;
  74. {
  75.     char buffer[DBZMAXKEY + 1];
  76.     datum mappedkey;
  77.  
  78.     (void) strcpy(buffer, key.dptr);
  79.     (void) rfc822ize(buffer);
  80.     mappedkey.dptr = buffer;
  81.     mappedkey.dsize = key.dsize;
  82.  
  83.     return(store(mappedkey, data));
  84. }
  85.