2 * <stdio.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 Jonathan Pryor
21 Mono_Posix_Syscall_L_ctermid (void)
27 Mono_Posix_Syscall_L_cuserid (void)
29 #if defined(__APPLE__) || defined (__OpenBSD__)
35 #endif /* ndef HOST_WIN32 */
38 Mono_Posix_Stdlib_fread (unsigned char *ptr
, mph_size_t size
, mph_size_t nmemb
, void *stream
)
40 mph_return_if_size_t_overflow (size
);
41 mph_return_if_size_t_overflow (nmemb
);
43 return fread (ptr
, (size_t) size
, (size_t) nmemb
, (FILE*) stream
);
47 Mono_Posix_Stdlib_fwrite (unsigned char *ptr
, mph_size_t size
, mph_size_t nmemb
, void *stream
)
49 mph_return_if_size_t_overflow (size
);
50 mph_return_if_size_t_overflow (nmemb
);
52 size_t ret
= fwrite (ptr
, (size_t) size
, (size_t) nmemb
, (FILE*) stream
);
54 // Workaround for a particular weirdness on Windows triggered by the
55 // StdioFileStreamTest.Write() test method. The test writes 15 bytes to a
56 // file, then rewinds the file pointer and reads the same bytes. It then
57 // writes 15 additional bytes to the file. This second write fails on
58 // Windows with 0 returned from fwrite(). Calling fseek() followed by a retry
59 // of fwrite() like we do here fixes the issue.
62 fseek (stream
, 0, SEEK_CUR
);
63 ret
= fwrite (ptr
+ (ret
* nmemb
), (size_t) size
, (size_t) nmemb
- ret
, (FILE*) stream
);
71 Mono_Posix_Stdlib_snprintf (char *s
, mph_size_t n
, char *format
, ...);
73 Mono_Posix_Stdlib_snprintf (char *s
, mph_size_t n
, char *format
, ...)
77 mph_return_if_size_t_overflow (n
);
79 va_start (ap
, format
);
80 r
= vsnprintf (s
, (size_t) n
, format
, ap
);
85 #endif /* def HAVE_VSNPRINTF */
88 Mono_Posix_Stdlib__IOFBF (void)
94 Mono_Posix_Stdlib__IOLBF (void)
100 Mono_Posix_Stdlib__IONBF (void)
106 Mono_Posix_Stdlib_BUFSIZ (void)
112 Mono_Posix_Stdlib_EOF (void)
118 Mono_Posix_Stdlib_FOPEN_MAX (void)
124 Mono_Posix_Stdlib_FILENAME_MAX (void)
130 Mono_Posix_Stdlib_L_tmpnam (void)
136 Mono_Posix_Stdlib_stdin (void)
142 Mono_Posix_Stdlib_stdout (void)
148 Mono_Posix_Stdlib_stderr (void)
154 Mono_Posix_Stdlib_TMP_MAX (void)
160 Mono_Posix_Stdlib_tmpfile (void)
166 Mono_Posix_Stdlib_setvbuf (void* stream
, void *buf
, int mode
, mph_size_t size
)
168 mph_return_if_size_t_overflow (size
);
169 return setvbuf (stream
, (char *) buf
, mode
, (size_t) size
);
173 Mono_Posix_Stdlib_setbuf (void* stream
, void* buf
)
175 setbuf (stream
, buf
);
180 Mono_Posix_Stdlib_fopen (char* path
, char* mode
)
182 return fopen (path
, mode
);
186 Mono_Posix_Stdlib_freopen (char* path
, char* mode
, void *stream
)
188 return freopen (path
, mode
, stream
);
192 Mono_Posix_Stdlib_fprintf (void* stream
, char* format
, char *message
)
194 return fprintf (stream
, format
, message
);
198 Mono_Posix_Stdlib_fgetc (void* stream
)
200 return fgetc (stream
);
204 Mono_Posix_Stdlib_fgets (char* str
, gint32 size
, void* stream
)
206 return fgets (str
, size
, stream
);
210 Mono_Posix_Stdlib_fputc (gint32 c
, void* stream
)
212 return fputc (c
, stream
);
216 Mono_Posix_Stdlib_fputs (char* s
, void* stream
)
218 return fputs (s
, stream
);
222 Mono_Posix_Stdlib_fclose (void* stream
)
224 return fclose (stream
);
228 Mono_Posix_Stdlib_fflush (void* stream
)
230 return fflush (stream
);
234 Mono_Posix_Stdlib_fseek (void* stream
, gint64 offset
, int origin
)
236 mph_return_if_long_overflow (offset
);
238 return fseek (stream
, offset
, origin
);
242 Mono_Posix_Stdlib_ftell (void* stream
)
244 return ftell (stream
);
248 Mono_Posix_Stdlib_CreateFilePosition (void)
250 fpos_t* pos
= malloc (sizeof(fpos_t));
255 Mono_Posix_Stdlib_fgetpos (void* stream
, void *pos
)
257 return fgetpos (stream
, (fpos_t*) pos
);
261 Mono_Posix_Stdlib_fsetpos (void* stream
, void *pos
)
263 return fsetpos (stream
, (fpos_t*) pos
);
267 Mono_Posix_Stdlib_rewind (void* stream
)
271 } while (errno
== EINTR
);
272 mph_return_if_val_in_list5(errno
, EAGAIN
, EBADF
, EFBIG
, EINVAL
, EIO
);
273 mph_return_if_val_in_list5(errno
, ENOSPC
, ENXIO
, EOVERFLOW
, EPIPE
, ESPIPE
);
278 Mono_Posix_Stdlib_clearerr (void* stream
)
280 clearerr (((FILE*) stream
));
285 Mono_Posix_Stdlib_ungetc (gint32 c
, void* stream
)
287 return ungetc (c
, stream
);
291 Mono_Posix_Stdlib_feof (void* stream
)
293 return feof (((FILE*) stream
));
297 Mono_Posix_Stdlib_ferror (void* stream
)
299 return ferror (((FILE*) stream
));
303 Mono_Posix_Stdlib_perror (const char* s
, int err
)
310 #define MPH_FPOS_LENGTH (sizeof(fpos_t)*2)
313 Mono_Posix_Stdlib_DumpFilePosition (char *dest
, void *pos
, gint32 len
)
316 unsigned char *posp
, *pose
;
319 return MPH_FPOS_LENGTH
;
321 if (pos
== NULL
|| len
<= 0) {
326 posp
= (unsigned char*) pos
;
327 pose
= posp
+ sizeof(fpos_t);
330 for ( ; posp
< pose
&& len
> 1; destp
+= 2, ++posp
, len
-= 2) {
331 sprintf (destp
, "%02X", *posp
);
335 dest
[MPH_FPOS_LENGTH
] = '\0';