diff --git a/doc/NEWS.md b/doc/NEWS.md index 064a3d7..ce0c6c1 100644 --- a/doc/NEWS.md +++ b/doc/NEWS.md @@ -8,6 +8,7 @@ * cleanup: improved the output formatting of "`make test`" * cleanup: skip test 10 (for *SIGPIPE*) if GNU "`head`" is not available, so "`make test`" on stock OpenBSD 7.3 works * cleanup: replace all calls to `sprintf()` and `snprintf()` with a new wrapper function `pv_snprintf()` to centralise compatibility changes + * cleanup: tidy up and fix compilation warning in "`--watchfd`" code 1.7.0 - 17 July 2023 * dropped: support for Red Hat Enterprise Linux and its derivatives has been dropped; removed the RPM spec file, and will no longer build binaries diff --git a/src/pv/watchpid.c b/src/pv/watchpid.c index 6a0c8f3..e8cbc61 100644 --- a/src/pv/watchpid.c +++ b/src/pv/watchpid.c @@ -232,10 +232,15 @@ int pv_watchfd_changed(pvwatchfd_t info) } #endif -#ifdef __APPLE__ + +/* + * Return the current file position of the given file descriptor, or -1 if + * the fd has closed or has changed in some way. + */ long long pv_watchfd_position(pvwatchfd_t info) { long long position; +#ifdef __APPLE__ struct vnode_fdinfowithpath vnodeInfo = { }; int32_t proc_fd = (int32_t) info->watch_fd; @@ -247,18 +252,7 @@ long long pv_watchfd_position(pvwatchfd_t info) } position = (long long) vnodeInfo.pfi.fi_offset; - - return position; -} - #else -/* - * Return the current file position of the given file descriptor, or -1 if - * the fd has closed or has changed in some way. - */ -long long pv_watchfd_position(pvwatchfd_t info) -{ - long long position; FILE *fptr; if (pv_watchfd_changed(info)) @@ -268,17 +262,18 @@ long long pv_watchfd_position(pvwatchfd_t info) if (NULL == fptr) return -1; position = -1; - fscanf(fptr, "pos: %llu", &position); + if (1 != fscanf(fptr, "pos: %llu", &position)) + position = -1; fclose(fptr); +#endif return position; } -#endif #ifdef __APPLE__ -int pidfds(pvstate_t state, unsigned int pid, struct proc_fdinfo **fds, - int *count) +static int pidfds(pvstate_t state, unsigned int pid, + struct proc_fdinfo **fds, int *count) { int size_needed = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, 0, 0); if (size_needed == -1) {