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
23afaf02
Commit
23afaf02
authored
Dec 10, 2013
by
Paolo Bosetti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made compatible with VisualStudio
parent
5a59fd3a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
29 deletions
+90
-29
include/mruby/ext/io.h
include/mruby/ext/io.h
+7
-7
mrbgem.rake
mrbgem.rake
+8
-0
src/file.c
src/file.c
+55
-15
src/file_test.c
src/file_test.c
+10
-7
src/io.c
src/io.c
+10
-0
No files found.
include/mruby/ext/io.h
View file @
23afaf02
...
...
@@ -11,15 +11,15 @@ extern "C" {
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#if !defined(_WIN32) || !defined(__MINGW32__)
#include <sys/wait.h>
#else
#if defined(_WIN32) || defined(_WIN64)
#include <winsock.h>
#else
#include <unistd.h>
#include <sys/wait.h>
#endif
#include <stdio.h>
#include <string.h>
...
...
mrbgem.rake
View file @
23afaf02
...
...
@@ -3,4 +3,12 @@ MRuby::Gem::Specification.new('mruby-io') do |spec|
spec
.
authors
=
'Internet Initiative Japan Inc.'
spec
.
cc
.
include_paths
<<
"
#{
build
.
root
}
/src"
case
RUBY_PLATFORM
when
/mingw|mswin/
spec
.
linker
.
libraries
+=
[
'Ws2_32'
]
#spec.cc.include_paths += ["C:/Windows/system/include"]
spec
.
linker
.
library_paths
+=
[
"C:/Windows/system"
]
end
end
src/file.c
View file @
23afaf02
...
...
@@ -10,15 +10,26 @@
#include "mruby/string.h"
#include "error.h"
#include <sys/file.h>
#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#ifndef _WIN32
#include <pwd.h>
#if defined(_WIN32) || defined(_WIN64)
#define UNLINK _unlink
#define GETCWD _getcwd
#define CHMOD(a, b) 0
#define MAXPATHLEN 1024
#define PATH_MAX MAX_PATH
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#include <direct.h>
#else
#define UNLINK unlink
#define GETCWD getcwd
#define CHMOD(a, b) chmod(a,b)
#include <sys/file.h>
#include <libgen.h>
#include <sys/param.h>
#include <pwd.h>
#endif
#define FILE_SEPARATOR "/"
...
...
@@ -44,16 +55,21 @@ extern mrb_value mrb_io_fileno(mrb_state *mrb, mrb_value io);
mrb_value
mrb_file_s_umask
(
mrb_state
*
mrb
,
mrb_value
klass
)
{
int
omask
=
0
;
#if defined(_WIN32) || defined(_WIN64)
/* nothing to do on windows */
#else
mrb_value
*
argv
;
int
argc
;
mrb_value
mask
;
mrb_get_args
(
mrb
,
"*"
,
&
argv
,
&
argc
);
int
omask
=
0
;
if
(
argc
==
0
)
{
omask
=
umask
(
0
);
umask
(
omask
);
}
else
if
(
argc
==
1
)
{
m
rb_value
m
ask
=
argv
[
0
];
mask
=
argv
[
0
];
if
(
!
mrb_nil_p
(
mask
)
&&
!
mrb_fixnum_p
(
mask
))
{
mask
=
mrb_check_convert_type
(
mrb
,
mask
,
MRB_TT_FIXNUM
,
"Fixnum"
,
"to_int"
);
}
...
...
@@ -64,6 +80,7 @@ mrb_file_s_umask(mrb_state *mrb, mrb_value klass)
}
else
{
mrb_raisef
(
mrb
,
E_ARGUMENT_ERROR
,
"wrong number of arguments (%d for 0..1)"
,
argc
);
}
#endif
return
mrb_fixnum_value
(
omask
);
}
...
...
@@ -72,15 +89,17 @@ mrb_file_s_unlink(mrb_state *mrb, mrb_value obj)
{
mrb_value
*
argv
;
int
n
,
i
,
argc
;
const
char
*
path
;
mrb_value
pathv
;
mrb_get_args
(
mrb
,
"*"
,
&
argv
,
&
argc
);
for
(
i
=
0
,
n
=
0
;
i
<
argc
;
i
++
)
{
mrb_value
pathv
=
argv
[
i
];
pathv
=
argv
[
i
];
if
(
mrb_type
(
pathv
)
!=
MRB_TT_STRING
)
{
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"can't convert %s into String"
,
mrb_obj_classname
(
mrb
,
pathv
));
}
const
char
*
path
=
mrb_string_value_cstr
(
mrb
,
&
pathv
);;
if
(
unlink
(
path
)
<
0
)
{
path
=
mrb_string_value_cstr
(
mrb
,
&
pathv
);;
if
(
UNLINK
(
path
)
<
0
)
{
mrb_sys_fail
(
mrb
,
path
);
}
else
{
n
++
;
...
...
@@ -97,8 +116,8 @@ mrb_file_rename_internal(mrb_state *mrb, mrb_value from, mrb_value to)
dst
=
mrb_string_value_cstr
(
mrb
,
&
to
);
if
(
rename
(
src
,
dst
)
<
0
)
{
if
(
chmod
(
dst
,
0666
)
==
0
&&
unlink
(
dst
)
==
0
&&
if
(
CHMOD
(
dst
,
0666
)
==
0
&&
UNLINK
(
dst
)
==
0
&&
rename
(
src
,
dst
)
==
0
)
return
mrb_fixnum_value
(
0
);
mrb_sys_fail
(
mrb
,
"mrb_file_rename_internal failed."
);
...
...
@@ -134,29 +153,50 @@ mrb_file_s_rename(mrb_state *mrb, mrb_value obj)
static
mrb_value
mrb_file_dirname
(
mrb_state
*
mrb
,
mrb_value
klass
)
{
#if defined(_WIN32) || defined(_WIN64)
char
dname
[
_MAX_DIR
];
char
*
path
;
mrb_value
s
;
mrb_get_args
(
mrb
,
"S"
,
&
s
);
path
=
mrb_str_to_cstr
(
mrb
,
s
);
_splitpath
((
const
char
*
)
path
,
NULL
,
dname
,
NULL
,
NULL
);
#else
char
*
dname
,
*
path
;
mrb_value
s
;
mrb_get_args
(
mrb
,
"S"
,
&
s
);
path
=
mrb_str_to_cstr
(
mrb
,
s
);
if
((
dname
=
dirname
(
path
))
==
NULL
)
{
mrb_sys_fail
(
mrb
,
"dirname"
);
}
#endif
return
mrb_str_new_cstr
(
mrb
,
dname
);
}
static
mrb_value
mrb_file_basename
(
mrb_state
*
mrb
,
mrb_value
klass
)
{
#if defined(_WIN32) || defined(_WIN64)
char
bname
[
_MAX_DIR
];
char
extname
[
_MAX_EXT
];
char
*
path
;
char
buffer
[
_MAX_DIR
+
_MAX_EXT
];
mrb_value
s
;
mrb_get_args
(
mrb
,
"S"
,
&
s
);
path
=
mrb_str_to_cstr
(
mrb
,
s
);
_splitpath
((
const
char
*
)
path
,
NULL
,
NULL
,
bname
,
extname
);
sprintf_s
(
buffer
,
_MAX_DIR
+
_MAX_EXT
,
"%s%s"
,
bname
,
extname
);
return
mrb_str_new_cstr
(
mrb
,
buffer
);
#else
char
*
bname
,
*
path
;
mrb_value
s
;
mrb_get_args
(
mrb
,
"S"
,
&
s
);
path
=
mrb_str_to_cstr
(
mrb
,
s
);
if
((
bname
=
basename
(
path
))
==
NULL
)
{
mrb_sys_fail
(
mrb
,
"basename"
);
}
return
mrb_str_new_cstr
(
mrb
,
bname
);
#endif
}
static
mrb_value
...
...
@@ -215,7 +255,7 @@ mrb_file__getwd(mrb_state *mrb, mrb_value klass)
mrb_value
path
;
path
=
mrb_str_buf_new
(
mrb
,
MAXPATHLEN
);
if
(
getcwd
(
RSTRING_PTR
(
path
),
MAXPATHLEN
)
==
NULL
)
{
if
(
GETCWD
(
RSTRING_PTR
(
path
),
MAXPATHLEN
)
==
NULL
)
{
mrb_sys_fail
(
mrb
,
"getcwd(2)"
);
}
mrb_str_resize
(
mrb
,
path
,
strlen
(
RSTRING_PTR
(
path
)));
...
...
src/file_test.c
View file @
23afaf02
...
...
@@ -10,15 +10,18 @@
#include "mruby/string.h"
#include "error.h"
#include <sys/file.h>
#include <libgen.h>
#if defined(_WIN32) || defined(_WIN64)
#define LSTAT stat
#else
#define LSTAT lstat
#include <sys/file.h>
#include <libgen.h>
#include <pwd.h>
#include <sys/param.h>
#endif
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#ifndef _WIN32
#include <pwd.h>
#endif
extern
struct
mrb_data_type
mrb_io_type
;
...
...
@@ -47,7 +50,7 @@ mrb_stat0(mrb_state *mrb, mrb_value obj, struct stat *st, int do_lstat)
tmp
=
mrb_funcall
(
mrb
,
obj
,
"is_a?"
,
1
,
str_klass
);
if
(
mrb_test
(
tmp
))
{
if
(
do_lstat
)
{
return
lstat
(
mrb_str_to_cstr
(
mrb
,
obj
),
st
);
return
LSTAT
(
mrb_str_to_cstr
(
mrb
,
obj
),
st
);
}
else
{
return
stat
(
mrb_str_to_cstr
(
mrb
,
obj
),
st
);
}
...
...
src/io.c
View file @
23afaf02
...
...
@@ -14,6 +14,16 @@
#include "mruby/ext/io.h"
#include "error.h"
#if defined(_WIN32) || defined(_WIN64)
#include <io.h>
#define open _open
#define close _close
#define read _read
#define write _write
#define lseek _lseek
#else
#endif
static
int
mrb_io_modestr_to_flags
(
mrb_state
*
mrb
,
const
char
*
modestr
);
static
int
mrb_io_modenum_to_flags
(
mrb_state
*
mrb
,
int
modenum
);
static
int
mrb_io_flags_to_modenum
(
mrb_state
*
mrb
,
int
flags
);
...
...
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