File: strdup.cc

package info (click to toggle)
grap 1.46-1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 912 kB
  • sloc: cpp: 3,260; yacc: 1,115; lex: 1,056; sh: 941; makefile: 42
file content (19 lines) | stat: -rw-r--r-- 299 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifdef STDC_HEADERS
#include <sys/types.h>
#endif

extern "C" {
    void * malloc(size_t size);
};

char *strdup(const char *s) {
    int len = strlen(s)+1;
    char *t;
    int i;

    if ( !(t = (char *) malloc(len)) ) return 0;
    else
	for ( i = 0; i < len; i++ ) t[i] = s[i];

    return t;
}