~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/xplt/src/play/all/pstrncat.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * pstrncat.c -- $Id: pstrncat.c,v 1.1 2003/03/08 15:26:47 travo Exp $
 
3
 * strncat that p_mallocs its destination
 
4
 *
 
5
 * Copyright (c) 1998.  See accompanying LEGAL file for details.
 
6
 */
 
7
 
 
8
#include "config.h"
 
9
#include "pstdlib.h"
 
10
#include <string.h>
 
11
 
 
12
char *
 
13
p_strncat(const char *s1, const char *s2, size_t n)
 
14
{
 
15
  if (s2) {
 
16
    size_t n1 = strlen(s2);
 
17
    char *d;
 
18
    if (!n) n = n1;
 
19
    else if (n1<n) n = n1;
 
20
    n1 = s1? strlen(s1) : 0;
 
21
    d = p_malloc(n1+n+1);
 
22
    if (s1) strcpy(d, s1);
 
23
    else d[0] = '\0';
 
24
    strncat(d+n1, s2, n);
 
25
    return d;
 
26
  } else {
 
27
    return p_strcpy(s1);
 
28
  }
 
29
}