summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index cfb54939cd..6575f56811 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -21,6 +21,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <alloca.h>
#include <inttypes.h>
#include <time.h>
#include <sys/time.h>
@@ -696,3 +697,12 @@ int unlink_noerrno(const char *path);
strcpy(stpcpy(_c_, _a_), _b_); \
_c_; \
})
+
+#define procfs_file_alloca(pid, field) \
+ ({ \
+ pid_t _pid_ = (pid); \
+ char *_r_; \
+ _r_ = alloca(sizeof("/proc/") -1 + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
+ sprintf(_r_, "/proc/%lu/" field, (unsigned long) _pid_); \
+ _r_; \
+ })