Rev 6790 | Rev 8185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6790 | Rev 8155 | ||
---|---|---|---|
Line 18... | Line 18... | ||
18 | /* File manipulation */ |
18 | /* File manipulation */ |
19 | 19 | ||
20 | enum{is_file, is_dir, is_exec, is_fifo, is_socket, is_unknown}; |
20 | enum{is_file, is_dir, is_exec, is_fifo, is_socket, is_unknown}; |
21 | struct stat ftst; |
21 | struct stat ftst; |
22 | 22 | ||
23 |
|
23 | /* A simple front-end of stat(). */ |
24 | int ftest(char *fname) |
24 | int ftest(char *fname) |
25 | { |
25 | { |
26 | if(strstr(fname,"..")!=NULL) return -1; /* parent directory not allowed */ |
26 | if(strstr(fname,"..")!=NULL) return -1; /* parent directory not allowed */ |
27 | if(stat(fname,&ftst)) return -1; |
27 | if(stat(fname,&ftst)) return -1; |
28 | if(S_ISREG(ftst.st_mode)) { |
28 | if(S_ISREG(ftst.st_mode)) { |
Line 33... | Line 33... | ||
33 | if(S_ISFIFO(ftst.st_mode)) return is_fifo; |
33 | if(S_ISFIFO(ftst.st_mode)) return is_fifo; |
34 | if(S_ISSOCK(ftst.st_mode)) return is_socket; |
34 | if(S_ISSOCK(ftst.st_mode)) return is_socket; |
35 | return is_unknown; |
35 | return is_unknown; |
36 | } |
36 | } |
37 | 37 | ||
38 |
|
38 | /* read the content of a file */ |
39 | void readfile(char *fname, char buf[], long int buflen) |
39 | void readfile(char *fname, char buf[], long int buflen) |
40 | { |
40 | { |
41 | int fd, st; |
41 | int fd, st; |
42 | long int l, lc; |
42 | long int l, lc; |
43 | buf[0]=0; |
43 | buf[0]=0; |
Line 48... | Line 48... | ||
48 | lc=read(fd,buf,l); close(fd); |
48 | lc=read(fd,buf,l); close(fd); |
49 | if(lc!=l) {buf[0]=0; return;} |
49 | if(lc!=l) {buf[0]=0; return;} |
50 | buf[lc]=0; _tolinux(buf); return; |
50 | buf[lc]=0; _tolinux(buf); return; |
51 | } |
51 | } |
52 | 52 | ||
53 |
|
53 | /* datafile structure: number of records. |
54 | |
54 | * tag=1 if direct access |
- | 55 | */ |
|
55 | unsigned int datafile_recordnum(char *p) |
56 | unsigned int datafile_recordnum(char *p) |
56 | { |
57 | { |
57 | char *pp, buf[MAX_FILELEN+1]; |
58 | char *pp, buf[MAX_FILELEN+1]; |
58 | int i; |
59 | int i; |
59 | 60 | ||
60 | readfile(p,buf,sizeof(buf)); |
61 | readfile(p,buf,sizeof(buf)); |
61 | if(buf[0]!=tag_string[1]) i=0; else i=1; |
62 | if(buf[0]!=tag_string[1]) i=0; else i=1; |
62 | for(pp=strstr(buf,tag_string); pp!=NULL; i++, pp=strstr(pp+1,tag_string)); |
63 | for(pp=strstr(buf,tag_string); pp!=NULL; i++, pp=strstr(pp+1,tag_string)); |
63 | return i; |
64 | return i; |
64 | } |
65 | } |
65 | 66 | ||
66 |
|
67 | /* datafile structure: find record n, starting from 1 */ |
67 | char *datafile_fnd_record(char *p, int n, char bf[]) |
68 | char *datafile_fnd_record(char *p, int n, char bf[]) |
68 | { |
69 | { |
69 | char *pp, *p2, buf[MAX_FILELEN+1]; |
70 | char *pp, *p2, buf[MAX_FILELEN+1]; |
70 | int i; |
71 | int i; |
71 | 72 |