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)
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 return fwrite (ptr
, (size_t) size
, (size_t) nmemb
, (FILE*) stream
);
57 Mono_Posix_Stdlib_snprintf (char *s
, mph_size_t n
, char *format
, ...);
59 Mono_Posix_Stdlib_snprintf (char *s
, mph_size_t n
, char *format
, ...)
63 mph_return_if_size_t_overflow (n
);
65 va_start (ap
, format
);
66 r
= vsnprintf (s
, (size_t) n
, format
, ap
);
71 #endif /* def HAVE_VSNPRINTF */
74 Mono_Posix_Stdlib__IOFBF (void)
80 Mono_Posix_Stdlib__IOLBF (void)
86 Mono_Posix_Stdlib__IONBF (void)
92 Mono_Posix_Stdlib_BUFSIZ (void)
98 Mono_Posix_Stdlib_EOF (void)
104 Mono_Posix_Stdlib_FOPEN_MAX (void)
110 Mono_Posix_Stdlib_FILENAME_MAX (void)
116 Mono_Posix_Stdlib_L_tmpnam (void)
122 Mono_Posix_Stdlib_stdin (void)
128 Mono_Posix_Stdlib_stdout (void)
134 Mono_Posix_Stdlib_stderr (void)
140 Mono_Posix_Stdlib_TMP_MAX (void)
146 Mono_Posix_Stdlib_setvbuf (void* stream
, void *buf
, int mode
, mph_size_t size
)
148 mph_return_if_size_t_overflow (size
);
149 return setvbuf (stream
, (char *) buf
, mode
, (size_t) size
);
153 Mono_Posix_Stdlib_setbuf (void* stream
, void* buf
)
155 setbuf (stream
, buf
);
160 Mono_Posix_Stdlib_fseek (void* stream
, gint64 offset
, int origin
)
162 mph_return_if_long_overflow (offset
);
164 return fseek (stream
, offset
, origin
);
168 Mono_Posix_Stdlib_ftell (void* stream
)
170 return ftell (stream
);
174 Mono_Posix_Stdlib_CreateFilePosition (void)
176 fpos_t* pos
= malloc (sizeof(fpos_t));
181 Mono_Posix_Stdlib_fgetpos (void* stream
, void *pos
)
183 return fgetpos (stream
, (fpos_t*) pos
);
187 Mono_Posix_Stdlib_fsetpos (void* stream
, void *pos
)
189 return fsetpos (stream
, (fpos_t*) pos
);
193 Mono_Posix_Stdlib_rewind (void* stream
)
197 } while (errno
== EINTR
);
198 mph_return_if_val_in_list5(errno
, EAGAIN
, EBADF
, EFBIG
, EINVAL
, EIO
);
199 mph_return_if_val_in_list5(errno
, ENOSPC
, ENXIO
, EOVERFLOW
, EPIPE
, ESPIPE
);
204 Mono_Posix_Stdlib_clearerr (void* stream
)
206 clearerr (((FILE*) stream
));
211 Mono_Posix_Stdlib_perror (const char* s
, int err
)
218 #define MPH_FPOS_LENGTH (sizeof(fpos_t)*2)
221 Mono_Posix_Stdlib_DumpFilePosition (char *dest
, void *pos
, gint32 len
)
224 unsigned char *posp
, *pose
;
227 return MPH_FPOS_LENGTH
;
229 if (pos
== NULL
|| len
<= 0) {
234 posp
= (unsigned char*) pos
;
235 pose
= posp
+ sizeof(fpos_t);
238 for ( ; posp
< pose
&& len
> 1; destp
+= 2, ++posp
, len
-= 2) {
239 sprintf (destp
, "%02X", *posp
);
243 dest
[MPH_FPOS_LENGTH
] = '\0';