[324961] Move type constraints checks into emit where it can be safely done (fixes...
[mono.git] / support / unistd.c
index c8b71ab74cd5d37f500097244ddc4a66c5a9bdce..5652329e13ff78abe8ca97b54789c5ded2522e7e 100644 (file)
@@ -4,7 +4,7 @@
  * Authors:
  *   Jonathan Pryor (jonpryor@vt.edu)
  *
- * Copyright (C) 2004 Jonathan Pryor
+ * Copyright (C) 2004-2006 Jonathan Pryor
  */
 
 #ifndef _GNU_SOURCE
@@ -27,11 +27,7 @@ G_BEGIN_DECLS
 mph_off_t
 Mono_Posix_Syscall_lseek (gint32 fd, mph_off_t offset, gint32 whence)
 {
-       short _whence;
        mph_return_if_off_t_overflow (offset);
-       if (Mono_Posix_FromSeekFlags (whence, &_whence) == -1)
-               return -1;
-       whence = _whence;
 
        return lseek (fd, offset, whence);
 }
@@ -44,7 +40,7 @@ Mono_Posix_Syscall_read (gint32 fd, void *buf, mph_size_t count)
 }
 
 mph_ssize_t
-Mono_Posix_Syscall_write (gint32 fd, const void *buf, mph_size_t count)
+Mono_Posix_Syscall_write (gint32 fd, void *buf, mph_size_t count)
 {
        mph_return_if_size_t_overflow (count);
        return write (fd, buf, (size_t) count);
@@ -60,7 +56,7 @@ Mono_Posix_Syscall_pread (gint32 fd, void *buf, mph_size_t count, mph_off_t offs
 }
 
 mph_ssize_t
-Mono_Posix_Syscall_pwrite (gint32 fd, const void *buf, mph_size_t count, mph_off_t offset)
+Mono_Posix_Syscall_pwrite (gint32 fd, void *buf, mph_size_t count, mph_off_t offset)
 {
        mph_return_if_size_t_overflow (count);
        mph_return_if_off_t_overflow (offset);
@@ -86,7 +82,7 @@ Mono_Posix_Syscall_pipe (gint32 *reading, gint32 *writing)
        return r;
 }
 
-char*
+void*
 Mono_Posix_Syscall_getcwd (char *buf, mph_size_t size)
 {
        mph_return_val_if_size_t_overflow (size, NULL);
@@ -94,37 +90,42 @@ Mono_Posix_Syscall_getcwd (char *buf, mph_size_t size)
 }
 
 gint64
-Mono_Posix_Syscall_fpathconf (int filedes, int name)
+Mono_Posix_Syscall_fpathconf (int filedes, int name, int defaultError)
 {
-       if (Mono_Posix_FromPathConf (name, &name) == -1)
+       errno = defaultError;
+       if (Mono_Posix_FromPathconfName (name, &name) == -1)
                return -1;
        return fpathconf (filedes, name);
 }
 
 gint64
-Mono_Posix_Syscall_pathconf (char *path, int name)
+Mono_Posix_Syscall_pathconf (const char *path, int name, int defaultError)
 {
-       if (Mono_Posix_FromPathConf (name, &name) == -1)
+       errno = defaultError;
+       if (Mono_Posix_FromPathconfName (name, &name) == -1)
                return -1;
        return pathconf (path, name);
 }
 
 gint64
-Mono_Posix_Syscall_sysconf (int name)
+Mono_Posix_Syscall_sysconf (int name, int defaultError)
 {
-       if (Mono_Posix_FromSysConf (name, &name) == -1)
+       errno = defaultError;
+       if (Mono_Posix_FromSysconfName (name, &name) == -1)
                return -1;
        return sysconf (name);
 }
 
-gint64
+#if HAVE_CONFSTR
+mph_size_t
 Mono_Posix_Syscall_confstr (int name, char *buf, mph_size_t len)
 {
        mph_return_if_size_t_overflow (len);
-       if (Mono_Posix_FromConfStr (name, &name) == -1)
+       if (Mono_Posix_FromConfstrName (name, &name) == -1)
                return -1;
        return confstr (name, buf, (size_t) len);
 }
+#endif  /* def HAVE_CONFSTR */
 
 #ifdef HAVE_TTYNAME_R
 gint32
@@ -146,12 +147,14 @@ Mono_Posix_Syscall_readlink (const char *path, char *buf, mph_size_t len)
        return r;
 }
 
