1 #include <stdio.h>
2 #include <string.h>
3 
feof_entry(void)4 static int feof_entry(void)
5 {
6     FILE *stream;
7     char data[] = "test fgetc";
8     char getc[sizeof(data)] = {0};
9     size_t size = 0;
10     int ret = 0;
11     int i=0;
12 
13     stream = fopen("fopen_file.txt","w+");
14     if (stream == NULL)
15     {
16         perror("fopen fail");
17         ret = -1;
18         goto __exit;
19     }
20 
21     fwrite(data, sizeof(data), 1, stream);
22     fclose(stream);
23 
24     stream = fopen("fopen_file.txt","r");
25     while(1)
26     {
27         getc[i] = fgetc(stream);
28         i++;
29         if( feof(stream) )
30         {
31             break ;
32         }
33     }
34 
35     if(strcmp(getc, data))
36     {
37         return -1;
38     }
39 
40     fclose(stream);
41 __exit:
42     return ret;
43 }
44 
45 #include <utest.h>
test_feof(void)46 static void test_feof(void)
47 {
48     uassert_int_equal(feof_entry(), 0);
49 }
testcase(void)50 static void testcase(void)
51 {
52     UTEST_UNIT_RUN(test_feof);
53 }
54 UTEST_TC_EXPORT(testcase, "posix.stdio_h.feof.c", RT_NULL, RT_NULL, 10);
55 
56