Last change
on this file since 1178 was
1178,
checked in by Bruno Cornec, 14 years ago
|
Continue to merge trunk memory management enhancements for libmondo-tools.c & libmondo-string.c
Introduction + test of a new function mr_strcat
|
File size:
1.1 KB
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | #include <assert.h> |
---|
5 | |
---|
6 | #include "mr_mem.h" |
---|
7 | #include "mr_file.h" |
---|
8 | |
---|
9 | void is_null(const char* str) |
---|
10 | { |
---|
11 | if (str == NULL) |
---|
12 | printf("pointer is null\n"); |
---|
13 | else |
---|
14 | printf("pointer is NOT null\n"); |
---|
15 | } |
---|
16 | |
---|
17 | int main(void) |
---|
18 | { |
---|
19 | char *str = NULL; |
---|
20 | FILE *fd = NULL; |
---|
21 | size_t n = 0; |
---|
22 | |
---|
23 | printf("*** Test with mr_malloc/mr_free\n"); |
---|
24 | str = mr_malloc(10); |
---|
25 | is_null(str); |
---|
26 | mr_free(str); |
---|
27 | is_null(str); |
---|
28 | |
---|
29 | printf("*** Test with mr_asprintf/mr_free\n"); |
---|
30 | mr_asprintf(&str,"Chain %s","of trust"); |
---|
31 | printf("Result: %s\n",str); |
---|
32 | mr_free(str); |
---|
33 | |
---|
34 | printf("*** Test with mr_strcat\n"); |
---|
35 | mr_asprintf(&str,"Another Chain"); |
---|
36 | mr_strcat(str," of trust"); |
---|
37 | printf("Result: %s\n",str); |
---|
38 | mr_free(str); |
---|
39 | |
---|
40 | printf("*** Test with mr_getline/mr_free\n"); |
---|
41 | fd = mr_fopen("/etc/passwd","r"); |
---|
42 | mr_getline(&str,&n,fd); |
---|
43 | printf("1st Result: %s",str); |
---|
44 | mr_getline(&str,&n,fd); |
---|
45 | printf("2nd Result: %s",str); |
---|
46 | mr_getline(&str,&n,fd); |
---|
47 | strcpy(str,"another line\n"); |
---|
48 | printf("3rd Result: %s",str); |
---|
49 | mr_free(str); |
---|
50 | |
---|
51 | printf("*** Test with NULL\n"); |
---|
52 | str = NULL; |
---|
53 | is_null(str); |
---|
54 | mr_free(str); |
---|
55 | is_null(str); |
---|
56 | |
---|
57 | return 0; |
---|
58 | } |
---|
59 | |
---|
Note: See
TracBrowser
for help on using the repository browser.