source: trunk/src/emx/src/lib/lgpl/string/strndup.c@ 1076

Last change on this file since 1076 was 1076, checked in by bird, 22 years ago

Initial porting.

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.5 KB
Line 
1/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19#ifdef __EMX__
20#include "libc-alias-glibc.h"
21#endif
22#ifdef HAVE_CONFIG_H
23# include "config.h"
24#endif
25
26#include <stdio.h>
27#include <sys/types.h>
28
29#if defined _LIBC || defined STDC_HEADERS
30# include <stdlib.h>
31# include <string.h>
32#else
33char *malloc ();
34#endif
35
36#undef __strndup
37#undef strndup
38
39#ifndef weak_alias
40# define __strndup strndup
41#endif
42
43char *
44__strndup (s, n)
45 const char *s;
46 size_t n;
47{
48 size_t len = __strnlen (s, n);
49 char *new = (char *) malloc (len + 1);
50
51 if (new == NULL)
52 return NULL;
53
54 new[len] = '\0';
55 return (char *) memcpy (new, s, len);
56}
57#ifdef libc_hidden_def
58libc_hidden_def (__strndup)
59#endif
60#ifdef weak_alias
61weak_alias (__strndup, strndup)
62#endif
Note: See TracBrowser for help on using the repository browser.