| 1 | .\" -*-nroff-*- |
| 2 | .de VS |
| 3 | .sp 1 |
| 4 | .RS |
| 5 | .nf |
| 6 | .ft B |
| 7 | .. |
| 8 | .de VE |
| 9 | .ft R |
| 10 | .fi |
| 11 | .RE |
| 12 | .sp 1 |
| 13 | .. |
| 14 | .TH fdflags 3 "23 July 1999" "Straylight/Edgeware" "mLib utilities library" |
| 15 | .SH "NAME" |
| 16 | fdflags \- set file and file descriptor flags |
| 17 | .\" @fdflags |
| 18 | .SH "SYNOPSIS" |
| 19 | .nf |
| 20 | .B "#include <mLib/fdflags.h>" |
| 21 | |
| 22 | .BI "int fdflags(int " fd , |
| 23 | .BI " unsigned " fbic ", unsigned " fxor , |
| 24 | .BI " unsigned " fdbic ", unsigned " fdxor ); |
| 25 | .fi |
| 26 | .SH "DESCRIPTION" |
| 27 | .B fdflags |
| 28 | is a convenience function for setting file and file descriptor flags |
| 29 | using |
| 30 | .BR fcntl (2). |
| 31 | .PP |
| 32 | The file flags are read using |
| 33 | .BR F_GETFL , |
| 34 | the new flags are calculated as |
| 35 | .sp 1 |
| 36 | .RS |
| 37 | .I new-flags |
| 38 | = |
| 39 | .BI ( old-flags |
| 40 | .B & |
| 41 | .BI ~ fbic ) |
| 42 | .B ^ |
| 43 | .I fxor |
| 44 | .RE |
| 45 | .sp 1 |
| 46 | and the result written back using |
| 47 | .BR F_SETFL . |
| 48 | .PP |
| 49 | Similarly the file descriptor flags are read using |
| 50 | .BR F_GETFD , |
| 51 | the new flags calculated as |
| 52 | .sp 1 |
| 53 | .RS |
| 54 | .I new-flags |
| 55 | = |
| 56 | .BI ( old-flags |
| 57 | .B & |
| 58 | .BI ~ fdbic ) |
| 59 | .B ^ |
| 60 | .I fdxor |
| 61 | .RE |
| 62 | .sp 1 |
| 63 | and the result written back using |
| 64 | .BR F_SETFD . |
| 65 | .PP |
| 66 | If all went well, |
| 67 | .B fdflags |
| 68 | returns zero; if there was an error, \-1 is returned. |
| 69 | .SH "EXAMPLES" |
| 70 | To set the non-blocking and close-on-exec flags: |
| 71 | .VS |
| 72 | fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC); |
| 73 | .VE |
| 74 | To clear the non-blocking and close-on-exec flags: |
| 75 | .VS |
| 76 | fdflags(fd, O_NONBLOCK, 0, FD_CLOEXEC, 0); |
| 77 | .VE |
| 78 | .sp -1 |
| 79 | .SH "SEE ALSO" |
| 80 | .BR mLib (3). |
| 81 | .SH "AUTHOR" |
| 82 | Mark Wooding, <mdw@distorted.org.uk> |