diff options
Diffstat (limited to 'bindings/linux/string.h')
-rw-r--r-- | bindings/linux/string.h | 26 |
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_ */ |