Skip to content

Commit

Permalink
check for availability of symbols instead of glibc defines
Browse files Browse the repository at this point in the history
in musl they are just redefines of the non-64 versions
  • Loading branch information
reinerh committed Oct 23, 2022
1 parent 8fa8ea4 commit 1e0d4c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions src/libtrace/libtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
// break recursivity on fopen call
typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode);
static orig_fopen_t orig_fopen = NULL;
typedef FILE *(*orig_fopen64_t)(const char *pathname, const char *mode);
static orig_fopen64_t orig_fopen64 = NULL;
typedef int (*orig_access_t)(const char *pathname, int mode);
static orig_access_t orig_access = NULL;

Expand Down Expand Up @@ -341,7 +339,9 @@ FILE *fopen(const char *pathname, const char *mode) {
return rv;
}

#ifdef __GLIBC__
#ifndef fopen64
typedef FILE *(*orig_fopen64_t)(const char *pathname, const char *mode);
static orig_fopen64_t orig_fopen64 = NULL;
FILE *fopen64(const char *pathname, const char *mode) {
if (!orig_fopen64)
orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64");
Expand All @@ -350,7 +350,7 @@ FILE *fopen64(const char *pathname, const char *mode) {
tprintf(ftty, "%u:%s:fopen64 %s:%p\n", mypid, myname, pathname, rv);
return rv;
}
#endif /* __GLIBC__ */
#endif


// freopen
Expand All @@ -365,7 +365,7 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
return rv;
}

#ifdef __GLIBC__
#ifndef freopen64
typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream);
static orig_freopen64_t orig_freopen64 = NULL;
FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
Expand All @@ -376,7 +376,7 @@ FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
tprintf(ftty, "%u:%s:freopen64 %s:%p\n", mypid, myname, pathname, rv);
return rv;
}
#endif /* __GLIBC__ */
#endif

// unlink
typedef int (*orig_unlink_t)(const char *pathname);
Expand Down Expand Up @@ -447,7 +447,7 @@ int stat(const char *pathname, struct stat *statbuf) {
return rv;
}

#ifdef __GLIBC__
#ifndef stat64
typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *statbuf);
static orig_stat64_t orig_stat64 = NULL;
int stat64(const char *pathname, struct stat64 *statbuf) {
Expand All @@ -458,7 +458,7 @@ int stat64(const char *pathname, struct stat64 *statbuf) {
tprintf(ftty, "%u:%s:stat64 %s:%d\n", mypid, myname, pathname, rv);
return rv;
}
#endif /* __GLIBC__ */
#endif

// lstat
typedef int (*orig_lstat_t)(const char *pathname, struct stat *statbuf);
Expand All @@ -472,7 +472,7 @@ int lstat(const char *pathname, struct stat *statbuf) {
return rv;
}

#ifdef __GLIBC__
#ifndef lstat64
typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *statbuf);
static orig_lstat64_t orig_lstat64 = NULL;
int lstat64(const char *pathname, struct stat64 *statbuf) {
Expand All @@ -483,7 +483,7 @@ int lstat64(const char *pathname, struct stat64 *statbuf) {
tprintf(ftty, "%u:%s:lstat64 %s:%d\n", mypid, myname, pathname, rv);
return rv;
}
#endif /* __GLIBC__ */
#endif

// opendir
typedef DIR *(*orig_opendir_t)(const char *pathname);
Expand Down
16 changes: 8 additions & 8 deletions src/libtracelog/libtracelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ FILE *fopen(const char *pathname, const char *mode) {
return rv;
}

#ifdef __GLIBC__
#ifndef fopen64
FILE *fopen64(const char *pathname, const char *mode) {
#ifdef DEBUG
printf("%s %s\n", __FUNCTION__, pathname);
Expand All @@ -420,7 +420,7 @@ FILE *fopen64(const char *pathname, const char *mode) {
FILE *rv = orig_fopen64(pathname, mode);
return rv;
}
#endif /* __GLIBC__ */
#endif


// freopen
Expand All @@ -441,7 +441,7 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
return rv;
}

#ifdef __GLIBC__
#ifndef freopen64
typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream);
static orig_freopen64_t orig_freopen64 = NULL;
FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
Expand All @@ -458,7 +458,7 @@ FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
FILE *rv = orig_freopen64(pathname, mode, stream);
return rv;
}
#endif /* __GLIBC__ */
#endif

// unlink
typedef int (*orig_unlink_t)(const char *pathname);
Expand Down Expand Up @@ -565,7 +565,7 @@ int stat(const char *pathname, struct stat *buf) {
return rv;
}

#ifdef __GLIBC__
#ifndef stat64
typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf);
static orig_stat64_t orig_stat64 = NULL;
int stat64(const char *pathname, struct stat64 *buf) {
Expand All @@ -582,7 +582,7 @@ int stat64(const char *pathname, struct stat64 *buf) {
int rv = orig_stat64(pathname, buf);
return rv;
}
#endif /* __GLIBC__ */
#endif

typedef int (*orig_lstat_t)(const char *pathname, struct stat *buf);
static orig_lstat_t orig_lstat = NULL;
Expand All @@ -601,7 +601,7 @@ int lstat(const char *pathname, struct stat *buf) {
return rv;
}

#ifdef __GLIBC__
#ifndef lstat64
typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *buf);
static orig_lstat64_t orig_lstat64 = NULL;
int lstat64(const char *pathname, struct stat64 *buf) {
Expand All @@ -618,7 +618,7 @@ int lstat64(const char *pathname, struct stat64 *buf) {
int rv = orig_lstat64(pathname, buf);
return rv;
}
#endif /* __GLIBC__ */
#endif

// access
typedef int (*orig_access_t)(const char *pathname, int mode);
Expand Down

0 comments on commit 1e0d4c1

Please sign in to comment.