patch: parentheses and remaining prototypes

Joel Sherrill joel.sherrill@OARcorp.com
Thu Sep 7 16:43:00 GMT 2000


"J. Johnston" wrote:
> 
> Werner Almesberger wrote:
> >
> > J. Johnston wrote:
> > > Patch has been checked in.
> >
> > Thanks ! Here's another one that just ran into.
> >
> > Possibly controversial issue: HAVE_NO_D_NAMLEN - I set it in my
> > sys/dirent.h because Linux doesn't have such a field.
> >

General warning for RTEMS related issues.  RTEMS does not use the
newlib posix subdirectory.  It has its own version of those routines.
It also has threads, posix semapahores, message queues, etc.

I am not 100% comfortable with the prototyping non-POSIX routines like
telldir().  If these need to be changed in newlib to be more correct,
then I will need to know so the RTEMS implementation can be fixed.

So Werner, I would appreciate it very much if you could flag me when
you spot something that can be improved on the RTEMS side.  Don't 
just put an ifdef RTEMS  and leave something ugly and hacky.  Let
us make it right.  It is easier to be standards compliant than teach
every package about your own breakage. :)

> I don't have a problem with using a define, except I would rather do it
> the opposite way round.  POSIX doesn't specify the field and defines d_name
> as being nul-terminated so I think it is better to do what glibc does and have the define:
> _DIRENT_HAVE_D_NAMLEN instead.  This would require changing the few libc/sys/xxxx/sys/dirent.h files
> that define d_namlen to define the macro as well (though many supply their own scandir).

Specific issue.. the RTEMS *dir() code is fairly recent in origin and
we tried to stay reasonably compatable with the newlib .h files.  If 
the RTEMS paths did not make the right decisions, let me know.

> In the POSIX.1 spec I have, there is reference to telldir not being included,
> however, it is prototyped as returning long.  The same is true when you look in the glibc
> /usr/include/dirent.h and the Solaris definition.  The man page on my linux box shows the
> BSD 4.3 definition which uses off_t.  My preference would be to leave it as returning "long" and
> have Cygwin change the prototype unless there proves to be some good reason to change it that
> I am unaware of.
> 
> -- Jeff Johnston (Red Hat Inc.)
> 
> >
> > ---------------------------------- ChangeLog ----------------------------------
> >
> > 2000-08-25  Werner Almesberger  <Werner.Almesberger@epfl.ch>
> >         * libc/posix/scandir.c (DIRSIZ, scandir): don't use
> >         struct dirent.d_namlen if HAVE_NO_D_NAMLEN is defined
> >         * libc/posix/scandir.c (alphasort): aligned prototype with
> >         libc/sys/cygwin/sys/dirent.h and simplified function body
> >         * libc/posix/telldir.c (telldir): aligned prototype with
> >         libc/sys/cygwin/sys/dirent.h
> >
> > ------------------------------------ patch ------------------------------------
> >
> > --- orig/newlib/libc/posix/scandir.c    Thu Feb 17 20:39:47 2000
> > +++ src/newlib/libc/posix/scandir.c     Fri Aug 25 01:16:40 2000
> > @@ -57,8 +57,13 @@
> >   * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
> >   */
> >  #undef DIRSIZ
> > +#ifndef HAVE_NO_D_NAMLEN
> >  #define DIRSIZ(dp) \
> >      ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
> > +#else
> > +#define DIRSIZ(dp) \
> > +    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + ((strlen((dp)->d_name)+1 + 3) &~ 3))
> > +#endif
> >
> >  #ifndef __P
> >  #define __P(args) ()
> > @@ -103,8 +108,12 @@
> >                         return(-1);
> >                 p->d_ino = d->d_ino;
> >                 p->d_reclen = d->d_reclen;
> > +#ifndef HAVE_NO_D_NAMLEN
> >                 p->d_namlen = d->d_namlen;
> >                 bcopy(d->d_name, p->d_name, p->d_namlen + 1);
> > +#else
> > +               strcpy(p->d_name, d->d_name);
> > +#endif
> >                 /*
> >                  * Check to make sure the array has space left and
> >                  * realloc the maximum size.
> > @@ -132,11 +141,10 @@
> >   */
> >  int
> >  alphasort(d1, d2)
> > -       const void *d1;
> > -       const void *d2;
> > +       const struct dirent **d1;
> > +       const struct dirent **d2;
> >  {
> > -       return(strcmp((*(struct dirent **)d1)->d_name,
> > -           (*(struct dirent **)d2)->d_name));
> > +       return(strcmp((*d1)->d_name, (*d2)->d_name));
> >  }
> >
> >  #endif /* ! HAVE_OPENDIR */
> > --- orig/newlib/libc/posix/telldir.c    Thu Feb 17 20:39:47 2000
> > +++ src/newlib/libc/posix/telldir.c     Fri Aug 25 01:10:05 2000
> > @@ -71,9 +71,9 @@
> >  /*
> >   * return a pointer into a directory
> >   */
> > -long
> > +off_t
> >  telldir(dirp)
> > -       const DIR *dirp;
> > +       DIR *dirp;
> >  {
> >         register int index;
> >         register struct ddloc *lp;
> >
> > --
> >   _________________________________________________________________________
> >  / Werner Almesberger, ICA, EPFL, CH       werner.almesberger@ica.epfl.ch /
> > /_IN_N_032__Tel_+41_21_693_6621__Fax_+41_21_693_6610_____________________/

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel@OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985


More information about the Newlib mailing list