blob: 2457de0c7be00de3cc991bf929cd141e2de754a8 (
plain)
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
28
29
30
31
32
33
34
35
36
37
38
|
//---------------
//- http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html
//---------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv) {
const char* source =
"strndup - duplicate a specific number of bytes from a string";
char* strdup_val = strndup(source, 0);
printf("1:%s\n", strdup_val);
free(strdup_val);
strdup_val = strndup(source, 7);
printf("2:%s\n", strdup_val);
free(strdup_val);
strdup_val = strndup(source, 1000);
printf("3:%s\n", strdup_val);
free(strdup_val);
strdup_val = strndup(source, 60);
printf("4:%s\n", strdup_val);
free(strdup_val);
strdup_val = strndup(source, 19);
printf("5:%s\n", strdup_val);
free(strdup_val);
strdup_val = strndup(source, -1);
printf("6:%s\n", strdup_val);
free(strdup_val);
return 0;
}
|