This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
using _FILE_OFFSET_BITS=64 with a non-gcc compiler
- To: libc-alpha at sources dot redhat dot com
- Subject: using _FILE_OFFSET_BITS=64 with a non-gcc compiler
- From: Bruno Haible <haible at ilog dot fr>
- Date: Mon, 12 Nov 2001 17:19:08 +0100 (CET)
Hi Ulrich and Paul,
Programs that use _FILE_OFFSET_BITS=64 with a non-gcc compiler get warnings
when using 'readdir'. One such program is gzip-1.3:
icc -DHAVE_CONFIG_H -I. -I. -I. -I/packages/intel/include -O2 -g -w1 -c gzip.c
gzip.c:
"gzip.c", line 1785: warning #556: a value of type "struct dirent64 *" cannot be assigned to an entity of type "struct dirent *"
while ((errno = 0, dp = readdir(dirp)) != NULL) {
^
What happens is: The autoconf script sets _FILE_OFFSET_BITS to 64. This
causes <features.h> to #define __USE_FILE_OFFSET64, __USE_LARGEFILE,
__USE_LARGEFILE64. (The last two so that functions like readdir64 get a
prototype.) <bits/dirent.h> then defines 'struct dirent' and 'struct dirent64'
to two different types but with identical fields and layout. <dirent.h>
then does
# define readdir readdir64
extern struct dirent64 *readdir64 (DIR *__dirp) __THROW;
But the user code has defined its variable 'dp' as being of type
'struct dirent *'.
To avoid the warning (and a similar one that would occur in 'readdir_r' and
'scandir') the types 'struct dirent' and 'struct dirent64' must be defined
to the same type. The simplest way to do this, without touching all
platform dependent */bits/dirent.h files, is the following patch. With it,
gzip-1.3 compiles without warning.
The same warning occurs also for uses of 'struct rlimit', for example in
textutils-2.0.15. Similarly, here 'struct rlimit' and 'struct rlimit64'
must be defined to the same type.
2001-11-11 Bruno Haible <haible@clisp.cons.org>
* dirent/dirent.h (dirent): Define as dirent64 if __USE_FILE_OFFSET64
and !__REDIRECT.
* resource/sys/resource.h (rlimit): Define as rlimit64 if
__USE_FILE_OFFSET64 and !__REDIRECT.
*** glibc-20011110/dirent/dirent.h.bak Tue Jul 10 22:57:41 2001
--- glibc-20011110/dirent/dirent.h Sat Nov 10 20:50:13 2001
***************
*** 320,325 ****
--- 320,333 ----
#endif /* Use BSD or misc. */
+ /* If __USE_FILE_OFFSET64 and we don't have __REDIRECT, we #define readdir
+ to readdir64, and its prototype returns a 'struct dirent64 *', but the
+ user's code expects to be able to designate it by 'struct dirent *'.
+ Similarly for scandir's second argument. */
+ #if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
+ # define dirent dirent64
+ #endif
+
__END_DECLS
#endif /* dirent.h */
*** glibc-20011110/resource/sys/resource.h.bak Tue Jul 10 22:59:48 2001
--- glibc-20011110/resource/sys/resource.h Sun Nov 11 16:53:48 2001
***************
*** 1,4 ****
! /* Copyright (C) 1992, 94, 96, 97, 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,4 ----
! /* Copyright (C) 1992, 94, 1996-1999, 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
***************
*** 99,104 ****
--- 99,111 ----
extern int setpriority (__priority_which_t __which, id_t __who, int __prio)
__THROW;
+ /* If __USE_FILE_OFFSET64 and we don't have __REDIRECT, we #define getrlimit
+ to getrlimit64, and its prototype uses a 'struct rlimit64 *', but the
+ user's code expects to be able to designate it by 'struct rlimit *'. */
+ #if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
+ # define rlimit rlimit64
+ #endif
+
__END_DECLS
#endif /* sys/resource.h */