|
|
| version 1.2, 2003/11/16 16:43:45 | version 1.6, 2003/12/19 16:08:01 |
|---|---|
| Line 2 | Line 2 |
| #include <sys/stat.h> | #include <sys/stat.h> |
| #include <time.h> | #include <time.h> |
| #if defined(WIN32) | #include <dirent.h> |
| #include <direct.h> | |
| #endif | |
| #include "codecnv.h" | #include "codecnv.h" |
| #include "dosio.h" | #include "dosio.h" |
| Line 34 dosio_term(void) | Line 32 dosio_term(void) |
| FILEH | FILEH |
| file_open(const char *path) | file_open(const char *path) |
| { | { |
| FILEH fh; | |
| fh = fopen(path, "rb+"); | |
| if (fh) | |
| return fh; | |
| return fopen(path, "rb"); | return fopen(path, "rb"); |
| } | } |
| Line 100 file_attr(const char *path) | Line 102 file_attr(const char *path) |
| if (stat(path, &sb) == 0) { | if (stat(path, &sb) == 0) { |
| if (S_ISDIR(sb.st_mode)) { | if (S_ISDIR(sb.st_mode)) { |
| return(FILEATTR_DIRECTORY); | return FILEATTR_DIRECTORY; |
| } | } |
| attr = 0; | attr = 0; |
| if (!(sb.st_mode & S_IWUSR)) { | if (!(sb.st_mode & S_IWUSR)) { |
| Line 215 file_attr_c(const char *sjis) | Line 217 file_attr_c(const char *sjis) |
| return file_attr_c(curpath); | 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); | |
| } | |
| #if 0 | |
| static int | static int |
| euckanji1st(const char *str, int pos) | euckanji1st(const char *str, int pos) |
| { | { |
| Line 228 euckanji1st(const char *str, int pos) | Line 282 euckanji1st(const char *str, int pos) |
| } | } |
| return ret; | return ret; |
| } | } |
| #endif | |
| void | |
| file_cpyname(char *dst, const char *src, int maxlen) | |
| { | |
| int i; | |
| if (maxlen--) { | |
| for (i = 0; i < maxlen && src[i] != '\0'; i++) { | |
| dst[i] = src[i]; | |
| } | |
| if (i > 0) { | |
| if (euckanji1st(src, i-1)) { | |
| i--; | |
| } | |
| } | |
| dst[i] = '\0'; | |
| } | |
| } | |
| void | void |
| file_catname(char *path, const char *sjis, int maxlen) | file_catname(char *path, const char *sjis, int maxlen) |
| Line 243 file_catname(char *path, const char *sji | Line 314 file_catname(char *path, const char *sji |
| } | } |
| if (maxlen) { | if (maxlen) { |
| codecnv_sjis2euc(path, maxlen, sjis, (UINT)-1); | codecnv_sjis2euc(path, maxlen, sjis, (UINT)-1); |
| for (;;) { | for (; path[0] != '\0'; path++) { |
| if (!ISKANJI(*path)) { | if (!ISKANJI(path[0])) { |
| if (*(path+1) == '\0') { | if (path[1] == '\0') { |
| break; | break; |
| } | } |
| path++; | path++; |
| } else if ((((*path) - 0x41) & 0xff) < 26) { | } else if ((((path[0]) - 0x41) & 0xff) < 26) { |
| *path |= 0x20; | path[0] |= 0x20; |
| } else if (*path == '\\') { | } else if (path[0] == '\\') { |
| *path = '/'; | path[0] = '/'; |
| } else if (*path == '\0') { | |
| break; | |
| } | } |
| path++; | |
| } | } |
| } | } |
| } | } |
| BOOL | |
| file_cmpname(const char *path, const char *sjis) | |
| { | |
| char euc[MAX_PATH]; | |
| codecnv_sjis2euc(euc, sizeof(euc), sjis, (UINT)-1); | |
| return strcmp(path, euc); | |
| } | |
| char * | char * |
| file_getname(char *path) | file_getname(char *path) |
| { | { |