@@ -65,7 +65,14 @@ inline FILE *fopen(const char *filename, const char *mode)
65
65
FILE * fopen_result ;
66
66
67
67
_Bool fopen_error ;
68
+
69
+ #if !defined(__linux__ ) || defined(__GLIBC__ )
68
70
fopen_result = fopen_error ?NULL :malloc (sizeof (FILE ));
71
+ #else
72
+ // libraries need to expose the definition of FILE; this is the
73
+ // case for musl
74
+ fopen_result = fopen_error ?NULL :malloc (sizeof (int ));
75
+ #endif
69
76
70
77
#ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
71
78
__CPROVER_set_must (fopen_result , "open" );
@@ -99,6 +106,11 @@ inline FILE* freopen(const char *filename, const char *mode, FILE *f)
99
106
#define __CPROVER_STDIO_H_INCLUDED
100
107
#endif
101
108
109
+ #ifndef __CPROVER_STDLIB_H_INCLUDED
110
+ #include <stdlib.h>
111
+ #define __CPROVER_STDLIB_H_INCLUDED
112
+ #endif
113
+
102
114
inline int fclose (FILE * stream )
103
115
{
104
116
__CPROVER_HIDE :;
@@ -135,19 +147,56 @@ inline FILE *fdopen(int handle, const char *mode)
135
147
"fdopen zero-termination of 2nd argument" );
136
148
#endif
137
149
150
+ #if !defined(__linux__ ) || defined(__GLIBC__ )
138
151
FILE * f = malloc (sizeof (FILE ));
152
+ #else
153
+ // libraries need to expose the definition of FILE; this is the
154
+ // case for musl
155
+ FILE * f = malloc (sizeof (int ));
156
+ #endif
139
157
140
158
return f ;
141
159
}
142
160
161
+ /* FUNCTION: _fdopen */
162
+
163
+ // This is for Apple
164
+
165
+ #ifndef __CPROVER_STDIO_H_INCLUDED
166
+ #include <stdio.h>
167
+ #define __CPROVER_STDIO_H_INCLUDED
168
+ #endif
169
+
170
+ #ifndef __CPROVER_STDLIB_H_INCLUDED
171
+ #include <stdlib.h>
172
+ #define __CPROVER_STDLIB_H_INCLUDED
173
+ #endif
174
+
175
+ #ifdef __APPLE__
176
+ inline FILE * _fdopen (int handle , const char * mode )
177
+ {
178
+ __CPROVER_HIDE :;
179
+ (void )handle ;
180
+ (void )* mode ;
181
+ #ifdef __CPROVER_STRING_ABSTRACTION
182
+ __CPROVER_assert (__CPROVER_is_zero_string (mode ),
183
+ "fdopen zero-termination of 2nd argument" );
184
+ #endif
185
+
186
+ FILE * f = malloc (sizeof (FILE ));
187
+
188
+ return f ;
189
+ }
190
+ #endif
191
+
143
192
/* FUNCTION: fgets */
144
193
145
194
#ifndef __CPROVER_STDIO_H_INCLUDED
146
195
#include <stdio.h>
147
196
#define __CPROVER_STDIO_H_INCLUDED
148
197
#endif
149
198
150
- inline char * fgets (char * str , int size , FILE * stream )
199
+ char * fgets (char * str , int size , FILE * stream )
151
200
{
152
201
__CPROVER_HIDE :;
153
202
__CPROVER_bool error ;
@@ -169,6 +218,16 @@ inline char *fgets(char *str, int size, FILE *stream)
169
218
__CPROVER_is_zero_string (str )= !error ;
170
219
__CPROVER_zero_string_length (str )= resulting_size ;
171
220
}
221
+ #else
222
+ if (size > 0 )
223
+ {
224
+ int str_length ;
225
+ __CPROVER_assume (str_length >=0 && str_length < size );
226
+ char contents_nondet [str_length ];
227
+ __CPROVER_array_replace (str , contents_nondet );
228
+ if (!error )
229
+ str [str_length ]= '\0' ;
230
+ }
172
231
#endif
173
232
174
233
return error ?0 :str ;
@@ -735,3 +794,43 @@ inline int vfprintf(FILE *stream, const char *restrict format, va_list arg)
735
794
736
795
return result ;
737
796
}
797
+
798
+ /* FUNCTION: vasprintf */
799
+
800
+ #ifndef __CPROVER_STDIO_H_INCLUDED
801
+ #include <stdio.h>
802
+ #define __CPROVER_STDIO_H_INCLUDED
803
+ #endif
804
+
805
+ #ifndef __CPROVER_STDARG_H_INCLUDED
806
+ #include <stdarg.h>
807
+ #define __CPROVER_STDARG_H_INCLUDED
808
+ #endif
809
+
810
+ #ifndef __CPROVER_STDLIB_H_INCLUDED
811
+ #include <stdlib.h>
812
+ #define __CPROVER_STDLIB_H_INCLUDED
813
+ #endif
814
+
815
+ inline int vasprintf (char * * ptr , const char * fmt , va_list ap )
816
+ {
817
+ (void )* fmt ;
818
+ (void )ap ;
819
+
820
+ int result_buffer_size ;
821
+ if (result_buffer_size <=0 )
822
+ return -1 ;
823
+
824
+ * ptr = malloc (result_buffer_size );
825
+ for (int i = 0 ; i < result_buffer_size ; ++ i )
826
+ {
827
+ char c ;
828
+ (* ptr )[i ]= c ;
829
+ if (c == '\0' )
830
+ break ;
831
+ }
832
+
833
+ __CPROVER_assume (i < result_buffer_size );
834
+
835
+ return i ;
836
+ }
0 commit comments