2005-09-14 Geoff Norton <gnorton@customerdna.com>
[mono.git] / support / unistd.c
index 42e02ecc5cc3ddae8296170146e1cae8d8237459..0de6f228534c9f1c6dd109eed39a71623c217681 100644 (file)
@@ -19,8 +19,6 @@
 #include <limits.h>
 #include <string.h>     /* for swab(3) on Mac OS X */
 
-#include <glib/gtypes.h>
-
 #include "map.h"
 #include "mph.h"
 
@@ -29,16 +27,9 @@ 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;
-#ifdef MPH_USE_64_API
-       return lseek64 (fd, offset, whence);
-#else
+
        return lseek (fd, offset, whence);
-#endif
 }
 
 mph_ssize_t
@@ -49,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,23 +51,17 @@ Mono_Posix_Syscall_pread (gint32 fd, void *buf, mph_size_t count, mph_off_t offs
 {
        mph_return_if_size_t_overflow (count);
        mph_return_if_off_t_overflow (offset);
-#ifdef MPH_USE_64_API
-       return pread64 (fd, buf, (size_t) count, offset);
-#else
+
        return pread (fd, buf, (size_t) count, (off_t) offset);
-#endif
 }
 
 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);
-#ifdef MPH_USE_64_API
-       return pwrite64 (fd, buf, (size_t) count, offset);
-#else
+
        return pwrite (fd, buf, (size_t) count, (off_t) offset);
-#endif
 }
 
 gint32
@@ -97,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);
@@ -113,7 +98,7 @@ Mono_Posix_Syscall_fpathconf (int filedes, int name)
 }
 
 gint64
-Mono_Posix_Syscall_pathconf (char *path, int name)
+Mono_Posix_Syscall_pathconf (const char *path, int name)
 {
        if (Mono_Posix_FromPathConf (name, &name) == -1)
                return -1;
@@ -128,7 +113,7 @@ Mono_Posix_Syscall_sysconf (int name)
        return sysconf (name);
 }
 
-gint64
+mph_size_t
 Mono_Posix_Syscall_confstr (int name, char *buf, mph_size_t len)
 {
        mph_return_if_size_t_overflow (len);
@@ -149,8 +134,12 @@ Mono_Posix_Syscall_ttyname_r (int fd, char *buf, mph_size_t len)
 gint32
 Mono_Posix_Syscall_readlink (const char *path, char *buf, mph_size_t len)
 {
+       int r;
        mph_return_if_size_t_overflow (len);
-       return readlink (path, buf, (size_t) len);
+       r = readlink (path, buf, (size_t) len);
+       if (r >= 0 && r < len)
+               buf [r] = '\0';
+       return r;
 }
 
 gint32
@@ -180,6 +169,7 @@ Mono_Posix_Syscall_gethostid (void)
        return gethostid ();
 }
 
+#ifdef HAVE_SETHOSTID
 gint32
 Mono_Posix_Syscall_sethostid (gint64 hostid)
 {
@@ -191,60 +181,53 @@ Mono_Posix_Syscall_sethostid (gint64 hostid)
        return sethostid ((long) hostid);
 #endif
 }
+#endif /* def HAVE_SETHOSTID */
 
+#ifdef HAVE_GETDOMAINNAME
 gint32
 Mono_Posix_Syscall_getdomainname (char *name, mph_size_t len)
 {
        mph_return_if_size_t_overflow (len);
        return getdomainname (name, (size_t) len);
 }
+#endif /* def HAVE_GETDOMAINNAME */
 
+#ifdef HAVE_SETDOMAINNAME
 gint32
 Mono_Posix_Syscall_setdomainname (const char *name, mph_size_t len)
 {
        mph_return_if_size_t_overflow (len);
        return setdomainname (name, (size_t) len);
 }
+#endif /* def HAVE_SETDOMAINNAME */
 
 gint32
 Mono_Posix_Syscall_truncate (const char *path, mph_off_t length)
 {
        mph_return_if_off_t_overflow (length);
-#ifdef MPH_USE_64_API
-       return truncate64 (path, length);
-#else
        return truncate (path, (off_t) length);
-#endif
 }
 
 gint32
 Mono_Posix_Syscall_ftruncate (int fd, mph_off_t length)
 {
        mph_return_if_off_t_overflow (length);
-#ifdef MPH_USE_64_API
-       return ftruncate64 (fd, length);
-#else
        return ftruncate (fd, (off_t) length);
-#endif
 }
 
 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;
-#ifdef MPH_USE_64_API
-       return lockf64 (fd, cmd, len);
-#else
        return lockf (fd, cmd, (off_t) len);
-#endif
 }
 
 void
 Mono_Posix_Syscall_swab (void *from, void *to, mph_ssize_t n)
 {
-       if (n > LONG_MAX || n < LONG_MAX)
+       if (mph_have_long_overflow (n))
                return;
        swab (from, to, (ssize_t) n);
 }