File: strcat_alloc.c

package info (click to toggle)
safecat 1.12-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 512 kB
  • ctags: 253
  • sloc: ansic: 1,938; makefile: 392; sh: 282
file content (27 lines) | stat: -rw-r--r-- 822 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "config.h"
#include "strcat_alloc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* ****************************************************************** */
char *strcat_alloc(const char *path,const char *filename) {
  /* Allocate a pointer to return. */
  char *retval = (char *)malloc(strlen(path) + strlen(filename) + 2);
  if(retval == NULL) {
    fprintf(stderr, "Could not allocate memory.\n");
    exit(1);
  }

  /* Copy the path and filename to the destination string. */
  memcpy(retval,path,strlen(path));
  if(retval[strlen(path)] != '/') {
    retval[strlen(path)] = '/';
    retval[strlen(path) + 1] = '\0';
  }

  /* Append the temp filename to our new strings. */
  strcat(retval,filename);
  return(retval);
}
/* ****************************************************************** */