New test.
[mono.git] / support / sys-stat.c
1 /*
2  * <sys/stat.h> wrapper functions.
3  *
4  * Authors:
5  *   Jonathan Pryor (jonpryor@vt.edu)
6  *
7  * Copyright (C) 2004-2006 Jonathan Pryor
8  */
9
10 #ifndef _GNU_SOURCE
11 #define _GNU_SOURCE
12 #endif /* ndef _GNU_SOURCE */
13
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <errno.h>
19
20 #include "map.h"
21 #include "mph.h"
22
23 G_BEGIN_DECLS
24
25 gint32
26 Mono_Posix_Syscall_stat (const char *file_name, struct Mono_Posix_Stat *buf)
27 {
28         int r;
29         struct stat _buf;
30
31         if (buf == NULL) {
32                 errno = EFAULT;
33                 return -1;
34         }
35         r = stat (file_name, &_buf);
36         if (r != -1 && Mono_Posix_ToStat (&_buf, buf) == -1)
37                 r = -1;
38         return r;
39 }
40
41 gint32
42 Mono_Posix_Syscall_fstat (int filedes, struct Mono_Posix_Stat *buf)
43 {
44         int r;
45         struct stat _buf;
46
47         if (buf == NULL) {
48                 errno = EFAULT;
49                 return -1;
50         }
51         r = fstat (filedes, &_buf);
52         if (r != -1 && Mono_Posix_ToStat (&_buf, buf) == -1)
53                 r = -1;
54         return r;
55 }
56
57 gint32
58 Mono_Posix_Syscall_lstat (const char *file_name, struct Mono_Posix_Stat *buf)
59 {
60         int r;
61         struct stat _buf;
62
63         if (buf == NULL) {
64                 errno = EFAULT;
65                 return -1;
66         }
67         r = lstat (file_name, &_buf);
68         if (r != -1 && Mono_Posix_ToStat (&_buf, buf) == -1)
69                 r = -1;
70         return r;
71 }
72
73 gint32
74 Mono_Posix_Syscall_mknod (const char *pathname, guint32 mode, mph_dev_t dev)
75 {
76         if (Mono_Posix_FromFilePermissions (mode, &mode) == -1)
77                 return -1;
78         return mknod (pathname, mode, dev);
79 }
80
81 G_END_DECLS
82
83 /*
84  * vim: noexpandtab
85  */