OpenCoverage

read-file.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/lib/read-file.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16-
17-
18-
19char *-
20fread_file (FILE *stream, size_t *length)-
21{-
22 char *buf = -
23 ((void *)0)-
24 ;-
25 size_t alloc = -
26 8192-
27 ;-
28-
29-
30-
31 {-
32 struct stat st;-
33-
34 if (fstat (fileno (stream), &st) >= 0
fstat (fileno ...am), &st) >= 0Description
TRUEevaluated 41 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEnever evaluated
&&
0-41
35 ((((
(((( st.st_mod... == (0100000))Description
TRUEevaluated 25 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • ptx
  • shuf
16-25
36 st.st_mode
(((( st.st_mod... == (0100000))Description
TRUEevaluated 25 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • ptx
  • shuf
16-25
37 )) & 0170000) == (0100000))
(((( st.st_mod... == (0100000))Description
TRUEevaluated 25 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • ptx
  • shuf
16-25
38 )-
39 {-
40 off_t pos = ftello (stream);-
41-
42 if (pos >= 0
pos >= 0Description
TRUEevaluated 25 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEnever evaluated
&& pos < st.st_size
pos < st.st_sizeDescription
TRUEevaluated 22 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEevaluated 3 times by 1 test
Evaluated by:
  • ptx
)
0-25
43 {-
44 off_t alloc_off = st.st_size - pos;-
45-
46-
47 if (-
48 (
(1844674407370... 1 < alloc_offDescription
TRUEnever evaluated
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • ptx
  • shuf
18446744073709551615UL)
(1844674407370... 1 < alloc_offDescription
TRUEnever evaluated
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • ptx
  • shuf
0-22
49 - 1 < alloc_off
(1844674407370... 1 < alloc_offDescription
TRUEnever evaluated
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • ptx
  • shuf
)
0-22
50 {-
51 -
52 (*__errno_location ()) -
53 = -
54 12-
55 ;-
56 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
57 ((void *)0)
never executed: return ((void *)0) ;
0
58 ;
never executed: return ((void *)0) ;
0
59 }-
60-
61 alloc = alloc_off + 1;-
62 }
executed 22 times by 2 tests: end of block
Executed by:
  • ptx
  • shuf
22
63 }
executed 25 times by 2 tests: end of block
Executed by:
  • ptx
  • shuf
25
64 }-
65-
66 if (!(buf = malloc (alloc))
!(buf = malloc (alloc))Description
TRUEnever evaluated
FALSEevaluated 41 times by 2 tests
Evaluated by:
  • ptx
  • shuf
)
0-41
67 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
68 ((void *)0)
never executed: return ((void *)0) ;
0
69 ;
never executed: return ((void *)0) ;
0
70-
71 {-
72 size_t size = 0;-
73 int save_errno;-
74-
75 for (;;)-
76 {-
77-
78-
79 size_t requested = alloc - size;-
80 size_t count = fread (buf + size, 1, requested, stream);-
81 size += count;-
82-
83 if (count != requested
count != requestedDescription
TRUEevaluated 41 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEevaluated 1 time by 1 test
Evaluated by:
  • shuf
)
1-41
84 {-
85 save_errno = -
86 (*__errno_location ())-
87 ;-
88 if (ferror (stream)
ferror (stream)Description
TRUEnever evaluated
FALSEevaluated 41 times by 2 tests
Evaluated by:
  • ptx
  • shuf
)
0-41
89 break;
never executed: break;
0
90-
91-
92 if (size < alloc - 1
size < alloc - 1Description
TRUEevaluated 19 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • ptx
  • shuf
)
19-22
93 {-
94 char *smaller_buf = realloc (buf, size + 1);-
95 if (smaller_buf !=
smaller_buf != ((void *)0)Description
TRUEevaluated 19 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEnever evaluated
0-19
96 ((void *)0)
smaller_buf != ((void *)0)Description
TRUEevaluated 19 times by 2 tests
Evaluated by:
  • ptx
  • shuf
FALSEnever evaluated
0-19
97 )-
98 buf = smaller_buf;
executed 19 times by 2 tests: buf = smaller_buf;
Executed by:
  • ptx
  • shuf
19
99 }
executed 19 times by 2 tests: end of block
Executed by:
  • ptx
  • shuf
19
100-
101 buf[size] = '\0';-
102 *length = size;-
103 return
executed 41 times by 2 tests: return buf;
Executed by:
  • ptx
  • shuf
buf;
executed 41 times by 2 tests: return buf;
Executed by:
  • ptx
  • shuf
41
104 }-
105-
106 {-
107 char *new_buf;-
108-
109 if (alloc ==
alloc == (1844...73709551615UL)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • shuf
0-1
110 (18446744073709551615UL)
alloc == (1844...73709551615UL)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • shuf
0-1
111 )-
112 {-
113 save_errno = -
114 12-
115 ;-
116 break;
never executed: break;
0
117 }-
118-
119 if (alloc <
alloc < (18446...L) - alloc / 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • shuf
FALSEnever evaluated
0-1
120 (18446744073709551615UL)
alloc < (18446...L) - alloc / 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • shuf
FALSEnever evaluated
0-1
121 - alloc / 2
alloc < (18446...L) - alloc / 2Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • shuf
FALSEnever evaluated
)
0-1
122 alloc = alloc + alloc / 2;
executed 1 time by 1 test: alloc = alloc + alloc / 2;
Executed by:
  • shuf
1
123 else-
124 alloc =
never executed: alloc = (18446744073709551615UL) ;
0
125 (18446744073709551615UL)
never executed: alloc = (18446744073709551615UL) ;
0
126 ;
never executed: alloc = (18446744073709551615UL) ;
0
127-
128 if (!(new_buf = realloc (buf, alloc))
!(new_buf = re... (buf, alloc))Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • shuf
)
0-1
129 {-
130 save_errno = -
131 (*__errno_location ())-
132 ;-
133 break;
never executed: break;
0
134 }-
135-
136 buf = new_buf;-
137 }-
138 }
executed 1 time by 1 test: end of block
Executed by:
  • shuf
1
139-
140 free (buf);-
141 -
142 (*__errno_location ()) -
143 = save_errno;-
144 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
145 ((void *)0)
never executed: return ((void *)0) ;
0
146 ;
never executed: return ((void *)0) ;
0
147 }-
148}-
149-
150static char *-
151internal_read_file (const char *filename, size_t *length, const char *mode)-
152{-
153 FILE *stream = fopen (filename, mode);-
154 char *out;-
155 int save_errno;-
156-
157 if (!stream
!streamDescription
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
)
0-15
158 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
159 ((void *)0)
never executed: return ((void *)0) ;
0
160 ;
never executed: return ((void *)0) ;
0
161-
162 out = fread_file (stream, length);-
163-
164 save_errno = -
165 (*__errno_location ())-
166 ;-
167-
168 if (-
169 rpl_fclose
rpl_fclose (stream) != 0Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
0-15
170 (stream) != 0
rpl_fclose (stream) != 0Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • ptx
)
0-15
171 {-
172 if (out
outDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
173 {-
174 save_errno = -
175 (*__errno_location ())-
176 ;-
177 free (out);-
178 }
never executed: end of block
0
179 -
180 (*__errno_location ()) -
181 = save_errno;-
182 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
183 ((void *)0)
never executed: return ((void *)0) ;
0
184 ;
never executed: return ((void *)0) ;
0
185 }-
186-
187 return
executed 15 times by 1 test: return out;
Executed by:
  • ptx
out;
executed 15 times by 1 test: return out;
Executed by:
  • ptx
15
188}-
189-
190-
191-
192-
193-
194-
195-
196char *-
197read_file (const char *filename, size_t *length)-
198{-
199 return
executed 15 times by 1 test: return internal_read_file (filename, length, "r");
Executed by:
  • ptx
internal_read_file (filename, length, "r");
executed 15 times by 1 test: return internal_read_file (filename, length, "r");
Executed by:
  • ptx
15
200}-
201char *-
202read_binary_file (const char *filename, size_t *length)-
203{-
204 return
never executed: return internal_read_file (filename, length, "rb");
internal_read_file (filename, length, "rb");
never executed: return internal_read_file (filename, length, "rb");
0
205}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2