* dir.c, file.c, io.c: use rb_sys_fail_path.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-02-24 07:37:48 +00:00
parent b8729f117c
commit 9acf2091e1
4 changed files with 30 additions and 23 deletions

View File

@ -1,3 +1,7 @@
Fri Feb 24 16:37:45 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* dir.c, file.c, io.c: use rb_sys_fail_path.
Fri Feb 24 15:49:07 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Feb 24 15:49:07 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (__builtin_unreachable): check for clang. * configure.in (__builtin_unreachable): check for clang.

12
dir.c
View File

@ -75,6 +75,8 @@ char *strchr(char*,char);
#define opendir(p) rb_w32_uopendir(p) #define opendir(p) rb_w32_uopendir(p)
#endif #endif
#define rb_sys_fail_path(path) rb_sys_fail(RSTRING_PTR(path))
#define FNM_NOESCAPE 0x01 #define FNM_NOESCAPE 0x01
#define FNM_PATHNAME 0x02 #define FNM_PATHNAME 0x02
#define FNM_DOTMATCH 0x04 #define FNM_DOTMATCH 0x04
@ -414,7 +416,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
dp->dir = opendir(RSTRING_PTR(dirname)); dp->dir = opendir(RSTRING_PTR(dirname));
} }
if (dp->dir == NULL) { if (dp->dir == NULL) {
rb_sys_fail(RSTRING_PTR(dirname)); rb_sys_fail_path(dirname);
} }
} }
dp->path = rb_str_dup_frozen(dirname); dp->path = rb_str_dup_frozen(dirname);
@ -750,7 +752,7 @@ static void
dir_chdir(VALUE path) dir_chdir(VALUE path)
{ {
if (chdir(RSTRING_PTR(path)) < 0) if (chdir(RSTRING_PTR(path)) < 0)
rb_sys_fail(RSTRING_PTR(path)); rb_sys_fail_path(path);
} }
static int chdir_blocking = 0; static int chdir_blocking = 0;
@ -927,7 +929,7 @@ dir_s_chroot(VALUE dir, VALUE path)
{ {
check_dirname(&path); check_dirname(&path);
if (chroot(RSTRING_PTR(path)) == -1) if (chroot(RSTRING_PTR(path)) == -1)
rb_sys_fail(RSTRING_PTR(path)); rb_sys_fail_path(path);
return INT2FIX(0); return INT2FIX(0);
} }
@ -965,7 +967,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
check_dirname(&path); check_dirname(&path);
if (mkdir(RSTRING_PTR(path), mode) == -1) if (mkdir(RSTRING_PTR(path), mode) == -1)
rb_sys_fail(RSTRING_PTR(path)); rb_sys_fail_path(path);
return INT2FIX(0); return INT2FIX(0);
} }
@ -984,7 +986,7 @@ dir_s_rmdir(VALUE obj, VALUE dir)
{ {
check_dirname(&dir); check_dirname(&dir);
if (rmdir(RSTRING_PTR(dir)) < 0) if (rmdir(RSTRING_PTR(dir)) < 0)
rb_sys_fail(RSTRING_PTR(dir)); rb_sys_fail_path(dir);
return INT2FIX(0); return INT2FIX(0);
} }

33
file.c
View File

