|
|
| version 1.12, 2004/07/08 14:21:50 | version 1.19, 2011/01/15 18:55:47 |
|---|---|
| Line 1 | Line 1 |
| /* $Id$ */ | |
| #include "compiler.h" | #include "compiler.h" |
| #include <sys/stat.h> | #include <sys/stat.h> |
| Line 9 | Line 7 |
| #include "dosio.h" | #include "dosio.h" |
| static char curpath[MAX_PATH]; | static OEMCHAR curpath[MAX_PATH]; |
| static char *curfilep = curpath; | static OEMCHAR *curfilep = curpath; |
| #define ISKANJI(c) ((((c) - 0xa1) & 0xff) < 0x5c) | #define ISKANJI(c) ((((c) - 0xa1) & 0xff) < 0x5c) |
| Line 29 dosio_term(void) | Line 27 dosio_term(void) |
| /* nothing to do */ | /* nothing to do */ |
| } | } |
| /* ファイル操作 */ | /* ファイル操作 */ |
| FILEH | FILEH |
| file_open(const char *path) | file_open(const OEMCHAR *path) |
| { | { |
| FILEH fh; | FILEH fh; |
| Line 42 file_open(const char *path) | Line 40 file_open(const char *path) |
| } | } |
| FILEH | FILEH |
| file_open_rb(const char *path) | file_open_rb(const OEMCHAR *path) |
| { | { |
| return fopen(path, "rb"); | return fopen(path, "rb"); |
| } | } |
| FILEH | FILEH |
| file_create(const char *path) | file_create(const OEMCHAR *path) |
| { | { |
| return fopen(path, "wb+"); | return fopen(path, "wb+"); |
| Line 96 file_getsize(FILEH handle) | Line 94 file_getsize(FILEH handle) |
| } | } |
| short | short |
| file_attr(const char *path) | file_attr(const OEMCHAR *path) |
| { | { |
| struct stat sb; | struct stat sb; |
| short attr; | short attr; |
| Line 148 file_getdatetime(FILEH handle, DOSDATE * | Line 146 file_getdatetime(FILEH handle, DOSDATE * |
| } | } |
| short | short |
| file_delete(const char *path) | file_delete(const OEMCHAR *path) |
| { | { |
| return (short)unlink(path); | return (short)unlink(path); |
| } | } |
| short | short |
| file_dircreate(const char *path) | file_dircreate(const OEMCHAR *path) |
| { | { |
| return (short)mkdir(path, 0777); | return (short)mkdir(path, 0777); |
| } | } |
| /* カレントファイル操作 */ | /* カレントファイル操作 */ |
| void | void |
| file_setcd(const char *exepath) | file_setcd(const OEMCHAR *exepath) |
| { | { |
| milstr_ncpy(curpath, exepath, sizeof(curpath)); | milstr_ncpy(curpath, exepath, sizeof(curpath)); |
| Line 173 file_setcd(const char *exepath) | Line 171 file_setcd(const char *exepath) |
| } | } |
| char * | char * |
| file_getcd(const char *filename) | file_getcd(const OEMCHAR *filename) |
| { | { |
| *curfilep = '\0'; | *curfilep = '\0'; |
| Line 182 file_getcd(const char *filename) | Line 180 file_getcd(const char *filename) |
| } | } |
| FILEH | FILEH |
| file_open_c(const char *filename) | file_open_c(const OEMCHAR *filename) |
| { | { |
| *curfilep = '\0'; | *curfilep = '\0'; |
| Line 191 file_open_c(const char *filename) | Line 189 file_open_c(const char *filename) |
| } | } |
| FILEH | FILEH |
| file_open_rb_c(const char *filename) | file_open_rb_c(const OEMCHAR *filename) |
| { | { |
| *curfilep = '\0'; | *curfilep = '\0'; |
| Line 200 file_open_rb_c(const char *filename) | Line 198 file_open_rb_c(const char *filename) |
| } | } |
| FILEH | FILEH |
| file_create_c(const char *filename) | file_create_c(const OEMCHAR *filename) |
| { | { |
| *curfilep = '\0'; | *curfilep = '\0'; |
| Line 209 file_create_c(const char *filename) | Line 207 file_create_c(const char *filename) |
| } | } |
| short | short |
| file_delete_c(const char *filename) | file_delete_c(const OEMCHAR *filename) |
| { | { |
| *curfilep = '\0'; | *curfilep = '\0'; |
| Line 218 file_delete_c(const char *filename) | Line 216 file_delete_c(const char *filename) |
| } | } |
| short | short |
| file_attr_c(const char *filename) | file_attr_c(const OEMCHAR *filename) |
| { | { |
| *curfilep = '\0'; | *curfilep = '\0'; |
| file_catname(curpath, filename, sizeof(curpath)); | file_catname(curpath, filename, sizeof(curpath)); |
| return file_attr_c(curpath); | return file_attr(curpath); |
| } | } |
| FLISTH | FLISTH |
| file_list1st(const char *dir, FLINFO *fli) | file_list1st(const OEMCHAR *dir, FLINFO *fli) |
| { | { |
| FLISTH ret; | FLISTH ret; |
| Line 258 file_list1st(const char *dir, FLINFO *fl | Line 256 file_list1st(const char *dir, FLINFO *fl |
| BOOL | BOOL |
| file_listnext(FLISTH hdl, FLINFO *fli) | file_listnext(FLISTH hdl, FLINFO *fli) |
| { | { |
| char buf[MAX_PATH]; | OEMCHAR buf[MAX_PATH]; |
| struct dirent *de; | struct dirent *de; |
| struct stat sb; | struct stat sb; |
| Line 301 file_listclose(FLISTH hdl) | Line 299 file_listclose(FLISTH hdl) |
| } | } |
| static int | static int |
| euckanji1st(const char *str, int pos) | euckanji1st(const OEMCHAR *str, int pos) |
| { | { |
| int ret; | int ret; |
| int c; | int c; |
| Line 315 euckanji1st(const char *str, int pos) | Line 313 euckanji1st(const char *str, int pos) |
| } | } |
| void | void |
| file_cpyname(char *dst, const char *src, int maxlen) | file_cpyname(OEMCHAR *dst, const OEMCHAR *src, int maxlen) |
| { | { |
| int i; | int i; |
| Line 333 file_cpyname(char *dst, const char *src, | Line 331 file_cpyname(char *dst, const char *src, |
| } | } |
| void | void |
| file_catname(char *path, const char *filename, int maxlen) | file_catname(OEMCHAR *path, const OEMCHAR *filename, int maxlen) |
| { | { |
| for (; maxlen > 0; path++, maxlen--) { | for (; maxlen > 0; path++, maxlen--) { |
| Line 352 file_catname(char *path, const char *fil | Line 350 file_catname(char *path, const char *fil |
| } else if (((*path - 0x41) & 0xff) < 26) { | } else if (((*path - 0x41) & 0xff) < 26) { |
| *path |= 0x20; | *path |= 0x20; |
| } else if (*path == '\\') { | } else if (*path == '\\') { |
| *path = '/'; | *path = G_DIR_SEPARATOR; |
| } | } |
| } | } |
| } | } |
| } | } |
| BOOL | BOOL |
| file_cmpname(const char *path, const char *path2) | file_cmpname(const OEMCHAR *path, const OEMCHAR *path2) |
| { | { |
| return strcmp(path, path2); | return strcasecmp(path, path2); |
| } | } |
| char * | OEMCHAR * |
| file_getname(char *path) | file_getname(const OEMCHAR *path) |
| { | { |
| char *ret; | const OEMCHAR *ret; |
| for (ret = path; *path != '\0'; path++) { | for (ret = path; *path != '\0'; path++) { |
| if (ISKANJI(*path)) { | if (ISKANJI(*path)) { |
| Line 376 file_getname(char *path) | Line 374 file_getname(char *path) |
| if (*path == '\0') { | if (*path == '\0') { |
| break; | break; |
| } | } |
| } else if (*path == '/') { | } else if (*path == G_DIR_SEPARATOR) { |
| ret = path + 1; | ret = path + 1; |
| } | } |
| } | } |
| return ret; | return (OEMCHAR *)ret; |
| } | } |
| void | void |
| file_cutname(char *path) | file_cutname(OEMCHAR *path) |
| { | { |
| char *p; | OEMCHAR *p; |
| p = file_getname(path); | p = file_getname(path); |
| *p = '\0'; | *p = '\0'; |
| } | } |
| char * | OEMCHAR * |
| file_getext(char *path) | file_getext(const OEMCHAR *path) |
| { | { |
| char *p, *q; | const OEMCHAR *p, *q; |
| for (p = file_getname(path), q = NULL; *p != '\0'; p++) { | for (p = file_getname(path), q = NULL; *p != '\0'; p++) { |
| if (*p == '.') { | if (*p == '.') { |
| Line 405 file_getext(char *path) | Line 403 file_getext(char *path) |
| if (q == NULL) { | if (q == NULL) { |
| q = p; | q = p; |
| } | } |
| return q; | return (char *)q; |
| } | } |
| void | void |
| file_cutext(char *path) | file_cutext(OEMCHAR *path) |
| { | { |
| char *p, *q; | OEMCHAR *p, *q; |
| for (p = file_getname(path), q = NULL; *p != '\0'; p++) { | for (p = file_getname(path), q = NULL; *p != '\0'; p++) { |
| if (*p == '.') { | if (*p == '.') { |
| Line 424 file_cutext(char *path) | Line 422 file_cutext(char *path) |
| } | } |
| void | void |
| file_cutseparator(char *path) | file_cutseparator(OEMCHAR *path) |
| { | { |
| int pos; | int pos; |
| pos = strlen(path) - 1; | pos = strlen(path) - 1; |
| if ((pos > 0) && (path[pos] == '/')) { | if ((pos > 0) && (path[pos] == G_DIR_SEPARATOR)) { |
| path[pos] = '\0'; | path[pos] = '\0'; |
| } | } |
| } | } |
| void | void |
| file_setseparator(char *path, int maxlen) | file_setseparator(OEMCHAR *path, int maxlen) |
| { | { |
| int pos; | int pos; |
| pos = strlen(path); | pos = strlen(path); |
| if ((pos) && (path[pos-1] != '/') && ((pos + 2) < maxlen)) { | if ((pos) && (path[pos-1] != G_DIR_SEPARATOR) && ((pos + 2) < maxlen)) { |
| path[pos++] = '/'; | path[pos++] = G_DIR_SEPARATOR; |
| path[pos] = '\0'; | path[pos] = '\0'; |
| } | } |
| } | } |