📄 posix.3
字号:
of characters in the unparsed portion of the string. TrulyPOSIX-compliant systems set $! ($ERRNO) to indicate a translationerror, so clear $! before calling strtod. However, non-POSIX systemsmay not check for overflow, and therefore will never set $!..Spstrtod should respect any \s-1POSIX\s0 \fI\fIsetlocale()\fI\fR settings..SpTo parse a string \f(CW$str\fR as a floating point number use.Sp.Vb 2\& $! = 0;\& ($num, $n_unparsed) = POSIX::strtod($str);.Ve.SpThe second returned item and $! can be used to check for valid input:.Sp.Vb 3\& if (($str eq \*(Aq\*(Aq) || ($n_unparsed != 0) || $!) {\& die "Non\-numeric input $str" . ($! ? ": $!\en" : "\en");\& }.Ve.SpWhen called in a scalar context strtod returns the parsed number..IP "strtok" 8.IX Item "strtok"\&\fIstrtok()\fR is C\-specific, use regular expressions instead, seeperlre, or \*(L"split\*(R" in perlfunc..IP "strtol" 8.IX Item "strtol"String to (long) integer translation. Returns the parsed number andthe number of characters in the unparsed portion of the string. TrulyPOSIX-compliant systems set $! ($ERRNO) to indicate a translationerror, so clear $! before calling strtol. However, non-POSIX systemsmay not check for overflow, and therefore will never set $!..Spstrtol should respect any \s-1POSIX\s0 \fI\fIsetlocale()\fI\fR settings..SpTo parse a string \f(CW$str\fR as a number in some base \f(CW$base\fR use.Sp.Vb 2\& $! = 0;\& ($num, $n_unparsed) = POSIX::strtol($str, $base);.Ve.SpThe base should be zero or between 2 and 36, inclusive. When the baseis zero or omitted strtol will use the string itself to determine thebase: a leading \*(L"0x\*(R" or \*(L"0X\*(R" means hexadecimal; a leading \*(L"0\*(R" meansoctal; any other leading characters mean decimal. Thus, \*(L"1234\*(R" isparsed as a decimal number, \*(L"01234\*(R" as an octal number, and \*(L"0x1234\*(R"as a hexadecimal number..SpThe second returned item and $! can be used to check for valid input:.Sp.Vb 3\& if (($str eq \*(Aq\*(Aq) || ($n_unparsed != 0) || !$!) {\& die "Non\-numeric input $str" . $! ? ": $!\en" : "\en";\& }.Ve.SpWhen called in a scalar context strtol returns the parsed number..IP "strtoul" 8.IX Item "strtoul"String to unsigned (long) integer translation. \fIstrtoul()\fR is identicalto \fIstrtol()\fR except that \fIstrtoul()\fR only parses unsigned integers. See\&\*(L"strtol\*(R" for details..SpNote: Some vendors supply \fIstrtod()\fR and \fIstrtol()\fR but not \fIstrtoul()\fR.Other vendors that do supply \fIstrtoul()\fR parse \*(L"\-1\*(R" as a valid value..IP "strxfrm" 8.IX Item "strxfrm"String transformation. Returns the transformed string..Sp.Vb 1\& $dst = POSIX::strxfrm( $src );.Ve.SpUsed in conjunction with the \f(CW\*(C`strcoll()\*(C'\fR function, see \*(L"strcoll\*(R"..SpNot really needed since Perl can do this transparently, seeperllocale..IP "sysconf" 8.IX Item "sysconf"Retrieves values of system configurable variables..SpThe following will get the machine's clock speed..Sp.Vb 1\& $clock_ticks = POSIX::sysconf( &POSIX::_SC_CLK_TCK );.Ve.SpReturns \f(CW\*(C`undef\*(C'\fR on failure..IP "system" 8.IX Item "system"This is identical to Perl's builtin \f(CW\*(C`system()\*(C'\fR function, see\&\*(L"system\*(R" in perlfunc..IP "tan" 8.IX Item "tan"This is identical to the C function \f(CW\*(C`tan()\*(C'\fR, returning thetangent of the numerical argument. See also Math::Trig..IP "tanh" 8.IX Item "tanh"This is identical to the C function \f(CW\*(C`tanh()\*(C'\fR, returning thehyperbolic tangent of the numerical argument. See also Math::Trig..IP "tcdrain" 8.IX Item "tcdrain"This is similar to the C function \f(CW\*(C`tcdrain()\*(C'\fR for drainingthe output queue of its argument stream..SpReturns \f(CW\*(C`undef\*(C'\fR on failure..IP "tcflow" 8.IX Item "tcflow"This is similar to the C function \f(CW\*(C`tcflow()\*(C'\fR for controllingthe flow of its argument stream..SpReturns \f(CW\*(C`undef\*(C'\fR on failure..IP "tcflush" 8.IX Item "tcflush"This is similar to the C function \f(CW\*(C`tcflush()\*(C'\fR for flushingthe I/O buffers of its argument stream..SpReturns \f(CW\*(C`undef\*(C'\fR on failure..IP "tcgetpgrp" 8.IX Item "tcgetpgrp"This is identical to the C function \f(CW\*(C`tcgetpgrp()\*(C'\fR for returning theprocess group identifier of the foreground process group of the controllingterminal..IP "tcsendbreak" 8.IX Item "tcsendbreak"This is similar to the C function \f(CW\*(C`tcsendbreak()\*(C'\fR for sendinga break on its argument stream..SpReturns \f(CW\*(C`undef\*(C'\fR on failure..IP "tcsetpgrp" 8.IX Item "tcsetpgrp"This is similar to the C function \f(CW\*(C`tcsetpgrp()\*(C'\fR for setting theprocess group identifier of the foreground process group of the controllingterminal..SpReturns \f(CW\*(C`undef\*(C'\fR on failure..IP "time" 8.IX Item "time"This is identical to Perl's builtin \f(CW\*(C`time()\*(C'\fR functionfor returning the number of seconds since the epoch(whatever it is for the system), see \*(L"time\*(R" in perlfunc..IP "times" 8.IX Item "times"The \fItimes()\fR function returns elapsed realtime since some point in the past(such as system startup), user and system times for this process, and userand system times used by child processes. All times are returned in clockticks..Sp.Vb 1\& ($realtime, $user, $system, $cuser, $csystem) = POSIX::times();.Ve.SpNote: Perl's builtin \f(CW\*(C`times()\*(C'\fR function returns four values, measured inseconds..IP "tmpfile" 8.IX Item "tmpfile"Use method \f(CW\*(C`IO::File::new_tmpfile()\*(C'\fR instead, or see File::Temp..IP "tmpnam" 8.IX Item "tmpnam"Returns a name for a temporary file..Sp.Vb 1\& $tmpfile = POSIX::tmpnam();.Ve.SpFor security reasons, which are probably detailed in your system'sdocumentation for the C library \fItmpnam()\fR function, this interfaceshould not be used; instead see File::Temp..IP "tolower" 8.IX Item "tolower"This is identical to the C function, except that it can apply to a singlecharacter or to a whole string. Consider using the \f(CW\*(C`lc()\*(C'\fR function,see \*(L"lc\*(R" in perlfunc, or the equivalent \f(CW\*(C`\eL\*(C'\fR operator inside doublequotishstrings..IP "toupper" 8.IX Item "toupper"This is identical to the C function, except that it can apply to a singlecharacter or to a whole string. Consider using the \f(CW\*(C`uc()\*(C'\fR function,see \*(L"uc\*(R" in perlfunc, or the equivalent \f(CW\*(C`\eU\*(C'\fR operator inside doublequotishstrings..IP "ttyname" 8.IX Item "ttyname"This is identical to the C function \f(CW\*(C`ttyname()\*(C'\fR for returning thename of the current terminal..IP "tzname" 8.IX Item "tzname"Retrieves the time conversion information from the \f(CW\*(C`tzname\*(C'\fR variable..Sp.Vb 2\& POSIX::tzset();\& ($std, $dst) = POSIX::tzname();.Ve.IP "tzset" 8.IX Item "tzset"This is identical to the C function \f(CW\*(C`tzset()\*(C'\fR for settingthe current timezone based on the environment variable \f(CW\*(C`TZ\*(C'\fR,to be used by \f(CW\*(C`ctime()\*(C'\fR, \f(CW\*(C`localtime()\*(C'\fR, \f(CW\*(C`mktime()\*(C'\fR, and \f(CW\*(C`strftime()\*(C'\fRfunctions..IP "umask" 8.IX Item "umask"This is identical to Perl's builtin \f(CW\*(C`umask()\*(C'\fR functionfor setting (and querying) the file creation permission mask,see \*(L"umask\*(R" in perlfunc..IP "uname" 8.IX Item "uname"Get name of current operating system..Sp.Vb 1\& ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();.Ve.SpNote that the actual meanings of the various fields are notthat well standardized, do not expect any great portability.The \f(CW$sysname\fR might be the name of the operating system,the \f(CW$nodename\fR might be the name of the host, the \f(CW$release\fRmight be the (major) release number of the operating system,the \f(CW$version\fR might be the (minor) release number of theoperating system, and the \f(CW$machine\fR might be a hardware identifier.Maybe..IP "ungetc" 8.IX Item "ungetc"Use method \f(CW\*(C`IO::Handle::ungetc()\*(C'\fR instead..IP "unlink" 8.IX Item "unlink"This is identical to Perl's builtin \f(CW\*(C`unlink()\*(C'\fR functionfor removing files, see \*(L"unlink\*(R" in perlfunc..IP "utime" 8.IX Item "utime"This is identical to Perl's builtin \f(CW\*(C`utime()\*(C'\fR functionfor changing the time stamps of files and directories,see \*(L"utime\*(R" in perlfunc..IP "vfprintf" 8.IX Item "vfprintf"\&\fIvfprintf()\fR is C\-specific, see \*(L"printf\*(R" in perlfunc instead..IP "vprintf" 8.IX Item "vprintf"\&\fIvprintf()\fR is C\-specific, see \*(L"printf\*(R" in perlfunc instead..IP "vsprintf" 8.IX Item "vsprintf"\&\fIvsprintf()\fR is C\-specific, see \*(L"sprintf\*(R" in perlfunc instead..IP "wait" 8.IX Item "wait"This is identical to Perl's builtin \f(CW\*(C`wait()\*(C'\fR function,see \*(L"wait\*(R" in perlfunc..IP "waitpid" 8.IX Item "waitpid"Wait for a child process to change state. This is identical to Perl'sbuiltin \f(CW\*(C`waitpid()\*(C'\fR function, see \*(L"waitpid\*(R" in perlfunc..Sp.Vb 2\& $pid = POSIX::waitpid( \-1, POSIX::WNOHANG );\& print "status = ", ($? / 256), "\en";.Ve.IP "wcstombs" 8.IX Item "wcstombs"This is identical to the C function \f(CW\*(C`wcstombs()\*(C'\fR.Perl does not have any support for the wide and multibytecharacters of the C standards, so this might be a ratheruseless function..IP "wctomb" 8.IX Item "wctomb"This is identical to the C function \f(CW\*(C`wctomb()\*(C'\fR.Perl does not have any support for the wide and multibytecharacters of the C standards, so this might be a ratheruseless function..IP "write" 8.IX Item "write"Write to a file. This uses file descriptors such as those obtained bycalling \f(CW\*(C`POSIX::open\*(C'\fR..Sp.Vb 3\& $fd = POSIX::open( "foo", &POSIX::O_WRONLY );\& $buf = "hello";\& $bytes = POSIX::write( $b, $buf, 5 );.Ve.SpReturns \f(CW\*(C`undef\*(C'\fR on failure..SpSee also \*(L"syswrite\*(R" in perlfunc..SH "CLASSES".IX Header "CLASSES".Sh "POSIX::SigAction".IX Subsection "POSIX::SigAction".IP "new" 8.IX Item "new"Creates a new \f(CW\*(C`POSIX::SigAction\*(C'\fR object which corresponds to the C\&\f(CW\*(C`struct sigaction\*(C'\fR. This object will be destroyed automatically whenit is no longer needed. The first parameter is the handler, a subreference. The second parameter is a \f(CW\*(C`POSIX::SigSet\*(C'\fR object, itdefaults to the empty set. The third parameter contains the\&\f(CW\*(C`sa_flags\*(C'\fR, it defaults to 0..Sp.Vb 2\& $sigset = POSIX::SigSet\->new(SIGINT, SIGQUIT);\& $sigaction = POSIX::SigAction\->new( \e&handler, $sigset, &POSIX::SA_NOCLDSTOP );.Ve.SpThis \f(CW\*(C`POSIX::SigAction\*(C'\fR object is intended for use with the \f(CW\*(C`POSIX::sigaction()\*(C'\fRfunction..IP "handler" 8.IX Item "handler".PD 0.IP "mask" 8.IX Item "mask".IP "flags" 8.IX Item "flags".PDaccessor functions to get/set the values of a SigAction object..Sp.Vb 2\& $sigset = $sigaction\->mask;\& $sigaction\->flags(&POSIX::SA_RESTART);.Ve.IP "safe" 8.IX Item "safe"accessor function for the \*(L"safe signals\*(R" flag of a SigAction object; seeperlipc for general information on safe (a.k.a. \*(L"deferred\*(R") signals. Ifyou wish to handle a signal safely, use this accessor to set the \*(L"safe\*(R" flagin the \f(CW\*(C`POSIX::SigAction\*(C'\fR object:.Sp.Vb 1\& $sigaction\->safe(1);.Ve.SpYou may also examine the \*(L"safe\*(R" flag on the output action object which isfilled in when given as the third parameter to \f(CW\*(C`POSIX::sigaction()\*(C'\fR:.Sp.Vb 4\& sigaction(SIGINT, $new_action, $old_action);\& if ($old_action\->safe) {\& # previous SIGINT handler used safe signals\& }.Ve.Sh "POSIX::SigRt".IX Subsection "POSIX::SigRt".ie n .IP "%SIGRT" 8.el .IP "\f(CW%SIGRT\fR" 8.IX Item "%SIGRT"A hash of the \s-1POSIX\s0 realtime signal handlers. It is an extension ofthe standard \f(CW%SIG\fR, the \f(CW$POSIX::SIGRT\fR{\s-1SIGRTMIN\s0} is roughly equivalentto \f(CW$SIG\fR{\s-1SIGRTMIN\s0}, but the right \s-1POSIX\s0 moves (see below) are made withthe POSIX::SigSet and POSIX::sigaction instead of accessing the \f(CW%SIG\fR..SpYou can set the \f(CW%POSIX::SIG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -