Rev 3756 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3756 | Rev 3757 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | char * test_stdio1(bool quiet) |
37 | char * test_stdio1(bool quiet) |
| 38 | { |
38 | { |
| 39 | FILE *f; |
39 | FILE *f; |
| 40 | char *file_name = "/readme"; |
40 | char *file_name = "/readme"; |
| 41 | size_t n; |
41 | size_t n; |
| - | 42 | int c; |
|
| 42 | 43 | ||
| 43 | printf("Open file '%s'\n", file_name); |
44 | printf("Open file '%s'\n", file_name); |
| 44 | errno = 0; |
45 | errno = 0; |
| 45 | f = fopen(file_name, "rt"); |
46 | f = fopen(file_name, "rt"); |
| 46 | 47 | ||
| Line 58... | Line 59... | ||
| 58 | printf("Read %d bytes.\n", n); |
59 | printf("Read %d bytes.\n", n); |
| 59 | 60 | ||
| 60 | buf[n] = '\0'; |
61 | buf[n] = '\0'; |
| 61 | printf("Read string '%s'.\n", buf); |
62 | printf("Read string '%s'.\n", buf); |
| 62 | 63 | ||
| - | 64 | printf("Seek to beginning.\n"); |
|
| - | 65 | if (fseek(f, 0, SEEK_SET) != 0) { |
|
| 63 | fclose(f); |
66 | fclose(f); |
| - | 67 | return "Failed seeking."; |
|
| - | 68 | } |
|
| - | 69 | ||
| - | 70 | printf("Read using fgetc().\n"); |
|
| - | 71 | while (true) { |
|
| - | 72 | c = fgetc(f); |
|
| - | 73 | if (c == EOF) break; |
|
| - | 74 | ||
| - | 75 | printf("'%c'", c); |
|
| - | 76 | } |
|
| - | 77 | ||
| - | 78 | printf("[EOF]\n"); |
|
| - | 79 | printf("Closing.\n"); |
|
| - | 80 | ||
| - | 81 | if (fclose(f) != 0) |
|
| - | 82 | return "Failed closing."; |
|
| 64 | 83 | ||
| 65 | return NULL; |
84 | return NULL; |
| 66 | } |
85 | } |