Lines 172-183
static int fileIsOk(char *fullname, stru
Link Here
|
172 |
/* find an image with paths and extensions from defaults files. returns |
172 |
/* find an image with paths and extensions from defaults files. returns |
173 |
* -1 if access denied or not found, 0 if ok. |
173 |
* -1 if access denied or not found, 0 if ok. |
174 |
*/ |
174 |
*/ |
175 |
int findImage(char *name, char *fullname) |
175 |
int findImage(char *name, char *fullname, size_t size) |
176 |
{ |
176 |
{ |
177 |
unsigned int p, e; |
177 |
unsigned int p, e; |
178 |
struct stat sbuf; |
178 |
struct stat sbuf; |
179 |
|
179 |
|
180 |
strcpy(fullname, name); |
180 |
strncpy(fullname, name, size); |
181 |
if (!strcmp(name, "stdin")) /* stdin is special name */ |
181 |
if (!strcmp(name, "stdin")) /* stdin is special name */ |
182 |
return (0); |
182 |
return (0); |
183 |
|
183 |
|
Lines 185-210
int findImage(char *name, char *fullname
Link Here
|
185 |
if (!stat(fullname, &sbuf)) |
185 |
if (!stat(fullname, &sbuf)) |
186 |
return (fileIsOk(fullname, &sbuf)); |
186 |
return (fileIsOk(fullname, &sbuf)); |
187 |
#ifndef NO_COMPRESS |
187 |
#ifndef NO_COMPRESS |
188 |
strcat(fullname, ".Z"); |
188 |
strncat(fullname, ".Z", size); |
189 |
if (!stat(fullname, &sbuf)) |
189 |
if (!stat(fullname, &sbuf)) |
190 |
return (fileIsOk(fullname, &sbuf)); |
190 |
return (fileIsOk(fullname, &sbuf)); |
191 |
#endif |
191 |
#endif |
192 |
|
192 |
|
193 |
for (p = 0; p < NumPaths; p++) { |
193 |
for (p = 0; p < NumPaths; p++) { |
194 |
sprintf(fullname, "%s/%s", Paths[p], name); |
194 |
snprintf(fullname, size, "%s/%s", Paths[p], name); |
195 |
if (!stat(fullname, &sbuf)) |
195 |
if (!stat(fullname, &sbuf)) |
196 |
return (fileIsOk(fullname, &sbuf)); |
196 |
return (fileIsOk(fullname, &sbuf)); |
197 |
#ifndef NO_COMPRESS |
197 |
#ifndef NO_COMPRESS |
198 |
strcat(fullname, ".Z"); |
198 |
strncat(fullname, ".Z", size); |
199 |
if (!stat(fullname, &sbuf)) |
199 |
if (!stat(fullname, &sbuf)) |
200 |
#endif |
200 |
#endif |
201 |
return (fileIsOk(fullname, &sbuf)); |
201 |
return (fileIsOk(fullname, &sbuf)); |
202 |
for (e = 0; e < NumExts; e++) { |
202 |
for (e = 0; e < NumExts; e++) { |
203 |
sprintf(fullname, "%s/%s%s", Paths[p], name, Exts[e]); |
203 |
snprintf(fullname, size, "%s/%s%s", Paths[p], name, Exts[e]); |
204 |
if (!stat(fullname, &sbuf)) |
204 |
if (!stat(fullname, &sbuf)) |
205 |
return (fileIsOk(fullname, &sbuf)); |
205 |
return (fileIsOk(fullname, &sbuf)); |
206 |
#ifndef NO_COMPRESS |
206 |
#ifndef NO_COMPRESS |
207 |
strcat(fullname, ".Z"); |
207 |
strncat(fullname, ".Z", size); |
208 |
if (!stat(fullname, &sbuf)) |
208 |
if (!stat(fullname, &sbuf)) |
209 |
return (fileIsOk(fullname, &sbuf)); |
209 |
return (fileIsOk(fullname, &sbuf)); |
210 |
#endif |
210 |
#endif |
Lines 212-222
int findImage(char *name, char *fullname
Link Here
|
212 |
} |
212 |
} |
213 |
|
213 |
|
214 |
for (e = 0; e < NumExts; e++) { |
214 |
for (e = 0; e < NumExts; e++) { |
215 |
sprintf(fullname, "%s%s", name, Exts[e]); |
215 |
snprintf(fullname, size, "%s%s", name, Exts[e]); |
216 |
if (!stat(fullname, &sbuf)) |
216 |
if (!stat(fullname, &sbuf)) |
217 |
return (fileIsOk(fullname, &sbuf)); |
217 |
return (fileIsOk(fullname, &sbuf)); |
218 |
#ifndef NO_COMPRESS |
218 |
#ifndef NO_COMPRESS |
219 |
strcat(fullname, ".Z"); |
219 |
strncat(fullname, ".Z", size); |
220 |
if (!stat(fullname, &sbuf)) |
220 |
if (!stat(fullname, &sbuf)) |
221 |
return (fileIsOk(fullname, &sbuf)); |
221 |
return (fileIsOk(fullname, &sbuf)); |
222 |
#endif |
222 |
#endif |
Lines 241-247
void listImages(void)
Link Here
|
241 |
for (a = 0; a < NumPaths; a++) { |
241 |
for (a = 0; a < NumPaths; a++) { |
242 |
printf("%s:\n", Paths[a]); |
242 |
printf("%s:\n", Paths[a]); |
243 |
fflush(stdout); |
243 |
fflush(stdout); |
244 |
sprintf(buf, "ls %s", Paths[a]); |
244 |
snprintf(buf, sizeof(buf)-1, "ls %s", Paths[a]); |
245 |
if (system(buf) < 0) { |
245 |
if (system(buf) < 0) { |
246 |
perror("ls"); |
246 |
perror("ls"); |
247 |
return; |
247 |
return; |
Lines 296-309
char *expandPath(char *p)
Link Here
|
296 |
var++; |
296 |
var++; |
297 |
else if (*p == '~') { |
297 |
else if (*p == '~') { |
298 |
buf1[b1] = '\0'; |
298 |
buf1[b1] = '\0'; |
299 |
strcat(buf1, getenv("HOME")); |
299 |
strncat(buf1, getenv("HOME"), sizeof(buf1)-1); |
300 |
b1 = strlen(buf1); |
300 |
b1 = strlen(buf1); |
301 |
var = 0; |
301 |
var = 0; |
302 |
} else if (*p == '/' || *p == '}') { |
302 |
} else if (*p == '/' || *p == '}') { |
303 |
if (var) { |
303 |
if (var) { |
304 |
buf1[b1] = '\0'; |
304 |
buf1[b1] = '\0'; |
305 |
buf2[b2] = '\0'; |
305 |
buf2[b2] = '\0'; |
306 |
strcat(buf1, getenv(buf2)); |
306 |
strncat(buf1, getenv(buf2), sizeof(buf1)); |
307 |
b1 = strlen(buf1); |
307 |
b1 = strlen(buf1); |
308 |
buf2[0] = '\0'; |
308 |
buf2[0] = '\0'; |
309 |
b2 = 0; |
309 |
b2 = 0; |