D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Dir
/
Filename :
fchdir-c.ri
back
Copy
U:RDoc::AnyMethod[iI"fchdir:ETI"Dir::fchdir;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"<Changes the current working directory to the directory ;TI"3specified by the integer file descriptor +fd+.;To:RDoc::Markup::BlankLine o; ; [I"NWhen passing a file descriptor over a UNIX socket or to a child process, ;TI"2using +fchdir+ instead of +chdir+ avoids the ;TI"m{time-of-check to time-of-use vulnerability}[https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use];T@o; ; [I";With no block, changes to the directory given by +fd+:;T@o:RDoc::Markup::Verbatim; [I""Dir.chdir('/var/spool/mail') ;TI"$Dir.pwd # => "/var/spool/mail" ;TI"dir = Dir.new('/usr') ;TI"fd = dir.fileno ;TI"Dir.fchdir(fd) ;TI"Dir.pwd # => "/usr" ;T:@format0o; ; [I"=With a block, temporarily changes the working directory:;T@o:RDoc::Markup::List: @type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0; [o; ; [I"'Calls the block with the argument.;To;;0; [o; ; [I"$Changes to the given directory.;To;;0; [o; ; [I")Executes the block (yields no args).;To;;0; [o; ; [I"-Restores the previous working directory.;To;;0; [o; ; [I"&Returns the block's return value.;T@o; ; [I" Example:;T@o;; [ I""Dir.chdir('/var/spool/mail') ;TI"$Dir.pwd # => "/var/spool/mail" ;TI"dir = Dir.new('/tmp') ;TI"fd = dir.fileno ;TI"Dir.fchdir(fd) do ;TI" Dir.pwd # => "/tmp" ;TI" end ;TI"$Dir.pwd # => "/var/spool/mail" ;T; 0o; ; [ I"This method uses the ;TI"J{fchdir()}[https://www.man7.org/linux/man-pages/man3/fchdir.3p.html] ;TI"%function defined by POSIX 2008; ;TI"Wthe method is not implemented on non-POSIX platforms (raises NotImplementedError).;T@o; ; [I"=Raises an exception if the file descriptor is not valid.;T@o; ; [ I"IIn a multi-threaded program an error is raised if a thread attempts ;TI"@to open a +chdir+ block while another thread has one open, ;TI"8or a call to +chdir+ without a block occurs inside ;TI"9a block passed to +chdir+ (even in the same thread).;T: @fileI" dir.c;T:0@omit_headings_from_table_of_contents_below0I":Dir.fchdir(fd) -> 0 Dir.fchdir(fd) { ... } -> object ;T0[ I" (p1);T@ZFI"Dir;TcRDoc::NormalClass00