[PATCH] libc/sysdeps/linux/common/isfdtype.c: add support for isfdtype()

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Fri Aug 2 12:16:56 UTC 2013


On 28 July 2013 15:08, Anthony G. Basile <basile at opensource.dyc.edu> wrote:
> From: "Anthony G. Basile" <blueness at gentoo.org>
>
> isfdtype(int fd, int fdtype) check whether a file descriptor fd is
> of type fdtype, where the types are defined in stat(2).  It is
> supported in glibc and BSD, and used by utilities such as acpid.

Failed to build for !LFS and we have stubs.c for (syscall)stubs.
Also moved it to some more appropriate directory.
Finally, if a symbol is not used internally we do not need to
play tricks to avoid relocations, so i have removed this as well.

Tweaked accordingly and installed, please try current master.
Thanks!
>
> Signed-off-by: Anthony G. Basile <blueness at gentoo.org>
> ---
>  include/sys/socket.h                 |  1 +
>  libc/sysdeps/linux/common/isfdtype.c | 43 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 44 insertions(+)
>  create mode 100644 libc/sysdeps/linux/common/isfdtype.c
>
> diff --git a/include/sys/socket.h b/include/sys/socket.h
> index 8642312..a9d5804 100644
> --- a/include/sys/socket.h
> +++ b/include/sys/socket.h
> @@ -261,6 +261,7 @@ extern int sockatmark (int __fd) __THROW;
>     returns 1 if FD is open on an object of the indicated type, 0 if not,
>     or -1 for errors (setting errno).  */
>  extern int isfdtype (int __fd, int __fdtype) __THROW;
> +libc_hidden_proto(isfdtype)
>  #endif
>
>  __END_DECLS
> diff --git a/libc/sysdeps/linux/common/isfdtype.c b/libc/sysdeps/linux/common/isfdtype.c
> new file mode 100644
> index 0000000..500b5f2
> --- /dev/null
> +++ b/libc/sysdeps/linux/common/isfdtype.c
> @@ -0,0 +1,43 @@
> +/* Determine whether descriptor has given property.
> +   Copyright (C) 1996-2013 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library 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
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <errno.h>
> +#include <sys/stat.h>
> +#include <sys/socket.h>
> +#include <sys/types.h>
> +
> +int
> +isfdtype (int fildes, int fdtype)
> +{
> +#ifdef __USE_MISC
> +  struct stat64 st;
> +  int result;
> +
> +  {
> +    int save_error = errno;
> +    result = fstat64 (fildes, &st);
> +    __set_errno (save_error);
> +  }
> +
> +  return result ?: (st.st_mode & S_IFMT) == (mode_t) fdtype;
> +#else
> +  __set_errno (ENOSYS);
> +  return -1;
> +#endif
> +}
> +libc_hidden_def(isfdtype)
> --
> 1.8.1.5
>
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://lists.busybox.net/mailman/listinfo/uclibc


More information about the uClibc mailing list