home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl_DR-0.10.tar.gz / enl_DR-0.10.tar / enl / file.c < prev    next >
C/C++ Source or Header  |  1997-06-19  |  1KB  |  101 lines

  1. #include "enlightenment.h"
  2.  
  3. void md(char *s)
  4. {
  5.    mkdir(s,S_IRWXU);
  6. }
  7.  
  8. int exists(char *s)
  9. {
  10.    struct stat st;
  11.    
  12.    if (stat(s,&st)==-1) return 0;
  13.    return 1;
  14. }
  15.  
  16. int isfile(char *s)
  17. {
  18.    struct stat st;
  19.    
  20.    if (stat(s,&st)==-1) return 0;
  21.    if (S_ISREG(st.st_mode)) return 1;
  22.    return 0;
  23. }
  24.  
  25. int isdir(char *s)
  26. {
  27.    struct stat st;
  28.    
  29.    if (stat(s,&st)==-1) return 0;
  30.    if (S_ISDIR(st.st_mode)) return 1;
  31.    return 0;
  32. }
  33.  
  34. char **ls(char *d, int *num)
  35. {
  36.    struct dirent **dir;
  37.    int n;
  38.    char **l;
  39.    int i;
  40.    
  41.    n=scandir(d,&dir,0,alphasort);
  42.    if (n<0) 
  43.      {
  44.     *num=0;
  45.     return NULL;
  46.      }
  47.    else
  48.      {
  49.     l=malloc(sizeof(char *)*n);
  50.     for (i=0;i<n;i++)
  51.       {
  52.          l[i]=malloc(strlen(dir[i]->d_name)+1);
  53.          strcpy(l[i],dir[i]->d_name);
  54.       }
  55.      }
  56.    return l;
  57. }
  58.  
  59. void rmls(char **l, int num)
  60. {
  61.    while(num--) free(l[num]);
  62.    free(l);
  63. }
  64.  
  65. void rm(char *s)
  66. {
  67.    unlink(s);
  68. }
  69.  
  70. void mv(char *s, char *ss)
  71. {
  72.    rename(s,ss);
  73. }
  74.  
  75. time_t moddate(char *s)
  76. {
  77.    struct stat st;
  78.    
  79.    if (!stat(s,&st)) return 0;
  80.    if (st.st_mtime>st.st_ctime) return st.st_mtime;
  81.    else return st.st_ctime;
  82. }
  83.  
  84. int filesize(char *s)
  85. {
  86.    struct stat st;
  87.    
  88.    if (!stat(s,&st)) return 0;
  89.    return (int)st.st_size;
  90. }
  91.  
  92. void cd(char *s)
  93. {
  94.    chdir(s);
  95. }
  96.  
  97. char *cwd(void)
  98. {
  99.    return getcwd(NULL,-1);
  100. }
  101.