зеркало из https://github.com/github/ruby.git
Use `File::NULL` instead of hard coded null device names
This commit is contained in:
Родитель
092c9b266a
Коммит
c8d0470bb0
|
@ -43,11 +43,7 @@ $" << "mkmf.rb"
|
|||
load File.expand_path("lib/mkmf.rb", srcdir)
|
||||
require 'optparse/shellwords'
|
||||
|
||||
if defined?(File::NULL)
|
||||
@null = File::NULL
|
||||
elsif !File.chardev?(@null = "/dev/null")
|
||||
@null = "nul"
|
||||
end
|
||||
@null = File::NULL
|
||||
|
||||
def verbose?
|
||||
$mflags.defined?("V") == "1"
|
||||
|
|
4
file.c
4
file.c
|
@ -4971,7 +4971,7 @@ rb_file_s_extname(VALUE klass, VALUE fname)
|
|||
*
|
||||
* Returns the string representation of the path
|
||||
*
|
||||
* File.path("/dev/null") #=> "/dev/null"
|
||||
* File.path(File::NULL) #=> "/dev/null"
|
||||
* File.path(Pathname.new("/tmp")) #=> "/tmp"
|
||||
*
|
||||
*/
|
||||
|
@ -6086,7 +6086,7 @@ rb_stat_z(VALUE obj)
|
|||
* the file otherwise.
|
||||
*
|
||||
* File.stat("testfile").size? #=> 66
|
||||
* File.stat("/dev/null").size? #=> nil
|
||||
* File.stat(File::NULL).size? #=> nil
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
6
io.c
6
io.c
|
@ -5256,7 +5256,7 @@ rb_io_close_on_exec_p(VALUE io)
|
|||
*
|
||||
* Sets a close-on-exec flag.
|
||||
*
|
||||
* f = open("/dev/null")
|
||||
* f = File.open(File::NULL)
|
||||
* f.close_on_exec = true
|
||||
* system("cat", "/proc/self/fd/#{f.fileno}") # cat: /proc/self/fd/3: No such file or directory
|
||||
* f.closed? #=> false
|
||||
|
@ -9634,11 +9634,11 @@ rb_io_autoclose_p(VALUE io)
|
|||
*
|
||||
* Sets auto-close flag.
|
||||
*
|
||||
* f = open("/dev/null")
|
||||
* f = File.open(File::NULL)
|
||||
* IO.for_fd(f.fileno).close
|
||||
* f.gets # raises Errno::EBADF
|
||||
*
|
||||
* f = open("/dev/null")
|
||||
* f = File.open(File::NULL)
|
||||
* g = IO.for_fd(f.fileno)
|
||||
* g.autoclose = false
|
||||
* g.close
|
||||
|
|
|
@ -2699,7 +2699,7 @@ MESSAGE
|
|||
when $mswin
|
||||
$nmake = ?m if /nmake/i =~ make
|
||||
end
|
||||
$ignore_error = $nmake ? '' : ' 2> /dev/null || true'
|
||||
$ignore_error = $nmake ? '' : " 2> #{File::NULL} || true"
|
||||
|
||||
RbConfig::CONFIG["srcdir"] = CONFIG["srcdir"] =
|
||||
$srcdir = arg_config("--srcdir", File.dirname($0))
|
||||
|
|
14
process.c
14
process.c
|
@ -4804,11 +4804,11 @@ rb_f_system(int argc, VALUE *argv, VALUE _)
|
|||
*
|
||||
* A filename can be specified as a hash value.
|
||||
*
|
||||
* pid = spawn(command, :in=>"/dev/null") # read mode
|
||||
* pid = spawn(command, :out=>"/dev/null") # write mode
|
||||
* pid = spawn(command, :in=>File::NULL) # read mode
|
||||
* pid = spawn(command, :out=>File::NULL) # write mode
|
||||
* pid = spawn(command, :err=>"log") # write mode
|
||||
* pid = spawn(command, [:out, :err]=>"/dev/null") # write mode
|
||||
* pid = spawn(command, 3=>"/dev/null") # read mode
|
||||
* pid = spawn(command, [:out, :err]=>File::NULL) # write mode
|
||||
* pid = spawn(command, 3=>File::NULL) # read mode
|
||||
*
|
||||
* For stdout and stderr (and combination of them),
|
||||
* it is opened in write mode.
|
||||
|
@ -6834,7 +6834,7 @@ static int rb_daemon(int nochdir, int noclose);
|
|||
* nochdir is true (i.e. non false), it changes the current
|
||||
* working directory to the root ("/"). Unless the argument
|
||||
* noclose is true, daemon() will redirect standard input,
|
||||
* standard output and standard error to /dev/null.
|
||||
* standard output and standard error to null device.
|
||||
* Return zero on success, or raise one of Errno::*.
|
||||
*/
|
||||
|
||||
|
@ -6854,6 +6854,8 @@ proc_daemon(int argc, VALUE *argv, VALUE _)
|
|||
return INT2FIX(n);
|
||||
}
|
||||
|
||||
extern const char ruby_null_device[];
|
||||
|
||||
static int
|
||||
rb_daemon(int nochdir, int noclose)
|
||||
{
|
||||
|
@ -6877,7 +6879,7 @@ rb_daemon(int nochdir, int noclose)
|
|||
if (!nochdir)
|
||||
err = chdir("/");
|
||||
|
||||
if (!noclose && (n = rb_cloexec_open("/dev/null", O_RDWR, 0)) != -1) {
|
||||
if (!noclose && (n = rb_cloexec_open(ruby_null_device, O_RDWR, 0)) != -1) {
|
||||
rb_update_max_fd(n);
|
||||
(void)dup2(n, 0);
|
||||
(void)dup2(n, 1);
|
||||
|
|
|
@ -1518,7 +1518,7 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
|
||||
stat = File.stat(f)
|
||||
unless stat.chardev?
|
||||
# /dev/null may be accessed by other processes
|
||||
# null device may be accessed by other processes
|
||||
assert_equal(stat.atime, File.atime(f), f)
|
||||
assert_equal(stat.ctime, File.ctime(f), f)
|
||||
assert_equal(stat.mtime, File.mtime(f), f)
|
||||
|
|
|
@ -154,8 +154,7 @@ class VCS
|
|||
alias dryrun? dryrun
|
||||
alias debug? debug
|
||||
|
||||
NullDevice = defined?(IO::NULL) ? IO::NULL :
|
||||
%w[/dev/null NUL NIL: NL:].find {|dev| File.exist?(dev)}
|
||||
NullDevice = IO::NULL
|
||||
|
||||
# returns
|
||||
# * the last revision of the current branch
|
||||
|
|
Загрузка…
Ссылка в новой задаче