summaryrefslogtreecommitdiff
path: root/bindings/linux/string.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2012-03-31 12:17:32 -0700
committerJoshua Haberman <jhaberman@gmail.com>2012-03-31 12:17:32 -0700
commitcca4818eb7769d6e776bdc30516a5f871f1d6393 (patch)
treee67dd65d5c016028ae976b09b2d69f6b7525aa5f /bindings/linux/string.h
parent26ed1e996171c8ffa2ced42ac69b1b82c1956e1f (diff)
Sync from internal Google development.
Diffstat (limited to 'bindings/linux/string.h')
-rw-r--r--bindings/linux/string.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/bindings/linux/string.h b/bindings/linux/string.h
new file mode 100644
index 0000000..69de3fa
--- /dev/null
+++ b/bindings/linux/string.h
@@ -0,0 +1,26 @@
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Copyright (c) 2012 Google Inc. See LICENSE for details.
+ * Author: Josh Haberman <jhaberman@gmail.com>
+ */
+
+#ifndef UPB_LINUX_STRING_H_
+#define UPB_LINUX_STRING_H_
+
+#include <linux/string.h>
+#include <stdlib.h>
+#include "upb/upb.h" // For INLINE.
+
+INLINE char *strdup(const char *s) {
+ size_t len = strlen(s);
+ char *ret = malloc(len + 1);
+ if (ret == NULL) return NULL;
+ // Be particularly defensive and guard against buffer overflow if there
+ // is a concurrent mutator.
+ strncpy(ret, s, len);
+ ret[len] = '\0';
+ return ret;
+}
+
+#endif /* UPB_DEF_H_ */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback