Prepare Mono for Android NDK with unified headers (#5680)
[mono.git] / support / macros.c
index c763a7ca2f8719d442cda74e017ee846fedf4fa8..e15fa76b7edb0a35774956c4e1070f10e366fd35 100644 (file)
@@ -1,3 +1,4 @@
+#include "mph.h"
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -7,6 +8,9 @@
 #include <errno.h>
 #include <dirent.h>
 #include <string.h>
+#include <glib.h>
+#include "mph.h" /* Don't remove or move after map.h! Works around issues with Android SDK unified headers */
+#include "map.h"
 
 int wifexited (int status)
 {
@@ -38,7 +42,7 @@ int wstopsig (int status)
        return WSTOPSIG (status);
 }
 
-int helper_Mono_Posix_Stat(char *filename, int dereference, 
+int helper_Mono_Posix_Stat(const char *filename, int dereference, 
        int *device,
        int *inode,
        int *mode,
@@ -46,12 +50,12 @@ int helper_Mono_Posix_Stat(char *filename, int dereference,
        int *uid,
        int *gid,
        int *rdev,
-       long *size,
-       long *blksize,
-       long *blocks,
-       long *atime,
-       long *mtime,
-       long *ctime
+       gint64 *size,
+       gint64 *blksize,
+       gint64 *blocks,
+       gint64 *atime,
+       gint64 *mtime,
+       gint64 *ctime
        ) {
        int ret;
        struct stat buf;
@@ -90,8 +94,67 @@ char *helper_Mono_Posix_GetGroupName(int gid) {
        return strdup (p->gr_name);
 }
 
-char *helper_Mono_Posix_readdir(DIR *dir) {
-       struct dirent* e = readdir(dir);
+char *helper_Mono_Posix_readdir(void *dir) {
+       struct dirent* e = readdir((DIR*) dir);
        if (e == NULL) return NULL;
        return strdup (e->d_name);
 }
+
+#if HAVE_GETPWNAM_R
+int helper_Mono_Posix_getpwnamuid (int mode, char *in_name, int in_uid,
+       char **account,
+       char **password,
+       int *uid,
+       int *gid,
+       char **name,
+       char **home,
+       char **shell);
+
+int helper_Mono_Posix_getpwnamuid (int mode, char *in_name, int in_uid,
+       char **account,
+       char **password,
+       int *uid,
+       int *gid,
+       char **name,
+       char **home,
+       char **shell
+       ) {
+
+       struct passwd pw, *pwp;
+       char buf[4096];
+       int ret;
+
+       if (mode == 0)
+               ret = getpwnam_r (in_name, &pw, buf, 4096, &pwp);
+       else
+               ret = getpwuid_r (in_uid, &pw, buf, 4096, &pwp);
+
+       if (ret == 0 && pwp == NULL) {
+               // Don't know why this happens, but it does.
+               // ret == 0, errno == 0, but no record was found.
+               ret = ENOENT;
+       }
+
+       if (ret) {
+               *account = NULL; // prevent marshalling unset pointers
+               *password = NULL;
+               *uid = 0;
+               *gid = 0;
+               *name = NULL;
+               *home = NULL;
+               *shell = NULL;
+               return ret;
+       }
+
+       *account = pwp->pw_name;
+       *password = pwp->pw_passwd;
+       *uid = pwp->pw_uid;
+       *gid = pwp->pw_gid;
+       *name = pwp->pw_gecos;
+       *home = pwp->pw_dir;
+       *shell = pwp->pw_shell;
+
+       return 0;
+}
+#endif  /* def HAVE_GETPWNAM_R */
+