From ca6e1c26e8ac218f83b0cec7616cb26dab979947 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Wed, 16 Feb 2000 19:47:51 +0000 Subject: Fcntl: more O_ constants, move SEEK_ to @EXPORT_OK (tag :seek), add S_I constants (and functions) (tag :mode); refer only to the SEEK_ of Fcntl, not the ones from POSIX or IO::; add SHUT_ to Socket; get trigonometric functions from Math::Trig instead of POSIX. p4raw-id: //depot/cfgperl@5118 --- ext/Fcntl/Fcntl.pm | 201 ++++++++++++++++++++++++++++++++++++++++++--- ext/Fcntl/Fcntl.xs | 225 ++++++++++++++++++++++++++++++++++++++++++++++++--- ext/Socket/Socket.pm | 114 +++++++++++++++++++++++++- ext/Socket/Socket.xs | 18 +++++ perl.h | 28 +++++++ pod/perldelta.pod | 7 +- pod/perlfunc.pod | 86 +++++++++++++++++--- pod/perlopentut.pod | 12 +-- t/lib/syslfs.t | 2 +- 9 files changed, 656 insertions(+), 37 deletions(-) diff --git a/ext/Fcntl/Fcntl.pm b/ext/Fcntl/Fcntl.pm index 43bec9903e..8758359532 100644 --- a/ext/Fcntl/Fcntl.pm +++ b/ext/Fcntl/Fcntl.pm @@ -37,8 +37,21 @@ applications the newer versions of these constants are suggested (O_APPEND, O_ASYNC, O_CREAT, O_DEFER, O_EXCL, O_NDELAY, O_NONBLOCK, O_SYNC, O_TRUNC). -Please refer to your native fcntl() and open() documentation to see -what constants are implemented in your system. +For ease of use also the SEEK_* constants (for seek() and sysseek(), +e.g. SEEK_END) and the S_I* constants (for chmod() and stat()) are +available for import. They can be imported either separately or using +the tags C<:seek> and C<:mode>. + +Please refer to your native fcntl(2), open(2), fseek(3), lseek(2) +(equal to Perl's seek() and sysseek(), respectively), and chmod(2) +documentation to see what constants are implemented in your system. + +See L to learn about the uses of the O_* constants +with sysopen(). + +See L and L about the SEEK_* constants. + +See L about the S_I* constants. =cut @@ -90,31 +103,32 @@ $VERSION = "1.03"; F_WRDNY F_WRLCK O_ACCMODE + O_ALIAS O_APPEND O_ASYNC O_BINARY O_CREAT O_DEFER + O_DIRECT + O_DIRECTORY O_DSYNC O_EXCL O_EXLOCK O_LARGEFILE O_NDELAY O_NOCTTY + O_NOFOLLOW O_NONBLOCK O_RDONLY O_RDWR + O_RSRC O_RSYNC O_SHLOCK O_SYNC + O_TEMPORARY O_TEXT O_TRUNC O_WRONLY - O_ALIAS - O_RSRC - SEEK_SET - SEEK_CUR - SEEK_END ); # Other items we are prepared to export if requested @@ -135,14 +149,183 @@ $VERSION = "1.03"; LOCK_NB LOCK_SH LOCK_UN + S_ISUID S_ISGID S_ISVTX S_ISTXT + _S_IFMT S_IFREG S_IFDIR S_IFLNK + S_IFSOCK S_IFBLK S_IFCHR S_IFIFO S_IFWHT S_ENFMT + S_IRUSR S_IWUSR S_IXUSR S_IRWXU + S_IRGRP S_IWGRP S_IXGRP S_IRWXG + S_IROTH S_IWOTH S_IXOTH S_IRWXO + S_IREAD S_IWRITE S_IEXEC + &S_ISREG &S_ISDIR &S_ISLNK &S_ISSOCK &S_ISBLK &S_ISCHR &S_ISFIFO + &S_ISWHT &S_ISENFMT &S_IFMT &S_IMODE + SEEK_SET + SEEK_CUR + SEEK_END ); # Named groups of exports %EXPORT_TAGS = ( 'flock' => [qw(LOCK_SH LOCK_EX LOCK_NB LOCK_UN)], 'Fcompat' => [qw(FAPPEND FASYNC FCREAT FDEFER FDSYNC FEXCL FLARGEFILE - FNDELAY FNONBLOCK FRSYNC FSYNC FTRUNC)], + FNDELAY FNONBLOCK FRSYNC FSYNC FTRUNC)], + 'seek' => [qw(SEEK_SET SEEK_CUR SEEK_END)], + 'mode' => [qw(S_ISUID S_ISGID S_ISVTX S_ISTXT + _S_IFMT S_IFREG S_IFDIR S_IFLNK + S_IFSOCK S_IFBLK S_IFCHR S_IFIFO S_IFWHT S_ENFMT + S_IRUSR S_IWUSR S_IXUSR S_IRWXU + S_IRGRP S_IWGRP S_IXGRP S_IRWXG + S_IROTH S_IWOTH S_IXOTH S_IRWXO + S_IREAD S_IWRITE S_IEXEC + &S_ISREG &S_ISDIR &S_ISLNK &S_ISSOCK + &S_ISBLK &S_ISCHR &S_ISFIFO + &S_ISWHT &S_ISENFMT + &S_IFMT &S_IMODE + )], ); +sub FD_CLOEXEC (); + +sub F_ALLOCSP (); +sub F_ALLOCSP64 (); +sub F_COMPAT (); +sub F_DUP2FD (); +sub F_DUPFD (); +sub F_EXLCK (); +sub F_FREESP (); +sub F_FREESP64 (); +sub F_FSYNC (); +sub F_FSYNC64 (); +sub F_GETFD (); +sub F_GETFL (); +sub F_GETLK (); +sub F_GETLK64 (); +sub F_GETOWN (); +sub F_NODNY (); +sub F_POSIX (); +sub F_RDACC (); +sub F_RDDNY (); +sub F_RDLCK (); +sub F_RWACC (); +sub F_RWDNY (); +sub F_SETFD (); +sub F_SETFL (); +sub F_SETLK (); +sub F_SETLK64 (); +sub F_SETLKW (); +sub F_SETLKW64 (); +sub F_SETOWN (); +sub F_SHARE (); +sub F_SHLCK (); +sub F_UNLCK (); +sub F_UNSHARE (); +sub F_WRACC (); +sub F_WRDNY (); +sub F_WRLCK (); + +sub O_ACCMODE (); +sub O_ALIAS (); +sub O_APPEND (); +sub O_ASYNC (); +sub O_BINARY (); +sub O_CREAT (); +sub O_DEFER (); +sub O_DIRECT (); +sub O_DIRECTORY (); +sub O_DSYNC (); +sub O_EXCL (); +sub O_EXLOCK (); +sub O_LARGEFILE (); +sub O_NDELAY (); +sub O_NOCTTY (); +sub O_NOFOLLOW (); +sub O_NONBLOCK (); +sub O_RDONLY (); +sub O_RDWR (); +sub O_RSRC (); +sub O_RSYNC (); +sub O_SHLOCK (); +sub O_SYNC (); +sub O_TEMPORARY (); +sub O_TEXT (); +sub O_TRUNC (); +sub O_WRONLY (); + +sub FAPPEND (); +sub FASYNC (); +sub FCREAT (); +sub FDEFER (); +sub FDSYNC (); +sub FEXCL (); +sub FLARGEFILE (); +sub FNDELAY (); +sub FNONBLOCK (); +sub FRSYNC (); +sub FSYNC (); +sub FTRUNC (); + +sub LOCK_EX (); +sub LOCK_NB (); +sub LOCK_SH (); +sub LOCK_UN (); + +sub SEEK_SET (); +sub SEEK_CUR (); +sub SEEK_END (); + +sub S_ISUID (); +sub S_ISGID (); +sub S_ISVTX (); +sub S_ISTXT (); +sub _S_IFMT (); +sub S_IFMT (;$); +sub S_IMODE ($); +sub S_IFREG (); +sub S_IFDIR (); +sub S_IFLNK (); +sub S_IFSOCK (); +sub S_IFBLK (); +sub S_IFCHR (); +sub S_IFIFO (); +sub S_IFWHT (); +sub S_ENFMT (); +sub S_IRUSR (); +sub S_IWUSR (); +sub S_IXUSR (); +sub S_IRWXU (); +sub S_IRGRP (); +sub S_IWGRP (); +sub S_IXGRP (); +sub S_IRWXG (); +sub S_IROTH (); +sub S_IWOTH (); +sub S_IXOTH (); +sub S_IRWXO (); +sub S_IREAD (); +sub S_IWRITE (); +sub S_IEXEC (); + +sub S_IFREG (); +sub S_IFDIR (); +sub S_IFLNK (); +sub S_IFSOCK (); +sub S_IFBLK (); +sub S_IFCHR (); +sub S_IFIFO (); +sub S_IFWHT (); +sub S_IFENFMT (); + +sub S_IFMT (;$) { @_ ? ( $_[0] & _S_IFMT ) : _S_IFMT } +sub S_IMODE ($) { $_[0] & 07777 } + +sub S_ISREG ($) { ( $_[0] & _S_IFMT ) == S_IFREG } +sub S_ISDIR ($) { ( $_[0] & _S_IFMT ) == S_IFDIR } +sub S_ISLNK ($) { ( $_[0] & _S_IFMT ) == S_IFLNK } +sub S_ISSOCK ($) { ( $_[0] & _S_IFMT ) == S_IFSOCK } +sub S_ISBLK ($) { ( $_[0] & _S_IFMT ) == S_IFBLK } +sub S_ISCHR ($) { ( $_[0] & _S_IFMT ) == S_IFCHR } +sub S_ISFIFO ($) { ( $_[0] & _S_IFMT ) == S_IFIFO } +sub S_ISWHT ($) { ( $_[0] & _S_IFMT ) == S_ISWHT } +sub S_ISENFMT ($) { ( $_[0] & _S_IFMT ) == S_ISENFMT } + sub AUTOLOAD { (my $constname = $AUTOLOAD) =~ s/.*:://; my $val = constant($constname, 0); @@ -157,7 +340,7 @@ sub AUTOLOAD { "; } } - *$AUTOLOAD = sub { $val }; + *$AUTOLOAD = sub () { $val }; goto &$AUTOLOAD; } diff --git a/ext/Fcntl/Fcntl.xs b/ext/Fcntl/Fcntl.xs index 08252b6538..8d4a073658 100644 --- a/ext/Fcntl/Fcntl.xs +++ b/ext/Fcntl/Fcntl.xs @@ -45,6 +45,14 @@ constant(char *name, int arg) { errno = 0; switch (*name) { + case '_': + if (strEQ(name, "_S_IFMT")) /* Yes, _S_IFMT. */ +#ifdef S_IFMT + return S_IFMT; +#else + goto not_there; +#endif + break; case 'F': if (strnEQ(name, "F_", 2)) { if (strEQ(name, "F_ALLOCSP")) @@ -413,6 +421,18 @@ constant(char *name, int arg) return O_DEFER; #else goto not_there; +#endif + if (strEQ(name, "O_DIRECT")) +#ifdef O_DIRECT + return O_DIRECT; +#else + goto not_there; +#endif + if (strEQ(name, "O_DIRECTORY")) +#ifdef O_DIRECTORY + return O_DIRECTORY; +#else + goto not_there; #endif if (strEQ(name, "O_DSYNC")) #ifdef O_DSYNC @@ -449,6 +469,12 @@ constant(char *name, int arg) return O_NOCTTY; #else goto not_there; +#endif + if (strEQ(name, "O_NOFOLLOW")) +#ifdef O_NOFOLLOW + return O_NOFOLLOW; +#else + goto not_there; #endif if (strEQ(name, "O_NONBLOCK")) #ifdef O_NONBLOCK @@ -485,6 +511,12 @@ constant(char *name, int arg) return O_SYNC; #else goto not_there; +#endif + if (strEQ(name, "O_TEMPORARY")) +#ifdef O_TEMPORARY + return O_TEMPORARY; +#else + goto not_there; #endif if (strEQ(name, "O_TEXT")) #ifdef O_TEXT @@ -520,25 +552,198 @@ constant(char *name, int arg) goto not_there; break; case 'S': - if (strEQ(name, "SEEK_CUR")) + switch (name[1]) { + case '_': + if (strEQ(name, "S_ISUID")) +#ifdef S_ISUID + return S_ISUID; +#else + goto not_there; +#endif + if (strEQ(name, "S_ISGID")) +#ifdef S_ISGID + return S_ISGID; +#else + goto not_there; +#endif + if (strEQ(name, "S_ISVTX")) +#ifdef S_ISVTX + return S_ISVTX; +#else + goto not_there; +#endif + if (strEQ(name, "S_ISTXT")) +#ifdef S_ISTXT + return S_ISTXT; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFREG")) +#ifdef S_IFREG + return S_IFREG; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFDIR")) +#ifdef S_IFDIR + return S_IFDIR; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFLNK")) +#ifdef S_IFLNK + return S_IFLNK; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFSOCK")) +#ifdef S_IFSOCK + return S_IFSOCK; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFBLK")) +#ifdef S_IFBLK + return S_IFBLK; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFCHR")) +#ifdef S_IFCHR + return S_IFCHR; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFIFO")) +#ifdef S_IFIFO + return S_IFIFO; +#else + goto not_there; +#endif + if (strEQ(name, "S_IFWHT")) +#ifdef S_IFWHT + return S_IFWHT; +#else + goto not_there; +#endif + if (strEQ(name, "S_ENFMT")) +#ifdef S_ENFMT + return S_ENFMT; +#else + goto not_there; +#endif + if (strEQ(name, "S_IRUSR")) +#ifdef S_IRUSR + return S_IRUSR; +#else + goto not_there; +#endif + if (strEQ(name, "S_IWUSR")) +#ifdef S_IWUSR + return S_IWUSR; +#else + goto not_there; +#endif + if (strEQ(name, "S_IXUSR")) +#ifdef S_IXUSR + return S_IXUSR; +#else + goto not_there; +#endif + if (strEQ(name, "S_IRWXU")) +#ifdef S_IRWXU + return S_IRWXU; +#else + goto not_there; +#endif + if (strEQ(name, "S_IRGRP")) +#ifdef S_IRGRP + return S_IRGRP; +#else + goto not_there; +#endif + if (strEQ(name, "S_IWGRP")) +#ifdef S_IWGRP + return S_IWGRP; +#else + goto not_there; +#endif + if (strEQ(name, "S_IXGRP")) +#ifdef S_IXGRP + return S_IXGRP; +#else + goto not_there; +#endif + if (strEQ(name, "S_IRWXG")) +#ifdef S_IRWXG + return S_IRWXG; +#else + goto not_there; +#endif + if (strEQ(name, "S_IROTH")) +#ifdef S_IROTH + return S_IROTH; +#else + goto not_there; +#endif + if (strEQ(name, "S_IWOTH")) +#ifdef S_IWOTH + return S_IWOTH; +#else + goto not_there; +#endif + if (strEQ(name, "S_IXOTH")) +#ifdef S_IXOTH + return S_IXOTH; +#else + goto not_there; +#endif + if (strEQ(name, "S_IRWXO")) +#ifdef S_IRWXO + return S_IRWXO; +#else + goto not_there; +#endif + if (strEQ(name, "S_IREAD")) +#ifdef S_IREAD + return S_IREAD; +#else + goto not_there; +#endif + if (strEQ(name, "S_IWRITE")) +#ifdef S_IWRITE + return S_IWRITE; +#else + goto not_there; +#endif + if (strEQ(name, "S_IEXEC")) +#ifdef S_IEXEC + return S_IEXEC; +#else + goto not_there; +#endif + break; + case 'E': + if (strEQ(name, "SEEK_CUR")) #ifdef SEEK_CUR - return SEEK_CUR; + return SEEK_CUR; #else - goto not_there; + return 1; #endif - if (strEQ(name, "SEEK_END")) + if (strEQ(name, "SEEK_END")) #ifdef SEEK_END - return SEEK_END; + return SEEK_END; #else - goto not_there; + return 2; #endif - if (strEQ(name, "SEEK_SET")) + if (strEQ(name, "SEEK_SET")) #ifdef SEEK_SET - return SEEK_SET; + return SEEK_SET; #else - goto not_there; + return 0; #endif - break; + break; + } } errno = EINVAL; return 0; diff --git a/ext/Socket/Socket.pm b/ext/Socket/Socket.pm index cec13ac47f..f83cb18399 100644 --- a/ext/Socket/Socket.pm +++ b/ext/Socket/Socket.pm @@ -244,6 +244,9 @@ use XSLoader (); SCM_CREDS SCM_RIGHTS SCM_TIMESTAMP + SHUT_RD + SHUT_RDWR + SHUT_WR SOCK_DGRAM SOCK_RAW SOCK_RDM @@ -320,6 +323,115 @@ sub sockaddr_un { } } +sub INADDR_ANY (); +sub INADDR_BROADCAST (); +sub INADDR_LOOPBACK (); +sub INADDR_LOOPBACK (); + +sub AF_802 (); +sub AF_APPLETALK (); +sub AF_CCITT (); +sub AF_CHAOS (); +sub AF_DATAKIT (); +sub AF_DECnet (); +sub AF_DLI (); +sub AF_ECMA (); +sub AF_GOSIP (); +sub AF_HYLINK (); +sub AF_IMPLINK (); +sub AF_INET (); +sub AF_LAT (); +sub AF_MAX (); +sub AF_NBS (); +sub AF_NIT (); +sub AF_NS (); +sub AF_OSI (); +sub AF_OSINET (); +sub AF_PUP (); +sub AF_SNA (); +sub AF_UNIX (); +sub AF_UNSPEC (); +sub AF_X25 (); +sub IOV_MAX (); +sub MSG_BCAST (); +sub MSG_CTLFLAGS (); +sub MSG_CTLIGNORE (); +sub MSG_CTRUNC (); +sub MSG_DONTROUTE (); +sub MSG_DONTWAIT (); +sub MSG_EOF (); +sub MSG_EOR (); +sub MSG_ERRQUEUE (); +sub MSG_FIN (); +sub MSG_MAXIOVLEN (); +sub MSG_MCAST (); +sub MSG_NOSIGNAL (); +sub MSG_OOB (); +sub MSG_PEEK (); +sub MSG_PROXY (); +sub MSG_RST (); +sub MSG_SYN (); +sub MSG_TRUNC (); +sub MSG_URG (); +sub MSG_WAITALL (); +sub PF_802 (); +sub PF_APPLETALK (); +sub PF_CCITT (); +sub PF_CHAOS (); +sub PF_DATAKIT (); +sub PF_DECnet (); +sub PF_DLI (); +sub PF_ECMA (); +sub PF_GOSIP (); +sub PF_HYLINK (); +sub PF_IMPLINK (); +sub PF_INET (); +sub PF_LAT (); +sub PF_MAX (); +sub PF_NBS (); +sub PF_NIT (); +sub PF_NS (); +sub PF_OSI (); +sub PF_OSINET (); +sub PF_PUP (); +sub PF_SNA (); +sub PF_UNIX (); +sub PF_UNSPEC (); +sub PF_X25 (); +sub SCM_CONNECT (); +sub SCM_CREDENTIALS (); +sub SCM_CREDS (); +sub SCM_RIGHTS (); +sub SCM_TIMESTAMP (); +sub SHUT_RD (); +sub SHUT_RDWR (); +sub SHUT_WR (); +sub SOCK_DGRAM (); +sub SOCK_RAW (); +sub SOCK_RDM (); +sub SOCK_SEQPACKET (); +sub SOCK_STREAM (); +sub SOL_SOCKET (); +sub SOMAXCONN (); +sub SO_ACCEPTCONN (); +sub SO_BROADCAST (); +sub SO_DEBUG (); +sub SO_DONTLINGER (); +sub SO_DONTROUTE (); +sub SO_ERROR (); +sub SO_KEEPALIVE (); +sub SO_LINGER (); +sub SO_OOBINLINE (); +sub SO_RCVBUF (); +sub SO_RCVLOWAT (); +sub SO_RCVTIMEO (); +sub SO_REUSEADDR (); +sub SO_SNDBUF (); +sub SO_SNDLOWAT (); +sub SO_SNDTIMEO (); +sub SO_TYPE (); +sub SO_USELOOPBACK (); +sub UIO_MAXIOV (); sub AUTOLOAD { my($constname); @@ -329,7 +441,7 @@ sub AUTOLOAD { my ($pack,$file,$line) = caller; croak "Your vendor has not defined Socket macro $constname, used"; } - eval "sub $AUTOLOAD { $val }"; + eval "sub $AUTOLOAD () { $val }"; goto &$AUTOLOAD; } diff --git a/ext/Socket/Socket.xs b/ext/Socket/Socket.xs index 6abc647c2f..752c3ddb10 100644 --- a/ext/Socket/Socket.xs +++ b/ext/Socket/Socket.xs @@ -661,6 +661,24 @@ constant(char *name, int arg) return SCM_TIMESTAMP; #else goto not_there; +#endif + if (strEQ(name, "SHUT_RD")) +#ifdef SHUT_RD + return SHUT_RD; +#else + return 0; +#endif + if (strEQ(name, "SHUT_RDWR")) +#ifdef SHUT_RDWR + return SHUT_RDWR; +#else + return 2; +#endif + if (strEQ(name, "SHUT_WR")) +#ifdef SHUT_WR + return SHUT_WR; +#else + return 1; #endif if (strEQ(name, "SOCK_DGRAM")) #ifdef SOCK_DGRAM diff --git a/perl.h b/perl.h index 0d3f0b8333..d2e80fa0b5 100644 --- a/perl.h +++ b/perl.h @@ -817,6 +817,10 @@ struct perl_mstats { * in the face of half-implementations.) */ +#ifdef I_SYSMODE +#include +#endif + #ifndef S_IFMT # ifdef _S_IFMT # define S_IFMT _S_IFMT @@ -911,6 +915,30 @@ struct perl_mstats { # define S_ISGID 02000 #endif +#ifndef S_IRWXU +# define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) +#endif + +#ifndef S_IRWXG +# define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP) +#endif + +#ifndef S_IRWXO +# define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH) +#endif + +#ifndef S_IREAD +# define S_IREAD S_IRUSR +#endif + +#ifndef S_IWRITE +# define S_IWRITE S_IWUSR +#endif + +#ifndef S_IEXEC +# define S_IEXEC S_IXUSR +#endif + #ifdef ff_next # undef ff_next #endif diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 46dd6564e4..4761ef03e9 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -1397,8 +1397,11 @@ large file (more than 4GB) access Note that the O_LARGEFILE is automatically/transparently added to sysopen() flags if large file support has been configured), Free/Net/OpenBSD locking behaviour flags F_FLOCK, F_POSIX, Linux F_SHLCK, and O_ACCMODE: the combined mask of -O_RDONLY, O_WRONLY, and O_RDWR. Also SEEK_SET, SEEK_CUR, and SEEK_END -added for one-stop shopping of the seek/sysseek constants. +O_RDONLY, O_WRONLY, and O_RDWR. The seek()/sysseek() constants +SEEK_SET, SEEK_CUR, and SEEK_END are available via the C<:seek> tag. +The chmod()/stat() S_IF* constants and S_IS* functions are available +via the C<:mode> tag. + =item File::Compare diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index e8f4fe0880..3d037438ab 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -423,7 +423,7 @@ modulo the caveats given in L. Returns the arctangent of Y/X in the range -PI to PI. -For the tangent operation, you may use the C +For the tangent operation, you may use the C function, or use the familiar relation: sub tan { sin($_[0]) / cos($_[0]) } @@ -559,6 +559,14 @@ successfully changed. See also L, if all you have is a string. $mode = '0644'; chmod oct($mode), 'foo'; # this is better $mode = 0644; chmod $mode, 'foo'; # this is best +You can also import the symbolic C constants from the Fcntl +module: + + use Fcntl ':mode'; + + chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; + # This is identical to the chmod 0755 of the above example. + =item chomp VARIABLE =item chomp LIST @@ -766,7 +774,7 @@ to check the condition at the top of the loop. Returns the cosine of EXPR (expressed in radians). If EXPR is omitted, takes cosine of C<$_>. -For the inverse cosine operation, you may use the C +For the inverse cosine operation, you may use the C function, or use this relation: sub acos { atan2( sqrt(1 - $_[0] * $_[0]), $_[0] ) } @@ -2319,7 +2327,7 @@ This scalar value is B locale dependent, see L, but instead a Perl builtin. Also see the C module (to convert the second, minutes, hours, ... back to seconds since the stroke of midnight the 1st of January 1970, the value returned by -time()), and the strftime(3) and mktime(3) function available via the +time()), and the strftime(3) and mktime(3) functions available via the POSIX module. To get somewhat similar but locale dependent date strings, set up your locale environment variables appropriately (please see L) and try for example: @@ -3719,9 +3727,8 @@ filehandle. The values for WHENCE are C<0> to set the new position to POSITION, C<1> to set it to the current position plus POSITION, and C<2> to set it to EOF plus POSITION (typically negative). For WHENCE you may use the constants C, C, and C -(start of the file, current position, end of the file) from any of the -modules Fcntl, C, or POSIX. Returns C<1> upon success, -C<0> otherwise. +(start of the file, current position, end of the file) from the Fcntl +module. Returns C<1> upon success, C<0> otherwise. If you want to position file for C or C, don't use C--buffering makes its effect on the file's system position @@ -3970,7 +3977,7 @@ processes. Returns the sine of EXPR (expressed in radians). If EXPR is omitted, returns sine of C<$_>. -For the inverse sine operation, you may use the C +For the inverse sine operation, you may use the C function, or use this relation: sub asin { atan2($_[0], sqrt(1 - $_[0] * $_[0])) } @@ -4491,7 +4498,8 @@ last stat or filetest are returned. Example: print "$file is executable NFS file\n"; } -(This works on machines only for which the device number is negative under NFS.) +(This works on machines only for which the device number is negative +under NFS.) Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a C<"%o"> @@ -4512,6 +4520,66 @@ The File::stat module provides a convenient, by-name access mechanism: $filename, $sb->size, $sb->mode & 07777, scalar localtime $sb->mtime; +You can import symbolic mode constants (C) and functions +(C) from the Fcntl module: + + use Fcntl ':mode'; + + $mode = (stat($filename))[2]; + + $user_rwx = ($mode & S_IRWXU) >> 6; + $group_read = ($mode & S_IRGRP) >> 3; + $other_execute = $mode & S_IXOTH; + + printf "Permissions are %04o\n", S_ISMODE($mode), "\n"; + + $is_setuid = $mode & S_ISUID; + $is_setgid = S_ISDIR($mode); + +You could write the last two using the C<-u> and C<-d> operators. +The commonly available S_IF* constants are + + # Permissions: read, write, execute, for user, group, others. + + S_IRWXU S_IRUSR S_IWUSR S_IXUSR + S_IRWXG S_IRGRP S_IWGRP S_IXGRP + S_IRWXO S_IROTH S_IWOTH S_IXOTH + + # Setuid/Setgid/Stickiness. + + S_ISUID S_ISGID S_ISVTX S_ISTXT + + # File types. Not necessarily all are available on your system. + + S_IFREG S_IFDIR S_IFLNK S_IFBLK S_ISCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT + + # The following are compatibility aliases for S_IRUSR, S_IWUSR, S_IXUSR. + + S_IREAD S_IWRITE S_IEXEC + +and the S_IF* functions are + + S_IFMODE($mode) the part of $mode containg the permission bits + and the setuid/setgid/sticky bits + + S_IFMT($mode) the part of $mode containing the file type + which can be bit-anded with e.g. S_IFREG + or with the following functions + + # The operators -f, -d, -l, -b, -c, -p, and -s. + + S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode) + S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode) + + # No direct -X operator counterpart, but for the first one + # the -g operator is often equivalent. The ENFMT stands for + # record flocking enforcement, a platform-dependent feature. + + S_ISENFMT($mode) S_ISWHT($mode) + +See your native chmod(2) and stat(2) documentation for more details +about the S_* constants. + =item study SCALAR =item study @@ -4751,7 +4819,7 @@ POSITION, C<1> to set the it to the current position plus POSITION, and C<2> to set it to EOF plus POSITION (typically negative). For WHENCE, you may also use the constants C, C, and C (start of the file, current position, end of the file) -from any of the modules Fcntl, C, or POSIX. +from the Fcntl module. Returns the new position, or the undefined value on failure. A position of zero is returned as the string C<"0 but true">; thus C returns diff --git a/pod/perlopentut.pod b/pod/perlopentut.pod index fd32bd9f49..cc9cf63ff2 100644 --- a/pod/perlopentut.pod +++ b/pod/perlopentut.pod @@ -303,11 +303,13 @@ from the Fcntl module, which supplies the following standard flags: O_TRUNC Truncate the file O_NONBLOCK Non-blocking access -Less common flags that are sometimes available on some operating systems -include C, C, C, C, C, -C, C, C, C, C, C -and C. Consult your open(2) manpage or its local equivalent -for details. +Less common flags that are sometimes available on some operating +systems include C, C, C, C, +C, C, C, C, C, +C, C and C. Consult your open(2) +manpage or its local equivalent for details. (Note: starting from +Perl release 5.6 the O_LARGEFILE flag, if available, is automatically +added to the sysopen() flags because large files are the the default.) Here's how to use C to emulate the simple C calls we had before. We'll omit the C<|| die $!> checks for clarity, but make sure diff --git a/t/lib/syslfs.t b/t/lib/syslfs.t index 942bb4dad6..3b040dc6ac 100644 --- a/t/lib/syslfs.t +++ b/t/lib/syslfs.t @@ -11,7 +11,7 @@ BEGIN { print "1..0\n# no 64-bit file offsets\n"; exit(0); } - require Fcntl; import Fcntl; + require Fcntl; import Fcntl qw(/^O_/ /^SEEK_/); } sub bye { -- cgit v1.2.1 From bf0c440fce1b379160a009c06867702b38dd9366 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Wed, 16 Feb 2000 22:29:11 +0000 Subject: HP-UX 64-bitness/largefile fixes. p4raw-id: //depot/cfgperl@5119 --- Configure | 14 +++-- config_h.SH | 6 ++ ext/SDBM_File/sdbm/sdbm.c | 2 +- hints/hpux.sh | 138 +++++++++++++++++++++++----------------------- perl.h | 4 +- 5 files changed, 89 insertions(+), 75 deletions(-) diff --git a/Configure b/Configure index 28d19d6a49..fedea43978 100755 --- a/Configure +++ b/Configure @@ -20,7 +20,7 @@ # $Id: Head.U,v 3.0.1.9 1997/02/28 15:02:09 ram Exp $ # -# Generated on Wed Feb 16 01:07:15 EET 2000 [metaconfig 3.0 PL70] +# Generated on Wed Feb 16 22:28:06 EET 2000 [metaconfig 3.0 PL70] # (with additional metaconfig patches by perlbug@perl.com) cat >/tmp/c1$$ <config.h -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un- #define PERL_XS_APIVERSION "$xs_apiversion" #define PERL_PM_APIVERSION "$pm_apiversion" +/* I_SYSMODE: + * This symbol, if defined, indicates that exists and + * should be included. + */ +#$i_sysmode I_SYSMODE /**/ + /* I_SYS_UTSNAME: * This symbol, if defined, indicates that exists and * should be included. diff --git a/ext/SDBM_File/sdbm/sdbm.c b/ext/SDBM_File/sdbm/sdbm.c index f58f4487c8..64c75cbb20 100644 --- a/ext/SDBM_File/sdbm/sdbm.c +++ b/ext/SDBM_File/sdbm/sdbm.c @@ -39,7 +39,7 @@ extern int errno; extern Malloc_t malloc proto((MEM_SIZE)); extern Free_t free proto((Malloc_t)); -extern Off_t lseek(int, Off_t, int); + #endif /* diff --git a/hints/hpux.sh b/hints/hpux.sh index 467ceb9f89..a03eed6401 100644 --- a/hints/hpux.sh +++ b/hints/hpux.sh @@ -101,11 +101,14 @@ EOM ;; esac -# Even if you use gcc, prefer the HP math library over the GNU one. - -case "`$cc -v 2>&1`" in -"*gcc*" ) test -d /lib/pa1.1 && ccflags="$ccflags -L/lib/pa1.1" ;; -esac +# Backward compatibility (uselonglong is deprecated). +case "$uselonglolong" in +"$define"|true|[yY]*) + case "$use64bits" in + '') use64bits="$define" ;; + esac + ;; +esac # Determine the architecture type of this system. # Keep leading tab below -- Configure Black Magic -- RAM, 03/02/97 @@ -139,6 +142,68 @@ else selecttype='int *' fi +case "$use64bits" in +$define|true|[yY]*) + if [ "$xxOsRevMajor" -lt 11 ]; then + cat <&4 + +64-bit compilation is not supported on HP-UX $xxOsRevMajor. +You need at least HP-UX 11.0. +Cannot continue, aborting. + +EOM + exit 1 + fi + + # Without the 64-bit libc we cannot do much. + if [ ! -f /lib/pa20_64/libc.sl ]; then + cat <&4 + +You do not seem to have the 64-bit libraries in /lib/pa20_64. +Most importantly, I cannot find /lib/pa20_64/libc.sl. +Cannot continue, aborting. + +EOM + exit 1 + fi + + ccflags="$ccflags +DD64" + ldflags="$ldflags +DD64" + loclibpth="$loclibpth /lib/pa20_64" + libscheck='case "`file $xxx`" in +*LP64*|*PA-RISC2.0*) ;; +*) xxx=/no/64-bit$xxx ;; +esac' + ld=/usr/bin/ld + ar=/usr/bin/ar + full_ar=$ar + + # The strict ANSI mode (-Aa) doesn't like the LL suffixes. + case "$ccflags" in + *-Aa*) + echo "(Changing from strict ANSI compilation to extended because of 64-bitness)" + ccflags=`echo $ccflags|sed 's@ -Aa @ -Ae @'` + ;; + esac + + set `echo " $libswanted " | sed -e 's@ dl @ @'` + libswanted="$*" + + case "`$cc -v 2>&1`" in + *gcc*) ccflags="$ccflags -L/lib/pa20_64" ;; + esac + ;; +*) loclibpth="$loclibpth /lib/pa1.1" + case "`$cc -v 2>&1`" in + *gcc*) ccflags="$ccflags -L/lib/pa20_64" ;; + esac + ;; +esac + +case "`getconf KERNEL_BITS 2>/dev/null`" in +*64*) ldflags="$ldflags -Wl,+vnocompatwarnings" ;; +esac + # Remove bad libraries that will cause problems # (This doesn't remove libraries that don't actually exist) # -lld is unneeded (and I can't figure out what it's used for anyway) @@ -289,69 +354,6 @@ EOM esac EOCBU -# This script UU/use64bits.cbu will get 'called-back' by Configure -# after it has prompted the user for whether to use 64 bits. -cat > UU/use64bits.cbu <<'EOCBU' -case "$use64bits" in -$define|true|[yY]*) - if [ "$xxOsRevMajor" -lt 11 ]; then - cat <&4 - -64-bit compilation is not supported on HP-UX $xxOsRevMajor. -You need at least HP-UX 11.0. -Cannot continue, aborting. - -EOM - exit 1 - fi - - # Without the 64-bit libc we cannot do much. - if [ ! -f /lib/pa20_64/libc.sl ]; then - cat <&4 - -You do not seem to have the 64-bit libraries in /lib/pa20_64. -Most importantly, I cannot find /lib/pa20_64/libc.sl. -Cannot continue, aborting. - -EOM - exit 1 - fi - - ld=/usr/bin/ld - ar=/usr/bin/ar - full_ar=$ar - - # The strict ANSI mode (-Aa) doesn't like the LL suffixes. - case "$ccflags" in - *-Aa*) - echo "(Changing from strict ANSI compilation to extended because of 64-bitness)" - ccflags=`echo $ccflags|sed 's@ -Aa @ -Ae @'` - ;; - esac - - set `echo " $libswanted " | sed -e 's@ dl @ @'` - libswanted="$*" - - ;; -esac -EOCBU - -case "$use64bits" in -$define|true|[yY]*) - glibpth="`echo $glibpth|sed 's: /lib/pa1.1 : /lib/pa20_64 :'`" - ccflags="$ccflags +DD64" - ldflags="$ldflags +DD64" - libscheck='case "`file $xxx`" in -*LP64*|*PA-RISC2.0*) ;; -*) xxx=/no/64-bit$xxx ;; -esac' - ;; -esac - -case "`getconf KERNEL_BITS 2>/dev/null`" in -*64*) ldflags="$ldflags -Wl,+vnocompatwarnings" ;; -esac - # This script UU/uselfs.cbu will get 'called-back' by Configure # after it has prompted the user for whether to use 64 bits. cat > UU/uselfs.cbu <<'EOCBU' diff --git a/perl.h b/perl.h index d2e80fa0b5..532afd0531 100644 --- a/perl.h +++ b/perl.h @@ -2083,9 +2083,9 @@ char *crypt (const char*, const char*); # ifndef getenv char *getenv (const char*); # endif /* !getenv */ -#if !defined(EPOC) && !(defined(__hpux) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) +# if !defined(EPOC) && !(defined(__hpux) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) Off_t lseek (int,Off_t,int); -#endif +# endif # endif /* !DONT_DECLARE_STD */ char *getlogin (void); #endif /* !__cplusplus */ -- cgit v1.2.1 From 0f0995aead468478b4762a509b5b43b9cae39825 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Wed, 16 Feb 2000 23:11:04 +0000 Subject: Regularize the use* questions, and replace "Configure *must* be run with -Duse..." with. "can be run". p4raw-id: //depot/cfgperl@5120 --- Configure | 71 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/Configure b/Configure index fedea43978..f134f87a9d 100755 --- a/Configure +++ b/Configure @@ -20,7 +20,7 @@ # $Id: Head.U,v 3.0.1.9 1997/02/28 15:02:09 ram Exp $ # -# Generated on Wed Feb 16 22:28:06 EET 2000 [metaconfig 3.0 PL70] +# Generated on Thu Feb 17 01:07:48 EET 2000 [metaconfig 3.0 PL70] # (with additional metaconfig patches by perlbug@perl.com) cat >/tmp/c1$$ < Date: Thu, 17 Feb 2000 22:09:09 +0000 Subject: Take out the -Wl,-z as we have survice so far without. p4raw-id: //depot/cfgperl@5124 --- hints/hpux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hints/hpux.sh b/hints/hpux.sh index a03eed6401..6ba51cf0b9 100644 --- a/hints/hpux.sh +++ b/hints/hpux.sh @@ -61,7 +61,7 @@ # # Lastly, you may want to include the "-z" HP linker flag so that # reading from a NULL pointer causes a SEGV. -ccflags="$ccflags -D_HPUX_SOURCE -Wl,-z" +ccflags="$ccflags -D_HPUX_SOURCE" # Check if you're using the bundled C compiler. This compiler doesn't support # ANSI C (the -Aa flag) nor can it produce shared libraries. Thus we have -- cgit v1.2.1