blob: 532e14ce5d17207480e01e79913b415fe7645671 (
plain)
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
35
36
37
38
39
40
41
42
43
44
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
/* only check this many filenames */
#define MAX_FNAMES 1024
/* FILENAME.EXT\0 = 13 */
#define FNAME_LEN 13
// #define DUPNAME_DEBUG
static char filenames[MAX_FNAMES][FNAME_LEN];
static int fncount;
/* linear search, slow, but only happens once at startup */
int is_dup_filename(const char *newname) {
int i;
for(i = 0; i < fncount; i++)
if(strncmp(newname, filenames[i], FNAME_LEN - 1) == 0)
return 1;
strncpy(filenames[fncount++], newname, FNAME_LEN - 1);
return 0;
}
#ifdef DUPNAME_DEBUG
int main(int argc, char **argv) {
int i;
while(++argv, --argc)
printf("%s: %d\n", *argv, is_dup_filename(*argv));
printf("filenames[]\n");
for(i = 0; i < fncount; i++)
printf(" %s\n", filenames[i]);
return 0;
}
#endif
|