Skip to content

Commit

Permalink
Merge pull request #779 from LLNL/fstat
Browse files Browse the repository at this point in the history
define stat wrappers depending on whether symbol is found
  • Loading branch information
adammoody authored Jul 10, 2023
2 parents f95abed + f19fac5 commit 4f50687
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 4 additions & 3 deletions client/src/unifyfs-stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3043,9 +3043,10 @@ __svfscanf(unifyfs_stream_t* fp, const char* fmt0, va_list ap)
* considered part of the scanset.
*/
static const u_char*
__sccl(tab, fmt)
char* tab;
const u_char* fmt;
__sccl(char* tab, const u_char* fmt)
//__sccl(tab, fmt)
//char* tab;
//const u_char* fmt;
{
int c, n, v;

Expand Down
21 changes: 18 additions & 3 deletions client/src/unifyfs-sysio.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,11 @@ static int __stat(const char* path, struct stat* buf)
return 0;
}

#if defined(HAVE_STAT64) || \
defined(HAVE_FSTAT64) || \
defined(HAVE___XSTAT64) || \
defined(HAVE___LXSTAT64) || \
defined(HAVE___FXSTAT64)
static int __stat64(const char* path, struct stat64* buf)
{
/* check that caller gave us a buffer to write to */
Expand Down Expand Up @@ -834,7 +839,7 @@ static int __stat64(const char* path, struct stat64* buf)
errno = 0;
return 0;
}

#endif

int UNIFYFS_WRAP(stat)(const char* path, struct stat* buf)
{
Expand All @@ -851,6 +856,7 @@ int UNIFYFS_WRAP(stat)(const char* path, struct stat* buf)
}
}

#ifdef HAVE_STAT64
int UNIFYFS_WRAP(stat64)(const char* path, struct stat64* buf)
{
LOGDBG("stat64 was called for %s", path);
Expand All @@ -864,21 +870,22 @@ int UNIFYFS_WRAP(stat64)(const char* path, struct stat64* buf)
int ret = UNIFYFS_REAL(stat64)(path, buf);
return ret;
}
return 0;
}
#endif

int UNIFYFS_WRAP(fstat)(int fd, struct stat* buf)
{
LOGDBG("fstat was called for fd: %d", fd);

/* check whether we should intercept this file descriptor */
if (unifyfs_intercept_fd(&fd)) {
int fid = unifyfs_get_fid_from_fd(fd);
/* check if the file is still active (e.g., not closed) */
int fid = unifyfs_get_fid_from_fd(fd);
if (fid == -1) {
errno = EBADF;
return -1;
}

const char* path = unifyfs_path_from_fid(posix_client, fid);
int ret = __stat(path, buf);
return ret;
Expand All @@ -889,13 +896,20 @@ int UNIFYFS_WRAP(fstat)(int fd, struct stat* buf)
}
}

#ifdef HAVE_FSTAT64
int UNIFYFS_WRAP(fstat64)(int fd, struct stat64* buf)
{
LOGDBG("fstat64 was called for fd: %d", fd);

/* check whether we should intercept this file descriptor */
if (unifyfs_intercept_fd(&fd)) {
/* check if the file is still active (e.g., not closed) */
int fid = unifyfs_get_fid_from_fd(fd);
if (fid == -1) {
errno = EBADF;
return -1;
}

const char* path = unifyfs_path_from_fid(posix_client, fid);
int ret = __stat64(path, buf);
return ret;
Expand All @@ -905,6 +919,7 @@ int UNIFYFS_WRAP(fstat64)(int fd, struct stat64* buf)
return ret;
}
}
#endif

/*
* NOTE on __xstat(2), __lxstat(2), and __fxstat(2)
Expand Down

0 comments on commit 4f50687

Please sign in to comment.