Last change
on this file since 1184 was 1178, checked in by Bruno Cornec, 17 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
|
Rev | Line | |
---|
[1105] | 1 | #include <stdio.h>
|
---|
| 2 | #include <stdlib.h>
|
---|
[1178] | 3 | #include <string.h>
|
---|
[1105] | 4 | #include <assert.h>
|
---|
| 5 |
|
---|
[1139] | 6 | #include "mr_mem.h"
|
---|
| 7 | #include "mr_file.h"
|
---|
| 8 |
|
---|
[1105] | 9 | void is_null(const char* str)
|
---|
| 10 | {
|
---|
[1139] | 11 | if (str == NULL)
|
---|
| 12 | printf("pointer is null\n");
|
---|
| 13 | else
|
---|
| 14 | printf("pointer is NOT null\n");
|
---|
[1105] | 15 | }
|
---|
| 16 |
|
---|
| 17 | int main(void)
|
---|
| 18 | {
|
---|
[1140] | 19 | char *str = NULL;
|
---|
[1139] | 20 | FILE *fd = NULL;
|
---|
| 21 | size_t n = 0;
|
---|
[1105] | 22 |
|
---|
[1139] | 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);
|
---|
[1105] | 28 |
|
---|
[1139] | 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);
|
---|
[1105] | 33 |
|
---|
[1178] | 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 |
|
---|
[1139] | 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);
|
---|
[1140] | 46 | mr_getline(&str,&n,fd);
|
---|
| 47 | strcpy(str,"another line\n");
|
---|
| 48 | printf("3rd Result: %s",str);
|
---|
[1139] | 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;
|
---|
[1105] | 58 | }
|
---|
| 59 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.