diff options
| author | Reckordp <[email protected]> | 2020-03-08 10:53:18 +0700 |
|---|---|---|
| committer | Reckordp <[email protected]> | 2020-03-08 10:53:18 +0700 |
| commit | ab1465d9d5faed9d396a04d0fafcd70f1c72dd59 (patch) | |
| tree | 0abbbdf847bfab3c936b8360639e6cb852d83d32 /mrbgems/mruby-io/src/file.c | |
| parent | 66c44b856811dd29531b116e7f53e1881b1f829e (diff) | |
| download | mruby-ab1465d9d5faed9d396a04d0fafcd70f1c72dd59.tar.gz mruby-ab1465d9d5faed9d396a04d0fafcd70f1c72dd59.zip | |
Traditional, UNC, and Device Is Absolute?
Diffstat (limited to 'mrbgems/mruby-io/src/file.c')
| -rw-r--r-- | mrbgems/mruby-io/src/file.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c index 25b1dd6e1..d3da5daaf 100644 --- a/mrbgems/mruby-io/src/file.c +++ b/mrbgems/mruby-io/src/file.c @@ -281,52 +281,56 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass) } #ifdef _WIN32 -#define IS_FILESEP(x) (x == FILE_SEPARATOR || x == FILE_ALT_SEPARATOR) -#define IS_VOLSEP(x) (x == VOLUME_SEPARATOR) +#define IS_FILESEP(x) (x == (*(char*)(FILE_SEPARATOR)) || x == (*(char*)(FILE_ALT_SEPARATOR))) +#define IS_VOLSEP(x) (x == (*(char*)(VOLUME_SEPARATOR))) #define IS_DEVICEID(x) (x == '.' || x == '?') +#define CHECK_UNCDEV_PATH (IS_FILESEP(path[0]) && IS_FILESEP(path[1])) static int is_absolute_traditional_path(const char *path, int len) { if (len < 3) return 0; - if (IS_FILESEP(path[0])) return 1; return (ISALPHA(path[0]) && IS_VOLSEP(path[1]) && IS_FILESEP(path[2])); } static int is_aboslute_unc_path(const char *path, int len) { if (len < 2) return 0; - return (IS_FILESEP(path[0]) && IS_FILESEP(path[1])); + return (CHECK_UNCDEV_PATH && !IS_DEVICEID(path[2])); } static int is_absolute_device_path(const char *path, int len) { if (len < 4) return 0; - return (is_aboslute_unc_path(path, len) && IS_DEVICEID(path[2]) && IS_FILESEP(path[3])); + return (CHECK_UNCDEV_PATH && IS_DEVICEID(path[2]) && IS_FILESEP(path[3])); } static int mrb_file_is_absolute_path(const char *path, int len) { - return ( - is_absolute_traditional_path(path, len) || - is_aboslute_unc_path(path, len) || - is_absolute_device_path(path, len) - ); + if (IS_FILESEP(path[0])) return 1; + if (len > 0) + return ( + is_absolute_traditional_path(path, len) || + is_aboslute_unc_path(path, len) || + is_absolute_device_path(path, len) + ); + else + return 0; +} #undef IS_FILESEP #undef IS_VOLSEP #undef IS_DEVICEID +#undef CHECK_UNCDEV_PATH #else static int mrb_file_is_absolute_path(const char *path) { -#define IS_FILESEP(x) (x == FILE_SEPARATOR) - return IS_FILESEP(path[0]); -#undef IS_FILESEP -#endif + return (path[0] == *(char*)(FILE_SEPARATOR)); } +#endif static mrb_value mrb_file__gethome(mrb_state *mrb, mrb_value klass) |
