diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-12-20 04:27:51 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-12-20 04:27:51 +0100 |
commit | cf95befdf44aeed8cac17f394ac5bdd00267a54c (patch) | |
tree | 0adb49938cbd6a74c4c1bebcdbd6064033e4a110 | |
parent | 9782dc0203056c9da1457caa761409c443b21446 (diff) | |
download | psutil-cf95befdf44aeed8cac17f394ac5bdd00267a54c.tar.gz |
refactor C macros
-rw-r--r-- | psutil/_psutil_bsd.c | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index cd5ec3d8..afe3834e 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -64,14 +64,7 @@ #ifdef PSUTIL_FREEBSD #include "arch/bsd/freebsd.h" #include "arch/bsd/freebsd_socks.h" -#elif PSUTIL_OPENBSD - #include "arch/bsd/openbsd.h" -#elif PSUTIL_NETBSD - #include "arch/bsd/netbsd.h" - #include "arch/bsd/netbsd_socks.h" -#endif -#ifdef PSUTIL_FREEBSD #include <net/if_media.h> #include <devstat.h> // get io counters #include <libutil.h> // process open files, shared libs (kinfo_getvmmap) @@ -80,27 +73,29 @@ #else #include <utmpx.h> #endif -#endif +#elif PSUTIL_OPENBSD + #include "arch/bsd/openbsd.h" -#ifdef PSUTIL_OPENBSD #include <utmp.h> #include <sys/vnode.h> // for VREG #define _KERNEL // for DTYPE_VNODE #include <sys/file.h> #undef _KERNEL #include <sys/sched.h> // for CPUSTATES & CP_* -#endif +#elif PSUTIL_NETBSD + #include "arch/bsd/netbsd.h" + #include "arch/bsd/netbsd_socks.h" -#if defined(PSUTIL_NETBSD) #include <utmpx.h> #include <sys/vnode.h> // for VREG #include <sys/sched.h> // for CPUSTATES & CP_* #ifndef DTYPE_VNODE - #define DTYPE_VNODE 1 + #define DTYPE_VNODE 1 #endif #endif + // convert a timeval struct to a double #define PSUTIL_TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0) @@ -412,7 +407,7 @@ psutil_cpu_count_logical(PyObject *self, PyObject *args) { */ static PyObject * psutil_cpu_times(PyObject *self, PyObject *args) { -#if defined(PSUTIL_NETBSD) +#ifdef PSUTIL_NETBSD u_int64_t cpu_time[CPUSTATES]; #else long cpu_time[CPUSTATES]; @@ -479,12 +474,12 @@ psutil_proc_open_files(PyObject *self, PyObject *args) { (kif->kf_vnode_type == KF_VTYPE_VREG)) { py_tuple = Py_BuildValue("(si)", kif->kf_path, kif->kf_fd); -#elif defined(PSUTIL_OPENBSD) +#elif PSUTIL_OPENBSD if ((kif->f_type == DTYPE_VNODE) && (kif->v_type == VREG)) { py_tuple = Py_BuildValue("(si)", "", kif->fd_fd); -#elif defined(PSUTIL_NETBSD) +#elif PSUTIL_NETBSD if ((kif->ki_ftype == DTYPE_VNODE) && (kif->ki_vtype == VREG)) { @@ -521,7 +516,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { long len; uint64_t flags; char opts[200]; -#if defined(PSUTIL_NETBSD) +#ifdef PSUTIL_NETBSD struct statvfs *fs = NULL; #else struct statfs *fs = NULL; @@ -534,7 +529,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { // get the number of mount points Py_BEGIN_ALLOW_THREADS -#if defined(PSUTIL_NETBSD) +#ifdef PSUTIL_NETBSD num = getvfsstat(NULL, 0, MNT_NOWAIT); #else num = getfsstat(NULL, 0, MNT_NOWAIT); @@ -553,7 +548,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { } Py_BEGIN_ALLOW_THREADS -#if defined(PSUTIL_NETBSD) +#ifdef PSUTIL_NETBSD num = getvfsstat(fs, len, MNT_NOWAIT); #else num = getfsstat(fs, len, MNT_NOWAIT); @@ -567,7 +562,7 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { for (i = 0; i < num; i++) { py_tuple = NULL; opts[0] = 0; -#if defined(PSUTIL_NETBSD) +#ifdef PSUTIL_NETBSD flags = fs[i].f_flag; #else flags = fs[i].f_flags; @@ -618,17 +613,17 @@ psutil_disk_partitions(PyObject *self, PyObject *args) { strlcat(opts, ",union", sizeof(opts)); if (flags & MNT_NOCOREDUMP) strlcat(opts, ",nocoredump", sizeof(opts)); -#if defined(MNT_RELATIME) +#ifdef MNT_RELATIME if (flags & MNT_RELATIME) strlcat(opts, ",relatime", sizeof(opts)); #endif if (flags & MNT_IGNORE) strlcat(opts, ",ignore", sizeof(opts)); -#if defined(MNT_DISCARD) +#ifdef MNT_DISCARD if (flags & MNT_DISCARD) strlcat(opts, ",discard", sizeof(opts)); #endif -#if defined(MNT_EXTATTR) +#ifdef MNT_EXTATTR if (flags & MNT_EXTATTR) strlcat(opts, ",extattr", sizeof(opts)); #endif |