@@@ much mess, mostly manpages
[mLib] / sys / fdflags.3.in
diff --git a/sys/fdflags.3.in b/sys/fdflags.3.in
new file mode 100644 (file)
index 0000000..c25fb63
--- /dev/null
@@ -0,0 +1,119 @@
+.\" -*-nroff-*-
+.\"
+.\" Manual for file descriptor flags
+.\"
+.\" (c) 1999, 2001, 2005, 2009, 2023, 2024 Straylight/Edgeware
+.\"
+.
+.\"----- Licensing notice ---------------------------------------------------
+.\"
+.\" This file is part of the mLib utilities library.
+.\"
+.\" mLib is free software: you can redistribute it and/or modify it under
+.\" the terms of the GNU Library General Public License as published by
+.\" the Free Software Foundation; either version 2 of the License, or (at
+.\" your option) any later version.
+.\"
+.\" mLib is distributed in the hope that it will be useful, but WITHOUT
+.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+.\" FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
+.\" License for more details.
+.\"
+.\" You should have received a copy of the GNU Library General Public
+.\" License along with mLib.  If not, write to the Free Software
+.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+.\" USA.
+.
+.\"--------------------------------------------------------------------------
+.so ../defs.man \" @@@PRE@@@
+.
+.\"--------------------------------------------------------------------------
+.TH fdflags 3mLib "23 July 1999" "Straylight/Edgeware" "mLib utilities library"
+.\" @fdflags
+.
+.\"--------------------------------------------------------------------------
+.SH "NAME"
+fdflags \- set file and file descriptor flags
+.
+.\"--------------------------------------------------------------------------
+.SH "SYNOPSIS"
+.
+.nf
+.B "#include <mLib/fdflags.h>"
+.PP
+.ta \w'\fBint fdflags('u
+.BI "int fdflags(int " fd ,
+.BI "  unsigned " fbic ", unsigned " fxor ,
+.BI "  unsigned " fdbic ", unsigned " fdxor );
+.fi
+.
+.\"--------------------------------------------------------------------------
+.SH "DESCRIPTION"
+.
+.B fdflags
+is a convenience function for setting file and file descriptor flags
+using
+.BR fcntl (2).
+.PP
+The file flags are read using
+.BR F_GETFL ,
+the new flags are calculated as
+.sp 1
+.RS
+.I new-flags
+=
+.BI ( old-flags
+.B &
+.BI ~ fbic )
+.B ^
+.I fxor
+.RE
+.sp 1
+and the result written back using
+.BR F_SETFL .
+.PP
+Similarly the file descriptor flags are read using
+.BR F_GETFD ,
+the new flags calculated as
+.sp 1
+.RS
+.I new-flags
+=
+.BI ( old-flags
+.B &
+.BI ~ fdbic )
+.B ^
+.I fdxor
+.RE
+.sp 1
+and the result written back using
+.BR F_SETFD .
+.PP
+If all went well,
+.B fdflags
+returns zero; if there was an error, \-1 is returned.
+.
+.\"--------------------------------------------------------------------------
+.SH "EXAMPLES"
+.
+To set the non-blocking and close-on-exec flags:
+.VS
+fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
+.VE
+To clear the non-blocking and close-on-exec flags:
+.VS
+fdflags(fd, O_NONBLOCK, 0, FD_CLOEXEC, 0);
+.VE
+.sp -1
+.
+.\"--------------------------------------------------------------------------
+.SH "SEE ALSO"
+.
+.BR mLib (3).
+.
+.\"--------------------------------------------------------------------------
+.SH "AUTHOR"
+.
+Mark Wooding, <mdw@distorted.org.uk>
+.
+.\"----- That's all, folks --------------------------------------------------