diff options
Diffstat (limited to 'psutil/_psutil_common.h')
| -rw-r--r-- | psutil/_psutil_common.h | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h index 34c428c0..6cf19d65 100644 --- a/psutil/_psutil_common.h +++ b/psutil/_psutil_common.h @@ -10,11 +10,15 @@ // --- Global vars / constants // ==================================================================== -extern int PSUTIL_TESTING; extern int PSUTIL_DEBUG; // a signaler for connections without an actual status static const int PSUTIL_CONN_NONE = 128; +// strncpy() variant which appends a null terminator. +#define PSUTIL_STRNCPY(dst, src, n) \ + strncpy(dst, src, n - 1); \ + dst[n - 1] = '\0' + // ==================================================================== // --- Backward compatibility with missing Python.h APIs // ==================================================================== @@ -95,10 +99,25 @@ PyObject* PyErr_SetFromOSErrnoWithSyscall(const char *syscall); // --- Global utils // ==================================================================== -PyObject* psutil_set_testing(PyObject *self, PyObject *args); -void psutil_debug(const char* format, ...); +PyObject* psutil_set_debug(PyObject *self, PyObject *args); int psutil_setup(void); + +// Print a debug message on stderr. +#define psutil_debug(...) do { \ + if (! PSUTIL_DEBUG) \ + break; \ + fprintf(stderr, "psutil-debug [%s:%d]> ", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n");} while(0) + + +// ==================================================================== +// --- BSD +// ==================================================================== + +void convert_kvm_err(const char *syscall, char *errbuf); + // ==================================================================== // --- Windows // ==================================================================== @@ -123,6 +142,14 @@ int psutil_setup(void); #define MALLOC_ZERO(x) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (x)) #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) + #define _NT_FACILITY_MASK 0xfff + #define _NT_FACILITY_SHIFT 16 + #define _NT_FACILITY(status) \ + ((((ULONG)(status)) >> _NT_FACILITY_SHIFT) & _NT_FACILITY_MASK) + + #define NT_NTWIN32(status) (_NT_FACILITY(status) == FACILITY_WIN32) + #define WIN32_FROM_NTSTATUS(status) (((ULONG)(status)) & 0xffff) + #define LO_T 1e-7 #define HI_T 429.4967296 |
