* 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
Родитель b8729f117c
Коммит 9acf2091e1
4 изменённых файлов: 30 добавлений и 23 удалений

Просмотреть файл

@ -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>
* configure.in (__builtin_unreachable): check for clang.

12
dir.c
Просмотреть файл

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

33
file.c
Просмотреть файл

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

4
io.c
Просмотреть файл

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