--- np2/x11/dosio.c 2003/11/17 13:17:16 1.3 +++ np2/x11/dosio.c 2003/12/19 16:08:01 1.6 @@ -2,6 +2,7 @@ #include #include +#include #include "codecnv.h" #include "dosio.h" @@ -31,15 +32,19 @@ dosio_term(void) FILEH file_open(const char *path) { + FILEH fh; - return fopen(path, "rb+"); + fh = fopen(path, "rb+"); + if (fh) + return fh; + return fopen(path, "rb"); } FILEH file_open_rb(const char *path) { - return fopen(path, "rb+"); + return fopen(path, "rb"); } FILEH @@ -212,6 +217,60 @@ file_attr_c(const char *sjis) return file_attr_c(curpath); } +FILEFINDH +file_find1st(const char *dir, FILEFINDT *fft) +{ + DIR *ret; + + ret = opendir(dir); + if (ret == NULL) { + return FILEFINDH_INVALID; + } + if (file_findnext((FILEFINDH)ret, fft) == SUCCESS) { + return (FILEFINDH)ret; + } + closedir(ret); + return FILEFINDH_INVALID; +} + +BOOL +file_findnext(FILEFINDH hdl, FILEFINDT *fft) +{ + struct dirent *de; + struct stat sb; + UINT32 attr; + UINT32 size; + + de = readdir((DIR *)hdl); + if (de == NULL) { + return FAILURE; + } + if (fft) { + mileuc_ncpy(fft->path, de->d_name, sizeof(fft->path)); + size = 0; + attr = 0; + if (stat(de->d_name, &sb) == 0) { + size = sb.st_size; + if (S_ISDIR(sb.st_mode)) { + attr = FILEATTR_DIRECTORY; + } + else if (!(sb.st_mode & S_IWUSR)) { + attr = FILEATTR_READONLY; + } + } + fft->size = size; + fft->attr = attr; + } + return SUCCESS; +} + +void +file_findclose(FILEFINDH hdl) +{ + + closedir((DIR *)hdl); +} + static int euckanji1st(const char *str, int pos) { @@ -233,7 +292,7 @@ file_cpyname(char *dst, const char *src, for (i = 0; i < maxlen && src[i] != '\0'; i++) { dst[i] = src[i]; } - if (i != 0) { + if (i > 0) { if (euckanji1st(src, i-1)) { i--; }