Date: Monday March 04, 2019 @ 04:05 Author: argrath Update of /cvsroot/perldocjp/docs/modules/File-Temp-0.22 In directory sf-cvs:/tmp/cvs-serv29312/modules/File-Temp-0.22 Added Files: Temp.pod Log Message: in progress =================================================================== File: Temp.pod Status: Up-to-date Working revision: 1.1 Sun Mar 3 19:05:05 2019 Repository revision: 1.1 /cvsroot/perldocjp/docs/modules/File-Temp-0.22/Temp.pod,v Existing Tags: No Tags Exist -------------- next part -------------- Index: docs/modules/File-Temp-0.22/Temp.pod diff -u /dev/null docs/modules/File-Temp-0.22/Temp.pod:1.1 --- /dev/null Mon Mar 4 04:05:05 2019 +++ docs/modules/File-Temp-0.22/Temp.pod Mon Mar 4 04:05:05 2019 @@ -0,0 +1,2185 @@ + +=encoding euc-jp + +=head1 NAME + +=begin original + +File::Temp - return name and handle of a temporary file safely + +=end original + +File::Temp - ¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤Î̾Á°¤È¥Ï¥ó¥É¥ë¤ò°ÂÁ´¤ËÊÖ¤¹ + +=begin __INTERNALS + +=head1 PORTABILITY + +(¥Ý¡¼¥¿¥Ó¥ê¥Æ¥£) + +=begin original + +This section is at the top in order to provide easier access to +porters. It is not expected to be rendered by a standard pod +formatting tool. Please skip straight to the SYNOPSIS section if you +are not trying to port this module to a new platform. + +=end original + +This section is at the top in order to provide easier access to +porters. It is not expected to be rendered by a standard pod +formatting tool. Please skip straight to the SYNOPSIS section if you +are not trying to port this module to a new platform. +(TBT) + +=begin original + +This module is designed to be portable across operating systems and it +currently supports Unix, VMS, DOS, OS/2, Windows and Mac OS +(Classic). When porting to a new OS there are generally three main +issues that have to be solved: + +=end original + +¤³¤Î¥â¥¸¥å¡¼¥ë¤Ï¥ª¥Ú¥ì¡¼¥Æ¥£¥ó¥°¥·¥¹¥Æ¥à¤ò¤Þ¤¿¤¤¤Ç°Ü¿¢¤Ç¤¤ë¤è¤¦¤Ë +À߷פµ¤ì¤Æ¤ª¤ê¡¢ +¸½ºß¡¢Unix¡¢VMS¡¢DOS¡¢OS/2¡¢Windows, Mac OS (Classic) ¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Þ¤¹¡£ +¿·¤·¤¤OS¤Ë°Ü¿¢¤¹¤ë¤È¤¤Ë¤Ï¡¢°ìÈÌŪ¤Ë¡¢»°¤Ä¤Î²ò·è¤µ¤ì¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤ +¼çÍפÊÌäÂ꤬¤¢¤ê¤Þ¤¹: + +=over 4 + +=item * + +=begin original + +Can the OS unlink an open file? If it can not then the +C<_can_unlink_opened_file> method should be modified. + +=end original + +¤½¤ÎOS¤Ï¡¢³«¤¤¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤òºï½ü¤Ç¤¤Þ¤¹¤«¡© +¤â¤·¤Ç¤¤Ê¤±¤ì¤Ð¡¢C<_can_unlink_opend_file>¥á¥½¥Ã¥É¤Ï½¤Àµ¤µ¤ì¤ë¤Ù¤¤Ç¤¹¡£ + +=item * + +=begin original + +Are the return values from C<stat> reliable? By default all the +return values from C<stat> are compared when unlinking a temporary +file using the filename and the handle. Operating systems other than +unix do not always have valid entries in all fields. If C<unlink0> fails +then the C<stat> comparison should be modified accordingly. + +=end original + +C<stat> ¤«¤éÊÖ¤µ¤ì¤ëÃͤϿ®Íê½ÐÍè¤Þ¤¹¤«? +¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢C<stat> ¤«¤é¤ÎÊÖ¤êÃͤÎÁ´¤Æ¤¬¡¢¥Õ¥¡¥¤¥ë̾¤È¥Ï¥ó¥É¥ë¤ò»È¤¦ +°ì»þ¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë¤È¤¤ËÈæ³Ó¤µ¤ì¤Þ¤¹¡£ +unix °Ê³°¤Î¥ª¥Ú¥ì¡¼¥Æ¥£¥ó¥°¥·¥¹¥Æ¥à¤Ç¤Ï¡¢Á´¤Æ¤Î¥Õ¥£¡¼¥ë¥É¤Ë¤Ä¤¤¤Æ¡¢ +ÂÅÅö¤Ê¹àÌܤ¬¤¢¤ë¤È¤Ï¸Â¤ê¤Þ¤»¤ó¡£ +C<unlink0> ¤¬¼ºÇÔ¤¹¤ë¤È¡¢C<stat> ¤ÎÈæ³Ó¤Ï¤½¤ì¤Ë¹ç¤ï¤»¤Æ½¤Àµ¤µ¤ì¤ë¤Ù¤¤Ç¤¹¡£ + +=item * + +=begin original + +Security. Systems that can not support a test for the sticky bit +on a directory can not use the MEDIUM and HIGH security tests. +The C<_can_do_level> method should be modified accordingly. + +=end original + +¥»¥¥å¥ê¥Æ¥£¡£ +¥Ç¥£¥ì¥¯¥È¥ê¤Î¥¹¥Æ¥£¥Ã¥¡¼¥Ó¥Ã¥È¤Î¥Æ¥¹¥È¤ò¥µ¥Ý¡¼¥È¤·¤Ê¤¤¥·¥¹¥Æ¥à¤Ï¡¢ +MEDIUM ¤È HIGH ¤Î¥»¥¥å¥ê¥Æ¥£¥Æ¥¹¥È¤ò»È¤¨¤Þ¤»¤ó¡£ +C<_can_do_level> ¥á¥½¥Ã¥É¤Ï¤½¤ì¤Ë±þ¤¸¤Æ½¤Àµ¤µ¤ì¤ë¤Ù¤¤Ç¤¹¡£ + +=back + +=end __INTERNALS + +=head1 SYNOPSIS + + use File::Temp qw/ tempfile tempdir /; + + $fh = tempfile(); + ($fh, $filename) = tempfile(); + + ($fh, $filename) = tempfile( $template, DIR => $dir); + ($fh, $filename) = tempfile( $template, SUFFIX => '.dat'); + ($fh, $filename) = tempfile( $template, TMPDIR => 1 ); + + binmode( $fh, ":utf8" ); + + $dir = tempdir( CLEANUP => 1 ); + ($fh, $filename) = tempfile( DIR => $dir ); + +=begin original + +Object interface: + +=end original + +¥ª¥Ö¥¸¥§¥¯¥È¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹: + + require File::Temp; + use File::Temp (); + use File::Temp qw/ :seekable /; + + $fh = File::Temp->new(); + $fname = $fh->filename; + + $fh = File::Temp->new(TEMPLATE => $template); + $fname = $fh->filename; + + $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' ); + print $tmp "Some data\n"; + print "Filename is $tmp\n"; + $tmp->seek( 0, SEEK_END ); + +=begin original + +The following interfaces are provided for compatibility with +existing APIs. They should not be used in new code. + +=end original + +The following interfaces are provided for compatibility with +existing APIs. They should not be used in new code. +(TBT) + +=begin original + +MkTemp family: + +=end original + +MkTemp ·Ï: + + use File::Temp qw/ :mktemp /; + + ($fh, $file) = mkstemp( "tmpfileXXXXX" ); + ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix); + + $tmpdir = mkdtemp( $template ); + + $unopened_file = mktemp( $template ); + +=begin original + +POSIX functions: + +=end original + +POSIX ´Ø¿ô: + + use File::Temp qw/ :POSIX /; + + $file = tmpnam(); + $fh = tmpfile(); + + ($fh, $file) = tmpnam(); + +=begin original + +Compatibility functions: + +=end original + +¸ß´¹´Ø¿ô: + + $unopened_file = File::Temp::tempnam( $dir, $pfx ); + +=head1 DESCRIPTION + +=begin original + +C<File::Temp> can be used to create and open temporary files in a safe +way. There is both a function interface and an object-oriented +interface. The File::Temp constructor or the tempfile() function can +be used to return the name and the open filehandle of a temporary +file. The tempdir() function can be used to create a temporary +directory. + +=end original + +C<File::Temp> ¤Ï¡¢°ÂÁ´¤ÊÊýË¡¤Ç¡¢°ì»þ¥Õ¥¡¥¤¥ë¤òºîÀ®¤·¡¢³«¤¯¤Î¤Ë»È¤¨¤Þ¤¹¡£ +´Ø¿ô¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤È¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ÎξÊý¤¬¤¢¤ê¤Þ¤¹¡£ +The File::Temp ¤Î¥³¥ó¥¹¥È¥é¥¯¥¿¤È tempfile() ´Ø¿ô¤Ï¡¢°ì»þ¥Õ¥¡¥¤¥ë¤Î̾Á°¤ª¤è¤Ó +³«¤¤¤¿¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤òÊÖ¤¹¤Î¤Ë»È¤ï¤ì¤Þ¤¹¡£ +tempdir() ´Ø¿ô¤Ï¡¢°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤¹¤ë¤Î¤Ë»È¤ï¤ì¤Þ¤¹¡£ + +=begin original + +The security aspect of temporary file creation is emphasized such that +a filehandle and filename are returned together. This helps guarantee +that a race condition can not occur where the temporary file is +created by another process between checking for the existence of the +file and its opening. Additional security levels are provided to +check, for example, that the sticky bit is set on world writable +directories. See L<"safe_level"> for more information. + +=end original + +°ì»þ¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë¤³¤È¤Î¥»¥¥å¥ê¥Æ¥£¤Î¦Ì̤¬¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È +¥Õ¥¡¥¤¥ë̾¤¬°ì½ï¤ËÊÖ¤µ¤ì¤ë¤È¤¤¤¦¤³¤È¤Ç¡¢¶¯Ä´¤µ¤ì¤Þ¤¹¡£ +¤³¤ì¤¬¡¢¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤«¤ò¥Á¥§¥Ã¥¯¤·¡¢¥Õ¥¡¥¤¥ë¤ò³«¤¤¤Æ¤¤¤ë´Ö¤Ë +ÊÌ¤Î¥×¥í¥»¥¹¤Ë¤è¤Ã¤Æ¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤¬ºî¤é¤ì¤ë¡¢¤È¤¤¤¦ +¶¥¹ç¾ò·ï¤¬µ¯¤³¤é¤Ê¤¤¤³¤È¤òÊݾڤ¹¤ë¤Î¤ò½õ¤±¤Æ¤¤¤Þ¤¹¡£ +ÄɲäΥ»¥¥å¥ê¥Æ¥£¥ì¥Ù¥ë¤¬Ä󶡤µ¤ì¤Æ¤¤¤Þ¤¹; +Î㤨¤Ð¡¢¥¹¥Æ¥£¥Ã¥¡¼¥Ó¥Ã¥È¤¬Á´Âνñ¤¹þ¤ß²Äǽ¤Ê¥Ç¥£¥ì¥¯¥È¥ê¤Ë +¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤«¤Î¥Á¥§¥Ã¥¯¤Ç¤¹¡£ +¾ÜºÙ¤Ï L<"safe_level"> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +For compatibility with popular C library functions, Perl implementations of +the mkstemp() family of functions are provided. These are, mkstemp(), +mkstemps(), mkdtemp() and mktemp(). + +=end original + +°ìÈÌŪ¤Ê C ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤È¤Î¸ß´¹À¤Î¤¿¤á¤Ë¡¢ +mkstemp() ´Ø¿ô¤ÎÃç´Ö¤Î Perl ¼ÂÁõ¤¬Ä󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£ +mkstemp(), mkstemps(), mkdtemp(), mktemp() ¤¬¤¢¤ê¤Þ¤¹¡£ + +=begin original + +Additionally, implementations of the standard L<POSIX|POSIX> +tmpnam() and tmpfile() functions are provided if required. + +=end original + +¤µ¤é¤Ë¡¢¤â¤·É¬Íפʤ顢ɸ½à¤Î L<POSIX|POSIX> ¤Î¼ÂÁõ¤Ç¤¢¤ë tmpnam() ¤È +tmpfile() ¤¬Ä󶡤µ¤ì¤Þ¤¹¡£ + +=begin original + +Implementations of mktemp(), tmpnam(), and tempnam() are provided, +but should be used with caution since they return only a filename +that was valid when function was called, so cannot guarantee +that the file will not exist by the time the caller opens the filename. + +=end original + +mktemp(), tmpanam(), tempnam() ¤Î¼ÂÁõ¤ÏÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¤¬¡¢ +Ãí°Õ¤·¤Æ»È¤ï¤ì¤ë¤Ù¤¤Ç¤¹; +¤Ê¤¼¤Ê¤é¡¢´Ø¿ô¤¬¸Æ¤Ð¤ì¤ë¤È¡¢ÂÅÅö¤Ê¥Õ¥¡¥¤¥ë̾¤À¤±¤òÊÖ¤¹¤Î¤Ç¡¢ +¸Æ¤Ó½Ð¤·Â¦¤¬¥Õ¥¡¥¤¥ë¤ò³«¤¯»þ¤Ë¤½¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤Ê¤¤¤³¤È¤ò +ÊݾڤǤ¤Ê¤¤¤«¤é¤Ç¤¹¡£ + +=begin original + +Filehandles returned by these functions support the seekable methods. + +=end original + +¤³¤ì¤é¤Î´Ø¿ô¤ÇÊÖ¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ï seekable ¥á¥½¥Ã¥É¤ËÂбþ¤·¤Æ¤¤¤Þ¤¹¡£ + +=cut + +=head1 OBJECT-ORIENTED INTERFACE + +(¥ª¥Ö¥¸¥§¥¯¥È»Ø¸þ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹) + +=begin original + +This is the primary interface for interacting with +C<File::Temp>. Using the OO interface a temporary file can be created +when the object is constructed and the file can be removed when the +object is no longer required. + +=end original + +This is the primary interface for interacting with +C<File::Temp>. Using the OO interface a temporary file can be created +when the object is constructed and the file can be removed when the +object is no longer required. +(TBT) + +=begin original + +Note that there is no method to obtain the filehandle from the +C<File::Temp> object. The object itself acts as a filehandle. Also, +the object is configured such that it stringifies to the name of the +temporary file, and can be compared to a filename directly. The object +isa C<IO::Handle> and isa C<IO::Seekable> so all those methods are +available. + +=end original + +Note that there is no method to obtain the filehandle from the +C<File::Temp> object. The object itself acts as a filehandle. Also, +the object is configured such that it stringifies to the name of the +temporary file, and can be compared to a filename directly. The object +isa C<IO::Handle> and isa C<IO::Seekable> so all those methods are +available. +(TBT) + +=over 4 + +=item B<new> + +=begin original + +Create a temporary file object. + +=end original + +°ì»þ¥Õ¥¡¥¤¥ë¥ª¥Ö¥¸¥§¥¯¥È¤òºîÀ®¤·¤Þ¤¹¡£ + + my $tmp = File::Temp->new(); + +=begin original + +by default the object is constructed as if C<tempfile> +was called without options, but with the additional behaviour +that the temporary file is removed by the object destructor +if UNLINK is set to true (the default). + +=end original + +by default the object is constructed as if C<tempfile> +was called without options, but with the additional behaviour +that the temporary file is removed by the object destructor +if UNLINK is set to true (the default). +(TBT) + +=begin original + +Supported arguments are the same as for C<tempfile>: UNLINK +(defaulting to true), DIR, EXLOCK and SUFFIX. Additionally, the filename +template is specified using the TEMPLATE option. The OPEN option +is not supported (the file is always opened). + +=end original + +Supported arguments are the same as for C<tempfile>: UNLINK +(defaulting to true), DIR, EXLOCK and SUFFIX. Additionally, the filename +template is specified using the TEMPLATE option. The OPEN option +is not supported (the file is always opened). +(TBT) + + $tmp = File::Temp->new( TEMPLATE => 'tempXXXXX', + DIR => 'mydir', + SUFFIX => '.dat'); + +=begin original + +Arguments are case insensitive. + +=end original + +°ú¿ô¤ÏÂçʸ»ú¾®Ê¸»ú¤ò̵»ë¤·¤Þ¤¹¡£ + +=begin original + +Can call croak() if an error occurs. + +=end original + +¥¨¥é¡¼¤¬µ¯¤¤ë¤È croak() ¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£ + +=cut + +=item B<newdir> + +=begin original + +Create a temporary directory using an object oriented interface. + +=end original + +Create a temporary directory using an object oriented interface. +(TBT) + + $dir = File::Temp->newdir(); + +=begin original + +By default the directory is deleted when the object goes out of scope. + +=end original + +By default the directory is deleted when the object goes out of scope. +(TBT) + +=begin original + +Supports the same options as the C<tempdir> function. Note that directories +created with this method default to CLEANUP => 1. + +=end original + +Supports the same options as the C<tempdir> function. Note that directories +created with this method default to CLEANUP => 1. +(TBT) + + $dir = File::Temp->newdir( $template, %options ); + +=cut + +=item B<filename> + +=begin original + +Return the name of the temporary file associated with this object +(if the object was created using the "new" constructor). + +=end original + +Return the name of the temporary file associated with this object +(if the object was created using the "new" constructor). +(TBT) + + $filename = $tmp->filename; + +=begin original + +This method is called automatically when the object is used as +a string. + +=end original + +This method is called automatically when the object is used as +a string. +(TBT) + +=cut + +=item B<dirname> + +=begin original + +Return the name of the temporary directory associated with this +object (if the object was created using the "newdir" constructor). + +=end original + +Return the name of the temporary directory associated with this +object (if the object was created using the "newdir" constructor). +(TBT) + + $dirname = $tmpdir->dirname; + +=begin original + +This method is called automatically when the object is used in string context. + +=end original + +This method is called automatically when the object is used in string context. +(TBT) + +=item B<unlink_on_destroy> + +=begin original + +Control whether the file is unlinked when the object goes out of scope. +The file is removed if this value is true and $KEEP_ALL is not. + +=end original + +Control whether the file is unlinked when the object goes out of scope. +The file is removed if this value is true and $KEEP_ALL is not. +(TBT) + + $fh->unlink_on_destroy( 1 ); + +=begin original + +Default is for the file to be removed. + +=end original + +Default is for the file to be removed. +(TBT) + +=cut + +=item B<DESTROY> + +=begin original + +When the object goes out of scope, the destructor is called. This +destructor will attempt to unlink the file (using C<unlink1>) +if the constructor was called with UNLINK set to 1 (the default state +if UNLINK is not specified). + +=end original + +When the object goes out of scope, the destructor is called. This +destructor will attempt to unlink the file (using C<unlink1>) +if the constructor was called with UNLINK set to 1 (the default state +if UNLINK is not specified). +(TBT) + +=begin original + +No error is given if the unlink fails. + +=end original + +No error is given if the unlink fails. +(TBT) + +=begin original + +If the object has been passed to a child process during a fork, the +file will be deleted when the object goes out of scope in the parent. + +=end original + +If the object has been passed to a child process during a fork, the +file will be deleted when the object goes out of scope in the parent. +(TBT) + +=begin original + +For a temporary directory object the directory will be removed +unless the CLEANUP argument was used in the constructor (and set to +false) or C<unlink_on_destroy> was modified after creation. + +=end original + +For a temporary directory object the directory will be removed +unless the CLEANUP argument was used in the constructor (and set to +false) or C<unlink_on_destroy> was modified after creation. +(TBT) + +=begin original + +If the global variable $KEEP_ALL is true, the file or directory +will not be removed. + +=end original + +If the global variable $KEEP_ALL is true, the file or directory +will not be removed. +(TBT) + +=cut + +=back + +=head1 FUNCTIONS + +(´Ø¿ô) + +=begin original + +This section describes the recommended interface for generating +temporary files and directories. + +=end original + +¤³¤ÎÀá¤Ç¤Ï¡¢°ì»þ¥Õ¥¡¥¤¥ë¤È°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤òÀ¸À®¤¹¤ë¤¿¤á¤Î¡¢ +¿ä¾©¤µ¤ì¤ë¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ë¤Ä¤¤¤ÆÀâÌÀ¤·¤Þ¤¹¡£ + +=over 4 + +=item B<tempfile> + +=begin original + +This is the basic function to generate temporary files. +The behaviour of the file can be changed using various options: + +=end original + +¤³¤ì¤Ï´ðËÜŪ¤Ê´Ø¿ô¤Ç¡¢°ì»þ¥Õ¥¡¥¤¥ë¤òÀ¸À®¤·¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë¤Î¿¶¤ëÉñ¤¤¤ÏÍÍ¡¹¤Ê¥ª¥×¥·¥ç¥ó¤ÇÊѹ¹¤Ç¤¤Þ¤¹: + + $fh = tempfile(); + ($fh, $filename) = tempfile(); + +=begin original + +Create a temporary file in the directory specified for temporary +files, as specified by the tmpdir() function in L<File::Spec>. + +=end original + +L<File::Spec> ¤Î tmpdir() ´Ø¿ô¤Ç»ØÄꤵ¤ì¤ë +°ì»þ¥Õ¥¡¥¤¥ëÍѤΥǥ£¥ì¥¯¥È¥ê¤Ë¡¢°ì»þ¥Õ¥¡¥¤¥ë¤òºîÀ®¤·¤Þ¤¹¡£ + + ($fh, $filename) = tempfile($template); + +=begin original + +Create a temporary file in the current directory using the supplied +template. Trailing `X' characters are replaced with random letters to +generate the filename. At least four `X' characters must be present +at the end of the template. + +=end original + +¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë¡¢Ä󶡤µ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¤ò»È¤Ã¤Æ¡¢ +°ì»þ¥Õ¥¡¥¤¥ë¤òºîÀ®¤·¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë̾¤òÀ¸À®¤¹¤ë¤È¤¤Ë¡¢ +ËöÈø¤Îʸ»ú `X' ¤Ï¥é¥ó¥À¥à¤Êʸ»ú¤ËÃÖ¤´¹¤¨¤é¤ì¤Þ¤¹¡£ +¾¯¤Ê¤¯¤È¤â»Í¤Ä¤Î `X' ʸ»ú¤¬¥Æ¥ó¥×¥ì¡¼¥È¤ÎËöÈø¤Ë¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ + + ($fh, $filename) = tempfile($template, SUFFIX => $suffix) + +=begin original + +Same as previously, except that a suffix is added to the template +after the `X' translation. Useful for ensuring that a temporary +filename has a particular extension when needed by other applications. +But see the WARNING at the end. + +=end original + +`X' ¤ÎÊÑ´¹¤Î¸å¤ËÀÜÈø¼¤¬²Ã¤¨¤é¤ì¤ë¤³¤È¤ò½ü¤¤¤Æ¡¢Á°¤Î¤â¤Î¤ÈƱ¤¸¤Ç¤¹¡£ +¾¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤ÇɬÍפȤµ¤ì¤ë¤È¤¤Ë¡¢ +¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤ËÆÃÊ̤γÈÄ¥»Ò¤¬¤¢¤ë¤è¤¦¤Ë¤·¤¿¤¤¾ì¹ç¤ËÊØÍø¤Ç¤¹¡£ +¤·¤«¤·¡¢ºÇ¸å¤Î·Ù¹ð¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + + ($fh, $filename) = tempfile($template, DIR => $dir); + +=begin original + +Translates the template as before except that a directory name +is specified. + +=end original + +¥Ç¥£¥ì¥¯¥È¥ê¤Î̾Á°¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¤Î¤ò½ü¤¤¤Æ¡¢ +Á°½Ò¤Î¤â¤Î¤ÈƱÍͤ˥ƥó¥×¥ì¡¼¥È¤òÊÑ´¹¤·¤Þ¤¹¡£ + + ($fh, $filename) = tempfile($template, TMPDIR => 1); + +=begin original + +Equivalent to specifying a DIR of "File::Spec->tmpdir", writing the file +into the same temporary directory as would be used if no template was +specified at all. + +=end original + +Equivalent to specifying a DIR of "File::Spec->tmpdir", writing the file +into the same temporary directory as would be used if no template was +specified at all. +(TBT) + + ($fh, $filename) = tempfile($template, UNLINK => 1); + +=begin original + +Return the filename and filehandle as before except that the file is +automatically removed when the program exits (dependent on +$KEEP_ALL). Default is for the file to be removed if a file handle is +requested and to be kept if the filename is requested. In a scalar +context (where no filename is returned) the file is always deleted +either (depending on the operating system) on exit or when it is +closed (unless $KEEP_ALL is true when the temp file is created). + +=end original + +Á°½Ò¤Î¤è¤¦¤Ë¥Õ¥¡¥¤¥ë̾¤È¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤òÊÖ¤·¤Þ¤¹¤¬¡¢($KEEP_ALL ¤Ë°Í¸¤·¤Æ) +¥×¥í¥°¥é¥à¤¬½ªÎ»¤·¤¿¤È¤¤Ë¼«Æ°Åª¤Ë°ì»þ¥Õ¥¡¥¤¥ë¤¬ºï½ü¤µ¤ì¤Þ¤¹¡£ +¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢¥Õ¥¡¥¤¥ë¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬Í׵ᤵ¤ì¤ì¤Ðºï½ü¤µ¤ì¡¢ +¥Õ¥¡¥¤¥ë̾¤¬Í׵ᤵ¤ì¤ì¤ÐÊÝ»ý¤µ¤ì¤Þ¤¹¡£ +(¥Õ¥¡¥¤¥ë̾¤¬ÊÖ¤µ¤ì¤Ê¤¤)¥¹¥«¥é¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢(¥ª¥Ú¥ì¡¼¥Æ¥£¥ó¥°¥·¥¹¥Æ¥à¤Ë +°Í¸¤·¤Æ)½ªÎ»»þ¤«¡¢(°ì»þ¥Õ¥¡¥¤¥ë¤¬ºîÀ®¤µ¤ì¤¿¤È¤¤Ë $KEEP_ALL ¤¬¿¿¤Ç¤Ê¤¤¸Â¤ê) +ÊĤ¸¤é¤ì¤¿¤È¤¤Ë¡¢¥Õ¥¡¥¤¥ë¤Ï¤¤¤Ä¤âºï½ü¤µ¤ì¤Þ¤¹¡£ + +=begin original + +Use the object-oriented interface if fine-grained control of when +a file is removed is required. + +=end original + +Use the object-oriented interface if fine-grained control of when +a file is removed is required. +(TBT) + +=begin original + +If the template is not specified, a template is always +automatically generated. This temporary file is placed in tmpdir() +(L<File::Spec>) unless a directory is specified explicitly with the +DIR option. + +=end original + +¥Æ¥ó¥×¥ì¡¼¥È¤¬»ØÄꤵ¤ì¤Ê¤¤¾ì¹ç¡¢¥Æ¥ó¥×¥ì¡¼¥È¤Ï¾ï¤Ë¼«Æ°Åª¤ËÀ¸À®¤µ¤ì¤Þ¤¹¡£ +¤³¤Î°ì»þ¥Õ¥¡¥¤¥ë¤Ï¡¢DIR ¥ª¥×¥·¥ç¥ó¤ÇÌÀ¼¨Åª¤Ë¥Ç¥£¥ì¥¯¥È¥ê¤¬»ØÄꤵ¤ì¤Ê¤¤¸Â¤ê¡¢ +tmpdir()(L<File::Spec>) ¤ËÃÖ¤«¤ì¤Þ¤¹¡£ + + $fh = tempfile( DIR => $dir ); + +=begin original + +If called in scalar context, only the filehandle is returned and the +file will automatically be deleted when closed on operating systems +that support this (see the description of tmpfile() elsewhere in this +document). This is the preferred mode of operation, as if you only +have a filehandle, you can never create a race condition by fumbling +with the filename. On systems that can not unlink an open file or can +not mark a file as temporary when it is opened (for example, Windows +NT uses the C<O_TEMPORARY> flag) the file is marked for deletion when +the program ends (equivalent to setting UNLINK to 1). The C<UNLINK> +flag is ignored if present. + +=end original + +¥¹¥«¥é¥³¥ó¥Æ¥¥¹¥È¤Ç¸Æ¤Ð¤ì¤ë¤È¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬ÊÖ¤µ¤ì¡¢ +ÊĤ¸¤é¤ì¤ë¤È¡¢¥ª¥Ú¥ì¡¼¥·¥ç¥ó¥·¥¹¥Æ¥à¤¬Âбþ¤·¤Æ¤¤¤ì¤Ð(¤³¤Îʸ½ñ¤Î¾¤Î¾ì½ê¤Ë +¤¢¤ë tmpfile() ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤)¡¢¥Õ¥¡¥¤¥ë¤Ï¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤À¤±¤ò»ý¤Ä¤Î¤Ê¤é¡¢¤³¤ì¤Ï¹¥¤Þ¤·¤¤ÊýË¡¤Ç¤¹; +¥Õ¥¡¥¤¥ë¥Í¡¼¥à¤òÊѹ¹¤¹¤ë¤³¤È¤Ç¶¥¹ç¾ò·ï¤òºî¤ë¤³¤È¤Ï¤¢¤ê¤Þ¤»¤ó¡£ +³«¤¤¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤òºï½ü¤Ç¤¤Ê¤¤¡¢¤¢¤ë¤¤¤Ï¥Õ¥¡¥¤¥ë¤ò³«¤¤¤Æ¤¤¤ë¤È +°ì»þŪ¤Ç¤¢¤ë¤È¤·¤Æ¥Õ¥¡¥¤¥ë¤Ë¥Þ¡¼¥¯¤ò¤Ä¤±¤ë¤³¤È¤Î¤Ç¤¤Ê¤¤¥·¥¹¥Æ¥à¤Ç¤Ï +(¤¿¤È¤¨¤Ð¡¢Windows NT ¤Ï¡¢C<O_TEMPORARY> ¥Õ¥é¥°¤ò»È¤¤¤Þ¤¹)¡¢ +¥Õ¥¡¥¤¥ë¤Ï¡¢¥×¥í¥°¥é¥à¤Î½ªÎ»»þ¤Ë¡¢ºï½üÍѤΥޡ¼¥¯¤¬¤Ä¤±¤é¤ì¤Þ¤¹ +(UNLINK ¤ò 1 ¤ËÀßÄꤹ¤ë¤Î¤ÈƱ¤¸)¡£ +C<UNLINK> ¥Õ¥é¥°¤Ï¡¢¤¢¤Ã¤Æ¤â̵»ë¤µ¤ì¤Þ¤¹¡£ + + (undef, $filename) = tempfile($template, OPEN => 0); + +=begin original + +This will return the filename based on the template but +will not open this file. Cannot be used in conjunction with +UNLINK set to true. Default is to always open the file +to protect from possible race conditions. A warning is issued +if warnings are turned on. Consider using the tmpnam() +and mktemp() functions described elsewhere in this document +if opening the file is not required. + +=end original + +¤³¤ì¤Ï¥Æ¥ó¥×¥ì¡¼¥È¤ò¸µ¤Ë¤·¤¿¥Õ¥¡¥¤¥ë̾¤òÊÖ¤·¤Þ¤¹¤¬¡¢¤½¤Î¥Õ¥¡¥¤¥ë¤ò +³«¤¤Þ¤»¤ó¡£ +UNILINK ¤ò¿¿¤ËÀßÄꤹ¤ë¤Î¤ÈƱ»þ¤Ë¤Ï»È¤¨¤Þ¤»¤ó¡£ +¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¾ï¤Ë¥Õ¥¡¥¤¥ë¤ò³«¤¡¢¶¥¹ç¾ò·ï¤Î²ÄǽÀ¤«¤éÊݸ¤Þ¤¹¡£ +·Ù¹ð¤¬Í¸ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¡¢·Ù¹ð¤¬½ÐÎϤµ¤ì¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë¤ò³«¤¯¤³¤È¤òÍ׵ᤷ¤Ê¤¤¤Ê¤é¡¢¤³¤Îʸ½ñ¤Î¾¤Î¾ì½ê¤ÇÀâÌÀ¤µ¤ì¤Æ¤¤¤ë +tmpnam() ¤È¡¢mktemp() ´Ø¿ô¤ò»È¤¦¤³¤È¤ò¸¡Æ¤¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +If the operating system supports it (for example BSD derived systems), the +filehandle will be opened with O_EXLOCK (open with exclusive file lock). +This can sometimes cause problems if the intention is to pass the filename +to another system that expects to take an exclusive lock itself (such as +DBD::SQLite) whilst ensuring that the tempfile is not reused. In this +situation the "EXLOCK" option can be passed to tempfile. By default EXLOCK +will be true (this retains compatibility with earlier releases). + +=end original + +If the operating system supports it (for example BSD derived systems), the +filehandle will be opened with O_EXLOCK (open with exclusive file lock). +This can sometimes cause problems if the intention is to pass the filename +to another system that expects to take an exclusive lock itself (such as +DBD::SQLite) whilst ensuring that the tempfile is not reused. In this +situation the "EXLOCK" option can be passed to tempfile. By default EXLOCK +will be true (this retains compatibility with earlier releases). +(TBT) + + ($fh, $filename) = tempfile($template, EXLOCK => 0); + +=begin original + +Options can be combined as required. + +=end original + +¥ª¥×¥·¥ç¥ó¤Ï¡¢É¬Íפ˱þ¤¸¤Æ¡¢ÁȤ߹ç¤ï¤»¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=item B<tempdir> + +=begin original + +This is the recommended interface for creation of temporary +directories. By default the directory will not be removed on exit +(that is, it won't be temporary; this behaviour can not be changed +because of issues with backwards compatibility). To enable removal +either use the CLEANUP option which will trigger removal on program +exit, or consider using the "newdir" method in the object interface which +will allow the directory to be cleaned up when the object goes out of +scope. + +=end original + +¤³¤ì¤Ï¡¢°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤¹¤ë¤¿¤á¤Î¿ä¾©¤µ¤ì¤ë¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ç¤¹¡£ +directories. By default the directory will not be removed on exit +(that is, it won't be temporary; this behaviour can not be changed +because of issues with backwards compatibility). To enable removal +either use the CLEANUP option which will trigger removal on program +exit, or consider using the "newdir" method in the object interface which +will allow the directory to be cleaned up when the object goes out of +scope. +(TBT) + +=begin original + +The behaviour of the function depends on the arguments: + +=end original + +¤³¤Î´Ø¿ô¤Î¿¶Éñ¤Ï°ú¿ô¤Ë¤è¤ê¤Þ¤¹: + + $tempdir = tempdir(); + +=begin original + +Create a directory in tmpdir() (see L<File::Spec|File::Spec>). + +=end original + +tmpdir() ¤Ç¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤·¤Þ¤¹ +(L<File::Spec|File::Spec> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤)¡£ + + $tempdir = tempdir( $template ); + +=begin original + +Create a directory from the supplied template. This template is +similar to that described for tempfile(). `X' characters at the end +of the template are replaced with random letters to construct the +directory name. At least four `X' characters must be in the template. + +=end original + +Ä󶡤µ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¤«¤é¡¢¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤·¤Þ¤¹¡£ +¤³¤Î¥Æ¥ó¥×¥ì¡¼¥È¤Ï tempfile() ¤ÇÀâÌÀ¤µ¤ì¤¿¤â¤Î¤È»÷¤Æ¤¤¤Þ¤¹¡£ +¥Æ¥ó¥×¥ì¡¼¥È¤ÎËöÈø¤Î `X' ʸ»ú¤Ï¥é¥ó¥À¥à¤Êʸ»ú¤ËÃÖ¤´¹¤¨¤é¤ì¡¢ +¥Ç¥£¥ì¥¯¥È¥ê̾¤òºî¤ê¤Þ¤¹¡£ +¥Æ¥ó¥×¥ì¡¼¥È¤Ë¤Ï¾¯¤Ê¤¯¤È¤â»Í¤Ä `X' ʸ»ú¤¬¤Ê¤±¤ì¤Ð¤¤¤±¤Þ¤»¤ó¡£ + + $tempdir = tempdir ( DIR => $dir ); + +=begin original + +Specifies the directory to use for the temporary directory. +The temporary directory name is derived from an internal template. + +=end original + +°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤Ë»È¤¦¥Ç¥£¥ì¥¯¥È¥ê¤ò»ØÄꤷ¤Þ¤¹¡£ +°ì»þ¥Ç¥£¥ì¥¯¥È¥ê̾¤Ï¡¢ÆâÉô¤Î¥Æ¥ó¥×¥ì¡¼¥È¤«¤éÀ¸À®¤µ¤ì¤Þ¤¹¡£ + + $tempdir = tempdir ( $template, DIR => $dir ); + +=begin original + +Prepend the supplied directory name to the template. The template +should not include parent directory specifications itself. Any parent +directory specifications are removed from the template before +prepending the supplied directory. + +=end original + +»ØÄꤵ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥ê̾¤ò¥Æ¥ó¥×¥ì¡¼¥È¤ËÁ°ÃÖ¤·¤Þ¤¹¡£ +¥Æ¥ó¥×¥ì¡¼¥È¤Ï¡¢¿Æ¥Ç¥£¥ì¥¯¥È¥ê»ØÄꤽ¤Î¤â¤Î¤ò´Þ¤à¤Ù¤¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£ +»ØÄꤵ¤ì¤¿¥Ç¥£¥ì¥¯¥È¥ê¤òÁ°ÃÖ¤¹¤ëÁ°¤Ë¡¢¿Æ¥Ç¥£¥ì¥¯¥È¥ê»ØÄê¤Ï +¥Æ¥ó¥×¥ì¡¼¥È¤«¤éºï½ü¤µ¤ì¤Þ¤¹¡£ + + $tempdir = tempdir ( $template, TMPDIR => 1 ); + +=begin original + +Using the supplied template, create the temporary directory in +a standard location for temporary files. Equivalent to doing + +=end original + +»ØÄꤵ¤ì¤¿ template ¤ò»È¤¦¤È¡¢°ì»þ¥Õ¥¡¥¤¥ë¤Î¤¿¤á¤Îɸ½à¤Î¾ì½ê¤Ë¡¢ +°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤òºî¤ê¤Þ¤¹¡£ +¼¡¤Î¤è¤¦¤Ë¤¹¤ë¤Î¤ÈƱ¤¸¤Ç¤¹¤¬: + + $tempdir = tempdir ( $template, DIR => File::Spec->tmpdir); + +=begin original + +but shorter. Parent directory specifications are stripped from the +template itself. The C<TMPDIR> option is ignored if C<DIR> is set +explicitly. Additionally, C<TMPDIR> is implied if neither a template +nor a directory are supplied. + +=end original + +¤è¤êû¤¯¤Ê¤ê¤Þ¤¹¡£ +¿Æ¥Ç¥£¥ì¥¯¥È¥ê»ØÄê¤Ï¥Æ¥ó¥×¥ì¡¼¥È¼«¿È¤«¤é½üµî¤µ¤ì¤Þ¤¹¡£ +C<DIR> ¤¬ÌÀ¼¨Åª¤ËÀßÄꤵ¤ì¤Æ¤¤¤ì¤Ð C<TMPDIR> ¥ª¥×¥·¥ç¥ó¤Ï̵»ë¤µ¤ì¤Þ¤¹¡£ +²Ã¤¨¤Æ¡¢¥Æ¥ó¥×¥ì¡¼¥È¤â¥Ç¥£¥ì¥¯¥È¥ê¤â»ØÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢ +C<TMPDIR> ¤¬²¾Äꤵ¤ì¤Þ¤¹¡£ + + $tempdir = tempdir( $template, CLEANUP => 1); + +=begin original + +Create a temporary directory using the supplied template, but +attempt to remove it (and all files inside it) when the program +exits. Note that an attempt will be made to remove all files from +the directory even if they were not created by this module (otherwise +why ask to clean it up?). The directory removal is made with +the rmtree() function from the L<File::Path|File::Path> module. +Of course, if the template is not specified, the temporary directory +will be created in tmpdir() and will also be removed at program exit. + +=end original + +°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤òÄ󶡤µ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¤ò»È¤Ã¤ÆºîÀ®¤·¤Þ¤¹¤¬¡¢ +¥×¥í¥°¥é¥à¤¬½ªÎ»¤¹¤ë¤È¤¤Ë¡¢¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê(¤ª¤è¤Ó¤½¤ÎÃæ¤ÎÁ´¤Æ¤Î¥Õ¥¡¥¤¥ë)¤ò +ºï½ü¤·¤è¤¦¤È¤·¤Þ¤¹¡£ +¤³¤Î»î¤ß¤Ï¡¢¤³¤Î¥â¥¸¥å¡¼¥ë¤¬ºî¤Ã¤Æ¤¤¤Ê¤¤¤â¤Î¤â´Þ¤á¤Æ¡¢ +¤½¤Î¥Ç¥£¥ì¥¯¥È¥ê¤«¤éÁ´¤Æ¤Î¥Õ¥¡¥¤¥ë¤òºï½ü¤·¤è¤¦¤È¤·¤Þ¤¹ +(¤µ¤â¤Ê¤±¤ì¤Ð¤Ê¤¼ºï½ü¤¹¤ë¤«¿Ò¤Í¤Þ¤¹¤«?)¡£ +¥Ç¥£¥ì¥¯¥È¥ê¤Î½üµî¤Ï L<File::Path|File::Path> ¤Î rmtree() ´Ø¿ô¤Ç +¹Ô¤Ê¤ï¤ì¤Þ¤¹¡£ +¤â¤Á¤í¤ó¡¢¥Æ¥ó¥×¥ì¡¼¥È¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢ +°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤Ï tempdir() ¤Ëºî¤é¤ì¡¢¥×¥í¥°¥é¥à¤Î½ªÎ»»þ¤Ëºï½ü¤µ¤ì¤Þ¤¹¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=back + +=head1 MKTEMP FUNCTIONS + +(MKTEMP ´Ø¿ô) + +=begin original + +The following functions are Perl implementations of the +mktemp() family of temp file generation system calls. + +=end original + +°Ê²¼¤Î´Ø¿ô¤Ï¡¢°ì»þ¥Õ¥¡¥¤¥ë¤òÀ¸À®¤¹¤ë¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ç¤¢¤ë +mktemp() ¤ÎÃç´Ö¤Î Perl ¤Î¼ÂÁõ¤Ç¤¹¡£ + +=over 4 + +=item B<mkstemp> + +=begin original + +Given a template, returns a filehandle to the temporary file and the name +of the file. + +=end original + +¥Æ¥ó¥×¥ì¡¼¥È¤òÍ¿¤¨¤ë¤È¡¢°ì»þ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È¥Õ¥¡¥¤¥ë̾¤òÊÖ¤·¤Þ¤¹¡£ + + ($fh, $name) = mkstemp( $template ); + +=begin original + +In scalar context, just the filehandle is returned. + +=end original + +¥¹¥«¥é¥³¥ó¥Æ¥¥¹¥È¤Ç¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤À¤±¤¬ÊÖ¤µ¤ì¤Þ¤¹¡£ + +=begin original + +The template may be any filename with some number of X's appended +to it, for example F</tmp/temp.XXXX>. The trailing X's are replaced +with unique alphanumeric combinations. + +=end original + +¥Æ¥ó¥×¥ì¡¼¥È¤Ï¡¢¤¤¤¯¤Ä¤«¤Î `X' ¤¬Äɲ䵤줿¥Õ¥¡¥¤¥ë̾¤«¤â¤·¤ì¤Þ¤»¤ó; +Î㤨¤Ð F</tmp/tmp.XXXX>¡£ +ËöÈø¤Î X ¤Ï¡¢¥æ¥Ë¡¼¥¯¤Ê±Ñ¿ô»ú¤ÎÁȹ礻¤ËÃÖ¤´¹¤¨¤é¤ì¤Þ¤¹¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=item B<mkstemps> + +=begin original + +Similar to mkstemp(), except that an extra argument can be supplied +with a suffix to be appended to the template. + +=end original + +mkstemp() ¤Ë»÷¤Æ¤¤¤Þ¤¹¤¬¡¢ÆÃÊ̤ʰú¿ô¤òÍ¿¤¨¤Æ¡¢ +¥Æ¥ó¥×¥ì¡¼¥È¤ËÀÜÈø¼¤òÄɲäǤ¤Þ¤¹¡£ + + ($fh, $name) = mkstemps( $template, $suffix ); + +=begin original + +For example a template of C<testXXXXXX> and suffix of C<.dat> +would generate a file similar to F<testhGji_w.dat>. + +=end original + +Î㤨¤Ð¡¢¥Æ¥ó¥×¥ì¡¼¥È ¤¬ C<testXXXXXX> ¤ÇÀÜÈø¼¤¬ C<.dat> ¤Ê¤é¡¢ +F<testthGji_w.dat> ¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¤òÀ¸À®¤·¤Þ¤¹¡£ + +=begin original + +Returns just the filehandle alone when called in scalar context. + +=end original + +¥¹¥«¥é¥³¥ó¥Æ¥¥¹¥È¤Ç¸Æ¤Ð¤ì¤ë¤È¡¢¤¿¤À¥Õ¥¡¥¤¥ë̾¤À¤±¤òÊÖ¤·¤Þ¤¹¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=item B<mkdtemp> + +=begin original + +Create a directory from a template. The template must end in +X's that are replaced by the routine. + +=end original + +¥Æ¥ó¥×¥ì¡¼¥È¤«¤é¥Ç¥£¥ì¥¯¥È¥ê¤òºîÀ®¤·¤Þ¤¹¡£ +¥ë¡¼¥Á¥ó¤Ë¤è¤Ã¤ÆÃÖ¤´¹¤¨¤é¤ì¤ë¥Æ¥ó¥×¥ì¡¼¥È¤Ï¡¢ +Ê£¿ô¤Î X ¤Ç½ª¤Ã¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ + + $tmpdir_name = mkdtemp($template); + +=begin original + +Returns the name of the temporary directory created. + +=end original + +ºîÀ®¤µ¤ì¤¿°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤Î̾Á°¤òÊÖ¤·¤Þ¤¹¡£ + +=begin original + +Directory must be removed by the caller. + +=end original + +¥Ç¥£¥ì¥¯¥È¥ê¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤Çºï½ü¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=item B<mktemp> + +=begin original + +Returns a valid temporary filename but does not guarantee +that the file will not be opened by someone else. + +=end original + +ÂÅÅö¤Ê°ì»þ¥Õ¥¡¥¤¥ë̾¤òÊÖ¤·¤Þ¤¹¡£ +¤Ç¤¹¤¬¡¢¤½¤Î¥Õ¥¡¥¤¥ë¤¬¡¢Â¾¤Î狼¤Ë³«¤«¤ì¤Æ¤¤¤Ê¤¤¤³¤È¤ÏÊݾڤ·¤Þ¤»¤ó¡£ + + $unopened_file = mktemp($template); + +=begin original + +Template is the same as that required by mkstemp(). + +=end original + +¥Æ¥ó¥×¥ì¡¼¥È¤Ï¡¢mkstemp() ¤ÇɬÍפȤµ¤ì¤ë¤Î¤ÈƱ¤¸¤Ç¤¹¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=back + +=head1 POSIX FUNCTIONS + +(POSIX ´Ø¿ô) + +=begin original + +This section describes the re-implementation of the tmpnam() +and tmpfile() functions described in L<POSIX> +using the mkstemp() from this module. + +=end original + +¤³¤ÎÀá¤Ï¡¢¤³¤Î¥â¥¸¥å¡¼¥ë¤«¤é mkstemp() ¤ò»È¤Ã¤Æ¤¤¤ë¡¢L<POSIX> ¤Ë +ÀâÌÀ¤µ¤ì¤Æ¤¤¤ë tmpnam() ¤È tmpfile() ´Ø¿ô¤ÎºÆ¼ÂÁõ¤òÀâÌÀ¤·¤Æ¤¤¤Þ¤¹¡£ + +=begin original + +Unlike the L<POSIX|POSIX> implementations, the directory used +for the temporary file is not specified in a system include +file (C<P_tmpdir>) but simply depends on the choice of tmpdir() +returned by L<File::Spec|File::Spec>. On some implementations this +location can be set using the C<TMPDIR> environment variable, which +may not be secure. +If this is a problem, simply use mkstemp() and specify a template. + +=end original + +L<POSIX|POSIX> ¤Î¼ÂÁõ¤È¤Ï°ã¤¤¡¢°ì»þ¥Õ¥¡¥¤¥ë¤Ë»È¤ï¤ì¤ë¥Ç¥£¥ì¥¯¥È¥ê¤Ï¡¢ +¥·¥¹¥Æ¥àÆâÉô¤Î¥Õ¥¡¥¤¥ë (C<P_tmpdir>) ¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢ +ñ½ã¤Ë¡¢L<File::Spec|File::Spec> ¤Ë¤è¤Ã¤Æ¡¢tmpdir() ¤¬ÊÖ¤¹¤â¤Î¤ÎÁªÂò¤Ë +°Í¤Ã¤Æ¤¤¤Þ¤¹¡£ +¼ÂÁõ¤Ë¤è¤Ã¤Æ¤Ï¡¢¤³¤Î¾ì½ê¤Ï¡¢C<TMPDIR> ´Ä¶ÊÑ¿ô¤ò»È¤Ã¤Æ +ÀßÄꤵ¤ì¤Æ¤¤¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡¢¤³¤ì¤Ï°ÂÁ´¤Ç¤Ï¤Ê¤¤¤«¤â¤·¤ì¤Þ¤»¤ó¡£ +¤³¤Î¤³¤È¤¬ÌäÂê¤Ê¤é¡¢Ã±½ã¤Ë¡¢mkstemp() ¤ò»È¤¤¡¢¥Æ¥ó¥×¥ì¡¼¥È¤ò»ØÄꤷ¤Æ²¼¤µ¤¤¡£ + +=over 4 + +=item B<tmpnam> + +=begin original + +When called in scalar context, returns the full name (including path) +of a temporary file (uses mktemp()). The only check is that the file does +not already exist, but there is no guarantee that that condition will +continue to apply. + +=end original + +¥¹¥«¥é¥³¥ó¥Æ¥¥¹¥È¤Ç¸Æ¤Ð¤ì¤¿¤é¡¢(mktemp() ¤ò»È¤¦)°ì»þ¥Õ¥¡¥¤¥ë¤Î +(¥Ñ¥¹¤ò´Þ¤ó¤À)¥Õ¥ë¥Í¡¼¥à¤òÊÖ¤·¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë¤¬´û¤Ë¸ºß¤·¤Ê¤¤¤³¤È¤À¤±¤ò¥Á¥§¥Ã¥¯¤·¤Þ¤¹¤¬¡¢ +¤½¤Î¾õÂÖ¤¬Å¬ÍѤµ¤ì³¤±¤ëÊݾڤϤ¢¤ê¤Þ¤»¤ó¡£ + + $file = tmpnam(); + +=begin original + +When called in list context, a filehandle to the open file and +a filename are returned. This is achieved by calling mkstemp() +after constructing a suitable template. + +=end original + +¥ê¥¹¥È¥³¥ó¥Æ¥¥¹¥È¤Ç¸Æ¤Ð¤ì¤ë¤È¡¢¥Õ¥¡¥¤¥ë¤ò³«¤¯¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È +¥Õ¥¡¥¤¥ë̾¤¬ÊÖ¤ê¤Þ¤¹¡£ +¤³¤ì¤Ï¡¢Å¬Àڤʥƥó¥×¥ì¡¼¥È¤òÁȤßΩ¤Æ¤¿¸å¤Ë mkstemp() ¤ò¸Æ¤Ö¤³¤È¤Ç +ãÀ®¤µ¤ì¤Þ¤¹¡£ + + ($fh, $file) = tmpnam(); + +=begin original + +If possible, this form should be used to prevent possible +race conditions. + +=end original + +²Äǽ¤Ê¤é¡¢ÀøºßŪ¤Ê¶¥¹ç¾õÂÖ¤òËɤ°¤¿¤á¤Ë¤³¤Î·Á¤Ç»È¤¦¤Ù¤¤Ç¤¹¡£ + +=begin original + +See L<File::Spec/tmpdir> for information on the choice of temporary +directory for a particular operating system. + +=end original + +ÆÃÄê¤Î¥ª¥Ú¥ì¡¼¥Æ¥£¥ó¥°¥·¥¹¥Æ¥à¤Ç +°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤òÁªÂò¤¹¤ë¤¿¤á¤Î¾ðÊó¤Ë¤Ä¤¤¤Æ¤Ï¡¢ +L<File::Spec/tmpdir> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=item B<tmpfile> + +=begin original + +Returns the filehandle of a temporary file. + +=end original + +°ì»þ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤òÊÖ¤·¤Þ¤¹¡£ + + $fh = tmpfile(); + +=begin original + +The file is removed when the filehandle is closed or when the program +exits. No access to the filename is provided. + +=end original + +¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬ÊĤ¸¤é¤ì¤ë¤È¤¤«¡¢¥×¥í¥°¥é¥à¤¬½ªÎ»¤¹¤ë¤È¤¤Ë¡¢ +¥Õ¥¡¥¤¥ë¤Ïºï½ü¤µ¤ì¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë̾¤Ø¤Î¥¢¥¯¥»¥¹¤ÏÄ󶡤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ + +=begin original + +If the temporary file can not be created undef is returned. +Currently this command will probably not work when the temporary +directory is on an NFS file system. + +=end original + +°ì»þ¥Õ¥¡¥¤¥ë¤¬ºî¤é¤ì¤Ê¤±¤ì¤Ð¡¢undef ¤¬ÊÖ¤ê¤Þ¤¹¡£ +°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤¬ NFS ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Î¾ì¹ç¡¢ +¸½ºß¤Î¤È¤³¤í¤³¤Î¥³¥Þ¥ó¥É¤Ï¤ª¤½¤é¤¯Æ°¤¤Þ¤»¤ó¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=back + +=head1 ADDITIONAL FUNCTIONS + +(Äɲäδؿô) + +=begin original + +These functions are provided for backwards compatibility +with common tempfile generation C library functions. + +=end original + +¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢¶¦Ä̤ΰì»þ¥Õ¥¡¥¤¥ëÀ¸À®¤Î C ¥é¥¤¥Ö¥é¥ê´Ø¿ô¤Î +¸åÊý¸ß´¹¤Î¤¿¤á¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£ + +=begin original + +They are not exported and must be addressed using the full package +name. + +=end original + +¥¨¥¯¥¹¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢´°Á´¤Ê¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ò»È¤Ã¤Æ +µ½Ò¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ + +=over 4 + +=item B<tempnam> + +=begin original + +Return the name of a temporary file in the specified directory +using a prefix. The file is guaranteed not to exist at the time +the function was called, but such guarantees are good for one +clock tick only. Always use the proper form of C<sysopen> +with C<O_CREAT | O_EXCL> if you must open such a filename. + +=end original + +ÀÜƬ¼¤ò»È¤Ã¤Æ»ØÄꤷ¤¿¥Ç¥£¥ì¥¯¥È¥êÆâ¤Ë¡¢°ì»þ¥Õ¥¡¥¤¥ë¤Î¥Õ¥¡¥¤¥ë̾¤òÊÖ¤·¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë¤Ï´Ø¿ô¤¬¸Æ¤Ð¤ì¤¿¤½¤Î¤È¤¤Ë¸ºß¤·¤Æ¤¤¤Ê¤¤¤³¤È¤òÊݾڤµ¤ì¤Þ¤¹¡£ +¤Ç¤¹¤¬¡¢¤³¤ÎÊݾڤϰì½Ö¤À¤±¤Î¤â¤Î¤Ç¤¹¡£ +¤½¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë̾¤ò³«¤«¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤Ê¤é¡¢ +C<O_CREAT | O_EXCL> ¤Ç¡¢C<sysopen> ¤ÎŬÀڤʷÁ¤ò¾ï¤Ë»È¤Ã¤Æ¤¯¤À¤µ¤¤¡£ + + $filename = File::Temp::tempnam( $dir, $prefix ); + +=begin original + +Equivalent to running mktemp() with $dir/$prefixXXXXXXXX +(using unix file convention as an example) + +=end original + +$dir/$prefixXXXXXXXXX ¤Ç¡¢mktemp() ¤ò¼Â¹Ô¤¹¤ë¤Î¤ÈƱ¤¸¤Ç¤¹¡£ +(Îã¤È¤·¤Æ¡¢unix ¤Î¥Õ¥¡¥¤¥ë¤Î´·Îã¤ò»È¤¤¤Þ¤¹) + +=begin original + +Because this function uses mktemp(), it can suffer from race conditions. + +=end original + +¤³¤Î´Ø¿ô¤Ï mktemp() ¤ò»È¤¦¤Î¤Ç¡¢¶¥¹ç¾õÂ֤αƶÁ¤ò¼õ¤±¤Þ¤¹¡£ + +=begin original + +Will croak() if there is an error. + +=end original + +¥¨¥é¡¼¤¬¤¢¤ë¤È croak() ¤·¤Þ¤¹¡£ + +=cut + +=back + +=head1 UTILITY FUNCTIONS + +(¥æ¡¼¥Æ¥£¥ê¥Æ¥£´Ø¿ô) + +=begin original + +Useful functions for dealing with the filehandle and filename. + +=end original + +¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È¥Õ¥¡¥¤¥ë̾¤ò°·¤¦¤¿¤á¤ÎÊØÍø´Ø¿ô¡£ + +=over 4 + +=item B<unlink0> + +=begin original + +Given an open filehandle and the associated filename, make a safe +unlink. This is achieved by first checking that the filename and +filehandle initially point to the same file and that the number of +links to the file is 1 (all fields returned by stat() are compared). +Then the filename is unlinked and the filehandle checked once again to +verify that the number of links on that file is now 0. This is the +closest you can come to making sure that the filename unlinked was the +same as the file whose descriptor you hold. + +=end original + +³«¤¤¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È¡¢´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥Õ¥¡¥¤¥ë̾¤òÍ¿¤¨¤ë¤È¡¢ +°ÂÁ´¤Ëºï½ü¤·¤Þ¤¹¡£ +¤³¤ì¤Ï¡¢¥Õ¥¡¥¤¥ë̾¤È¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬Æ±¤¸¥Õ¥¡¥¤¥ë¤ò»Ø¤·¡¢ +¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯¤Î¿ô¤¬¡¢°ì¤Ä¤Ç¤¢¤ë¤³¤È +(stat()¤¬ÊÖ¤¹Á´¤Æ¤Î¥Õ¥£¡¼¥ë¥É¤¬Èæ³Ó¤µ¤ì¤Þ¤¹)¤ò +ºÇ½é¤Ë¥Á¥§¥Ã¥¯¤¹¤ë¤³¤È¤Ç¡¢¼Â¸½¤·¤Þ¤¹¡£ +¤½¤ì¤«¤é¥Õ¥¡¥¤¥ë̾¤¬ºï½ü¤µ¤ì¤Æ¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤¬ºÆ¤Ó¥Á¥§¥Ã¥¯¤µ¤ì¡¢ +¤½¤Î¥Õ¥¡¥¤¥ë¤Î¥ê¥ó¥¯¤Î¿ô¤¬º£ÅÙ¤Ï 0 ¤Ç¤¢¤ë¤³¤È¤ò¸¡¾Ú¤·¤Þ¤¹¡£ +¤³¤Î¤³¤È¤Ï¡¢ÊÝ»ý¤·¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Èºï½ü¤µ¤ì¤¿¥Õ¥¡¥¤¥ë̾¤¬ +Ʊ¤¸¤Ç¤¢¤ë¤³¤È¤ò³Î¤«¤á¤ë¤Î¤Ë¡¢ºÇ¤â¼þÅþ¤Ç¤¹¡£ + + unlink0($fh, $path) + or die "Error unlinking file $path safely"; + +=begin original + +Returns false on error but croaks() if there is a security +anomaly. The filehandle is not closed since on some occasions this is +not required. + +=end original + +¥¨¥é¡¼¤Î¤È¤¤Ïµ¶¤òÊÖ¤·¤Þ¤¹¤¬¡¢¥»¥¥å¥ê¥Æ¥£ÌäÂ꤬¤¢¤Ã¤¿¾ì¹ç¤Ï croak() ¤·¤Þ¤¹¡£ +¤³¤ì¤¬É¬ÍפǤʤ¤¾ì¹ç¤¬¤¢¤ë¤Î¤Ç¡¢¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤ÏÊĤ¸¤Þ¤»¤ó¡£ + +=begin original + +On some platforms, for example Windows NT, it is not possible to +unlink an open file (the file must be closed first). On those +platforms, the actual unlinking is deferred until the program ends and +good status is returned. A check is still performed to make sure that +the filehandle and filename are pointing to the same thing (but not at +the time the end block is executed since the deferred removal may not +have access to the filehandle). + +=end original + +¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ë¤è¤Ã¤Æ¤Ï(Î㤨¤Ð¡¢Windows NT)¡¢³«¤¤¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤ò +ºï½ü¤Ç¤¤Ê¤¤¤â¤Î¤â¤¢¤ê¤Þ¤¹ +(¥Õ¥¡¥¤¥ë¤Ï¤Þ¤ºÊĤ¸¤é¤ì¤Ê¤±¤ì¤Ð¤¤¤±¤Þ¤»¤ó)¡£ +¤½¤ì¤é¤Î¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ç¤Ï¡¢¥×¥í¥°¥é¥à¤¬½ªÎ»¤·¡¢Îɤ¤¾õÂ֤ˤʤë¤Þ¤Ç¡¢ +¼ÂºÝ¤Îºï½ü¤Ï¿ø¤¨ÃÖ¤«¤ì¤Þ¤¹¡£ +¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤È¥Õ¥¡¥¤¥ë̾¤¬Æ±¤¸¤Î¤ò»Ø¤¹»ö¤ò³Î¤«¤á¤ë¤Þ¤Ç¡¢¥Á¥§¥Ã¥¯¤Ï +¹Ô¤Ê¤ï¤ì¤Þ¤¹¡£ +(¤·¤«¤·¡¢ºÇ¸å¤Î¥Ö¥í¥Ã¥¯¤¬¼Â¹Ô¤µ¤ì¤¿»þÅÀ¤Ç¤Ê¤±¤ì¤Ð¡¢ +¿ø¤¨ÃÖ¤«¤ì¤¿ºï½ü¤Ï¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Ë¥¢¥¯¥»¥¹¤·¤Ê¤¤¤Ç¤·¤ç¤¦¡£) + +=begin original + +Additionally, on Windows NT not all the fields returned by stat() can +be compared. For example, the C<dev> and C<rdev> fields seem to be +different. Also, it seems that the size of the file returned by stat() +does not always agree, with C<stat(FH)> being more accurate than +C<stat(filename)>, presumably because of caching issues even when +using autoflush (this is usually overcome by waiting a while after +writing to the tempfile before attempting to C<unlink0> it). + +=end original + +¤µ¤é¤Ë¡¢Windows NT ¤Ï¡¢stat() ¤¬Èæ³Ó¤µ¤ì¤ëÁ´¤Æ¤Î¥Õ¥£¡¼¥ë¥É¤òÊÖ¤·¤Þ¤»¤ó¡£ +Î㤨¤Ð¡¢C<dev> ¤È C<rdev> ¥Õ¥£¡¼¥ë¥É¤Ï°Û¤Ê¤Ã¤Æ¤¤¤ë¤è¤¦¤Ç¤¹¡£ +¤Þ¤¿¡¢stat() ¤¬ÊÖ¤¹¥Õ¥¡¥¤¥ë¤Î¥µ¥¤¥º¤Ï¡¢¾ï¤Ë¤Ï°ìÃפ·¤Þ¤»¤ó; +C<stat(FH)> ¤Ï¡¢C<stat(filename)> ¤è¤ê¤â¡¢¶¸¤¤¤¬¤¢¤ê¤Þ¤»¤ó; +¤ª¤½¤é¤¯¡¢Î㤨¼«Æ°¥Õ¥é¥Ã¥·¥å¤ò»È¤Ã¤Æ¤¤¤Æ¤â¡¢¥¥ã¥Ã¥·¥ó¥°¤ÎÌäÂê¤Ë¤è¤ë¤â¤Î¤Ç¤¹ +(¤³¤ì¤ÏÉáÄÌ¡¢°ì»þ¥Õ¥¡¥¤¥ë¤Ë½ñ¤¹þ¤ó¤À¸å¡¢¤½¤ì¤ò C<unlink0> ¤¬»î¤µ¤ì¤ëÁ°¤Ë +¤·¤Ð¤é¤¯ÂԤĤ³¤È¤Ç¡¢Âнè¤Ç¤¤Þ¤¹)¡£ + +=begin original + +Finally, on NFS file systems the link count of the file handle does +not always go to zero immediately after unlinking. Currently, this +command is expected to fail on NFS disks. + +=end original + +ºÇ¸å¤Ë¡¢NFS ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢ ¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤Î¥ê¥ó¥¯¥«¥¦¥ó¥È¤Ï¡¢ +ºï½ü¤Î¸å¡¢¤¹¤°¤Ë¤Ï¡¢¾ï¤Ë¤Ï 0 ¤Ë¤Ê¤ê¤Þ¤»¤ó¡£ +¸½ºß¤³¤Î¥³¥Þ¥ó¥É¤Ï¡¢NFS ¥Ç¥£¥¹¥¯¾å¤Ç¤Ï¼ºÇÔ¤¹¤ë¤ÈÁÛÄꤵ¤ì¤Þ¤¹¡£ + +=begin original + +This function is disabled if the global variable $KEEP_ALL is true +and an unlink on open file is supported. If the unlink is to be deferred +to the END block, the file is still registered for removal. + +=end original + +This function is disabled if the global variable $KEEP_ALL is true +and an unlink on open file is supported. If the unlink is to be deferred +to the END block, the file is still registered for removal. +(TBT) + +=begin original + +This function should not be called if you are using the object oriented +interface since the it will interfere with the object destructor deleting +the file. + +=end original + +This function should not be called if you are using the object oriented +interface since the it will interfere with the object destructor deleting +the file. +(TBT) + +=cut + +=item B<cmpstat> + +=begin original + +Compare C<stat> of filehandle with C<stat> of provided filename. This +can be used to check that the filename and filehandle initially point +to the same file and that the number of links to the file is 1 (all +fields returned by stat() are compared). + +=end original + +Compare C<stat> of filehandle with C<stat> of provided filename. This +can be used to check that the filename and filehandle initially point +to the same file and that the number of links to the file is 1 (all +fields returned by stat() are compared). +(TBT) + + cmpstat($fh, $path) + or die "Error comparing handle with file"; + +=begin original + +Returns false if the stat information differs or if the link count is +greater than 1. Calls croak if there is a security anomaly. + +=end original + +Returns false if the stat information differs or if the link count is +greater than 1. Calls croak if there is a security anomaly. +(TBT) + +=begin original + +On certain platforms, for example Windows, not all the fields returned by stat() +can be compared. For example, the C<dev> and C<rdev> fields seem to be +different in Windows. Also, it seems that the size of the file +returned by stat() does not always agree, with C<stat(FH)> being more +accurate than C<stat(filename)>, presumably because of caching issues +even when using autoflush (this is usually overcome by waiting a while +after writing to the tempfile before attempting to C<unlink0> it). + +=end original + +On certain platforms, for example Windows, not all the fields returned by stat() +can be compared. For example, the C<dev> and C<rdev> fields seem to be +different in Windows. Also, it seems that the size of the file +returned by stat() does not always agree, with C<stat(FH)> being more +accurate than C<stat(filename)>, presumably because of caching issues +even when using autoflush (this is usually overcome by waiting a while +after writing to the tempfile before attempting to C<unlink0> it). +(TBT) + +=begin original + +Not exported by default. + +=end original + +Not exported by default. +(TBT) + +=cut + +=item B<unlink1> + +=begin original + +Similar to C<unlink0> except after file comparison using cmpstat, the +filehandle is closed prior to attempting to unlink the file. This +allows the file to be removed without using an END block, but does +mean that the post-unlink comparison of the filehandle state provided +by C<unlink0> is not available. + +=end original + +Similar to C<unlink0> except after file comparison using cmpstat, the +filehandle is closed prior to attempting to unlink the file. This +allows the file to be removed without using an END block, but does +mean that the post-unlink comparison of the filehandle state provided +by C<unlink0> is not available. +(TBT) + + unlink1($fh, $path) + or die "Error closing and unlinking file"; + +=begin original + +Usually called from the object destructor when using the OO interface. + +=end original + +Usually called from the object destructor when using the OO interface. +(TBT) + +=begin original + +Not exported by default. + +=end original + +Not exported by default. +(TBT) + +=begin original + +This function is disabled if the global variable $KEEP_ALL is true. + +=end original + +This function is disabled if the global variable $KEEP_ALL is true. +(TBT) + +=begin original + +Can call croak() if there is a security anomaly during the stat() +comparison. + +=end original + +Can call croak() if there is a security anomaly during the stat() +comparison. +(TBT) + +=cut + +=item B<cleanup> + +=begin original + +Calling this function will cause any temp files or temp directories +that are registered for removal to be removed. This happens automatically +when the process exits but can be triggered manually if the caller is sure +that none of the temp files are required. This method can be registered as +an Apache callback. + +=end original + +Calling this function will cause any temp files or temp directories +that are registered for removal to be removed. This happens automatically +when the process exits but can be triggered manually if the caller is sure +that none of the temp files are required. This method can be registered as +an Apache callback. +(TBT) + +=begin original + +On OSes where temp files are automatically removed when the temp file +is closed, calling this function will have no effect other than to remove +temporary directories (which may include temporary files). + +=end original + +On OSes where temp files are automatically removed when the temp file +is closed, calling this function will have no effect other than to remove +temporary directories (which may include temporary files). +(TBT) + + File::Temp::cleanup(); + +=begin original + +Not exported by default. + +=end original + +Not exported by default. +(TBT) + +=back + +=head1 PACKAGE VARIABLES + +(¥Ñ¥Ã¥±¡¼¥¸ÊÑ¿ô) + +=begin original + +These functions control the global state of the package. + +=end original + +¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢¥Ñ¥Ã¥±¡¼¥¸¤Î¥°¥í¡¼¥Ð¥ë¤Ê¾õÂÖ¤òÀ©¸æ¤·¤Þ¤¹¡£ + +=over 4 + +=item B<safe_level> + +=begin original + +Controls the lengths to which the module will go to check the safety of the +temporary file or directory before proceeding. +Options are: + +=end original + +¤³¤Î¥â¥¸¥å¡¼¥ë¤¬½èÍýÁ°¤Ë°ì»þ¥Õ¥¡¥¤¥ë¤«°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤ò +°ÂÁ´¤Ë¥Á¥§¥Ã¥¯¤·¤è¤¦¤È¤¹¤ëÄøÅÙ¤òÀ©¸æ¤·¤Þ¤¹¡£ +¥ª¥×¥·¥ç¥ó: + +=over 8 + +=item STANDARD + +=begin original + +Do the basic security measures to ensure the directory exists and is +writable, that temporary files are opened only if they do not already +exist, and that possible race conditions are avoided. Finally the +L<unlink0|"unlink0"> function is used to remove files safely. + +=end original + +´ðËÜŪ¤Ê¥»¥¥å¥ê¥Æ¥£¤ÎÄøÅ٤ǡ¢°Ê²¼¤Î¤³¤È¤òÊݾڤ·¤Þ¤¹; +¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¡¢½ñ¤¹þ¤ß²Äǽ¤Ç¤¢¤ë¤³¤È; +°ì»þ¥Õ¥¡¥¤¥ë¤Ï¡¢¤Þ¤À¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Î¤ß³«¤¤¤Æ¤¤¤Æ¡¢¶¥¹ç¾ò·ï¤¬ +Èò¤±¤é¤ì¤Æ¤¤¤ë¤³¤È¡£ +ºÇ¸å¤Ë¡¢¥Õ¥¡¥¤¥ë¤ò°ÂÁ´¤Ëºï½ü¤¹¤ë¤¿¤á¤Ë +L<unlink0|"unlink0"> ´Ø¿ô¤¬»È¤ï¤ì¤Þ¤¹¡£ + +=item MEDIUM + +=begin original + +In addition to the STANDARD security, the output directory is checked +to make sure that it is owned either by root or the user running the +program. If the directory is writable by group or by other, it is then +checked to make sure that the sticky bit is set. + +=end original + +STANDARD ¤Î°ÂÁ´À¤Ë²Ã¤¨¤Æ¡¢½ÐÎϥǥ£¥ì¥¯¥È¥ê¤¬ root ¤Þ¤¿¤Ï +¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤·¤Æ¤¤¤ë¥æ¡¼¥¶¤Î¤É¤Á¤é¤«¤Ë¤è¤Ã¤Æ +½êͤµ¤ì¤Æ¤¤¤ë¤³¤È¤ò³Î¤«¤á¤ë¥Á¥§¥Ã¥¯¤ò¤·¤Þ¤¹¡£ +¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¾¤Î¥°¥ë¡¼¥×¤«¥æ¡¼¥¶¤Ë¤è¤Ã¤Æ½ñ¤¹þ¤ß²Äǽ¤Ç¤¢¤ë¤Ê¤é¤Ð¡¢ +¥¹¥Æ¥£¥Ã¥¡¼¥Ó¥Ã¥È¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ë¤³¤È¤ò³Î¤«¤á¤ë¥Á¥§¥Ã¥¯¤ò¤·¤Þ¤¹¡£ + +=begin original + +Will not work on platforms that do not support the C<-k> test +for sticky bit. + +=end original + +¥¹¥Æ¥£¥Ã¥¡¼¥Ó¥Ã¥È¤Î¤¿¤á¤Î C<-k> ¥Æ¥¹¥È¤ËÂбþ¤·¤Æ¤¤¤Ê¤¤¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ç¤Ï +Æ°ºî¤·¤Þ¤»¤ó¡£ + +=item HIGH + +=begin original + +In addition to the MEDIUM security checks, also check for the +possibility of ``chown() giveaway'' using the L<POSIX|POSIX> +sysconf() function. If this is a possibility, each directory in the +path is checked in turn for safeness, recursively walking back to the +root directory. + +=end original + +MEDIUM ¤Î°ÂÁ´À¥Á¥§¥Ã¥¯¤Ë²Ã¤¨¤Æ¡¢L<POSIX|POSIX> sysconf() ´Ø¿ô¤ò»È¤Ã¤Æ¡¢ +``chown() giveaway'' ¤Î²ÄǽÀ¤â¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£ +¤â¤·¤³¤Î²ÄǽÀ¤¬¤¢¤ì¤Ð¡¢¤½¤ì¤¾¤ì¤Î¥Ñ¥¹¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ï¡¢ +¥ë¡¼¥È¥Ç¥£¥ì¥¯¥È¥ê¤Þ¤ÇºÆµ¢Åª¤Ë°ÂÁ´À¤¬¥Á¥§¥Ã¥¯¤µ¤ì¤Þ¤¹¡£ + +=begin original + +For platforms that do not support the L<POSIX|POSIX> +C<_PC_CHOWN_RESTRICTED> symbol (for example, Windows NT) it is +assumed that ``chown() giveaway'' is possible and the recursive test +is performed. + +=end original + +L<POSIX|POSIX> ¤Î C<_PC_CHOWN_RESTRICTED> ¥·¥ó¥Ü¥ë¤ËÂбþ¤·¤Ê¤¤ +¥×¥é¥Ã¥È¥Õ¥©¡¼¥à(¤¿¤È¤¨¤Ð¡¢Windows NT)¤Ç¤Ï¡¢ +`chown() giveaway'' ¤¬²Äǽ¤Ç¤¢¤ë¤È²¾Äꤷ¡¢ºÆµ¢Åª¤Ê¥Æ¥¹¥È¤¬¹Ô¤ï¤ì¤Þ¤¹¡£ + +=back + +=begin original + +The level can be changed as follows: + +=end original + +¥ì¥Ù¥ë¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤·¤ÆÊѹ¹¤Ç¤¤Þ¤¹: + + File::Temp->safe_level( File::Temp::HIGH ); + +=begin original + +The level constants are not exported by the module. + +=end original + +¥ì¥Ù¥ëÄê¿ô¤Ï¥â¥¸¥å¡¼¥ë¤Ë¤è¤Ã¤Æ¥¨¥¯¥¹¥Ý¡¼¥È¤µ¤ì¤Þ¤»¤ó¡£ + +=begin original + +Currently, you must be running at least perl v5.6.0 in order to +run with MEDIUM or HIGH security. This is simply because the +safety tests use functions from L<Fcntl|Fcntl> that are not +available in older versions of perl. The problem is that the version +number for Fcntl is the same in perl 5.6.0 and in 5.005_03 even though +they are different versions. + +=end original + +MEDIUM ¤« HIGH ¤Î¥»¥¥å¥ê¥Æ¥£¤ò¼Â¹Ô¤¹¤ë¤¿¤á¤Ë¤Ï¡¢ +º£¤Î¤È¤³¤í¾¯¤Ê¤¯¤È¤â Perl v5.6.0 ¤ÇÆ°¤«¤µ¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£ +¤³¤ì¤Ïñ½ã¤Ë¡¢°ÂÁ´¤Ê¥Æ¥¹¥È¤Ï v5.6.0 ¤è¤ê¸Å¤¤¥Ð¡¼¥¸¥ç¥ó¤Î perl ¤Ç¤Ï +ÍøÍѤǤ¤Ê¤¤ <Fcntl|Fcntl> ¤«¤é´Ø¿ô¤ò»È¤¦¤«¤é¤Ç¤¹¡£ +perl 5.6.0 ¤È¡¢5.005_03 ¤Î Fcntl ¤Î¥Ð¡¼¥¸¥ç¥óÈֹ椬¡¢¤½¤ì¤é¤Ï +°ã¤¦¤â¤Î¤Ç¤¢¤ë¤Ë¤â¤«¤«¤ï¤é¤º¡¢ +¥Ð¡¼¥¸¥ç¥óÈֹ椬Ʊ¤¸¤Ç¤¢¤ë¤³¤È¤¬ÌäÂê¤Ç¤¹¡£ + +=begin original + +On systems that do not support the HIGH or MEDIUM safety levels +(for example Win NT or OS/2) any attempt to change the level will +be ignored. The decision to ignore rather than raise an exception +allows portable programs to be written with high security in mind +for the systems that can support this without those programs failing +on systems where the extra tests are irrelevant. + +=end original + +HIGH ¤È¡¢MEDIUM ¤Î°ÂÁ´¥ì¥Ù¥ë¤ò¥µ¥Ý¡¼¥È¤·¤Ê¤¤ OS(Win NT ¤ä OS/2) ¤Ç¤Ï¡¢ +¥ì¥Ù¥ë¤òÊѹ¹¤·¤è¤¦¤È¤·¤Æ¤â̵»ë¤µ¤ì¤Þ¤¹¡£ +Îã³°¤òµ¯¤³¤µ¤º¤Ë̵»ë¤¹¤ë¤È¸À¤¦·èÄê¤Ë¤è¤ê¡¢ +°Ü¿¢À¤Î¤¢¤ë¥×¥í¥°¥é¥à¤ò¡¢ +ÄɲäΥƥ¹¥È¤¬Ìµ°ÕÌ£¤Ç¤¢¤ë¥·¥¹¥Æ¥à¤Ç¥×¥í¥°¥é¥à¤¬¼ºÇÔ¤¹¤ë¤È¤¤¤¦¤³¤È¤Ê¤·¤Ë¡¢ +¹â¤¤°ÂÁ´À¤ËÂбþ¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¥·¥¹¥Æ¥à¤Î¤³¤È¤ò¹Í¤¨¤Æ¡¢ +¹â¤¤¥»¥¥å¥ê¥Æ¥£¤Ç½ñ¤¯¤³¤È¤ò²Äǽ¤Ë¤·¤Þ¤¹¡£ + +=begin original + +If you really need to see whether the change has been accepted +simply examine the return value of C<safe_level>. + +=end original + +¤â¤·¡¢¼ÂºÝ¤ËÊѹ¹¤¬¼õ¤±Æþ¤ì¤é¤ì¤¿¤«¤É¤¦¤«¤ò³Îǧ¤¹¤ëɬÍפ¬¤¢¤ë¤Ê¤é¡¢ +ñ¤Ë C<safe_level> ¤ÎÊÖ¤êÃͤò¤òÄ´¤Ù¤Æ¤¯¤À¤µ¤¤¡£ + + $newlevel = File::Temp->safe_level( File::Temp::HIGH ); + die "Could not change to high security" + if $newlevel != File::Temp::HIGH; + +=cut + +=item TopSystemUID + +=begin original + +This is the highest UID on the current system that refers to a root +UID. This is used to make sure that the temporary directory is +owned by a system UID (C<root>, C<bin>, C<sys> etc) rather than +simply by root. + +=end original + +¤³¤ì¤Ï root UID ¤ò»²¾È¤¹¤ë¸½ºß¤Î¥·¥¹¥Æ¥à¤Ç¤â¤Ã¤È¤â¹â¤¤ UID ¤Ç¤¹¡£ +¤³¤ì¤Ï°ì»þ¥Ç¥£¥ì¥¯¥È¥ê¤¬Ã±½ã¤Ë root ¤Î¤â¤Î¤Ç¤¢¤ë¤Î¤Ç¤Ï¤Ê¤¯¤Æ¡¢ +¥·¥¹¥Æ¥à UID ¤Î¤â¤Î(C<root>, C<bin>, C<sys> ¤Ê¤É)¤Ç¤¢¤ë¤³¤È¤ò³Î¤«¤á¤ë¤Î¤Ë¡¢ +»È¤ï¤ì¤Þ¤¹¡£ + +=begin original + +This is required since on many unix systems C</tmp> is not owned +by root. + +=end original + +¿¤¯¤Î unix ¤Î¥·¥¹¥Æ¥à¤Ç¡¢C</tmp> ¤Ï root ¤Î¤â¤Î¤Ç¤Ï¤Ê¤¤¤Î¤Ç¡¢ +¤³¤ì¤¬É¬ÍפȤµ¤ì¤Þ¤¹¡£ + +=begin original + +Default is to assume that any UID less than or equal to 10 is a root +UID. + +=end original + +¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢10 °Ê²¼¤Î¤â¤Î¤Ï¤É¤ó¤Ê UID ¤â root UID ¤ÈÁÛÄꤷ¤Þ¤¹¡£ + + File::Temp->top_system_uid(10); + my $topid = File::Temp->top_system_uid; + +=begin original + +This value can be adjusted to reduce security checking if required. +The value is only relevant when C<safe_level> is set to MEDIUM or higher. + +=end original + +ɬÍפʤé¤Ð¤³¤ÎÃͤòÄ´À°¤·¤Æ¥»¥¥å¥ê¥Æ¥£¥Á¥§¥Ã¥¯¤ò²¼¤²¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£ +¤³¤ÎÃÍ¤Ï C<safe_level> ¤¬MEDIUM °Ê¾å¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë´ØÏ¢¤¬¤¢¤ê¤Þ¤¹¡£ + +=cut + +=item B<$KEEP_ALL> + +=begin original + +Controls whether temporary files and directories should be retained +regardless of any instructions in the program to remove them +automatically. This is useful for debugging but should not be used in +production code. + +=end original + +Controls whether temporary files and directories should be retained +regardless of any instructions in the program to remove them +automatically. This is useful for debugging but should not be used in +production code. +(TBT) + + $File::Temp::KEEP_ALL = 1; + +=begin original + +Default is for files to be removed as requested by the caller. + +=end original + +Default is for files to be removed as requested by the caller. +(TBT) + +=begin original + +In some cases, files will only be retained if this variable is true +when the file is created. This means that you can not create a temporary +file, set this variable and expect the temp file to still be around +when the program exits. + +=end original + +In some cases, files will only be retained if this variable is true +when the file is created. This means that you can not create a temporary +file, set this variable and expect the temp file to still be around +when the program exits. +(TBT) + +=item B<$DEBUG> + +=begin original + +Controls whether debugging messages should be enabled. + +=end original + +Controls whether debugging messages should be enabled. +(TBT) + + $File::Temp::DEBUG = 1; + +=begin original + +Default is for debugging mode to be disabled. + +=end original + +Default is for debugging mode to be disabled. +(TBT) + +=back + +=head1 WARNING + +(·Ù¹ð) + +=begin original + +For maximum security, endeavour always to avoid ever looking at, +touching, or even imputing the existence of the filename. You do not +know that that filename is connected to the same file as the handle +you have, and attempts to check this can only trigger more race +conditions. It's far more secure to use the filehandle alone and +dispense with the filename altogether. + +=end original + +ºÇ¹â¤Î¥»¥¥å¥ê¥Æ¥£¤Î¤¿¤á¤Ë¤Ï¡¢¤¢¤ë¥Õ¥¡¥¤¥ë¤Î¸ºß¤ò¡¢Ä´¤Ù¤¿¤ê¡¢ +ºîÀ®¤·¤¿¤ê¡¢²¾Äꤷ¤¿¤ê¤¹¤ë¤³¤È¤òÈò¤±¤ë¤è¤¦¤ËÅØÎϤ·¤Æ²¼¤µ¤¤¡£ +¤½¤Î¥Õ¥¡¥¤¥ë̾¤¬¤¢¤Ê¤¿¤Î»ý¤Ã¤Æ¤¤¤ë¥Ï¥ó¥É¥ë¤ÈƱ¤¸¥Õ¥¡¥¤¥ë¤Ë +Àܳ¤µ¤ì¤Æ¤¤¤ë¤«¤É¤¦¤«¤Ï¤ï¤«¤ê¤Þ¤»¤ó¤·¡¢ +¤½¤ì¤òÄ´¤Ù¤è¤¦¤È¤¹¤ë¤³¤È¤Ï¤è¤ê¿¤¯¤Î¶¥¹ç¾õÂÖ¤ò°ú¤µ¯¤³¤¹¤À¤±¤Ç¤¹¡£ +¥Õ¥¡¥¤¥ë¥Ï¥ó¥É¥ë¤À¤±¤ò»È¤¤¡¢¥Õ¥¡¥¤¥ë̾¤ÈÀÚ¤êÎ¥¤¹Êý¤¬¤¢¤ë¤«¤Ë°ÂÁ´¤Ç¤¹¡£ + +=begin original + +If you need to pass the handle to something that expects a filename +then, on a unix system, use C<"/dev/fd/" . fileno($fh)> for arbitrary +programs, or more generally C<< "+<=&" . fileno($fh) >> for Perl +programs. You will have to clear the close-on-exec bit on that file +descriptor before passing it to another process. + +=end original + +¥Õ¥¡¥¤¥ë¥Í¡¼¥à¤ò´üÂÔ¤¹¤ë¤â¤Î¤Ë¥Ï¥ó¥É¥ë¤òÅϤ¹É¬Íפ¬¤¢¤ë¤Ê¤é¡¢ +unix ¥·¥¹¥Æ¥à¤Ç¤Ï¡¢Ç¤°Õ¤Î¥×¥í¥°¥é¥à¤ËÂФ·¤Æ C<"/dev/fd/" . fileno($fh)> ¤ò +»È¤Ã¤Æ¤¯¤À¤µ¤¤; +¤Þ¤¿¤Ï¡¢¤è¤ê°ìÈÌŪ¤Ë Perl ¤Î¥×¥í¥°¥é¥à¤Î¤¿¤á¤Ë +C<< "+<=&" . fileno($fh) >> ¤ò»È¤Ã¤Æ²¼¤µ¤¤¡£ +¾¤Î¥×¥í¥»¥¹¤Ë¤½¤ì¤òÅϤ¹Á°¤Ë¥Õ¥¡¥¤¥ëµ½Ò»Ò¤Ç close-on-exec ¥Ó¥Ã¥È +¤ò¥¯¥ê¥¢¤¹¤ëɬÍפ¬¤¢¤ë¤Ç¤½¤·¤ç¤¦¡£ + + use Fcntl qw/F_SETFD F_GETFD/; + fcntl($tmpfh, F_SETFD, 0) + or die "Can't clear close-on-exec flag on temp fh: $!\n"; + +=head2 Temporary files and NFS + +(°ì»þ¥Õ¥¡¥¤¥ë¤È NFS) + +=begin original + +Some problems are associated with using temporary files that reside +on NFS file systems and it is recommended that a local filesystem +is used whenever possible. Some of the security tests will most probably +fail when the temp file is not local. Additionally, be aware that +the performance of I/O operations over NFS will not be as good as for +a local disk. + +=end original + +NFS ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ë¤¢¤ë°ì»þ¥Õ¥¡¥¤¥ë¤ò»È¤¦¤³¤È¤Ë´Ø¤·¤Æ¤Ï¤¤¤¯¤Ä¤«¤Î +ÌäÂ꤬¤¢¤ê¡¢½ÐÍè¤ë¸Â¤ê¥í¡¼¥«¥ë¤Î¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤ò»È¤¦¤³¤È¤¬ +¿ä¾©¤µ¤ì¤Þ¤¹¡£ +¤¤¤¯¤Ä¤«¤Î¥»¥¥å¥ê¥Æ¥£¥Æ¥¹¥È¤Ï¡¢°ì»þ¥Õ¥¡¥¤¥ë¤¬¥í¡¼¥«¥ë¤Ë¤Ê¤¤¾ì¹ç¡¢ +¤Û¤È¤ó¤É¤¿¤¤¤Æ¤¤¼ºÇÔ¤¹¤ë¤Ç¤·¤ç¤¦¡£ +¹¹¤Ë¡¢NFS ±Û¤·¤Î I/O Áàºî¤Ï¥í¡¼¥«¥ë¥Ç¥£¥¹¥¯¤Û¤ÉÎɤ¯¤Ê¤¤¤³¤È¤Ë +µ¤¤ò¤Ä¤±¤Æ²¼¤µ¤¤¡£ + +=head2 Forking + +(fork ¤¹¤ë) + +=begin original + +In some cases files created by File::Temp are removed from within an +END block. Since END blocks are triggered when a child process exits +(unless C<POSIX::_exit()> is used by the child) File::Temp takes care +to only remove those temp files created by a particular process ID. This +means that a child will not attempt to remove temp files created by the +parent process. + +=end original + +¾ì¹ç¤Ë¤è¤Ã¤Æ¤Ï File::Temp ¤Ë¤è¤Ã¤Æºî¤é¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï END ¥Ö¥í¥Ã¥¯¤ÎÃæ¤Ç +ºï½ü¤µ¤ì¤Þ¤¹¡£ +(C<POSIX::_exit()> ¤¬»Ò¤Ç»È¤ï¤ì¤Æ¤¤¤Ê¤¤¸Â¤ê) »Ò¥×¥í¥»¥¹¤Î½ªÎ»»þ¤Ë +END ¥Ö¥í¥Ã¥¯¤¬¼Â¹Ô¤µ¤ì¤ë¤Î¤Ç¡¢ +File::Temp ¤ÏÆÃÄê¤Î¥×¥í¥»¥¹ ID ¤ÇºîÀ®¤µ¤ì¤¿°ì»þ¥Õ¥¡¥¤¥ë¤Î¤ß¤òºï½ü¤¹¤ë¤è¤¦¤Ë +Ãí°Õ¤òʧ¤¤¤Þ¤¹¡£ +¤Ä¤Þ¤ê¡¢»Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤Ë¤è¤Ã¤Æºî¤é¤ì¤¿°ì»þ¥Õ¥¡¥¤¥ë¤ò +ºï½ü¤·¤è¤¦¤È¤·¤Þ¤»¤ó¡£ + +=begin original + +If you are forking many processes in parallel that are all creating +temporary files, you may need to reset the random number seed using +srand(EXPR) in each child else all the children will attempt to walk +through the same set of random file names and may well cause +themselves to give up if they exceed the number of retry attempts. + +=end original + +If you are forking many processes in parallel that are all creating +temporary files, you may need to reset the random number seed using +srand(EXPR) in each child else all the children will attempt to walk +through the same set of random file names and may well cause +themselves to give up if they exceed the number of retry attempts. +(TBT) + +=head2 Directory removal + +(¥Ç¥£¥ì¥¯¥È¥ê¤Îºï½ü) + +=begin original + +Note that if you have chdir'ed into the temporary directory and it is +subsequently cleaned up (either in the END block or as part of object +destruction), then you will get a warning from File::Path::rmtree(). + +=end original + +Note that if you have chdir'ed into the temporary directory and it is +subsequently cleaned up (either in the END block or as part of object +destruction), then you will get a warning from File::Path::rmtree(). +(TBT) + +=head2 BINMODE + +=begin original + +The file returned by File::Temp will have been opened in binary mode +if such a mode is available. If that is not correct, use the C<binmode()> +function to change the mode of the filehandle. + +=end original + +The file returned by File::Temp will have been opened in binary mode +if such a mode is available. If that is not correct, use the C<binmode()> +function to change the mode of the filehandle. +(TBT) + +=begin original + +Note that you can modify the encoding of a file opened by File::Temp +also by using C<binmode()>. + +=end original + +Note that you can modify the encoding of a file opened by File::Temp +also by using C<binmode()>. +(TBT) + +=head1 HISTORY + +(Îò»Ë) + +=begin original + +Originally began life in May 1999 as an XS interface to the system +mkstemp() function. In March 2000, the OpenBSD mkstemp() code was +translated to Perl for total control of the code's +security checking, to ensure the presence of the function regardless of +operating system and to help with portability. The module was shipped +as a standard part of perl from v5.6.1. + +=end original + +¤â¤È¤â¤È¤Ï¡¢1999 ǯ¤Î 5 ·î¤Ë¥·¥¹¥Æ¥à¤Î mkstemp() ´Ø¿ô¤Ø¤Î +XS ¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤È¤·¤ÆÀ¸¤Þ¤ì¤Þ¤·¤¿¡£ +2000 ǯ 5 ·î¤Ë¡¢¥³¡¼¥É¤Î¥»¥¥å¥ê¥Æ¥£¥Á¥§¥Ã¥¯¤ò´°Á´¤ËÀ©¸æ¤¹¤ë¤¿¤á¤Ë¡¢ +OpenBSD ¤Î mkstemp() ¥³¡¼¥É¤¬ Perl ¤Ë°Ü¿¢¤µ¤ì¤Þ¤·¤¿; +¥ª¥Ú¥ì¡¼¥Æ¥£¥ó¥°¥·¥¹¥Æ¥à¤Ë°Í¸¤·¤Ê¤¤´Ø¿ô¤Î¸ºß¤òÊݾڤ¹¤ë¤³¤È¤Ë¤Ê¤ê¡¢ +°Ü¿¢À¤ò½õ¤±¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤·¤¿¡£ +¤³¤Î¥â¥¸¥å¡¼¥ë¤Ï v5.6.1 ¤«¤é perl ¤Îɸ½à¤È¤·¤ÆÇÛÉÛ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£ + +=head1 SEE ALSO + +L<POSIX/tmpnam>, L<POSIX/tmpfile>, L<File::Spec>, L<File::Path> + +=begin original + +See L<IO::File> and L<File::MkTemp>, L<Apache::TempFile> for +different implementations of temporary file handling. + +=end original + +°ì»þ¥Õ¥¡¥¤¥ë¤ò°·¤¦°Û¤Ê¤Ã¤¿¼ÂÁõ¤Ë¤Ä¤¤¤Æ¤Ï L<IO::File>, L<File::MkTemp>, +L<Apache::TempFile> ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£ + +=begin original + +See L<File::Tempdir> for an alternative object-oriented wrapper for +the C<tempdir> function. + +=end original + +See L<File::Tempdir> for an alternative object-oriented wrapper for +the C<tempdir> function. +(TBT) + +=head1 AUTHOR + +Tim Jenness E<lt>tjenn****@cpan*****<gt> + +Copyright (C) 2007-2009 Tim Jenness. +Copyright (C) 1999-2007 Tim Jenness and the UK Particle Physics and +Astronomy Research Council. All Rights Reserved. This program is free +software; you can redistribute it and/or modify it under the same +terms as Perl itself. + +Original Perl implementation loosely based on the OpenBSD C code for +mkstemp(). Thanks to Tom Christiansen for suggesting that this module +should be written and providing ideas for code improvements and +security enhancements. + +=cut + +=begin meta + +Update: SHIRAKATA Kentaro <argra****@ub32*****> (0.12-) +Status: in progress + +=end meta +