Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / support / sys-utsname.c
1 /*
2  * <sys/sendfile.h> wrapper functions.
3  *
4  * Authors:
5  *   Jonathan Pryor (jonpryor@vt.edu)
6  *
7  * Copyright (C) 2004 Jonathan Pryor
8  */
9
10 #include <sys/types.h>
11 #include <errno.h>
12 #include <stdlib.h>
13
14 #include "map.h"
15 #include "mph.h"
16
17 #include <sys/utsname.h>
18
19 G_BEGIN_DECLS
20
21 static const mph_string_offset_t
22 utsname_offsets[] = {
23         MPH_STRING_OFFSET(struct utsname, sysname,  MPH_STRING_OFFSET_ARRAY),
24         MPH_STRING_OFFSET(struct utsname, nodename, MPH_STRING_OFFSET_ARRAY),
25         MPH_STRING_OFFSET(struct utsname, release,  MPH_STRING_OFFSET_ARRAY),
26         MPH_STRING_OFFSET(struct utsname, version,  MPH_STRING_OFFSET_ARRAY),
27         MPH_STRING_OFFSET(struct utsname, machine,  MPH_STRING_OFFSET_ARRAY)
28 };
29
30 static const mph_string_offset_t
31 mph_utsname_offsets[] = {
32         MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, sysname,  MPH_STRING_OFFSET_PTR),
33         MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, nodename, MPH_STRING_OFFSET_PTR),
34         MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, release,  MPH_STRING_OFFSET_PTR),
35         MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, version,  MPH_STRING_OFFSET_PTR),
36         MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, machine,  MPH_STRING_OFFSET_PTR)
37 };
38
39 int
40 Mono_Posix_Syscall_uname (struct Mono_Posix_Syscall__Utsname *buf)
41 {
42         struct utsname _buf;
43         int r;
44
45         if (!buf) {
46                 errno = EFAULT;
47                 return -1;
48         }
49
50         r = uname (&_buf);
51         if (r == 0) {
52                 buf->_buf_ = _mph_copy_structure_strings (buf, mph_utsname_offsets,
53                                 &_buf, utsname_offsets, sizeof(utsname_offsets)/sizeof(utsname_offsets[0]));
54                 buf->domainname = NULL;
55                 if (!buf->_buf_) {
56                         errno = ENOMEM;
57                         return -1;
58                 }
59         }
60         return r;
61 }
62
63 G_END_DECLS
64
65 /*
66  * vim: noexpandtab
67  */