On Thursday 22 March 2007 12:29, Joerg Schilling wrote:
> Stefan Teleman <[EMAIL PROTECTED]> wrote:
> > On Thursday 22 March 2007 10:21, Joerg Schilling wrote:
> > > But BTW: dirfd() would be just:
> > >
> > > #define dirfd(dp) (dp)->dd_fd
> >
> > This works really well when (dp) is NULL.
>
> ???
>
> Garbage in -> garbage out.
>
> Do not expect to get useful results in case that you
> use useless input.

/* testnulldir.c */

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

#define dirfd(dp)    (dp)->dd_fd
static const char* dirname = "/this/baby/does/not/exist";

int
main(int argc, char* argv[])
{
    DIR* dir;
    int fd;

    fd = dirfd(opendir(dirname));
    (void) fprintf(stderr, "dirname fd = %ld\n", fd);
    return 0;
}

[EMAIL PROTECTED]/tmp][03/22/2007 12:26:45][242]>> echo $CFLAGS
-Xc -erroff=%all -errshort=full -errfmt=error -errwarn=%none -xO3 -s -xjobs=2 
-xregs=no%frameptr -dalign -xprefetch=auto 
-xprefetch_auto_type=indirect_array_access -xprefetch_level=3 -xbuiltin=%all 
-xcsi -xinline=%auto -xustr=ascii_utf16_ushort -z 
combreloc -z redlocsym -z nodefaultlib -z now -z rescan -z 
absexec -xipo=0 -xildoff -xldscope=symbolic -xrestrict=%all -xF=%none 
-xalias_level=std -xsafe=mem -xthreadvar -lc -lpthread -lposix4 -lrt -mt 
-D_REENTRANT -D__EXTENSIONS__=1 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 
-D_XPG4 -D_XPG4_2 -D_XPG6 -D_POSIX_PTHREAD_SEMANTICS -D_XOPEN_SOURCE=600 
-D_POSIX_C_SOURCE=200112L -D__XOPEN_OR_POSIX -D_STRICT_STDC -D_STRICT_STDC__ 
-D_STDC_C99 -DAPR_BUCKET_DEBUG=1 -DAPR_RING_DEBUG=1 -DAPR_POOL_DEBUG=0 
-DSOLARIS -DSOLARIS10 -DSOLARIS2=10 -DUSE_SOLARIS -DNDEBUG -DNO_DEBUG -KPIC 
-xtarget=pentium4 -xarch=sse2 -xchip=pentium4 -xcache=8/64/4:256/128/8 -xO3 -s
[EMAIL PROTECTED]/tmp][03/22/2007 12:26:47][243]>> 

[EMAIL PROTECTED]/tmp][03/22/2007 12:26:47][243]>> $CC $CFLAGS 
$LDFLAGS testnulldir.c -o testnulldir
"testnulldir.c", line 14: error: undefined struct/union member: dd_fd
c99: acomp failed for testnulldir.c
[EMAIL PROTECTED]/tmp][03/22/2007 12:27:23][244]>> 

we now change

#define dirfd(dp)    (dp)->dd_fd

to

#define dirfd(dp)    (dp)->d_fd

[EMAIL PROTECTED]/tmp][03/22/2007 12:28:10][246]>> $CC $CFLAGS 
$LDFLAGS testnulldir.c -o testnulldir
[EMAIL PROTECTED]/tmp][03/22/2007 12:28:12][247]>> ./testnulldir 
Segmentation fault (core dumped)
[EMAIL PROTECTED]/tmp][03/22/2007 12:28:17][248]>> 

--Stefan

-- 
Stefan Teleman                  'Nobody Expects the Spanish Inquisition'
KDE e.V.                                                -Monty Python
[EMAIL PROTECTED]
_______________________________________________
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org

Reply via email to