Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
5.3 KiB

  1. package Fcntl;
  2. =head1 NAME
  3. Fcntl - load the C Fcntl.h defines
  4. =head1 SYNOPSIS
  5. use Fcntl;
  6. use Fcntl qw(:DEFAULT :flock);
  7. =head1 DESCRIPTION
  8. This module is just a translation of the C F<fcntl.h> file.
  9. Unlike the old mechanism of requiring a translated F<fcntl.ph>
  10. file, this uses the B<h2xs> program (see the Perl source distribution)
  11. and your native C compiler. This means that it has a
  12. far more likely chance of getting the numbers right.
  13. =head1 NOTE
  14. Only C<#define> symbols get translated; you must still correctly
  15. pack up your own arguments to pass as args for locking functions, etc.
  16. =head1 EXPORTED SYMBOLS
  17. By default your system's F_* and O_* constants (eg, F_DUPFD and
  18. O_CREAT) and the FD_CLOEXEC constant are exported into your namespace.
  19. You can request that the flock() constants (LOCK_SH, LOCK_EX, LOCK_NB
  20. and LOCK_UN) be provided by using the tag C<:flock>. See L<Exporter>.
  21. You can request that the old constants (FAPPEND, FASYNC, FCREAT,
  22. FDEFER, FEXCL, FNDELAY, FNONBLOCK, FSYNC, FTRUNC) be provided for
  23. compatibility reasons by using the tag C<:Fcompat>. For new
  24. applications the newer versions of these constants are suggested
  25. (O_APPEND, O_ASYNC, O_CREAT, O_DEFER, O_EXCL, O_NDELAY, O_NONBLOCK,
  26. O_SYNC, O_TRUNC).
  27. For ease of use also the SEEK_* constants (for seek() and sysseek(),
  28. e.g. SEEK_END) and the S_I* constants (for chmod() and stat()) are
  29. available for import. They can be imported either separately or using
  30. the tags C<:seek> and C<:mode>.
  31. Please refer to your native fcntl(2), open(2), fseek(3), lseek(2)
  32. (equal to Perl's seek() and sysseek(), respectively), and chmod(2)
  33. documentation to see what constants are implemented in your system.
  34. See L<perlopentut> to learn about the uses of the O_* constants
  35. with sysopen().
  36. See L<perlfunc/seek> and L<perlfunc/sysseek> about the SEEK_* constants.
  37. See L<perlfunc/stat> about the S_I* constants.
  38. =cut
  39. use strict;
  40. our($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $AUTOLOAD);
  41. require Exporter;
  42. use XSLoader ();
  43. @ISA = qw(Exporter);
  44. BEGIN {
  45. $VERSION = "1.06";
  46. }
  47. # Items to export into callers namespace by default
  48. # (move infrequently used names to @EXPORT_OK below)
  49. @EXPORT =
  50. qw(
  51. FD_CLOEXEC
  52. F_ALLOCSP
  53. F_ALLOCSP64
  54. F_COMPAT
  55. F_DUP2FD
  56. F_DUPFD
  57. F_EXLCK
  58. F_FREESP
  59. F_FREESP64
  60. F_FSYNC
  61. F_FSYNC64
  62. F_GETFD
  63. F_GETFL
  64. F_GETLK
  65. F_GETLK64
  66. F_GETOWN
  67. F_NODNY
  68. F_POSIX
  69. F_RDACC
  70. F_RDDNY
  71. F_RDLCK
  72. F_RWACC
  73. F_RWDNY
  74. F_SETFD
  75. F_SETFL
  76. F_SETLK
  77. F_SETLK64
  78. F_SETLKW
  79. F_SETLKW64
  80. F_SETOWN
  81. F_SHARE
  82. F_SHLCK
  83. F_UNLCK
  84. F_UNSHARE
  85. F_WRACC
  86. F_WRDNY
  87. F_WRLCK
  88. O_ACCMODE
  89. O_ALIAS
  90. O_APPEND
  91. O_ASYNC
  92. O_BINARY
  93. O_CREAT
  94. O_DEFER
  95. O_DIRECT
  96. O_DIRECTORY
  97. O_DSYNC
  98. O_EXCL
  99. O_EXLOCK
  100. O_LARGEFILE
  101. O_NDELAY
  102. O_NOCTTY
  103. O_NOFOLLOW
  104. O_NOINHERIT
  105. O_NONBLOCK
  106. O_RANDOM
  107. O_RAW
  108. O_RDONLY
  109. O_RDWR
  110. O_RSRC
  111. O_RSYNC
  112. O_SEQUENTIAL
  113. O_SHLOCK
  114. O_SYNC
  115. O_TEMPORARY
  116. O_TEXT
  117. O_TRUNC
  118. O_WRONLY
  119. );
  120. # Other items we are prepared to export if requested
  121. @EXPORT_OK = qw(
  122. DN_ACCESS
  123. DN_ATTRIB
  124. DN_CREATE
  125. DN_DELETE
  126. DN_MODIFY
  127. DN_MULTISHOT
  128. DN_RENAME
  129. FAPPEND
  130. FASYNC
  131. FCREAT
  132. FDEFER
  133. FDSYNC
  134. FEXCL
  135. FLARGEFILE
  136. FNDELAY
  137. FNONBLOCK
  138. FRSYNC
  139. FSYNC
  140. FTRUNC
  141. F_GETLEASE
  142. F_GETSIG
  143. F_NOTIFY
  144. F_SETLEASE
  145. F_SETSIG
  146. LOCK_EX
  147. LOCK_MAND
  148. LOCK_NB
  149. LOCK_READ
  150. LOCK_RW
  151. LOCK_SH
  152. LOCK_UN
  153. LOCK_WRITE
  154. O_IGNORE_CTTY
  155. O_NOATIME
  156. O_NOLINK
  157. O_NOTRANS
  158. SEEK_CUR
  159. SEEK_END
  160. SEEK_SET
  161. S_IFSOCK S_IFBLK S_IFCHR S_IFIFO S_IFWHT S_ENFMT
  162. S_IREAD S_IWRITE S_IEXEC
  163. S_IRGRP S_IWGRP S_IXGRP S_IRWXG
  164. S_IROTH S_IWOTH S_IXOTH S_IRWXO
  165. S_IRUSR S_IWUSR S_IXUSR S_IRWXU
  166. S_ISUID S_ISGID S_ISVTX S_ISTXT
  167. _S_IFMT S_IFREG S_IFDIR S_IFLNK
  168. &S_ISREG &S_ISDIR &S_ISLNK &S_ISSOCK &S_ISBLK &S_ISCHR &S_ISFIFO
  169. &S_ISWHT &S_ISENFMT &S_IFMT &S_IMODE
  170. );
  171. # Named groups of exports
  172. %EXPORT_TAGS = (
  173. 'flock' => [qw(LOCK_SH LOCK_EX LOCK_NB LOCK_UN)],
  174. 'Fcompat' => [qw(FAPPEND FASYNC FCREAT FDEFER FDSYNC FEXCL FLARGEFILE
  175. FNDELAY FNONBLOCK FRSYNC FSYNC FTRUNC)],
  176. 'seek' => [qw(SEEK_SET SEEK_CUR SEEK_END)],
  177. 'mode' => [qw(S_ISUID S_ISGID S_ISVTX S_ISTXT
  178. _S_IFMT S_IFREG S_IFDIR S_IFLNK
  179. S_IFSOCK S_IFBLK S_IFCHR S_IFIFO S_IFWHT S_ENFMT
  180. S_IRUSR S_IWUSR S_IXUSR S_IRWXU
  181. S_IRGRP S_IWGRP S_IXGRP S_IRWXG
  182. S_IROTH S_IWOTH S_IXOTH S_IRWXO
  183. S_IREAD S_IWRITE S_IEXEC
  184. S_ISREG S_ISDIR S_ISLNK S_ISSOCK
  185. S_ISBLK S_ISCHR S_ISFIFO
  186. S_ISWHT S_ISENFMT
  187. S_IFMT S_IMODE
  188. )],
  189. );
  190. # Force the constants to become inlined
  191. BEGIN {
  192. XSLoader::load 'Fcntl', $VERSION;
  193. }
  194. sub S_IFMT { @_ ? ( $_[0] & _S_IFMT() ) : _S_IFMT() }
  195. sub S_IMODE { $_[0] & 07777 }
  196. sub S_ISREG { ( $_[0] & _S_IFMT() ) == S_IFREG() }
  197. sub S_ISDIR { ( $_[0] & _S_IFMT() ) == S_IFDIR() }
  198. sub S_ISLNK { ( $_[0] & _S_IFMT() ) == S_IFLNK() }
  199. sub S_ISSOCK { ( $_[0] & _S_IFMT() ) == S_IFSOCK() }
  200. sub S_ISBLK { ( $_[0] & _S_IFMT() ) == S_IFBLK() }
  201. sub S_ISCHR { ( $_[0] & _S_IFMT() ) == S_IFCHR() }
  202. sub S_ISFIFO { ( $_[0] & _S_IFMT() ) == S_IFIFO() }
  203. sub S_ISWHT { ( $_[0] & _S_IFMT() ) == S_IFWHT() }
  204. sub S_ISENFMT { ( $_[0] & _S_IFMT() ) == S_IFENFMT() }
  205. sub AUTOLOAD {
  206. (my $constname = $AUTOLOAD) =~ s/.*:://;
  207. die "&Fcntl::constant not defined" if $constname eq 'constant';
  208. my ($error, $val) = constant($constname);
  209. if ($error) {
  210. my (undef,$file,$line) = caller;
  211. die "$error at $file line $line.\n";
  212. }
  213. no strict 'refs';
  214. *$AUTOLOAD = sub { $val };
  215. goto &$AUTOLOAD;
  216. }
  217. 1;