Merge pull request #3968 from BrzVlad/fix-monitor-exception
[mono.git] / support / unistd.c
index 5652329e13ff78abe8ca97b54789c5ded2522e7e..1123f2bc0fac9112b60e8f398e11b685eb59783c 100644 (file)
@@ -7,6 +7,8 @@
  * Copyright (C) 2004-2006 Jonathan Pryor
  */
 
+#include <config.h>
+
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #endif /* ndef _GNU_SOURCE */
@@ -136,16 +138,29 @@ Mono_Posix_Syscall_ttyname_r (int fd, char *buf, mph_size_t len)
 }
 #endif /* ndef HAVE_TTYNAME_R */
 
-gint32
-Mono_Posix_Syscall_readlink (const char *path, char *buf, mph_size_t len)
+gint64
+Mono_Posix_Syscall_readlink (const char *path, unsigned char *buf, mph_size_t len)
 {
-       int r;
+       gint64 r;
+       mph_return_if_size_t_overflow (len);
+       r = readlink (path, (char*) buf, (size_t) len);
+       if (r >= 0 && r < len)
+               buf [r] = '\0';
+       return r;
+}
+
+#ifdef HAVE_READLINKAT
+gint64
+Mono_Posix_Syscall_readlinkat (int dirfd, const char *path, unsigned char *buf, mph_size_t len)
+{
+       gint64 r;
        mph_return_if_size_t_overflow (len);
-       r = readlink (path, buf, (size_t) len);
+       r = readlinkat (dirfd, path, (char*) buf, (size_t) len);
        if (r >= 0 && r < len)
                buf [r] = '\0';
        return r;
 }
+#endif /* def HAVE_READLINKAT */
 
 #if HAVE_GETLOGIN_R
 gint32