diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-10-16 16:10:25 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-10-16 16:10:25 +0000 |
commit | b5dc7a0276055951ac0b73863e0c496d9ada68bc (patch) | |
tree | 0e0cdad7c7a977b792550bd52c2e59f64bd1ea91 /lib | |
parent | fe83cf65234b817450b4b23fcb27269821db2a84 (diff) |
Implement isfdtype(3) as per the POSIX.1g draft; requested by David Hill
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 22 | ||||
-rw-r--r-- | lib/libc/gen/isfdtype.3 | 82 | ||||
-rw-r--r-- | lib/libc/gen/isfdtype.c | 37 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 | ||||
-rw-r--r-- | lib/libc_r/shlib_version | 2 |
5 files changed, 132 insertions, 13 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 19bb3710012..2508d80174d 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.33 2002/06/08 04:52:55 fgsch Exp $ +# $OpenBSD: Makefile.inc,v 1.34 2002/10/16 16:10:24 millert Exp $ # gen sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/gen ${LIBCSRCDIR}/gen @@ -9,8 +9,8 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.c login_cap.c basename.c \ errno.c exec.c fnmatch.c fstab.c ftok.c fts.c getbsize.c getcap.c \ getcwd.c getdomainname.c getgrent.c getgrouplist.c gethostname.c \ getloadavg.c getlogin.c getmntinfo.c getnetgrent.c getpagesize.c \ - getpwent.c getttyent.c getusershell.c glob.c initgroups.c \ - isatty.c isctype.c lockf.c login_cap.c nice.c nlist.c opendir.c \ + getpwent.c getttyent.c getusershell.c glob.c initgroups.c isatty.c \ + isctype.c isfdtype.c lockf.c login_cap.c nice.c nlist.c opendir.c \ pause.c popen.c psignal.c pw_dup.c pwcache.c raise.c readdir.c \ readpassphrase.c rewinddir.c scandir.c seekdir.c setdomainname.c \ sethostname.c setjmperr.c setmode.c setproctitle.c siginterrupt.c \ @@ -49,14 +49,14 @@ MAN+= alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 confstr.3 \ getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 getmntinfo.3 \ getnetgrent.3 getpagesize.3 getpass.3 getpwent.3 getttyent.3 \ getusershell.3 glob.3 initgroups.3 isalnum.3 isalpha.3 isascii.3 \ - isblank.3 iscntrl.3 isdigit.3 isgraph.3 isinf.3 islower.3 isprint.3 \ - ispunct.3 isspace.3 isupper.3 isxdigit.3 ldexp.3 lockf.3 login_cap.3 \ - modf.3 nice.3 nlist.3 pause.3 popen.3 psignal.3 pw_dup.3 pwcache.3 \ - raise.3 readpassphrase.3 scandir.3 setjmp.3 setmode.3 setproctitle.3 \ - siginterrupt.3 signal.3 sigsetops.3 sleep.3 sysconf.3 sysctl.3 \ - strtofflags.3 syslog.3 time.3 times.3 timezone.3 toascii.3 tolower.3 \ - toupper.3 ttyname.3 ualarm.3 uname.3 unvis.3 usleep.3 utime.3 \ - valloc.3 vis.3 + isblank.3 iscntrl.3 isdigit.3 isfdtype.3 isgraph.3 isinf.3 islower.3 \ + isprint.3 ispunct.3 isspace.3 isupper.3 isxdigit.3 ldexp.3 lockf.3 \ + login_cap.3 modf.3 nice.3 nlist.3 pause.3 popen.3 psignal.3 pw_dup.3 \ + pwcache.3 raise.3 readpassphrase.3 scandir.3 setjmp.3 setmode.3 \ + setproctitle.3 siginterrupt.3 signal.3 sigsetops.3 sleep.3 sysconf.3 \ + sysctl.3 strtofflags.3 syslog.3 time.3 times.3 timezone.3 toascii.3 \ + tolower.3 toupper.3 ttyname.3 ualarm.3 uname.3 unvis.3 usleep.3 \ + utime.3 valloc.3 vis.3 MLINKS+=auth_subr.3 auth_open.3 auth_subr.3 auth_call.3 auth_subr.3 \ auth_challenge.3 auth_subr.3 auth_check_change.3 auth_subr.3 \ diff --git a/lib/libc/gen/isfdtype.3 b/lib/libc/gen/isfdtype.3 new file mode 100644 index 00000000000..3a1f5bebe1d --- /dev/null +++ b/lib/libc/gen/isfdtype.3 @@ -0,0 +1,82 @@ +.\" +.\" Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $OpenBSD: isfdtype.3,v 1.1 2002/10/16 16:10:24 millert Exp $ +.\" +.Dd October 15, 2002 +.Dt ISFDTYPE 3 +.Os +.Sh NAME +.Nm isfdtype +.Nd determine whether a file descriptor is of a specific type +.Sh SYNOPSIS +.Fd #include <sys/stat.h> +.Ft int +.Fn isfdtype "int fd" "int fdtype" +.Sh DESCRIPTION +The +.Fn isfdtype +function checks whether or not the file descriptor +.Fa fd +is of type +.Fa fdtype . +.Pp +A list of possible file types may be found in +.Xr stat 2 +and the +.Cm <sys/stat.h> +include file. +.Sh RETURN VALUES +The +.Fn isfdtype +function returns 1 if +.Fa fd +is of type +.Fa fdtype +and 0 if it is not. +If +.Fn isfdtype +fails, a value of \-1 is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +The following error codes may be set in +.Va errno : +.Bl -tag -width Er +.It Bq Er EBADF +.Fa fd +is not a valid open file descriptor. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr stat 2 +.Sh STANDARDS +The +.Fn isfdtype +function is expected to conform to \*(Px 1003.1g. +.Sh HISTORY +The +.Fn isfdtype +function first appeared in +.Ox 3.3 . diff --git a/lib/libc/gen/isfdtype.c b/lib/libc/gen/isfdtype.c new file mode 100644 index 00000000000..237dd8ae892 --- /dev/null +++ b/lib/libc/gen/isfdtype.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/stat.h> + +int +isfdtype(int fd, int fdtype) +{ + struct stat sb; + + if (fstat(fd, &sb) != 0) + return (-1); + + return ((sb.st_mode & S_IFMT) == fdtype); +} diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index a3973fd5093..a3c1bf374a9 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,2 +1,2 @@ major=28 -minor=5 # note: remember to update minor in ../libc_r/shlib_version +minor=6 # note: remember to update minor in ../libc_r/shlib_version diff --git a/lib/libc_r/shlib_version b/lib/libc_r/shlib_version index dbad0b945e1..c228c1690ed 100644 --- a/lib/libc_r/shlib_version +++ b/lib/libc_r/shlib_version @@ -1,2 +1,2 @@ major=6 -minor=5 +minor=6 |