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