public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [Linux-ia64] readdir(3) return and error code
@ 2002-05-02 14:55 Jacky Malcles
  2002-05-02 16:42 ` Andreas Schwab
  0 siblings, 1 reply; 2+ messages in thread
From: Jacky Malcles @ 2002-05-02 14:55 UTC (permalink / raw)
  To: linux-ia64

While doing some testing I came across something that is odd for me,
according to readdir(3) EBADF is returned for an invalid argument.

I'm doing a basic call with a bad argument i,e:
    struct dirent *dptr;
    dptr = readdir("test_dir_1");

I thought that the call would return
  errno = 9 : Bad file descriptor and dptr=NULL

 but,

 on an ia32 platform (Linux version 2.4.9-31custom)
I get:

Program received signal SIGSEGV, Segmentation fault.
__readdir (dirp=0x804be44) at ../sysdeps/unix/readdir.c:82
82      ../sysdeps/unix/readdir.c: No such file or directory.
        in ../sysdeps/unix/readdir.c
(gdb) where
#0  __readdir (dirp=0x804be44) at ../sysdeps/unix/readdir.c:82
#1  0x08049113 in main ()
#2  0x40045507 in __libc_start_main (main=0x8049020 <main>, argc=1,
    ubp_av=0xbfffe524, init=0x8048b7c <_init>, fini=0x804bde0 <_fini>,
    rtld_fini=0x4000dc14 <_dl_fini>, stack_end=0xbfffe51c)
    at ../sysdeps/generic/libc-start.c:129
(gdb)

if I do this to an ia64 platform (Linux version 2.4.17)
I get
errno = 9 : Bad file descriptor and dptr=NULL,


so, is there anything wrong with the libc ? 
can or cannot I write a test code like that ?
is it a pb of shell, version ...

thanks for your help,

Email : Jacky.Malcles@bull.net


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Linux-ia64] readdir(3) return and error code
  2002-05-02 14:55 [Linux-ia64] readdir(3) return and error code Jacky Malcles
@ 2002-05-02 16:42 ` Andreas Schwab
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Schwab @ 2002-05-02 16:42 UTC (permalink / raw)
  To: linux-ia64

Jacky Malcles <Jacky.Malcles@bull.net> writes:

|> While doing some testing I came across something that is odd for me,
|> according to readdir(3) EBADF is returned for an invalid argument.

The POSIX standard says:

    The readdir() function may fail if:

    [EBADF] The dirp argument does not refer to an open directory stream.

(Note that readdir() is not _required_ to fail in this case.)

|> I'm doing a basic call with a bad argument i,e:
|>     struct dirent *dptr;
|>     dptr = readdir("test_dir_1");

This is complete garbage, so you cannot expect anything usefull according
to the GIGO priciple.  A string is not remotely anything matching DIR*,
all bets are off.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-05-02 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-02 14:55 [Linux-ia64] readdir(3) return and error code Jacky Malcles
2002-05-02 16:42 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox