summaryrefslogtreecommitdiff
path: root/include/libsysfs.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libsysfs.h')
-rw-r--r--include/libsysfs.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/libsysfs.h b/include/libsysfs.h
index c6dff1e..29194f6 100644
--- a/include/libsysfs.h
+++ b/include/libsysfs.h
@@ -27,6 +27,24 @@
#include <string.h>
#include "dlist.h"
+/*
+ * Defines to prevent buffer overruns
+ */
+#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1)
+#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
+
+#define safestrcpymax(to, from, max) \
+do { \
+ to[max-1] = '\0'; \
+ strncpy(to, from, max-1); \
+} while (0)
+
+#define safestrcatmax(to, from, max) \
+do { \
+ to[max-1] = '\0'; \
+ strncat(to, from, max - strlen(to)-1); \
+} while (0)
+
/*
* Generic #defines go here..
*/