~ubuntu-branches/ubuntu/feisty/icoutils/feisty

« back to all changes in this revision

Viewing changes to compat/lib/strndup.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-05-26 15:15:36 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050526151536-uzg8vlhedkx1nwcx
Tags: 0.25.0-1
* New upstream release.
  - 'make distclean' fixed; revert workarounds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1996, 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
2
 
 
3
 
   NOTE: The canonical source of this file is maintained with the GNU C Library.
4
 
   Bugs can be reported to bug-glibc@prep.ai.mit.edu.
5
 
 
6
 
   This program is free software; you can redistribute it and/or modify it
7
 
   under the terms of the GNU General Public License as published by the
8
 
   Free Software Foundation; either version 2, or (at your option) any
9
 
   later version.
10
 
 
11
 
   This program is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this program; if not, write to the Free Software Foundation,
18
 
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
# include "config.h"
22
 
#endif
23
 
 
24
 
#include <stdlib.h>
25
 
#include <string.h>
26
 
 
27
 
#ifndef HAVE_DECL_STRNLEN
28
 
"this configure-time declaration test was not run"
29
 
#endif
30
 
#if !HAVE_DECL_STRNLEN
31
 
size_t strnlen ();
32
 
#endif
33
 
 
34
 
#undef __strndup
35
 
#undef strndup
36
 
 
37
 
#ifndef weak_alias
38
 
# define __strndup strndup
39
 
#endif
40
 
 
41
 
char *
42
 
__strndup (const char *s, size_t n)
43
 
{
44
 
  size_t len = strnlen (s, n);
45
 
  char *new = malloc (len + 1);
46
 
 
47
 
  if (new == NULL)
48
 
    return NULL;
49
 
 
50
 
  new[len] = '\0';
51
 
  return memcpy (new, s, len);
52
 
}
53
 
#ifdef weak_alias
54
 
weak_alias (__strndup, strndup)
55
 
#endif