Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
55f32026
Unverified
Commit
55f32026
authored
Mar 08, 2020
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Mar 08, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4952 from Reckordp/master
Traditional, UNC, and Drive Path
parents
4398bae5
a8d508c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
10 deletions
+51
-10
AUTHORS
AUTHORS
+3
-0
mrbgems/mruby-io/src/file.c
mrbgems/mruby-io/src/file.c
+48
-10
No files found.
AUTHORS
View file @
55f32026
...
@@ -42,3 +42,6 @@ of this list.
...
@@ -42,3 +42,6 @@ of this list.
Masahiro Wakame
Masahiro Wakame
YAMAMOTO Masaya
YAMAMOTO Masaya
KOBAYASHI Shuji
KOBAYASHI Shuji
RIZAL Reckordp
mrbgems/mruby-io/src/file.c
View file @
55f32026
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
#if defined(_WIN32) || defined(_WIN64)
#if defined(_WIN32) || defined(_WIN64)
#define PATH_SEPARATOR ";"
#define PATH_SEPARATOR ";"
#define FILE_ALT_SEPARATOR "\\"
#define FILE_ALT_SEPARATOR "\\"
#define VOLUME_SEPARATOR ":"
#else
#else
#define PATH_SEPARATOR ":"
#define PATH_SEPARATOR ":"
#endif
#endif
...
@@ -279,20 +280,57 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass)
...
@@ -279,20 +280,57 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass)
return
path
;
return
path
;
}
}
#ifdef _WIN32
#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
;
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
(
CHECK_UNCDEV_PATH
&&
!
IS_DEVICEID
(
path
[
2
]));
}
static
int
is_absolute_device_path
(
const
char
*
path
,
int
len
)
{
if
(
len
<
4
)
return
0
;
return
(
CHECK_UNCDEV_PATH
&&
IS_DEVICEID
(
path
[
2
])
&&
IS_FILESEP
(
path
[
3
]));
}
static
int
static
int
mrb_file_is_absolute_path
(
const
char
*
path
)
mrb_file_is_absolute_path
(
const
char
*
path
,
int
len
)
{
{
#ifdef _WIN32
if
(
IS_FILESEP
(
path
[
0
]))
return
1
;
#define IS_PATHSEP(x) (x == '/' || x == '\\')
if
(
len
>
0
)
if
(
ISALPHA
(
path
[
0
]))
return
(
return
(
strlen
(
path
)
>
2
&&
path
[
1
]
==
':'
&&
IS_PATHSEP
(
path
[
2
]));
is_absolute_traditional_path
(
path
,
len
)
||
is_aboslute_unc_path
(
path
,
len
)
||
is_absolute_device_path
(
path
,
len
)
);
else
else
return
(
IS_PATHSEP
(
path
[
0
])
&&
IS_PATHSEP
(
path
[
1
]));
return
0
;
#undef IS_PATHSEP
}
#undef IS_FILESEP
#undef IS_VOLSEP
#undef IS_DEVICEID
#undef CHECK_UNCDEV_PATH
#else
#else
return
(
path
[
0
]
==
'/'
);
static
int
#endif
mrb_file_is_absolute_path
(
const
char
*
path
)
{
return
(
path
[
0
]
==
*
(
char
*
)(
FILE_SEPARATOR
));
}
}
#endif
static
mrb_value
static
mrb_value
mrb_file__gethome
(
mrb_state
*
mrb
,
mrb_value
klass
)
mrb_file__gethome
(
mrb_state
*
mrb
,
mrb_value
klass
)
...
@@ -335,7 +373,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass)
...
@@ -335,7 +373,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass)
if
(
home
==
NULL
)
{
if
(
home
==
NULL
)
{
return
mrb_nil_value
();
return
mrb_nil_value
();
}
}
if
(
!
mrb_file_is_absolute_path
(
home
))
{
if
(
!
mrb_file_is_absolute_path
(
home
,
strlen
(
home
)
))
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"non-absolute home"
);
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"non-absolute home"
);
}
}
}
else
{
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment