summaryrefslogtreecommitdiff
path: root/bindings/linux/string.h
blob: 69de3fa0e9fb102bc1048327d1464a3270c9a82b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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