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> |
---|
9 | #include "synctree.h" |
---|
10 | |
---|
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) |
---|
20 | { char *p = (char *) alloca(strlen(fname) + strlen(date_db_name) + 1); |
---|
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 | } |
---|
32 | } |
---|
33 | if (!*dbmpp) abort(); |
---|
34 | key.dptr = rindex(fname,'/'); |
---|
35 | key.dptr++; |
---|
36 | key.dsize = strlen(key.dptr); |
---|
37 | |
---|
38 | datum_date_db = dbm_fetch(*dbmpp,key); |
---|
39 | if (datum_date_db.dptr == NULL) return (time_t) 0; /* a 0 time_t */ |
---|
40 | else if (datum_date_db.dsize != sizeof(time_t)) |
---|
41 | { fprintf(stderr, "get_date: dsize != sizeof(time_t) in datum returned by dbm_fetch()"); |
---|
42 | return (time_t) 0; |
---|
43 | } |
---|
44 | else { |
---|
45 | time_t temp; |
---|
46 | bcopy (datum_date_db.dptr, (char *)&temp, sizeof(temp)); |
---|
47 | return temp; |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | set_date(dbmpp,fname,date) |
---|
52 | DBM **dbmpp; |
---|
53 | char *fname; |
---|
54 | time_t date; |
---|
55 | { |
---|
56 | extern char *date_db_name; |
---|
57 | datum key; |
---|
58 | datum date_db_datum; |
---|
59 | if (*dbmpp == NULL) |
---|
60 | { char *p = (char *) alloca(strlen(fname) + strlen(date_db_name) + 1); |
---|
61 | char *pp; |
---|
62 | (void) strcpy(p,fname); |
---|
63 | pp = rindex(p,'/'); |
---|
64 | pp++; |
---|
65 | (void) strcpy(pp,date_db_name); |
---|
66 | *dbmpp = dbm_open(p, O_RDWR|O_CREAT, 00644); |
---|
67 | if (!dbmpp) abort(); |
---|
68 | } |
---|
69 | |
---|
70 | key.dptr = rindex(fname,'/'); |
---|
71 | key.dptr++; |
---|
72 | key.dsize = strlen(key.dptr); |
---|
73 | date_db_datum.dptr = (char *) &date; |
---|
74 | date_db_datum.dsize = sizeof(date); |
---|
75 | (void) dbm_store(*dbmpp, key, date_db_datum, DBM_REPLACE); |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|