Cleanup the mess that ptr_in_nursery became with all file split going on.
[mono-project.git] / support / macros.c
blobd2cf5e7bcdbb95922b01c51f2200283350af380d
1 #include "mph.h"
2 #include <sys/types.h>
3 #include <sys/wait.h>
4 #include <sys/stat.h>
5 #include <unistd.h>
6 #include <pwd.h>
7 #include <grp.h>
8 #include <errno.h>
9 #include <dirent.h>
10 #include <string.h>
11 #include <glib.h>
12 #include "map.h"
14 int wifexited (int status)
16 return WIFEXITED (status);
19 int wexitstatus (int status)
21 return WEXITSTATUS (status);
24 int wifsignaled (int status)
26 return WIFSIGNALED (status);
29 int wtermsig (int status)
31 return WTERMSIG (status);
34 int wifstopped (int status)
36 return WIFSTOPPED (status);
39 int wstopsig (int status)
41 return WSTOPSIG (status);
44 int helper_Mono_Posix_Stat(const char *filename, int dereference,
45 int *device,
46 int *inode,
47 int *mode,
48 int *nlinks,
49 int *uid,
50 int *gid,
51 int *rdev,
52 gint64 *size,
53 gint64 *blksize,
54 gint64 *blocks,
55 gint64 *atime,
56 gint64 *mtime,
57 gint64 *ctime
58 ) {
59 int ret;
60 struct stat buf;
62 if (!dereference)
63 ret = stat(filename, &buf);
64 else
65 ret = lstat(filename, &buf);
67 if (ret) return ret;
69 *device = buf.st_dev;
70 *inode = buf.st_ino;
71 *mode = buf.st_mode;
72 *nlinks = buf.st_nlink;
73 *uid = buf.st_uid;
74 *gid = buf.st_gid;
75 *rdev = buf.st_rdev;
76 *size = buf.st_size;
77 *blksize = buf.st_blksize;
78 *blocks = buf.st_blocks;
79 *atime = buf.st_atime;
80 *mtime = buf.st_mtime;
81 *ctime = buf.st_ctime;
82 return 0;
85 char *helper_Mono_Posix_GetUserName(int uid) {
86 struct passwd *p = getpwuid(uid);
87 if (p == NULL) return NULL;
88 return strdup (p->pw_name);
90 char *helper_Mono_Posix_GetGroupName(int gid) {
91 struct group *p = getgrgid(gid);
92 if (p == NULL) return NULL;
93 return strdup (p->gr_name);
96 char *helper_Mono_Posix_readdir(void *dir) {
97 struct dirent* e = readdir((DIR*) dir);
98 if (e == NULL) return NULL;
99 return strdup (e->d_name);
102 #if HAVE_GETPWNAM_R
103 int helper_Mono_Posix_getpwnamuid (int mode, char *in_name, int in_uid,
104 char **account,
105 char **password,
106 int *uid,
107 int *gid,
108 char **name,
109 char **home,
110 char **shell
113 struct passwd pw, *pwp;
114 char buf[4096];
115 int ret;
117 if (mode == 0)
118 ret = getpwnam_r (in_name, &pw, buf, 4096, &pwp);
119 else
120 ret = getpwuid_r (in_uid, &pw, buf, 4096, &pwp);
122 if (ret == 0 && pwp == NULL) {
123 // Don't know why this happens, but it does.
124 // ret == 0, errno == 0, but no record was found.
125 ret = ENOENT;
128 if (ret) {
129 *account = NULL; // prevent marshalling unset pointers
130 *password = NULL;
131 *uid = 0;
132 *gid = 0;
133 *name = NULL;
134 *home = NULL;
135 *shell = NULL;
136 return ret;
139 *account = pwp->pw_name;
140 *password = pwp->pw_passwd;
141 *uid = pwp->pw_uid;
142 *gid = pwp->pw_gid;
143 *name = pwp->pw_gecos;
144 *home = pwp->pw_dir;
145 *shell = pwp->pw_shell;
147 return 0;
149 #endif /* def HAVE_GETPWNAM_R */