1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | #if defined(__BORLANDC__) && defined(__WIN32__) |
35 | #undef __WIN32__ |
36 | #endif |
37 | |
38 | #ifdef __APPLE__ |
39 | #include <sys/types.h> |
40 | #endif |
41 | #include <dirent.h> |
42 | #include "extern.h" |
43 | #include "sysintf.h" |
44 | |
45 | |
46 | typedef struct ent { |
47 | char *name; |
48 | uint32 hkey; |
49 | time_t mtime; |
50 | int isdir; |
51 | struct ent *next; |
52 | } Entry, *EntryPtr; |
53 | |
54 | |
55 | typedef struct mydir { |
56 | char *path; |
57 | uint32 hkey; |
58 | EntryPtr entries; |
59 | struct mydir *next; |
60 | } DirEntry, *DirEntryPtr; |
61 | |
62 | static DirEntryPtr dtab[HASH_TABLE_SIZE200]; |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | PUBLIC time_t |
86 | CacheStat(path, force) |
87 | char *path; |
88 | int force; |
89 | { |
90 | struct stat stbuf; |
91 | DirEntryPtr dp; |
92 | EntryPtr ep; |
93 | uint32 hkey; |
94 | uint16 hv; |
95 | char *fpath; |
96 | char *spath; |
97 | char *comp; |
98 | char *dir; |
99 | char *udir; |
100 | int loaded=FALSE0; |
101 | |
102 | if (If_root_path(path)) |
| |
103 | spath = path; |
104 | else |
105 | spath = Build_path(Pwd,path); |
106 | |
107 | fpath = DmStrDup(spath); |
108 | |
109 | comp = Basename(fpath); |
110 | dir = Filedir(fpath); |
111 | |
112 | |
113 | if( !STOBOOL(DcacheRespCase)(DcacheRespCase && ((*DcacheRespCase | 0x20) == 'y')) ) { |
| |
114 | udir = DmStrDup(dir); |
115 | strlwr(comp); |
116 | strlwr(dir); |
117 | } else |
118 | udir = dir; |
119 | |
120 | hv = Hash(dir,&hkey); |
121 | |
122 | for(dp=dtab[hv]; dp; dp=dp->next) |
| 3 | | Loop condition is true. Entering loop body | |
|
| 4 | | Loop condition is true. Entering loop body | |
|
| 5 | | Loop condition is true. Entering loop body | |
|
123 | if (hkey == dp->hkey && strcmp(dp->path,dir) == 0) |
| |
124 | break; |
| 7 | | Execution continues on line 126 | |
|
125 | |
126 | if (!dp) { |
| |
127 | |
128 | DIR *dirp; |
129 | struct dirent *direntp; |
130 | |
131 | if( Verbose & V_DIR_CACHE0x04 ) |
132 | printf( "%s: Caching directory [%s]\n", Pname, dir ); |
133 | |
134 | |
135 | loaded = TRUE1; |
136 | |
137 | TALLOC(dp,1,DirEntry)if ((dp = (DirEntry*) calloc((unsigned int)(1), (size_t)sizeof (DirEntry))) == (DirEntry*)0) {No_ram();}; |
138 | dp->next = dtab[hv]; |
139 | dtab[hv] = dp; |
140 | dp->path = DmStrDup(dir); |
141 | dp->hkey = hkey; |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | if (Set_dir(udir) == 0) { |
155 | if((dirp=opendir(".")) != NIL(DIR)((DIR*)((void*)0))) { |
156 | while((direntp=readdir(dirp)) != NULL((void*)0)) { |
157 | TALLOC(ep,1,Entry)if ((ep = (Entry*) calloc((unsigned int)(1), (size_t)sizeof(Entry ))) == (Entry*)0) {No_ram();}; |
158 | ep->name = DmStrDup(direntp->d_name); |
159 | if( !STOBOOL(DcacheRespCase)(DcacheRespCase && ((*DcacheRespCase | 0x20) == 'y')) ) |
160 | strlwr(ep->name); |
161 | |
162 | Hash(ep->name, &ep->hkey); |
163 | |
164 | ep->next = dp->entries; |
165 | dp->entries = ep; |
166 | DMSTATstat(direntp->d_name,&stbuf); |
167 | ep->isdir = (stbuf.st_mode & S_IFDIR0040000); |
168 | ep->mtime = stbuf.st_mtimest_mtim.tv_sec; |
169 | } |
170 | closedir(dirp); |
171 | } |
172 | Set_dir(Pwd); |
173 | } |
174 | } |
175 | |
176 | Hash(comp, &hkey); |
177 | |
178 | |
179 | if (dp) { |
| |
180 | for(ep=dp->entries; ep; ep=ep->next) |
| 10 | | Loop condition is false. Execution continues on line 187 | |
|
181 | if(hkey == ep->hkey && strcmp(ep->name,comp) == 0) |
182 | break; |
183 | } |
184 | else |
185 | ep = NULL((void*)0); |
186 | |
187 | if( force && !loaded) { |
| |
188 | if (strlen(comp) > NameMax || DMSTATstat(spath,&stbuf) != 0) { |
| |
189 | |
190 | if (strlen(comp) > NameMax) |
191 | Warning( "File [%s] longer than value of NAMEMAX [%d].\n\ |
192 | Assume unix time 0.\n", comp, NameMax ); |
193 | if(ep) |
194 | ep->mtime = 0L; |
195 | } |
196 | else { |
197 | if (!ep) { |
| |
198 | TALLOC(ep,1,Entry)if ((ep = (Entry*) calloc((unsigned int)(1), (size_t)sizeof(Entry ))) == (Entry*)0) {No_ram();}; |
| 14 | | Within the expansion of the macro 'TALLOC':
| |
b | Assuming pointer value is null |
|
199 | ep->name = DmStrDup(comp); |
| 15 | | Access to field 'name' results in a dereference of a null pointer (loaded from variable 'ep') |
|
200 | if( !STOBOOL(DcacheRespCase)(DcacheRespCase && ((*DcacheRespCase | 0x20) == 'y')) ) |
201 | strlwr(ep->name); |
202 | Hash(ep->name, &ep->hkey); |
203 | ep->next = dp->entries; |
204 | ep->isdir = (stbuf.st_mode & S_IFDIR0040000); |
205 | dp->entries = ep; |
206 | } |
207 | |
208 | ep->mtime = stbuf.st_mtimest_mtim.tv_sec; |
209 | } |
210 | |
211 | if( Verbose & V_DIR_CACHE0x04 ) |
212 | printf("%s: Updating dir cache entry for [%s], new time is %ld\n", |
213 | Pname, spath, ep ? ep->mtime : 0L); |
214 | } |
215 | |
216 | if( udir != dir ) |
217 | FREE(udir)free((char*)(udir)); |
218 | |
219 | FREE(fpath)free((char*)(fpath)); |
220 | return(!ep ? (time_t)0L : ((STOBOOL(Augmake)(Augmake && ((*Augmake | 0x20) == 'y')) && ep->isdir)?0L:ep->mtime)); |
221 | } |