Diff for /np2/x11/dosio.c between versions 1.3 and 1.10

version 1.3, 2003/11/17 13:17:16 version 1.10, 2004/02/06 16:51:21
Line 1 Line 1
   /*      $Id$    */
   
 #include "compiler.h"  #include "compiler.h"
   
 #include <sys/stat.h>  
 #include <time.h>  #include <time.h>
   
 #include "codecnv.h"  #include "codecnv.h"
Line 31  dosio_term(void) Line 32  dosio_term(void)
 FILEH  FILEH
 file_open(const char *path)  file_open(const char *path)
 {  {
           FILEH fh;
   
         return fopen(path, "rb+");          fh = fopen(path, "rb+");
           if (fh)
                   return fh;
           return fopen(path, "rb");
 }  }
   
 FILEH  FILEH
 file_open_rb(const char *path)  file_open_rb(const char *path)
 {  {
   
         return fopen(path, "rb+");          return fopen(path, "rb");
 }  }
   
 FILEH  FILEH
Line 108  file_attr(const char *path) Line 113  file_attr(const char *path)
         return -1;          return -1;
 }  }
   
 short  static BOOL
 file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime)  cnvdatetime(struct stat *sb, DOSDATE *dosdate, DOSTIME *dostime)
 {  {
         struct stat sb;  
         struct tm *ftime;          struct tm *ftime;
   
         if (fstat(fileno(handle), &sb) == 0) {          ftime = localtime(&sb->st_mtime);
                 ftime = localtime(&sb.st_mtime);          if (ftime) {
                 if (ftime) {                  if (dosdate) {
                         if (dosdate) {                          dosdate->year = ftime->tm_year + 1900;
                                 dosdate->year = ftime->tm_year + 1900;                          dosdate->month = ftime->tm_mon + 1;
                                 dosdate->month = ftime->tm_mon + 1;                          dosdate->day = ftime->tm_mday;
                                 dosdate->day = ftime->tm_mday;  
                         }  
                         if (dostime) {  
                                 dostime->hour = ftime->tm_hour;  
                                 dostime->minute = ftime->tm_min;  
                                 dostime->second = ftime->tm_sec;  
                         }  
                         return 0;  
                 }                  }
                   if (dostime) {
                           dostime->hour = ftime->tm_hour;
                           dostime->minute = ftime->tm_min;
                           dostime->second = ftime->tm_sec;
                   }
                   return SUCCESS;
         }          }
           return FAILURE;
   }
   
   short
   file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime)
   {
           struct stat sb;
   
           if ((fstat(fileno(handle), &sb) == 0)
            && (cnvdatetime(&sb, dosdate, dostime)))
                   return 0;
         return -1;          return -1;
 }  }
   
Line 212  file_attr_c(const char *sjis) Line 225  file_attr_c(const char *sjis)
         return file_attr_c(curpath);          return file_attr_c(curpath);
 }  }
   
   FLISTH
   file_list1st(const char *dir, FLINFO *fli)
   {
           FLISTH ret;
   
           ret = (FLISTH)malloc(sizeof(_FLISTH));
           if (ret == NULL) {
                   VERBOSE(("file_list1st: couldn't alloc memory (size = %d)", sizeof(_FLISTH)));
                   return FLISTH_INVALID;
           }
   
           mileuc_ncpy(ret->path, dir, sizeof(ret->path));
           file_setseparator(ret->path, sizeof(ret->path));
           ret->hdl = opendir(ret->path);
           VERBOSE(("file_list1st: opendir(%s)", ret->path));
           if (ret->hdl == NULL) {
                   VERBOSE(("file_list1st: opendir failure"));
                   free(ret);
                   return FLISTH_INVALID;
           }
           if (file_listnext((FLISTH)ret, fli) == SUCCESS) {
                   return (FLISTH)ret;
           }
           VERBOSE(("file_list1st: file_listnext failure"));
           closedir(ret->hdl);
           free(ret);
           return FLISTH_INVALID;
   }
   
   BOOL
   file_listnext(FLISTH hdl, FLINFO *fli)
   {
           char buf[MAX_PATH];
           struct dirent *de;
           struct stat sb;
   
           de = readdir(hdl->hdl);
           if (de == NULL) {
                   VERBOSE(("file_listnext: readdir failure"));
                   return FAILURE;
           }
   
           milstr_ncpy(buf, hdl->path, sizeof(buf));
           mileuc_ncat(buf, de->d_name, sizeof(buf));
           if (stat(buf, &sb) != 0) {
                   VERBOSE(("file_listnext: stat failure. (path = %s)", buf));
                   return FAILURE;
           }
   
           fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME;
           fli->size = sb.st_size;
           fli->attr = 0;
           if (S_ISDIR(sb.st_mode)) {
                   fli->attr |= FILEATTR_DIRECTORY;
           }
           if (!(sb.st_mode & S_IWUSR)) {
                   fli->attr |= FILEATTR_READONLY;
           }
           cnvdatetime(&sb, &fli->date, &fli->time);
           mileuc_ncpy(fli->path, de->d_name, sizeof(fli->path));
           VERBOSE(("file_listnext: success"));
           return SUCCESS;
   }
   
   void
   file_listclose(FLISTH hdl)
   {
   
           if (hdl) {
                   closedir(hdl->hdl);
                   free(hdl);
           }
   }
   
 static int  static int
 euckanji1st(const char *str, int pos)  euckanji1st(const char *str, int pos)
 {  {
Line 233  file_cpyname(char *dst, const char *src, Line 320  file_cpyname(char *dst, const char *src,
                 for (i = 0; i < maxlen && src[i] != '\0'; i++) {                  for (i = 0; i < maxlen && src[i] != '\0'; i++) {
                         dst[i] = src[i];                          dst[i] = src[i];
                 }                  }
                 if (i != 0) {                  if (i > 0) {
                         if (euckanji1st(src, i-1)) {                          if (euckanji1st(src, i-1)) {
                                 i--;                                  i--;
                         }                          }

Removed from v.1.3  
changed lines
  Added in v.1.10


RetroPC.NET-CVS <cvs@retropc.net>