+#if HAVE_GETLOGIN_R
 gint32
 Mono_Posix_Syscall_getlogin_r (char *buf, mph_size_t len)
 {
        mph_return_if_size_t_overflow (len);
        return getlogin_r (buf, (size_t) len);
 }
+#endif  /* def HAVE_GETLOGIN_R */
 
 gint32
 Mono_Posix_Syscall_gethostname (char *buf, mph_size_t len)
@@ -160,18 +163,22 @@ Mono_Posix_Syscall_gethostname (char *buf, mph_size_t len)
        return gethostname (buf, (size_t) len);
 }
 
+#if HAVE_SETHOSTNAME
 gint32
 Mono_Posix_Syscall_sethostname (const char *name, mph_size_t len)
 {
        mph_return_if_size_t_overflow (len);
        return sethostname (name, (size_t) len);
 }
+#endif  /* def HAVE_SETHOSTNAME */
 
+#if HAVE_GETHOSTID
 gint64
 Mono_Posix_Syscall_gethostid (void)
 {
        return gethostid ();
 }
+#endif  /* def HAVE_GETHOSTID */
 
 #ifdef HAVE_SETHOSTID
 gint32
@@ -205,12 +212,17 @@ Mono_Posix_Syscall_setdomainname (const char *name, mph_size_t len)
 }
 #endif /* def HAVE_SETDOMAINNAME */
 
+/* Android implements truncate, but doesn't declare it.
+ * Result is a warning during compilation, so skip it.
+ */
+#ifndef PLATFORM_ANDROID
 gint32
 Mono_Posix_Syscall_truncate (const char *path, mph_off_t length)
 {
        mph_return_if_off_t_overflow (length);
        return truncate (path, (off_t) length);
 }
+#endif
 
 gint32
 Mono_Posix_Syscall_ftruncate (int fd, mph_off_t length)
@@ -219,22 +231,53 @@ Mono_Posix_Syscall_ftruncate (int fd, mph_off_t length)
        return ftruncate (fd, (off_t) length);
 }
 
+#if HAVE_LOCKF
 gint32
 Mono_Posix_Syscall_lockf (int fd, int cmd, mph_off_t len)
 {
        mph_return_if_off_t_overflow (len);
-       if (Mono_Posix_FromLockFlags (cmd, &cmd) == -1)
+       if (Mono_Posix_FromLockfCommand (cmd, &cmd) == -1)
                return -1;
        return lockf (fd, cmd, (off_t) len);
 }
+#endif  /* def HAVE_LOCKF */
 
-void
+#if HAVE_SWAB
+int
 Mono_Posix_Syscall_swab (void *from, void *to, mph_ssize_t n)
 {
        if (mph_have_long_overflow (n))
-               return;
+               return -1;
        swab (from, to, (ssize_t) n);
+       return 0;
+}
+#endif  /* def HAVE_SWAB */
+
+#if HAVE_SETUSERSHELL
+int
+Mono_Posix_Syscall_setusershell (void)
+{
+       setusershell ();
+       return 0;
 }
+#endif  /* def HAVE_SETUSERSHELL */
+
+#if HAVE_ENDUSERSHELL
+int
+Mono_Posix_Syscall_endusershell (void)
+{
+       endusershell ();
+       return 0;
+}
+#endif  /* def HAVE_ENDUSERSHELL */
+
+int
+Mono_Posix_Syscall_sync (void)
+{
+       sync ();
+       return 0;
+}
+
 
 G_END_DECLS