Skip to content

Commit

Permalink
preload: Fix building with _FILE_OFFSET_BITS
Browse files Browse the repository at this point in the history
Unsetting `_FILE_OFFSET_BITS` causes time_t to be treated as 32-bit
instead of the 64-bit that we want with `-D_TIME_BITS=64`.

Fixes #216

Co-Authored-By: Steve Langasek <[email protected]>
Co-Authored-By: Martin Pitt <[email protected]>
  • Loading branch information
3 people authored and martinpitt committed Mar 24, 2024
1 parent 5ad05a4 commit 5e5ee15
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/libumockdev-preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,30 @@
* along with umockdev; If not, see <http://www.gnu.org/licenses/>.
*/

/* override -D_FILE_OFFSET_BITS, it breaks us */
#undef _FILE_OFFSET_BITS

/* for getting stat64 */
#define _GNU_SOURCE

#include <features.h>

#ifdef __GLIBC__
/* Remove gcc asm aliasing so that our interposed symbols work as expected */
#include <sys/cdefs.h>

#include <stddef.h>
extern int __REDIRECT_NTH (__ttyname_r_alias, (int __fd, char *__buf,
size_t __buflen), ttyname_r);

#ifdef __REDIRECT
#undef __REDIRECT
#endif
#define __REDIRECT(name, proto, alias) name proto
#ifdef __REDIRECT_NTH
#undef __REDIRECT_NTH
#endif
#define __REDIRECT_NTH(name, proto, alias) name proto __THROW

#endif /* __GLIBC__ */

#include <assert.h>
#include <errno.h>
#include <dirent.h>
Expand Down Expand Up @@ -63,6 +81,14 @@
#include "utils.h"
#include "ioctl_tree.h"

#ifdef __GLIBC__
/* Fixup for making a mess with __REDIRECT above */
#ifdef __USE_TIME_BITS64
#define clock_gettime __clock_gettime64
extern int clock_gettime(clockid_t clockid, struct timespec *tp);
#endif
#endif

/* fix missing O_TMPFILE on some systems */
#ifndef O_TMPFILE
#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
Expand Down

0 comments on commit 5e5ee15

Please sign in to comment.