From cca4818eb7769d6e776bdc30516a5f871f1d6393 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 31 Mar 2012 12:17:32 -0700 Subject: Sync from internal Google development. --- bindings/linux/string.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 bindings/linux/string.h (limited to 'bindings/linux/string.h') 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 + */ + +#ifndef UPB_LINUX_STRING_H_ +#define UPB_LINUX_STRING_H_ + +#include +#include +#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_ */ -- cgit v1.2.3