Back to index

wims  3.65+svn20090927
Enumerations | Functions
files.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  {
  is_file, is_dir, is_exec, is_fifo,
  is_socket, is_unknown
}

Functions

int ftest (char *fname)
void readfile (char *fname, char buf[], long int buflen)
unsigned int datafile_recordnum (char *p)
char * datafile_fnd_record (char *p, int n, char bf[])

Enumeration Type Documentation

anonymous enum
Enumerator:
is_file 
is_dir 
is_exec 
is_fifo 
is_socket 
is_unknown 

Definition at line 20 of file files.c.


Function Documentation

char* datafile_fnd_record ( char *  p,
int  n,
char  bf[] 
)

Definition at line 67 of file files.c.

{
    char *pp, *p2, buf[MAX_FILELEN+1];
    int i;

    bf[0]=0;
    if(n<0) return bf;
    readfile(p,buf,sizeof(buf));
    if(buf[0]!=tag_string[1]) i=0; else i=1;
    if(i<n) {
       for(i++, pp=strstr(buf,tag_string);
           i<n && pp!=NULL;
           i++, pp=strstr(pp+1,tag_string));
    }
    else {
       if(i>n) goto end;
       pp=buf-1;
    }
    if(pp==NULL) { /* n too big */
       goto end;
    }
    if(n>0) pp+=strlen(tag_string); else pp=buf;
    p2=strstr(pp,tag_string); if(p2) *p2=0;
    mystrncpy(bf,pp,MAX_LINELEN);
    end: return bf;
}

Here is the call graph for this function:

unsigned int datafile_recordnum ( char *  p)

Definition at line 55 of file files.c.

{
    char *pp, buf[MAX_FILELEN+1];
    int i;

    readfile(p,buf,sizeof(buf));
    if(buf[0]!=tag_string[1]) i=0; else i=1;
    for(pp=strstr(buf,tag_string); pp!=NULL; i++, pp=strstr(pp+1,tag_string)); 
    return i;
}

Here is the call graph for this function:

int ftest ( char *  fname)

Definition at line 24 of file files.c.

{
    if(strstr(fname,"..")!=NULL) return -1; /* parent directory not allowed */
    if(stat(fname,&ftst)) return -1;
    if(S_ISREG(ftst.st_mode)) {
       if((ftst.st_mode&(S_IXUSR|S_IXGRP|S_IXOTH))!=0) return is_exec;
       else return is_file;
    }
    if(S_ISDIR(ftst.st_mode)) return is_dir;
    if(S_ISFIFO(ftst.st_mode)) return is_fifo;
    if(S_ISSOCK(ftst.st_mode)) return is_socket;
    return is_unknown;
}
void readfile ( char *  fname,
char  buf[],
long int  buflen 
)

Definition at line 39 of file files.c.

{
    int fd, t, st;
    long int l, lc;
    t=0; buf[0]=0;
    st=ftest(fname); if(st!=is_file) return;
    l=ftst.st_size; if(l<=0) return;
    if(l>=buflen) l=buflen-1;      /* silent trancation */
    fd=open(fname,O_RDONLY); if(fd==-1) return;
    lc=read(fd,buf,l); close(fd);
    if(lc!=l) {buf[0]=0; return;}
    buf[lc]=0; _tolinux(buf); return;
}

Here is the call graph for this function: