2004-03-27 Atsushi Enomoto <atsushi@ximian.com>
[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
8 int wifexited (int status)
9 {
10         return WIFEXITED (status);
11 }
12
13 int wexitstatus (int status)
14 {
15         return WEXITSTATUS (status);
16 }
17
18 int wifsignaled (int status)
19 {
20         return WIFSIGNALED (status);
21 }
22
23 int wtermsig (int status)
24 {
25         return WTERMSIG (status);
26 }
27
28 int wifstopped (int status)
29 {
30         return WIFSTOPPED (status);
31 }
32
33 int wstopsig (int status)
34 {
35         return WSTOPSIG (status);
36 }
37
38 int helper_Mono_Posix_Stat(char *filename, int dereference, 
39         int *device,
40         int *inode,
41         int *mode,
42         int *nlinks,
43         int *uid,
44         int *gid,
45         int *rdev,
46         long *size,
47         long *blksize,
48         long *blocks,
49         long *atime,
50         long *mtime,
51         long *ctime
52         ) {
53         int ret;
54         struct stat buf;
55         
56         if (!dereference)
57                 ret = stat(filename, &buf);
58         else
59                 ret = lstat(filename, &buf);
60         
61         if (ret) return ret;
62         
63         *device = buf.st_dev;
64         *inode = buf.st_ino;
65         *mode = buf.st_mode;
66         *nlinks = buf.st_nlink;
67         *uid = buf.st_uid;
68         *gid = buf.st_gid;
69         *rdev = buf.st_rdev;
70         *size = buf.st_size;
71         *blksize = buf.st_blksize;
72         *blocks = buf.st_blocks;
73         *atime = buf.st_atime;
74         *mtime = buf.st_mtime;
75         *ctime = buf.st_ctime;
76         return 0;
77 }
78
79 char *helper_Mono_Posix_GetUserName(int uid) {
80         struct passwd *p = getpwuid(uid);
81         if (p == NULL) return NULL;
82         return p->pw_name;
83 }
84 char *helper_Mono_Posix_GetGroupName(int gid) {
85         struct group *p = getgrgid(gid);
86         if (p == NULL) return NULL;
87         return p->gr_name;
88 }
89