This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: using _FILE_OFFSET_BITS=64 with a non-gcc compiler
Ulrich Drepper writes:
> Changing
>
> #define readdir readdir64
>
> to
>
> #define readdir ((struct dirent *(*) (DIR *)) readdir64)
>
> makes things work with only a little drawback: function pointer
> assignments of the form
>
> struct dirent *(*fp) (DIR *) = &readdir;
>
> will fail due to a syntax error. But
>
> struct dirent *(*fp) (DIR *) = readdir;
>
> works and does the same. If this is more acceptable I'll accept a
> patch.
Here is a patch to that effect. But note that for 'stat', 'statfs', 'statvfs'
the #define approach doesn't work:
struct stat buf;
would expand to
struct (* (int (*) (const char *, struct stat *)) stat64) buf;
which gives a syntax error.
Therefore in these cases the 'static inline' approach is used. It is
namespace clean but has the slight drawback that &stat is not the
same in different compilation units - but this drawback is already
present in <sys/stat.h> when using GNU C.
2001-11-21 Bruno Haible <bruno@clisp.org>
Provide correctly typed function redirections if __USE_FILE_OFFSET64
is defined and not using GNU C.
* dirent/dirent.h (readdir): Define as readdir64 with different
return value type.
(readdir_r): Define as readdir64_r with different argument types.
(scandir): Define as scandir64 with different argument types.
* io/ftw.h (ftw): Define as ftw64 with different argument types.
(nftw): Define as nftw64 with different argument types.
* resource/sys/resource.h (getrlimit): Define as getrlimit64 with
different argument types.
(setrlimit): Define as setrlimit64 with different argument types.
* rt/aio.h (aio_read): Define as aio_read64 with different argument
types.
(aio_write): Define as aio_write64 with different argument types.
(lio_listio): Define as lio_listio64 with different argument types.
(aio_error): Define as aio_error64 with different argument types.
(aio_return): Define as aio_return64 with different argument types.
(aio_cancel): Define as aio_cancel64 with different argument types.
(aio_suspend): Define as aio_suspend64 with different argument types.
(aio_fsync): Define as aio_fsync64 with different argument types.
* io/sys/stat.h (stat): Define as inline function calling stat64.
(fstat): Define as fstat64 with different argument types.
(lstat): Define as lstat64 with different argument types.
(__fxstat): Define as __fxstat64 with different argument types.
(__xstat): Define as __xstat64 with different argument types.
(__lxstat): Define as __lxstat64 with different argument types.
* io/sys/statfs.h (statfs): Define as inline function calling statfs64.
(fstatfs): Define as fstatfs64 with different argument types.
* io/sys/statvfs.h (statvfs): Define as inline function calling
statvfs64.
(fstatvfs): Define as fstatvfs64 with different argument types.
--- glibc-20011110/dirent/dirent.h.bak Tue Jul 10 22:57:41 2001
+++ glibc-20011110/dirent/dirent.h Mon Nov 19 02:27:03 2001
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1991-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
@@ -148,7 +148,7 @@
# ifdef __REDIRECT
extern struct dirent *__REDIRECT (readdir, (DIR *__dirp) __THROW, readdir64);
# else
-# define readdir readdir64
+# define readdir (* (struct dirent * (*) (DIR *)) readdir64)
# endif
#endif
@@ -171,7 +171,9 @@
struct dirent **__restrict __result) __THROW,
readdir64_r);
# else
-# define readdir_r readdir64_r
+# define readdir_r (* (int (*) (DIR *__restrict, struct dirent *__restrict, \
+ struct dirent **__restrict)) \
+ readdir64_r)
# endif
# endif
@@ -237,7 +239,11 @@
int (*__cmp) (__const void *, __const void *)) __THROW,
scandir64);
# else
-# define scandir scandir64
+# define scandir (* (int (*) (__const char *__restrict, \
+ struct dirent ***__restrict, \
+ int (*) (__const struct dirent *), \
+ int (*) (__const void *, __const void *))) \
+ scandir64)
# endif
# endif
--- glibc-20011110/io/ftw.h.bak Tue Jul 10 22:58:51 2001
+++ glibc-20011110/io/ftw.h Mon Nov 19 02:27:03 2001
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1996-1999, 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
@@ -112,7 +112,7 @@
extern int __REDIRECT (ftw, (__const char *__dir, __ftw_func_t __func,
int __descriptors) __THROW, ftw64);
# else
-# define ftw ftw64
+# define ftw (* (int (*) (__const char *, __ftw_func_t, int)) ftw64)
# endif
#endif
#ifdef __USE_LARGEFILE64
@@ -131,7 +131,7 @@
extern int __REDIRECT (nftw, (__const char *__dir, __nftw_func_t __func,
int __descriptors, int __flag) __THROW, nftw64);
# else
-# define nftw nftw64
+# define nftw (* (int (*) (__const char *, __nftw_func_t, int, int)) nftw64)
# endif
# endif
# ifdef __USE_LARGEFILE64
--- glibc-20011110/resource/sys/resource.h.bak Tue Jul 10 22:59:48 2001
+++ glibc-20011110/resource/sys/resource.h Mon Nov 19 02:27:03 2001
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 94, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1994, 1996-99, 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
@@ -56,7 +56,8 @@
struct rlimit *__rlimits) __THROW,
getrlimit64);
# else
-# define getrlimit getrlimit64
+# define getrlimit (* (int (*) (__rlimit_resource_t, struct rlimit *)) \
+ getrlimit64)
# endif
#endif
#ifdef __USE_LARGEFILE64
@@ -76,7 +77,9 @@
__const struct rlimit *__rlimits) __THROW,
setrlimit64);
# else
-# define setrlimit setrlimit64
+# define setrlimit (* (int (*) (__rlimit_resource_t, \
+ __const struct rlimit *)) \
+ setrlimit64)
# endif
#endif
#ifdef __USE_LARGEFILE64
--- glibc-20011110/rt/aio.h.bak Tue Jul 10 22:59:48 2001
+++ glibc-20011110/rt/aio.h Mon Nov 19 02:27:03 2001
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 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
@@ -200,14 +200,18 @@
aio_fsync64);
# else
-# define aio_read aio_read64
-# define aio_write aio_write64
-# define lio_listio lio_listio64
-# define aio_error aio_error64
-# define aio_return aio_return64
-# define aio_cancel aio_cancel64
-# define aio_suspend aio_suspend64
-# define aio_fsync aio_fsync64
+# define aio_read (* (int (*) (struct aiocb *)) aio_read64)
+# define aio_write (* (int (*) (struct aiocb *)) aio_write64)
+# define lio_listio (* (int (*) (int, struct aiocb *__const [__restrict_arr],\
+ int, struct sigevent *__restrict)) \
+ lio_listio64)
+# define aio_error (* (int (*) (__const struct aiocb *)) aio_error64)
+# define aio_return (* (__ssize_t (*) (struct aiocb *)) aio_return64)
+# define aio_cancel (* (int (*) (int, struct aiocb *)) aio_cancel64)
+# define aio_suspend (* (int (*) (__const struct aiocb *__const [], int, \
+ __const struct timespec *__restrict)) \
+ aio_suspend64)
+# define aio_fsync (* int (*) (int, struct aiocb *) aio_fsync64)
# endif
#endif
--- glibc-20011110/io/sys/stat.h.bak Tue Jul 10 22:58:52 2001
+++ glibc-20011110/io/sys/stat.h Wed Nov 21 01:54:12 2001
@@ -211,8 +211,7 @@
stat64);
extern int __REDIRECT (fstat, (int __fd, struct stat *__buf) __THROW, fstat64);
# else
-# define stat stat64
-# define fstat fstat64
+# define fstat (* (int (*) (int, struct stat *)) fstat64)
# endif
#endif
#ifdef __USE_LARGEFILE64
@@ -220,6 +219,13 @@
struct stat64 *__restrict __buf) __THROW;
extern int fstat64 (int __fd, struct stat64 *__buf) __THROW;
#endif
+#if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
+static __inline int stat (__const char *__restrict __file,
+ struct stat *__restrict __buf) __THROW
+{
+ return stat64 (__file, (struct stat64 *) __buf);
+}
+#endif
#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
# ifndef __USE_FILE_OFFSET64
@@ -234,7 +240,9 @@
struct stat *__restrict __buf) __THROW,
lstat64);
# else
-# define lstat lstat64
+# define lstat (* (int (*) (__const char *__restrict, \
+ struct stat *__restrict)) \
+ lstat64)
# endif
# endif
# ifdef __USE_LARGEFILE64
@@ -320,9 +328,10 @@
__lxstat64);
# else
-# define __fxstat __fxstat64
-# define __xstat __xstat64
-# define __lxstat __lxstat64
+# define __fxstat (* (int (*) (int, int, struct stat *)) __fxstat64)
+# define __xstat (* (int (*) (int, __const char *, struct stat *)) __xstat64)
+# define __lxstat (* (int (*) (int, __const char *, struct stat *)) \
+ __lxstat64)
# endif
#endif
--- glibc-20011110/io/sys/statfs.h.bak Tue Jul 10 22:58:52 2001
+++ glibc-20011110/io/sys/statfs.h Wed Nov 21 01:54:41 2001
@@ -1,5 +1,5 @@
/* Definitions for getting information about a filesystem.
- Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 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
@@ -35,13 +35,17 @@
extern int __REDIRECT (statfs,
(__const char *__file, struct statfs *__buf) __THROW,
statfs64);
-# else
-# define statfs statfs64
# endif
#endif
#ifdef __USE_LARGEFILE64
extern int statfs64 (__const char *__file, struct statfs64 *__buf) __THROW;
#endif
+#if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
+static __inline int statfs (__const char *__file, struct statfs *__buf) __THROW
+{
+ return statfs64 (__file, (struct statfs64 *) __buf);
+}
+#endif
/* Return information about the filesystem containing the file FILDES
refers to. */
@@ -52,7 +56,7 @@
extern int __REDIRECT (fstatfs, (int __fildes, struct statfs *__buf) __THROW,
fstatfs64);
# else
-# define fstatfs fstatfs64
+# define fstatfs (* (int (*) (int, struct statfs *)) fstatfs64)
# endif
#endif
#ifdef __USE_LARGEFILE64
--- glibc-20011110/io/sys/statvfs.h.bak Tue Jul 10 22:58:52 2001
+++ glibc-20011110/io/sys/statvfs.h Wed Nov 21 01:55:04 2001
@@ -1,5 +1,5 @@
/* Definitions for getting information about a filesystem.
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 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
@@ -57,14 +57,19 @@
(__const char *__restrict __file,
struct statvfs *__restrict __buf) __THROW,
statvfs64);
-# else
-# define statvfs statvfs64
# endif
#endif
#ifdef __USE_LARGEFILE64
extern int statvfs64 (__const char *__restrict __file,
struct statvfs64 *__restrict __buf) __THROW;
#endif
+#if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
+static __inline int statvfs (__const char *__restrict __file,
+ struct statvfs *__restrict __buf) __THROW
+{
+ return statvfs64 (__file, (struct statvfs64 *) __buf);
+}
+#endif
/* Return information about the filesystem containing the file FILDES
refers to. */
@@ -75,7 +80,7 @@
extern int __REDIRECT (fstatvfs, (int __fildes, struct statvfs *__buf) __THROW,
fstatvfs64);
# else
-# define fstatvfs fstatvfs64
+# define fstatvfs (* (int (*) (int, struct statvfs *)) fstatvfs64)
# endif
#endif
#ifdef __USE_LARGEFILE64