File: strdup2.c

package info (click to toggle)
sctk 2.4.10-20151007-1312Z%2Bdfsg2-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 17,332 kB
  • ctags: 4,598
  • sloc: ansic: 25,664; cpp: 13,648; perl: 9,898; sh: 1,566; makefile: 916
file content (21 lines) | stat: -rw-r--r-- 733 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
/* file strdup2.c */

#if !defined(COMPILE_ENVIRONMENT)
#include "stdcenvf.h" /* std compile environment for functions */
#endif

 /******************************************************/
 /*  strdup_safe(ps,calling_proc)                      */
 /*  Like strdup(ps) except fatal err if malloc fails. */
 /******************************************************/
 Char *strdup_safe(Char *ps, Char *calling_proc)
 {Char *proc = "strdup_safe";
  Char *pd;
if (db_level > 3) printf("%sdoing %s\n",pdb,proc);
  pd = (Char*)malloc((size_t)strlen(ps)+1);
  if (pd == NULL) fatal_error(calling_proc,"MEM ALLOC",-1);
  else   pd = strcpy(pd,ps);
  if (memory_trace) printf("%s MALLOC %xl\n",pdb,(long)pd);
  return pd;
 }
/* end strdup2.c */