File: add.c

package info (click to toggle)
mh 6.8.4-28
  • links: PTS
  • area: main
  • in suites: slink
  • size: 7,012 kB
  • ctags: 7,496
  • sloc: ansic: 75,211; sh: 3,112; lisp: 2,205; ml: 1,894; makefile: 724; perl: 482; csh: 150; tcl: 66; sed: 43; awk: 7
file content (24 lines) | stat: -rw-r--r-- 475 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* add.c - concatenate two strings in managed memory */

#include "../h/mh.h"
#include <stdio.h>


char   *add (this, that)
register char  *this,
               *that;
{
    register char  *cp;

    if (!this)
	this = "";
    if (!that)
	that = "";
    if ((cp = malloc ((unsigned) (strlen (this) + strlen (that) + 1))) == NULL)
	adios (NULLCP, "unable to allocate string storage");

    (void) sprintf (cp, "%s%s", that, this);
    if (*that)
	free (that);
    return cp;
}