Subversion Repositories wimsdev

Rev

Rev 8185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8185 Rev 8849
Line 24... Line 24...
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)) {
29
        if((ftst.st_mode&(S_IXUSR|S_IXGRP|S_IXOTH))!=0) return is_exec;
29
      if((ftst.st_mode&(S_IXUSR|S_IXGRP|S_IXOTH))!=0) return is_exec;
30
        else return is_file;
30
      else return is_file;
31
    }
31
    }
32
    if(S_ISDIR(ftst.st_mode)) return is_dir;
32
    if(S_ISDIR(ftst.st_mode)) return is_dir;
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;
Line 41... Line 41...
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;
44
    st=ftest(fname); if(st!=is_file) return;
44
    st=ftest(fname); if(st!=is_file) return;
45
    l=ftst.st_size; if(l<=0) return;
45
    l=ftst.st_size; if(l<=0) return;
46
    if(l>=buflen) l=buflen-1;   /* silent trancation */
46
    if(l>=buflen) l=buflen-1;      /* silent trancation */
47
    fd=open(fname,O_RDONLY); if(fd==-1) return;
47
    fd=open(fname,O_RDONLY); if(fd==-1) return;
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
}
Line 73... Line 73...
73
    bf[0]=0;
73
    bf[0]=0;
74
    if(n<0) return bf;
74
    if(n<0) return bf;
75
    readfile(p,buf,sizeof(buf));
75
    readfile(p,buf,sizeof(buf));
76
    if(buf[0]!=tag_string[1]) i=0; else i=1;
76
    if(buf[0]!=tag_string[1]) i=0; else i=1;
77
    if(i<n) {
77
    if(i<n) {
78
        for(i++, pp=strstr(buf,tag_string);
78
      for(i++, pp=strstr(buf,tag_string);
79
            i<n && pp!=NULL;
79
          i<n && pp!=NULL;
80
            i++, pp=strstr(pp+1,tag_string));
80
          i++, pp=strstr(pp+1,tag_string));
81
    }
81
    }
82
    else {
82
    else {
83
        if(i>n) goto end;
83
      if(i>n) goto end;
84
        pp=buf-1;
84
      pp=buf-1;
85
    }
85
    }
86
    if(pp==NULL) { /* n too big */
86
    if(pp==NULL) { /* n too big */
87
        goto end;
87
      goto end;
88
    }
88
    }
89
    if(n>0) pp+=strlen(tag_string); else pp=buf;
89
    if(n>0) pp+=strlen(tag_string); else pp=buf;
90
    p2=strstr(pp,tag_string); if(p2) *p2=0;
90
    p2=strstr(pp,tag_string); if(p2) *p2=0;
91
    mystrncpy(bf,pp,MAX_LINELEN);
91
    mystrncpy(bf,pp,MAX_LINELEN);
92
    end: return bf;
92
    end: return bf;