aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmdsserver/macros.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/libmdsserver/macros.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h
index 0c2a2e2..bb4e1c3 100644
--- a/src/libmdsserver/macros.h
+++ b/src/libmdsserver/macros.h
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
+#include <string.h>
*/
@@ -180,5 +181,39 @@
buf_next(buffer, type, 1)
+/**
+ * Check whether two strings are equal
+ *
+ * @param a:char* One of the strings
+ * @param b:char* The other of the strings
+ * @return :int Whether the strings are equal
+ */
+#define strequals(a, b) \
+ (strcmp(a, b) == 0)
+
+
+/**
+ * Check whether a string starts with another string
+ *
+ * @param haystack:char* The string to inspect
+ * @param needle:char* The string `haystack` should start with
+ * @return :int Whether `haystack` starts with `needle`
+ */
+#define startswith(haystack, needle) \
+ (strstr(haystack, needle) == haystack)
+
+
+/**
+ * Set effective user and the effective group to the
+ * real user and the real group, respectively. If the
+ * group cannot be set, the user till not be set either.
+ *
+ * @return :int Non-zero on error
+ */
+#define drop_privileges() \
+ ((getegid() == getgid() ? 0 : setegid(getgid())) || \
+ (geteuid() == getuid() ? 0 : seteuid(getuid())))
+
+
#endif