mirror of https://github.com/xzeldon/htop.git
Add compat wrapper for fstatat
This commit is contained in:
parent
049046c700
commit
bbf01054bf
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
htop - Compat.c
|
||||||
|
(C) 2020 Christian Göttsche
|
||||||
|
Released under the GNU GPLv2, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "Compat.h"
|
||||||
|
#ifndef HAVE_FSTATAT
|
||||||
|
#include "XUtils.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int Compat_fstatat(int dirfd,
|
||||||
|
const char* dirpath,
|
||||||
|
const char* pathname,
|
||||||
|
struct stat* statbuf,
|
||||||
|
int flags) {
|
||||||
|
|
||||||
|
#ifdef HAVE_FSTATAT
|
||||||
|
|
||||||
|
(void)dirpath;
|
||||||
|
|
||||||
|
return fstatat(dirfd, pathname, statbuf, flags);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
(void)dirfd;
|
||||||
|
|
||||||
|
char path[4096];
|
||||||
|
xSnprintf(path, sizeof(path), "%s/%s", dirpath, pathname);
|
||||||
|
|
||||||
|
if (flags & AT_SYMLINK_NOFOLLOW)
|
||||||
|
return lstat(path, statbuf);
|
||||||
|
|
||||||
|
return stat(path, statbuf);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef HEADER_Compat
|
||||||
|
#define HEADER_Compat
|
||||||
|
/*
|
||||||
|
htop - Compat.h
|
||||||
|
(C) 2020 Christian Göttsche
|
||||||
|
Released under the GNU GPLv2, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
|
int Compat_fstatat(int dirfd,
|
||||||
|
const char* dirpath,
|
||||||
|
const char* pathname,
|
||||||
|
struct stat* statbuf,
|
||||||
|
int flags);
|
||||||
|
|
||||||
|
#endif /* HEADER_Compat */
|
|
@ -26,6 +26,7 @@ myhtopsources = \
|
||||||
ColorsPanel.c \
|
ColorsPanel.c \
|
||||||
ColumnsPanel.c \
|
ColumnsPanel.c \
|
||||||
CommandScreen.c \
|
CommandScreen.c \
|
||||||
|
Compat.c \
|
||||||
CPUMeter.c \
|
CPUMeter.c \
|
||||||
CRT.c \
|
CRT.c \
|
||||||
DateMeter.c \
|
DateMeter.c \
|
||||||
|
@ -79,6 +80,7 @@ myhtopheaders = \
|
||||||
ColorsPanel.h \
|
ColorsPanel.h \
|
||||||
ColumnsPanel.h \
|
ColumnsPanel.h \
|
||||||
CommandScreen.h \
|
CommandScreen.h \
|
||||||
|
Compat.h \
|
||||||
DateMeter.h \
|
DateMeter.h \
|
||||||
DateTimeMeter.h \
|
DateTimeMeter.h \
|
||||||
DiskIOMeter.h \
|
DiskIOMeter.h \
|
||||||
|
|
|
@ -88,7 +88,7 @@ AC_TYPE_UID_T
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
AC_FUNC_CLOSEDIR_VOID
|
AC_FUNC_CLOSEDIR_VOID
|
||||||
AC_FUNC_STAT
|
AC_FUNC_STAT
|
||||||
AC_CHECK_FUNCS([memmove strncasecmp strstr strdup])
|
AC_CHECK_FUNCS([fstatat memmove strncasecmp strstr strdup])
|
||||||
|
|
||||||
save_cflags="${CFLAGS}"
|
save_cflags="${CFLAGS}"
|
||||||
CFLAGS="${CFLAGS} -std=c99"
|
CFLAGS="${CFLAGS} -std=c99"
|
||||||
|
|
|
@ -22,6 +22,7 @@ in the source distribution for its full text.
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/user.h>
|
#include <sys/user.h>
|
||||||
|
|
||||||
|
#include "Compat.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
#include "FreeBSDProcess.h"
|
#include "FreeBSDProcess.h"
|
||||||
#include "Macros.h"
|
#include "Macros.h"
|
||||||
|
@ -338,7 +339,7 @@ static void FreeBSDProcessList_scanTTYs(ProcessList* pl) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
struct stat info;
|
struct stat info;
|
||||||
if (fstatat(dirFd, entry->d_name, &info, 0) < 0)
|
if (Compat_fstatat(dirFd, "/dev", entry->d_name, &info, 0) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!S_ISCHR(info.st_mode))
|
if (!S_ISCHR(info.st_mode))
|
||||||
|
@ -365,7 +366,7 @@ err1:
|
||||||
const struct dirent* entry;
|
const struct dirent* entry;
|
||||||
while ((entry = readdir(dirPtr))) {
|
while ((entry = readdir(dirPtr))) {
|
||||||
struct stat info;
|
struct stat info;
|
||||||
if (fstatat(dirFd, entry->d_name, &info, 0) < 0)
|
if (Compat_fstatat(dirFd, "/dev/pts", entry->d_name, &info, 0) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!S_ISCHR(info.st_mode))
|
if (!S_ISCHR(info.st_mode))
|
||||||
|
|
Loading…
Reference in New Issue