Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rb_file_able_p function #4677

Merged
merged 4 commits into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 8 additions & 12 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ int flock(int, int);
#include "ruby/thread.h"
#include "ruby/util.h"

#define RBOOL(v) ((v) ? Qtrue : Qfalse)

VALUE rb_cFile;
VALUE rb_mFileTest;
VALUE rb_cStat;
Expand Down Expand Up @@ -1830,8 +1832,7 @@ rb_file_exists_p(VALUE obj, VALUE fname)
static VALUE
rb_file_readable_p(VALUE obj, VALUE fname)
{
if (rb_eaccess(fname, R_OK) < 0) return Qfalse;
return Qtrue;
return RBOOL(rb_eaccess(fname, R_OK) >= 0);
}

/*
Expand All @@ -1848,8 +1849,7 @@ rb_file_readable_p(VALUE obj, VALUE fname)
static VALUE
rb_file_readable_real_p(VALUE obj, VALUE fname)
{
if (rb_access(fname, R_OK) < 0) return Qfalse;
return Qtrue;
return RBOOL(rb_access(fname, R_OK) >= 0);
}

#ifndef S_IRUGO
Expand Down Expand Up @@ -1904,8 +1904,7 @@ rb_file_world_readable_p(VALUE obj, VALUE fname)
static VALUE
rb_file_writable_p(VALUE obj, VALUE fname)
{
if (rb_eaccess(fname, W_OK) < 0) return Qfalse;
return Qtrue;
return RBOOL(rb_eaccess(fname, W_OK) >= 0);
}

/*
Expand All @@ -1922,8 +1921,7 @@ rb_file_writable_p(VALUE obj, VALUE fname)
static VALUE
rb_file_writable_real_p(VALUE obj, VALUE fname)
{
if (rb_access(fname, W_OK) < 0) return Qfalse;
return Qtrue;
return RBOOL(rb_access(fname, W_OK) >= 0);
}

/*
Expand Down Expand Up @@ -1974,8 +1972,7 @@ rb_file_world_writable_p(VALUE obj, VALUE fname)
static VALUE
rb_file_executable_p(VALUE obj, VALUE fname)
{
if (rb_eaccess(fname, X_OK) < 0) return Qfalse;
return Qtrue;
return RBOOL(rb_eaccess(fname, X_OK) >= 0);
}

/*
Expand All @@ -1996,8 +1993,7 @@ rb_file_executable_p(VALUE obj, VALUE fname)
static VALUE
rb_file_executable_real_p(VALUE obj, VALUE fname)
{
if (rb_access(fname, X_OK) < 0) return Qfalse;
return Qtrue;
return RBOOL(rb_access(fname, X_OK) >= 0);
}

#ifndef S_ISREG
Expand Down