Merge pull request #3953 from rolfbjarne/offsets-tool-autoreclone
[mono.git] / support / stdio.c
index 0ab5a11243c0ec71356f318c7e7c0964dd375ccb..b914dfdb1d098ec4d4518fd5b28f13b770200b2c 100644 (file)
@@ -16,7 +16,7 @@
 
 G_BEGIN_DECLS
 
-#ifndef PLATFORM_WIN32
+#ifndef HOST_WIN32
 gint32
 Mono_Posix_Syscall_L_ctermid (void)
 {
@@ -26,9 +26,13 @@ Mono_Posix_Syscall_L_ctermid (void)
 gint32
 Mono_Posix_Syscall_L_cuserid (void)
 {
+#if defined(__APPLE__) || defined (__OpenBSD__)
+       return -1;
+#else
        return L_cuserid;
+#endif
 }
-#endif /* ndef PLATFORM_WIN32 */
+#endif /* ndef HOST_WIN32 */
 
 mph_size_t
 Mono_Posix_Stdlib_fread (unsigned char *ptr, mph_size_t size, mph_size_t nmemb, void *stream)
@@ -138,6 +142,12 @@ Mono_Posix_Stdlib_TMP_MAX (void)
        return TMP_MAX;
 }
 
+void*
+Mono_Posix_Stdlib_tmpfile (void)
+{
+       return tmpfile ();
+}
+
 gint32
 Mono_Posix_Stdlib_setvbuf (void* stream, void *buf, int mode, mph_size_t size)
 {
@@ -148,9 +158,62 @@ Mono_Posix_Stdlib_setvbuf (void* stream, void *buf, int mode, mph_size_t size)
 int 
 Mono_Posix_Stdlib_setbuf (void* stream, void* buf)
 {
-       errno = 0;
        setbuf (stream, buf);
-       return errno == 0 ? 0 : -1;
+       return 0;
+}
+
+void*
+Mono_Posix_Stdlib_fopen (char* path, char* mode)
+{
+       return fopen (path, mode);
+}
+
+void*
+Mono_Posix_Stdlib_freopen (char* path, char* mode, void *stream)
+{
+       return freopen (path, mode, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fprintf (void* stream, char* format, char *message)
+{
+       return fprintf (stream, format, message);
+}
+
+gint32
+Mono_Posix_Stdlib_fgetc (void* stream)
+{
+       return fgetc (stream);
+}
+
+char*
+Mono_Posix_Stdlib_fgets (char* str, gint32 size, void* stream)
+{
+       return fgets (str, size, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fputc (gint32 c, void* stream)
+{
+       return fputc (c, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fputs (char* s, void* stream)
+{
+       return fputs (s, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fclose (void* stream)
+{
+       return fclose (stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fflush (void* stream)
+{
+       return fflush (stream);
 }
 
 gint32
@@ -189,25 +252,45 @@ Mono_Posix_Stdlib_fsetpos (void* stream, void *pos)
 int
 Mono_Posix_Stdlib_rewind (void* stream)
 {
-       errno = 0;
-       rewind (stream);
-       return errno == 0 ? 0 : -1;
+       do {
+               rewind (stream);
+       } while (errno == EINTR);
+       mph_return_if_val_in_list5(errno, EAGAIN, EBADF, EFBIG, EINVAL, EIO);
+       mph_return_if_val_in_list5(errno, ENOSPC, ENXIO, EOVERFLOW, EPIPE, ESPIPE);
+       return 0;
 }
 
 int
 Mono_Posix_Stdlib_clearerr (void* stream)
 {
-       errno = 0;
        clearerr (((FILE*) stream));
-       return errno == 0 ? 0 : -1;
+       return 0;
+}
+
+gint32
+Mono_Posix_Stdlib_ungetc (gint32 c, void* stream)
+{
+       return ungetc (c, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_feof (void* stream)
+{
+       return feof (stream);
+}
+
+gint32
+Mono_Posix_Stdlib_ferror (void* stream)
+{
+       return ferror (stream);
 }
 
 int
-Mono_Posix_Stdlib_perror (const char* s)
+Mono_Posix_Stdlib_perror (const char* s, int err)
 {
-       errno = 0;
+       errno = err;
        perror (s);
-       return errno == 0 ? 0 : -1;
+       return 0;
 }
 
 #define MPH_FPOS_LENGTH (sizeof(fpos_t)*2)