patch: parentheses and remaining prototypes
Werner Almesberger
almesber@lrc.epfl.ch
Sun Aug 27 09:57:00 GMT 2000
J. Johnston wrote:
> 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
Good point, I've changed it accordingly.
> 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).
It's actually rather weird: besides Linux, the only targets that set
posix_dir=posix are *-*-cygwin* and powerpcle-*-pe. Incidently, they also
set sys_dir=cygwin, and libc/sys/cygwin/sys/dirent.h has no d_namelen
either. I don't quite understand how all this compiles for cygwin ...
So I didn't change any headers for _DIRENT_HAVE_D_NAMLEN: cygwin seems be
be better off without it anyway, and the others don't use libc/posix
anyway.
> My preference would be to leave [telldir] 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.
Okay, my patch adjusts the prototype. If there's a significant
compatibility issue, we'd have to have a #define for this too, but
that's up to the cygwin people to decide.
- Werner
---------------------------------- ChangeLog ----------------------------------
2000-08-27 Werner Almesberger <Werner.Almesberger@epfl.ch>
* libc/posix/scandir.c (DIRSIZ, scandir): use struct dirent.d_namlen
only if _DIRENT_HAVE_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) libc/sys/cygwin/sys/dirent.h
(telldir): changed "telldir" prototype to long telldir (DIR *)
as mentioned in annex B of POSIX.1
------------------------------------ patch ------------------------------------
--- orig/newlib/libc/posix/scandir.c Thu Feb 17 20:39:47 2000
+++ src/newlib/libc/posix/scandir.c Sun Aug 27 18:41:07 2000
@@ -57,8 +57,13 @@
* null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
*/
#undef DIRSIZ
+#ifdef _DIRENT_HAVE_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;
+#ifdef _DIRENT_HAVE_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 Sun Aug 27 18:25:00 2000
@@ -73,7 +73,7 @@
*/
long
telldir(dirp)
- const DIR *dirp;
+ DIR *dirp;
{
register int index;
register struct ddloc *lp;
--- orig/newlib/libc/sys/cygwin/sys/dirent.h Thu Feb 17 20:39:49 2000
+++ src/newlib/libc/sys/cygwin/sys/dirent.h Sun Aug 27 18:36:41 2000
@@ -44,7 +44,7 @@
int closedir (DIR *);
#ifndef _POSIX_SOURCE
-off_t telldir (DIR *);
+long telldir (DIR *);
void seekdir (DIR *, off_t loc);
int scandir (const char *__dir,
--
_________________________________________________________________________
/ Werner Almesberger, ICA, EPFL, CH werner.almesberger@ica.epfl.ch /
/_IN_N_032__Tel_+41_21_693_6621__Fax_+41_21_693_6610_____________________/
More information about the Newlib
mailing list