aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2021-05-05 19:58:47 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2021-05-05 19:58:47 -0400
commit70c312779ecad328a8003b93ebe253c4598b6980 (patch)
treeedd173bbba824632cb55b7818367744a6a4de691
parenta92b4038179c3706bd176097be1caabd88824755 (diff)
downloadcleanpath-70c312779ecad328a8003b93ebe253c4598b6980.tar.gz
Add
* OS detection * linux specfic limits header
-rw-r--r--include/cleanpath.h34
-rw-r--r--lib/cleanpath.c4
2 files changed, 34 insertions, 4 deletions
diff --git a/include/cleanpath.h b/include/cleanpath.h
index 4e7d35d..321f921 100644
--- a/include/cleanpath.h
+++ b/include/cleanpath.h
@@ -1,6 +1,32 @@
#ifndef CLEANPATH_CLEANPATH_H
#define CLEANPATH_CLEANPATH_H
+// Define some platform detection shortcuts
+#define OS_DARWIN 0
+#define OS_WINDOWS 0
+#define OS_LINUX 0
+#define OS_SUPPORTED 0
+
+#if defined(__APPLE__) && defined(__MACH__)
+# undef OS_DARWIN
+# define OS_DARWIN 1
+# undef OS_SUPPORTED
+# define OS_SUPPORTED 1
+
+#elif defined(_WIN32)
+# undef OS_WINDOWS
+# define OS_WINDOWS 1
+
+#elif defined(__linux) || defined(__linux__)
+# undef OS_LINUX
+# define OS_LINUX 1
+# undef OS_SUPPORTED
+# define OS_SUPPORTED 1
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
#define CLEANPATH_VERSION "0.1.0"
#define CLEANPATH_FILTER_NONE -1
#define CLEANPATH_FILTER_EXACT 0
@@ -11,11 +37,11 @@
#define CLEANPATH_SEP ":"
struct CleanPath {
- char *data; // Pointer to the path string
- size_t data_len; // Length of the path string
- char *sep; // Pointer to the separator used to split the data string
+ char *data; // Pointer to the path string
+ size_t data_len; // Length of the path string
+ char *sep; // Pointer to the separator used to split the data string
char *part[CLEANPATH_PART_MAX]; // Array of pointers to path elements
- size_t part_nelem; // Total number of elements in part array
+ size_t part_nelem; // Total number of elements in part array
};
// Prototypes
diff --git a/lib/cleanpath.c b/lib/cleanpath.c
index 344c705..d7f207d 100644
--- a/lib/cleanpath.c
+++ b/lib/cleanpath.c
@@ -4,6 +4,10 @@
#include <regex.h>
#include "cleanpath.h"
+#if OS_LINUX
+#include <linux/limits.h>
+#endif
+
/**
* Split path into parts by sep
* @param path a string (e.g. "/path1:/path2:/pathN")