summaryrefslogtreecommitdiff
path: root/support/strndup.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@src.gnome.org>1998-03-04 07:27:47 +0000
committerTom Tromey <tromey@src.gnome.org>1998-03-04 07:27:47 +0000
commita3e0e6e106c26d96b8dc93fe4ae13998b869aca3 (patch)
tree3a5a99f92e8bd8890f9fdec3257a97e7de1bae08 /support/strndup.c
parent14aef94e9aabba307fdfb769cd3f1d4bf513d4de (diff)
downloadshared-mime-info-a3e0e6e106c26d96b8dc93fe4ae13998b869aca3.tar.gz
Initial revision
svn path=/trunk/; revision=97
Diffstat (limited to 'support/strndup.c')
-rw-r--r--support/strndup.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/support/strndup.c b/support/strndup.c
new file mode 100644
index 00000000..72635bb9
--- /dev/null
+++ b/support/strndup.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+char *
+__strndup (const char *s, size_t n)
+{
+ size_t len = strnlen (s, n);
+ char *new = malloc (len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return memcpy (new, s, len);
+}
+weak_alias (__strndup, strndup)