[6243] | 1 | /* Copyright (C) 1988 Tim Shepard All rights reserved. */ |
---|
| 2 | |
---|
| 3 | #include <stdio.h> |
---|
| 4 | #include <sys/file.h> |
---|
| 5 | #include <sys/types.h> |
---|
| 6 | #include <string.h> |
---|
| 7 | #include <time.h> |
---|
| 8 | #include <ndbm.h> |
---|
[7940] | 9 | #include "synctree.h" |
---|
| 10 | |
---|
[6243] | 11 | time_t get_date(dbmpp,fname) |
---|
| 12 | DBM **dbmpp; |
---|
| 13 | char *fname; |
---|
| 14 | { |
---|
| 15 | extern char *date_db_name; |
---|
| 16 | datum key; |
---|
| 17 | datum datum_date_db; |
---|
| 18 | |
---|
| 19 | if (*dbmpp == NULL) |
---|
[10717] | 20 | { char *p = (char *) malloc(strlen(fname) + strlen(date_db_name) + 1); |
---|
[6243] | 21 | char *pp; |
---|
| 22 | (void) strcpy(p,fname); |
---|
| 23 | pp = rindex(p,'/'); |
---|
| 24 | pp++; |
---|
| 25 | (void) strcpy(pp,date_db_name); |
---|
| 26 | |
---|
| 27 | *dbmpp = dbm_open(p, O_RDWR|O_CREAT, 00644); |
---|
| 28 | if (!*dbmpp) { |
---|
| 29 | perror(p); |
---|
| 30 | exit(1); |
---|
| 31 | } |
---|
[10717] | 32 | free(p); |
---|
[6243] | 33 | } |
---|
| 34 | if (!*dbmpp) abort(); |
---|
| 35 | key.dptr = rindex(fname,'/'); |
---|
| 36 | key.dptr++; |
---|
| 37 | key.dsize = strlen(key.dptr); |
---|
| 38 | |
---|
| 39 | datum_date_db = dbm_fetch(*dbmpp,key); |
---|
| 40 | if (datum_date_db.dptr == NULL) return (time_t) 0; /* a 0 time_t */ |
---|
| 41 | else if (datum_date_db.dsize != sizeof(time_t)) |
---|
| 42 | { fprintf(stderr, "get_date: dsize != sizeof(time_t) in datum returned by dbm_fetch()"); |
---|
| 43 | return (time_t) 0; |
---|
| 44 | } |
---|
| 45 | else { |
---|
| 46 | time_t temp; |
---|
| 47 | bcopy (datum_date_db.dptr, (char *)&temp, sizeof(temp)); |
---|
| 48 | return temp; |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | set_date(dbmpp,fname,date) |
---|
| 53 | DBM **dbmpp; |
---|
| 54 | char *fname; |
---|
| 55 | time_t date; |
---|
| 56 | { |
---|
| 57 | extern char *date_db_name; |
---|
| 58 | datum key; |
---|
| 59 | datum date_db_datum; |
---|
| 60 | if (*dbmpp == NULL) |
---|
[10717] | 61 | { char *p = (char *) malloc(strlen(fname) + strlen(date_db_name) + 1); |
---|
[6243] | 62 | char *pp; |
---|
| 63 | (void) strcpy(p,fname); |
---|
| 64 | pp = rindex(p,'/'); |
---|
| 65 | pp++; |
---|
| 66 | (void) strcpy(pp,date_db_name); |
---|
| 67 | *dbmpp = dbm_open(p, O_RDWR|O_CREAT, 00644); |
---|
| 68 | if (!dbmpp) abort(); |
---|
[10717] | 69 | free(p); |
---|
[6243] | 70 | } |
---|
| 71 | |
---|
| 72 | key.dptr = rindex(fname,'/'); |
---|
| 73 | key.dptr++; |
---|
| 74 | key.dsize = strlen(key.dptr); |
---|
| 75 | date_db_datum.dptr = (char *) &date; |
---|
| 76 | date_db_datum.dsize = sizeof(date); |
---|
| 77 | (void) dbm_store(*dbmpp, key, date_db_datum, DBM_REPLACE); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|