summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2014-11-14 19:54:07 -0500
committerAnthony G. Basile <blueness@gentoo.org>2014-11-14 19:54:07 -0500
commit1425cbb6062425663480dac8e4e1327cd93c5a98 (patch)
tree4a7dd43febe346e368c27585311c207602b8fb4e /src/shared/util.h
parentd1952898c7604c4075d3ca4cd1988a248dac67f1 (diff)
src/shared/util.{c,h}: import needed functions from upstream
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index a25b2f5aec..ebb02a66b9 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -180,6 +180,10 @@ char *strnappend(const char *s, const char *suffix, size_t length);
char *truncate_nl(char *s);
int rmdir_parents(const char *path, const char *stop);
+
+int get_process_comm(pid_t pid, char **name);
+int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line);
+
char hexchar(int x) _const_;
char octchar(int x) _const_;
@@ -374,6 +378,10 @@ static inline void *mempset(void *s, int c, size_t n) {
return (uint8_t*)s + n;
}
+
+void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size);
+#define GREEDY_REALLOC(array, allocated, need) \
+ greedy_realloc((void**) &(array), &(allocated), (need), sizeof((array)[0]))
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;
}
@@ -412,6 +420,19 @@ int unlink_noerrno(const char *path);
_d_; \
})
+#define procfs_file_alloca(pid, field) \
+ ({ \
+ pid_t _pid_ = (pid); \
+ const char *_r_; \
+ if (_pid_ == 0) { \
+ _r_ = ("/proc/self/" field); \
+ } else { \
+ _r_ = alloca(strlen("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
+ sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_); \
+ } \
+ _r_; \
+ })
+
static inline void qsort_safe(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *)) {
if (nmemb) {