This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / support / macros.c
1 #include <sys/types.h>
2 #include <sys/wait.h>
3 #include <sys/stat.h>
4 #include <unistd.h>
5 #include <pwd.h>
6 #include <grp.h>
7 #include <errno.h>
8 #include <dirent.h>
9 #include <string.h>
10
11 int wifexited (int status)
12 {
13         return WIFEXITED (status);
14 }
15
16 int wexitstatus (int status)
17 {
18         return WEXITSTATUS (status);
19 }
20
21 int wifsignaled (int status)
22 {
23         return WIFSIGNALED (status);
24 }
25
26 int wtermsig (int status)
27 {
28         return WTERMSIG (status);
29 }
30
31 int wifstopped (int status)
32 {
33         return WIFSTOPPED (status);
34 }
35
36 int wstopsig (int status)
37 {
38         return WSTOPSIG (status);
39 }
40
41 int helper_Mono_Posix_Stat(char *filename, int dereference, 
42         int *device,
43         int *inode,
44         int *mode,
45         int *nlinks,
46         int *uid,
47         int *gid,
48         int *rdev,
49         long *size,
50         long *blksize,
51         long *blocks,
52         long *atime,
53         long *mtime,
54         long *ctime
55         ) {
56         int ret;
57         struct stat buf;
58         
59         if (!dereference)
60                 ret = stat(filename, &buf);
61         else
62                 ret = lstat(filename, &buf);
63         
64         if (ret) return ret;
65         
66         *device = buf.st_dev;
67         *inode = buf.st_ino;
68         *mode = buf.st_mode;
69         *nlinks = buf.st_nlink;
70         *uid = buf.st_uid;
71         *gid = buf.st_gid;
72         *rdev = buf.st_rdev;
73         *size = buf.st_size;
74         *blksize = buf.st_blksize;
75         *blocks = buf.st_blocks;
76         *atime = buf.st_atime;
77         *mtime = buf.st_mtime;
78         *ctime = buf.st_ctime;
79         return 0;
80 }
81
82 char *helper_Mono_Posix_GetUserName(int uid) {
83         struct passwd *p = getpwuid(uid);
84         if (p == NULL) return NULL;
85         return strdup (p->pw_name);
86 }
87 char *helper_Mono_Posix_GetGroupName(int gid) {
88         struct group *p = getgrgid(gid);
89         if (p == NULL) return NULL;
90         return strdup (p->gr_name);
91 }
92
93 char *helper_Mono_Posix_readdir(DIR *dir) {
94         struct dirent* e = readdir(dir);
95         if (e == NULL) return NULL;
96         return strdup (e->d_name);
97 }