Last change
on this file since 1151 was 1140, checked in by Bruno Cornec, 17 years ago |
Try to fix some valgrind reports (note that this version still doesn't work)
|
File size:
959 bytes
|
Rev | Line | |
---|
[1105] | 1 | #include <stdio.h>
|
---|
| 2 | #include <stdlib.h>
|
---|
| 3 | #include <assert.h>
|
---|
| 4 |
|
---|
[1139] | 5 | #include "mr_mem.h"
|
---|
| 6 | #include "mr_file.h"
|
---|
| 7 |
|
---|
[1105] | 8 | void is_null(const char* str)
|
---|
| 9 | {
|
---|
[1139] | 10 | if (str == NULL)
|
---|
| 11 | printf("pointer is null\n");
|
---|
| 12 | else
|
---|
| 13 | printf("pointer is NOT null\n");
|
---|
[1105] | 14 | }
|
---|
| 15 |
|
---|
| 16 | int main(void)
|
---|
| 17 | {
|
---|
[1140] | 18 | char *str = NULL;
|
---|
[1139] | 19 | FILE *fd = NULL;
|
---|
| 20 | size_t n = 0;
|
---|
[1105] | 21 |
|
---|
[1139] | 22 | printf("*** Test with mr_malloc/mr_free\n");
|
---|
| 23 | str = mr_malloc(10);
|
---|
| 24 | is_null(str);
|
---|
| 25 | mr_free(str);
|
---|
| 26 | is_null(str);
|
---|
[1105] | 27 |
|
---|
[1139] | 28 | printf("*** Test with mr_asprintf/mr_free\n");
|
---|
| 29 | mr_asprintf(&str,"Chain %s","of trust");
|
---|
| 30 | printf("Result: %s\n",str);
|
---|
| 31 | mr_free(str);
|
---|
[1105] | 32 |
|
---|
[1139] | 33 | printf("*** Test with mr_getline/mr_free\n");
|
---|
| 34 | fd = mr_fopen("/etc/passwd","r");
|
---|
| 35 | mr_getline(&str,&n,fd);
|
---|
| 36 | printf("1st Result: %s",str);
|
---|
| 37 | mr_getline(&str,&n,fd);
|
---|
| 38 | printf("2nd Result: %s",str);
|
---|
[1140] | 39 | mr_getline(&str,&n,fd);
|
---|
| 40 | strcpy(str,"another line\n");
|
---|
| 41 | printf("3rd Result: %s",str);
|
---|
[1139] | 42 | mr_free(str);
|
---|
| 43 |
|
---|
| 44 | printf("*** Test with NULL\n");
|
---|
| 45 | str = NULL;
|
---|
| 46 | is_null(str);
|
---|
| 47 | mr_free(str);
|
---|
| 48 | is_null(str);
|
---|
| 49 |
|
---|
| 50 | return 0;
|
---|
[1105] | 51 | }
|
---|
| 52 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.