[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fpathconf returns 127 on error
From: |
Andreas Jaeger |
Subject: |
Re: fpathconf returns 127 on error |
Date: |
20 Mar 2001 08:58:22 +0100 |
User-agent: |
Gnus/5.090001 (Oort Gnus v0.01) XEmacs/21.1 (Channel Islands) |
Nathan Straz <address@hidden> writes:
> I'm doing some NEGATIVE testing on fpathconf() and I don't believe what
> I'm seeing. Instead of getting -1 returned, I get 127. The man pages,
> the info pages, and the source all say that -1 should be returned.
> Below is a small test program that shows the type of thing I am trying.
> Calling pathconf() with a non-existent path also returns 127.
>
> I've tried this program on i386 and ia64, glibc 2.2.2, 2.1.2 and 2.1.3.
> I've tried gcc and sgicc (Pro64). Am I doing something so trivially
> wrong that I don't see it?
>
>
> Script started on Mon Mar 19 16:55:03 2001
> address@hidden /extra/code% ldd --version
> ldd (GNU libc) 2.2.2
> Copyright (C) 1999 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> Written by Roland McGrath and Ulrich Drepper.
> address@hidden /extra/code% gcc --version
> 2.95.3
> address@hidden /extra/code% uname -a
> Linux maine 2.4.2 #1 Thu Feb 22 10:48:52 CST 2001 i686 unknown
> address@hidden /extra/code% cat fpathconf.c
> #include <unistd.h>
> #include <errno.h>
> #include <string.h>
> #include <stdio.h>
>
> int main()
> {
> long ret;
>
> ret = fpathconf(-1, _PC_LINK_MAX);
> printf("%hhd, errno: %d %s\n", ret, errno, strerror(errno));
>
> return ret;
> }
> address@hidden /extra/code% make fpathconf
> cc fpathconf.c -o fpathconf
> address@hidden /extra/code% ./fpathconf
> 127, errno: 9 Bad file descriptor
> address@hidden /extra/code% exit
>
> Script done on Mon Mar 19 16:55:40 2001
Here's a patch to fix this. Or should the check instead be:
if (__fstatfs (fd, &fsbuf) < 0)
{
if (errno == ENOSYS)
/* not possible, return the default value. */
return LINUX_LINK_MAX;
/* Some error occured. */
return -1;
}
Andreas
2001-03-20 Andreas Jaeger <address@hidden>
* sysdeps/unix/sysv/linux/fpathconf.c (__fpathconf): Check for bad
file descriptor.
Index: fpathconf.c
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/unix/sysv/linux/fpathconf.c,v
retrieving revision 1.3
diff -u -c -r1.3 fpathconf.c
*** fpathconf.c 2000/06/08 10:04:50 1.3
--- fpathconf.c 2001/03/20 07:55:19
***************
*** 1,5 ****
/* Linux specific extensions to fpathconf.
! Copyright (C) 1991, 95, 96, 98, 99, 2000 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
--- 1,5 ----
/* Linux specific extensions to fpathconf.
! Copyright (C) 1991, 95, 96, 98, 99, 2000, 2001 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
***************
*** 17,22 ****
--- 17,23 ----
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+ #include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <sys/statfs.h>
***************
*** 42,50 ****
/* Determine the filesystem type. */
if (__fstatfs (fd, &fsbuf) < 0)
! /* not possible, return the default value. */
! return LINUX_LINK_MAX;
!
switch (fsbuf.f_type)
{
case EXT2_SUPER_MAGIC:
--- 43,56 ----
/* Determine the filesystem type. */
if (__fstatfs (fd, &fsbuf) < 0)
! {
! if (errno == EBADF)
! return -1;
!
! /* not possible, return the default value. */
! return LINUX_LINK_MAX;
! }
!
switch (fsbuf.f_type)
{
case EXT2_SUPER_MAGIC:
--
Andreas Jaeger
SuSE Labs address@hidden
private address@hidden
http://www.suse.de/~aj