@ -94,6 +94,8 @@ int flock(int, int);
#define STAT(p, s) stat((p), (s)) #define STAT(p, s) stat((p), (s))
#endif #endif
#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
#if defined(__BEOS__) || defined(__HAIKU__) /* should not change ID if -1 */ #if defined(__BEOS__) || defined(__HAIKU__) /* should not change ID if -1 */
static int static int
be_chown(const char *path, uid_t owner, gid_t group) be_chown(const char *path, uid_t owner, gid_t group)
@ -879,7 +881,7 @@ rb_file_s_stat(VALUE klass, VALUE fname)
rb_secure(4); rb_secure(4);
FilePathValue(fname); FilePathValue(fname);
if (rb_stat(fname, &st) < 0) { if (rb_stat(fname, &st) < 0) {
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
return stat_new(&st); return stat_new(&st);
} }
@ -905,7 +907,6 @@ rb_io_stat(VALUE obj)
rb_io_t *fptr; rb_io_t *fptr;
struct stat st; struct stat st;
#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
GetOpenFile(obj, fptr); GetOpenFile(obj, fptr);
if (fstat(fptr->fd, &st) == -1) { if (fstat(fptr->fd, &st) == -1) {
rb_sys_fail_path(fptr->pathv); rb_sys_fail_path(fptr->pathv);
@ -937,7 +938,7 @@ rb_file_s_lstat(VALUE klass, VALUE fname)
FilePathValue(fname); FilePathValue(fname);
fname = rb_str_encode_ospath(fname); fname = rb_str_encode_ospath(fname);
if (lstat(StringValueCStr(fname), &st) == -1) { if (lstat(StringValueCStr(fname), &st) == -1) {
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
return stat_new(&st); return stat_new(&st);
#else #else
@ -1706,7 +1707,7 @@ rb_file_s_size(VALUE klass, VALUE fname)
if (rb_stat(fname, &st) < 0) { if (rb_stat(fname, &st) < 0) {
FilePathValue(fname); FilePathValue(fname);
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
return OFFT2NUM(st.st_size); return OFFT2NUM(st.st_size);
} }
@ -1776,7 +1777,7 @@ rb_file_s_ftype(VALUE klass, VALUE fname)
FilePathValue(fname); FilePathValue(fname);
fname = rb_str_encode_ospath(fname); fname = rb_str_encode_ospath(fname);
if (lstat(StringValueCStr(fname), &st) == -1) { if (lstat(StringValueCStr(fname), &st) == -1) {
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
return rb_file_ftype(&st); return rb_file_ftype(&st);
@ -1799,7 +1800,7 @@ rb_file_s_atime(VALUE klass, VALUE fname)
if (rb_stat(fname, &st) < 0) { if (rb_stat(fname, &st) < 0) {
FilePathValue(fname); FilePathValue(fname);
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
return stat_atime(&st); return stat_atime(&st);
} }
@ -1845,7 +1846,7 @@ rb_file_s_mtime(VALUE klass, VALUE fname)
if (rb_stat(fname, &st) < 0) { if (rb_stat(fname, &st) < 0) {
FilePathValue(fname); FilePathValue(fname);
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
return stat_mtime(&st); return stat_mtime(&st);
} }
@ -1894,7 +1895,7 @@ rb_file_s_ctime(VALUE klass, VALUE fname)
if (rb_stat(fname, &st) < 0) { if (rb_stat(fname, &st) < 0) {
FilePathValue(fname); FilePathValue(fname);
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
return stat_ctime(&st); return stat_ctime(&st);
} }
@ -3358,7 +3359,7 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l
if (!NIL_P(checkval)) { if (!NIL_P(checkval)) {
if (checkval == ID2SYM(resolving)) { if (checkval == ID2SYM(resolving)) {
errno = ELOOP; errno = ELOOP;
rb_sys_fail(RSTRING_PTR(testpath)); rb_sys_fail_path(testpath);
} }
else { else {
*resolvedp = rb_str_dup(checkval); *resolvedp = rb_str_dup(checkval);
@ -3372,12 +3373,12 @@ realpath_rec(long *prefixlenp, VALUE *resolvedp, const char *unresolved, VALUE l
if (ret == -1) { if (ret == -1) {
if (errno == ENOENT) { if (errno == ENOENT) {
if (strict || !last || *unresolved_firstsep) if (strict || !last || *unresolved_firstsep)
rb_sys_fail(RSTRING_PTR(testpath)); rb_sys_fail_path(testpath);
*resolvedp = testpath; *resolvedp = testpath;
break; break;
} }
else { else {
rb_sys_fail(RSTRING_PTR(testpath)); rb_sys_fail_path(testpath);
} }
} }
#ifdef HAVE_READLINK #ifdef HAVE_READLINK
@ -4001,18 +4002,18 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
path = rb_str_encode_ospath(path); path = rb_str_encode_ospath(path);
#ifdef HAVE_TRUNCATE #ifdef HAVE_TRUNCATE
if (truncate(StringValueCStr(path), pos) < 0) if (truncate(StringValueCStr(path), pos) < 0)
rb_sys_fail(RSTRING_PTR(path)); rb_sys_fail_path(path);
#else /* defined(HAVE_CHSIZE) */ #else /* defined(HAVE_CHSIZE) */
{ {
int tmpfd; int tmpfd;
if ((tmpfd = rb_cloexec_open(StringValueCStr(path), 0, 0)) < 0) { if ((tmpfd = rb_cloexec_open(StringValueCStr(path), 0, 0)) < 0) {
rb_sys_fail(RSTRING_PTR(path)); rb_sys_fail_path(path);
} }
rb_update_max_fd(tmpfd); rb_update_max_fd(tmpfd);
if (chsize(tmpfd, pos) < 0) { if (chsize(tmpfd, pos) < 0) {
close(tmpfd); close(tmpfd);
rb_sys_fail(RSTRING_PTR(path)); rb_sys_fail_path(path);
} }
close(tmpfd); close(tmpfd);
} }
@ -4350,7 +4351,7 @@ rb_f_test(int argc, VALUE *argv)
CHECK(1); CHECK(1);
if (rb_stat(fname, &st) == -1) { if (rb_stat(fname, &st) == -1) {
FilePathValue(fname); FilePathValue(fname);
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
switch (cmd) { switch (cmd) {
@ -4439,7 +4440,7 @@ rb_stat_init(VALUE obj, VALUE fname)
FilePathValue(fname); FilePathValue(fname);
fname = rb_str_encode_ospath(fname); fname = rb_str_encode_ospath(fname);
if (STAT(StringValueCStr(fname), &st) == -1) { if (STAT(StringValueCStr(fname), &st) == -1) {
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
if (DATA_PTR(obj)) { if (DATA_PTR(obj)) {
xfree(DATA_PTR(obj)); xfree(DATA_PTR(obj));

4
io.c
View File

@ -4968,7 +4968,7 @@ rb_sysopen(VALUE fname, int oflags, mode_t perm)
fd = rb_sysopen_internal(&data); fd = rb_sysopen_internal(&data);
} }
if (fd < 0) { if (fd < 0) {
rb_sys_fail(RSTRING_PTR(fname)); rb_sys_fail_path(fname);
} }
} }
return fd; return fd;
@ -5635,7 +5635,7 @@ pipe_open(struct rb_exec_arg *eargp, VALUE prog, const char *modestr, int fmode,
fp = popen(cmd, modestr); fp = popen(cmd, modestr);
if (eargp) if (eargp)
rb_run_exec_options(&sarg, NULL); rb_run_exec_options(&sarg, NULL);
if (!fp) rb_sys_fail(RSTRING_PTR(prog)); if (!fp) rb_sys_fail_path(prog);
fd = fileno(fp); fd = fileno(fp);
#endif #endif