Skip to content

Commit c4943c9

Browse files
committed
C library: provide implementations of fopen64, freopen64
Some implementations map fopen and freopen, respectively, to the above when large-file support is enabled. To us, large-file support makes no difference, so just use a single implementation for both cases. Will eventually fix Debian bug report 1069438.
1 parent 2d63a71 commit c4943c9

File tree

2 files changed

+68
-26
lines changed

2 files changed

+68
-26
lines changed

src/ansi-c/library/stdio.c

+66-26
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,12 @@ __CPROVER_HIDE:;
7272

7373
void fclose_cleanup(void *stream);
7474
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
75+
FILE *fopen64(const char *filename, const char *mode)
7576

76-
FILE *fopen(const char *filename, const char *mode)
77+
FILE *fopen(const char *filename, const char *mode)
7778
{
7879
__CPROVER_HIDE:;
79-
(void)*filename;
80-
(void)*mode;
81-
#ifdef __CPROVER_STRING_ABSTRACTION
82-
__CPROVER_assert(__CPROVER_is_zero_string(filename), "fopen zero-termination of 1st argument");
83-
__CPROVER_assert(__CPROVER_is_zero_string(mode), "fopen zero-termination of 2nd argument");
84-
#endif
85-
86-
FILE *fopen_result;
87-
88-
__CPROVER_bool fopen_error=__VERIFIER_nondet___CPROVER_bool();
89-
90-
#if !defined(__linux__) || defined(__GLIBC__)
91-
fopen_result=fopen_error?NULL:malloc(sizeof(FILE));
92-
#else
93-
// libraries need to expose the definition of FILE; this is the
94-
// case for musl
95-
fopen_result=fopen_error?NULL:malloc(sizeof(int));
96-
#endif
97-
98-
#ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
99-
__CPROVER_set_must(fopen_result, "open");
100-
__CPROVER_cleanup(fopen_result, fclose_cleanup);
101-
#endif
102-
103-
return fopen_result;
80+
return fopen64(filename, mode);
10481
}
10582

10683
/* FUNCTION: _fopen */
@@ -152,14 +129,77 @@ __CPROVER_HIDE:;
152129
}
153130
#endif
154131

132+
/* FUNCTION: fopen64 */
133+
134+
#ifndef __CPROVER_STDIO_H_INCLUDED
135+
# include <stdio.h>
136+
# define __CPROVER_STDIO_H_INCLUDED
137+
#endif
138+
139+
#ifndef __CPROVER_STDLIB_H_INCLUDED
140+
# include <stdlib.h>
141+
# define __CPROVER_STDLIB_H_INCLUDED
142+
#endif
143+
144+
void fclose_cleanup(void *stream);
145+
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool(void);
146+
147+
FILE *fopen64(const char *filename, const char *mode)
148+
{
149+
__CPROVER_HIDE:;
150+
(void)*filename;
151+
(void)*mode;
152+
#ifdef __CPROVER_STRING_ABSTRACTION
153+
__CPROVER_assert(
154+
__CPROVER_is_zero_string(filename),
155+
"fopen zero-termination of 1st argument");
156+
__CPROVER_assert(
157+
__CPROVER_is_zero_string(mode), "fopen zero-termination of 2nd argument");
158+
#endif
159+
160+
FILE *fopen_result;
161+
162+
__CPROVER_bool fopen_error = __VERIFIER_nondet___CPROVER_bool();
163+
164+
#if !defined(__linux__) || defined(__GLIBC__)
165+
fopen_result = fopen_error ? NULL : malloc(sizeof(FILE));
166+
#else
167+
// libraries need to expose the definition of FILE; this is the
168+
// case for musl
169+
fopen_result = fopen_error ? NULL : malloc(sizeof(int));
170+
#endif
171+
172+
#ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
173+
__CPROVER_set_must(fopen_result, "open");
174+
__CPROVER_cleanup(fopen_result, fclose_cleanup);
175+
#endif
176+
177+
return fopen_result;
178+
}
179+
155180
/* FUNCTION: freopen */
156181

157182
#ifndef __CPROVER_STDIO_H_INCLUDED
158183
#include <stdio.h>
159184
#define __CPROVER_STDIO_H_INCLUDED
160185
#endif
161186

187+
FILE *freopen64(const char *filename, const char *mode, FILE *f);
188+
162189
FILE *freopen(const char *filename, const char *mode, FILE *f)
190+
{
191+
__CPROVER_HIDE:;
192+
return freopen64(filename, mode, f);
193+
}
194+
195+
/* FUNCTION: freopen64 */
196+
197+
#ifndef __CPROVER_STDIO_H_INCLUDED
198+
# include <stdio.h>
199+
# define __CPROVER_STDIO_H_INCLUDED
200+
#endif
201+
202+
FILE *freopen64(const char *filename, const char *mode, FILE *f)
163203
{
164204
__CPROVER_HIDE:;
165205
(void)*filename;

src/ansi-c/library_check.sh

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ perl -p -i -e 's/^__swbuf\n//' __functions # putc, FreeBSD
5555
perl -p -i -e 's/^__CPROVER_deallocate\n//' __functions # free-01
5656
perl -p -i -e 's/^__builtin_alloca\n//' __functions # alloca-01
5757
perl -p -i -e 's/^fclose_cleanup\n//' __functions # fopen
58+
perl -p -i -e 's/^fopen64\n//' __functions # fopen
59+
perl -p -i -e 's/^freopen64\n//' __functions # freopen
5860
perl -p -i -e 's/^munmap\n//' __functions # mmap-01
5961
perl -p -i -e 's/^__fgets_chk\n//' __functions # fgets-01/__fgets_chk.desc
6062
perl -p -i -e 's/^__fprintf_chk\n//' __functions # fprintf-01/__fprintf_chk.desc

0 commit comments

Comments
 (0)