home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Doc / libfcntl.tex / libfcntl.txt
LaTeX Document  |  1995-12-17  |  2.3 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% gt2 Textdatei (UNIX) default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 25 20 4d 61 6e 75 61 6c | 20 74 65 78 74 20 62 79 |% Manual| text by|
|00000010| 20 4a 61 61 70 20 56 65 | 72 6d 65 75 6c 65 6e 0a | Jaap Ve|rmeulen.|
|00000020| 5c 73 65 63 74 69 6f 6e | 7b 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000030| 6e 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |n Module| \sectco|
|00000040| 64 65 7b 66 63 6e 74 6c | 7d 7d 0a 5c 62 69 6d 6f |de{fcntl|}}.\bimo|
|00000050| 64 69 6e 64 65 78 7b 66 | 63 6e 74 6c 7d 0a 5c 69 |dindex{f|cntl}.\i|
|00000060| 6e 64 65 78 69 69 7b 5c | 55 4e 49 58 7b 7d 7d 7b |ndexii{\|UNIX{}}{|
|00000070| 66 69 6c 65 20 63 6f 6e | 74 72 6f 6c 7d 0a 5c 69 |file con|trol}.\i|
|00000080| 6e 64 65 78 69 69 7b 5c | 55 4e 49 58 7b 7d 7d 7b |ndexii{\|UNIX{}}{|
|00000090| 49 2f 4f 20 63 6f 6e 74 | 72 6f 6c 7d 0a 54 68 69 |I/O cont|rol}.Thi|
|000000a0| 73 20 6d 6f 64 75 6c 65 | 20 70 65 72 66 6f 72 6d |s module| perform|
|000000b0| 73 20 66 69 6c 65 20 63 | 6f 6e 74 72 6f 6c 20 61 |s file c|ontrol a|
|000000c0| 6e 64 20 49 2f 4f 20 63 | 6f 6e 74 72 6f 6c 20 6f |nd I/O c|ontrol o|
|000000d0| 6e 20 66 69 6c 65 20 64 | 65 73 63 72 69 70 74 6f |n file d|escripto|
|000000e0| 72 73 2e 0a 49 74 20 69 | 73 20 61 6e 20 69 6e 74 |rs..It i|s an int|
|000000f0| 65 72 66 61 63 65 20 74 | 6f 20 74 68 65 20 5c 64 |erface t|o the \d|
|00000100| 66 6e 7b 66 63 6e 74 6c | 28 29 7d 20 61 6e 64 20 |fn{fcntl|()} and |
|00000110| 5c 64 66 6e 7b 69 6f 63 | 74 6c 28 29 7d 20 5c 55 |\dfn{ioc|tl()} \U|
|00000120| 4e 49 58 7b 7d 20 72 6f | 75 74 69 6e 65 73 2e 0a |NIX{} ro|utines..|
|00000130| 46 69 6c 65 20 64 65 73 | 63 72 69 70 74 6f 72 73 |File des|criptors|
|00000140| 20 63 61 6e 20 62 65 20 | 6f 62 74 61 69 6e 65 64 | can be |obtained|
|00000150| 20 77 69 74 68 20 74 68 | 65 20 5c 64 66 6e 7b 66 | with th|e \dfn{f|
|00000160| 69 6c 65 6e 6f 28 29 7d | 20 6d 65 74 68 6f 64 20 |ileno()}| method |
|00000170| 6f 66 20 61 0a 66 69 6c | 65 20 6f 72 20 73 6f 63 |of a.fil|e or soc|
|00000180| 6b 65 74 20 6f 62 6a 65 | 63 74 2e 0a 54 68 65 20 |ket obje|ct..The |
|00000190| 6d 6f 64 75 6c 65 20 64 | 65 66 69 6e 65 73 20 74 |module d|efines t|
|000001a0| 68 65 20 66 6f 6c 6c 6f | 77 69 6e 67 20 66 75 6e |he follo|wing fun|
|000001b0| 63 74 69 6f 6e 73 3a 0a | 5c 72 65 6e 65 77 63 6f |ctions:.|\renewco|
|000001c0| 6d 6d 61 6e 64 7b 5c 69 | 6e 64 65 78 73 75 62 69 |mmand{\i|ndexsubi|
|000001d0| 74 65 6d 7d 7b 28 69 6e | 20 6d 6f 64 75 6c 65 20 |tem}{(in| module |
|000001e0| 73 74 72 75 63 74 29 7d | 0a 5c 62 65 67 69 6e 7b |struct)}|.\begin{|
|000001f0| 66 75 6e 63 64 65 73 63 | 7d 7b 66 63 6e 74 6c 7d |funcdesc|}{fcntl}|
|00000200| 7b 66 64 5c 2c 20 6f 70 | 5c 6f 70 74 69 6f 6e 61 |{fd\, op|\optiona|
|00000210| 6c 7b 5c 2c 20 61 72 67 | 7d 7d 0a 20 20 50 65 72 |l{\, arg|}}. Per|
|00000220| 66 6f 72 6d 20 74 68 65 | 20 72 65 71 75 65 73 74 |form the| request|
|00000230| 65 64 20 6f 70 65 72 61 | 74 69 6f 6e 20 6f 6e 20 |ed opera|tion on |
|00000240| 66 69 6c 65 20 64 65 73 | 63 72 69 70 74 6f 72 20 |file des|criptor |
|00000250| 5c 63 6f 64 65 7b 5c 76 | 61 72 7b 66 64 7d 7d 2e |\code{\v|ar{fd}}.|
|00000260| 0a 20 20 54 68 65 20 6f | 70 65 72 61 74 69 6f 6e |. The o|peration|
|00000270| 20 69 73 20 64 65 66 69 | 6e 65 64 20 62 79 20 5c | is defi|ned by \|
|00000280| 63 6f 64 65 7b 5c 76 61 | 72 7b 6f 70 7d 7d 20 61 |code{\va|r{op}} a|
|00000290| 6e 64 20 69 73 20 6f 70 | 65 72 61 74 69 6e 67 20 |nd is op|erating |
|000002a0| 73 79 73 74 65 6d 0a 20 | 20 64 65 70 65 6e 64 65 |system. | depende|
|000002b0| 6e 74 2e 20 20 54 79 70 | 69 63 61 6c 6c 79 20 74 |nt. Typ|ically t|
|000002c0| 68 65 73 65 20 63 6f 64 | 65 73 20 63 61 6e 20 62 |hese cod|es can b|
|000002d0| 65 20 72 65 74 72 69 65 | 76 65 64 20 66 72 6f 6d |e retrie|ved from|
|000002e0| 20 74 68 65 20 6c 69 62 | 72 61 72 79 0a 20 20 6d | the lib|rary. m|
|000002f0| 6f 64 75 6c 65 20 5c 63 | 6f 64 65 7b 46 43 4e 54 |odule \c|ode{FCNT|
|00000300| 4c 7d 2e 20 54 68 65 20 | 61 72 67 75 6d 65 6e 74 |L}. The |argument|
|00000310| 20 5c 63 6f 64 65 7b 5c | 76 61 72 7b 61 72 67 7d | \code{\|var{arg}|
|00000320| 7d 20 69 73 20 6f 70 74 | 69 6f 6e 61 6c 2c 20 61 |} is opt|ional, a|
|00000330| 6e 64 0a 20 20 64 65 66 | 61 75 6c 74 73 20 74 6f |nd. def|aults to|
|00000340| 20 74 68 65 20 69 6e 74 | 65 67 65 72 20 76 61 6c | the int|eger val|
|00000350| 75 65 20 5c 63 6f 64 65 | 7b 30 7d 2e 20 20 57 68 |ue \code|{0}. Wh|
|00000360| 65 6e 0a 20 20 69 74 20 | 69 73 20 70 72 65 73 65 |en. it |is prese|
|00000370| 6e 74 2c 20 69 74 20 63 | 61 6e 20 65 69 74 68 65 |nt, it c|an eithe|
|00000380| 72 20 62 65 20 61 6e 20 | 69 6e 74 65 67 65 72 20 |r be an |integer |
|00000390| 76 61 6c 75 65 2c 20 6f | 72 20 61 20 73 74 72 69 |value, o|r a stri|
|000003a0| 6e 67 2e 20 20 57 69 74 | 68 0a 20 20 74 68 65 20 |ng. Wit|h. the |
|000003b0| 61 72 67 75 6d 65 6e 74 | 20 6d 69 73 73 69 6e 67 |argument| missing|
|000003c0| 20 6f 72 20 61 6e 20 69 | 6e 74 65 67 65 72 20 76 | or an i|nteger v|
|000003d0| 61 6c 75 65 2c 20 74 68 | 65 20 72 65 74 75 72 6e |alue, th|e return|
|000003e0| 20 76 61 6c 75 65 20 6f | 66 20 74 68 69 73 0a 20 | value o|f this. |
|000003f0| 20 66 75 6e 63 74 69 6f | 6e 20 69 73 20 74 68 65 | functio|n is the|
|00000400| 20 69 6e 74 65 67 65 72 | 20 72 65 74 75 72 6e 20 | integer| return |
|00000410| 76 61 6c 75 65 20 6f 66 | 20 74 68 65 20 72 65 61 |value of| the rea|
|00000420| 6c 20 5c 63 6f 64 65 7b | 66 63 6e 74 6c 28 29 7d |l \code{|fcntl()}|
|00000430| 0a 20 20 63 61 6c 6c 2e | 20 20 57 68 65 6e 20 74 |. call.| When t|
|00000440| 68 65 20 61 72 67 75 6d | 65 6e 74 20 69 73 20 61 |he argum|ent is a|
|00000450| 20 73 74 72 69 6e 67 20 | 69 74 20 72 65 70 72 65 | string |it repre|
|00000460| 73 65 6e 74 73 20 61 20 | 62 69 6e 61 72 79 0a 20 |sents a |binary. |
|00000470| 20 73 74 72 75 63 74 75 | 72 65 2c 20 65 2e 67 2e | structu|re, e.g.|
|00000480| 5c 20 63 72 65 61 74 65 | 64 20 62 79 20 5c 63 6f |\ create|d by \co|
|00000490| 64 65 7b 73 74 72 75 63 | 74 2e 70 61 63 6b 28 29 |de{struc|t.pack()|
|000004a0| 7d 2e 20 54 68 65 20 62 | 69 6e 61 72 79 20 64 61 |}. The b|inary da|
|000004b0| 74 61 20 69 73 0a 20 20 | 63 6f 70 69 65 64 20 74 |ta is. |copied t|
|000004c0| 6f 20 61 20 62 75 66 66 | 65 72 20 77 68 6f 73 65 |o a buff|er whose|
|000004d0| 20 61 64 64 72 65 73 73 | 20 69 73 20 70 61 73 73 | address| is pass|
|000004e0| 65 64 20 74 6f 20 74 68 | 65 20 72 65 61 6c 20 5c |ed to th|e real \|
|000004f0| 63 6f 64 65 7b 66 63 6e | 74 6c 28 29 7d 0a 20 20 |code{fcn|tl()}. |
|00000500| 63 61 6c 6c 2e 20 20 54 | 68 65 20 72 65 74 75 72 |call. T|he retur|
|00000510| 6e 20 76 61 6c 75 65 20 | 61 66 74 65 72 20 61 20 |n value |after a |
|00000520| 73 75 63 63 65 73 73 66 | 75 6c 20 63 61 6c 6c 20 |successf|ul call |
|00000530| 69 73 20 74 68 65 20 63 | 6f 6e 74 65 6e 74 73 20 |is the c|ontents |
|00000540| 6f 66 0a 20 20 74 68 65 | 20 62 75 66 66 65 72 2c |of. the| buffer,|
|00000550| 20 63 6f 6e 76 65 72 74 | 65 64 20 74 6f 20 61 20 | convert|ed to a |
|00000560| 73 74 72 69 6e 67 20 6f | 62 6a 65 63 74 2e 20 20 |string o|bject. |
|00000570| 49 6e 20 63 61 73 65 20 | 74 68 65 0a 20 20 5c 63 |In case |the. \c|
|00000580| 6f 64 65 7b 66 63 6e 74 | 6c 28 29 7d 20 66 61 69 |ode{fcnt|l()} fai|
|00000590| 6c 73 2c 20 61 6e 20 5c | 63 6f 64 65 7b 49 4f 45 |ls, an \|code{IOE|
|000005a0| 72 72 6f 72 7d 20 77 69 | 6c 6c 20 62 65 20 72 61 |rror} wi|ll be ra|
|000005b0| 69 73 65 64 2e 0a 5c 65 | 6e 64 7b 66 75 6e 63 64 |ised..\e|nd{funcd|
|000005c0| 65 73 63 7d 0a 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |esc}.\be|gin{func|
|000005d0| 64 65 73 63 7d 7b 69 6f | 63 74 6c 7d 7b 66 64 5c |desc}{io|ctl}{fd\|
|000005e0| 2c 20 6f 70 5c 2c 20 61 | 72 67 7d 0a 20 20 54 68 |, op\, a|rg}. Th|
|000005f0| 69 73 20 66 75 6e 63 74 | 69 6f 6e 20 69 73 20 69 |is funct|ion is i|
|00000600| 64 65 6e 74 69 63 61 6c | 20 74 6f 20 74 68 65 20 |dentical| to the |
|00000610| 5c 63 6f 64 65 7b 66 63 | 6e 74 6c 28 29 7d 20 66 |\code{fc|ntl()} f|
|00000620| 75 6e 63 74 69 6f 6e 2c | 20 65 78 63 65 70 74 0a |unction,| except.|
|00000630| 20 20 74 68 61 74 20 74 | 68 65 20 6f 70 65 72 61 | that t|he opera|
|00000640| 74 69 6f 6e 73 20 61 72 | 65 20 74 79 70 69 63 61 |tions ar|e typica|
|00000650| 6c 6c 79 20 64 65 66 69 | 6e 65 64 20 69 6e 20 74 |lly defi|ned in t|
|00000660| 68 65 20 6c 69 62 72 61 | 72 79 20 6d 6f 64 75 6c |he libra|ry modul|
|00000670| 65 0a 20 20 5c 63 6f 64 | 65 7b 49 4f 43 54 4c 7d |e. \cod|e{IOCTL}|
|00000680| 2e 0a 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|00000690| 0a 49 66 20 74 68 65 20 | 6c 69 62 72 61 72 79 20 |.If the |library |
|000006a0| 6d 6f 64 75 6c 65 73 20 | 5c 63 6f 64 65 7b 46 43 |modules |\code{FC|
|000006b0| 4e 54 4c 7d 20 6f 72 20 | 5c 63 6f 64 65 7b 49 4f |NTL} or |\code{IO|
|000006c0| 43 54 4c 7d 20 61 72 65 | 20 6d 69 73 73 69 6e 67 |CTL} are| missing|
|000006d0| 2c 20 79 6f 75 0a 63 61 | 6e 20 66 69 6e 64 20 74 |, you.ca|n find t|
|000006e0| 68 65 20 6f 70 63 6f 64 | 65 73 20 69 6e 20 74 68 |he opcod|es in th|
|000006f0| 65 20 43 20 69 6e 63 6c | 75 64 65 20 66 69 6c 65 |e C incl|ude file|
|00000700| 73 20 5c 63 6f 64 65 7b | 73 79 73 2f 66 63 6e 74 |s \code{|sys/fcnt|
|00000710| 6c 7d 20 61 6e 64 0a 5c | 63 6f 64 65 7b 73 79 73 |l} and.\|code{sys|
|00000720| 2f 69 6f 63 74 6c 7d 2e | 20 59 6f 75 20 63 61 6e |/ioctl}.| You can|
|00000730| 20 63 72 65 61 74 65 20 | 74 68 65 20 6d 6f 64 75 | create |the modu|
|00000740| 6c 65 73 20 79 6f 75 72 | 73 65 6c 66 20 77 69 74 |les your|self wit|
|00000750| 68 20 74 68 65 20 68 32 | 70 79 0a 73 63 72 69 70 |h the h2|py.scrip|
|00000760| 74 2c 20 66 6f 75 6e 64 | 20 69 6e 20 74 68 65 20 |t, found| in the |
|00000770| 5c 63 6f 64 65 7b 54 6f | 6f 6c 73 2f 73 63 72 69 |\code{To|ols/scri|
|00000780| 70 74 73 7d 20 64 69 72 | 65 63 74 6f 72 79 2e 0a |pts} dir|ectory..|
|00000790| 5c 73 74 6d 6f 64 69 6e | 64 65 78 7b 46 43 4e 54 |\stmodin|dex{FCNT|
|000007a0| 4c 7d 0a 5c 73 74 6d 6f | 64 69 6e 64 65 78 7b 49 |L}.\stmo|dindex{I|
|000007b0| 4f 43 54 4c 7d 0a 45 78 | 61 6d 70 6c 65 73 20 28 |OCTL}.Ex|amples (|
|000007c0| 61 6c 6c 20 6f 6e 20 61 | 20 53 56 52 34 20 63 6f |all on a| SVR4 co|
|000007d0| 6d 70 6c 69 61 6e 74 20 | 73 79 73 74 65 6d 29 3a |mpliant |system):|
|000007e0| 0a 5c 62 63 6f 64 65 5c | 62 65 67 69 6e 7b 76 65 |.\bcode\|begin{ve|
|000007f0| 72 62 61 74 69 6d 7d 0a | 69 6d 70 6f 72 74 20 73 |rbatim}.|import s|
|00000800| 74 72 75 63 74 2c 20 46 | 43 4e 54 4c 0a 66 69 6c |truct, F|CNTL.fil|
|00000810| 65 20 3d 20 6f 70 65 6e | 28 2e 2e 2e 29 0a 72 76 |e = open|(...).rv|
|00000820| 20 3d 20 66 63 6e 74 6c | 28 66 69 6c 65 2e 66 69 | = fcntl|(file.fi|
|00000830| 6c 65 6e 6f 28 29 2c 20 | 46 43 4e 54 4c 2e 4f 5f |leno(), |FCNTL.O_|
|00000840| 4e 44 45 4c 41 59 2c 20 | 31 29 0a 6c 6f 63 6b 64 |NDELAY, |1).lockd|
|00000850| 61 74 61 20 3d 20 73 74 | 72 75 63 74 2e 70 61 63 |ata = st|ruct.pac|
|00000860| 6b 28 27 68 68 6c 6c 68 | 68 27 2c 20 46 43 4e 54 |k('hhllh|h', FCNT|
|00000870| 4c 2e 46 5f 57 52 4c 43 | 4b 2c 20 30 2c 20 30 2c |L.F_WRLC|K, 0, 0,|
|00000880| 20 30 2c 20 30 2c 20 30 | 29 0a 72 76 20 3d 20 66 | 0, 0, 0|).rv = f|
|00000890| 63 6e 74 6c 28 66 69 6c | 65 2e 66 69 6c 65 6e 6f |cntl(fil|e.fileno|
|000008a0| 28 29 2c 20 46 43 4e 54 | 4c 2e 46 5f 53 45 54 4c |(), FCNT|L.F_SETL|
|000008b0| 4b 57 2c 20 6c 6f 63 6b | 64 61 74 61 29 0a 5c 65 |KW, lock|data).\e|
|000008c0| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 5c 65 63 6f |nd{verba|tim}\eco|
|000008d0| 64 65 0a 4e 6f 74 65 20 | 74 68 61 74 20 69 6e 20 |de.Note |that in |
|000008e0| 74 68 65 20 66 69 72 73 | 74 20 65 78 61 6d 70 6c |the firs|t exampl|
|000008f0| 65 20 74 68 65 20 72 65 | 74 75 72 6e 20 76 61 6c |e the re|turn val|
|00000900| 75 65 20 76 61 72 69 61 | 62 6c 65 20 5c 63 6f 64 |ue varia|ble \cod|
|00000910| 65 7b 72 76 7d 20 77 69 | 6c 6c 0a 68 6f 6c 64 20 |e{rv} wi|ll.hold |
|00000920| 61 6e 20 69 6e 74 65 67 | 65 72 20 76 61 6c 75 65 |an integ|er value|
|00000930| 3b 20 69 6e 20 74 68 65 | 20 73 65 63 6f 6e 64 20 |; in the| second |
|00000940| 65 78 61 6d 70 6c 65 20 | 69 74 20 77 69 6c 6c 20 |example |it will |
|00000950| 68 6f 6c 64 20 61 20 73 | 74 72 69 6e 67 0a 76 61 |hold a s|tring.va|
|00000960| 6c 75 65 2e 0a | |lue.. | |
+--------+-------------------------+-------------------------+--------+--------+