Permalink
Browse files

* map.h: Flush; add Mono_Posix_Syscall__Utsname, Mono_Posix_Syscall_…

…uname()

	  declarations.
	* Makefile.am: Add sys-utsname.c to the build.
	* sys-utsname.c: Added; binding for uname(2).
	* mph.h: Change definition of _mph_copy_structure_strings() so that the
	  offset array specifies whether the string is a pointer (char*) or inline
	  array (char[]) within the structure.  Necessary because most bound
	  structure string members are pointers, but `struct utsname' uses arrays.
	* fstab.c, pwd.c: Update offset array generation due to above.
	* x-struct-str.c: Update _mph_copy_structure_strings() as above.

svn path=/trunk/mono/; revision=91500
  • Loading branch information...
Jonathan Pryor
Jonathan Pryor committed Dec 17, 2007
1 parent 641303e commit aaf6f0a81667378a517259bd7356b88be5ec8c02
Showing with 176 additions and 53 deletions.
  1. +13 −0 support/ChangeLog
  2. +1 −0 support/Makefile.am
  3. +30 −30 support/fstab.c
  4. +12 −0 support/map.h
  5. +13 −2 support/mph.h
  6. +12 −12 support/pwd.c
  7. +67 −0 support/sys-utsname.c
  8. +28 −9 support/x-struct-str.c
View
@@ -1,3 +1,16 @@
+2007-12-17 Jonathan Pryor <jpryor@novell.com>
+
+ * map.h: Flush; add Mono_Posix_Syscall__Utsname, Mono_Posix_Syscall_uname()
+ declarations.
+ * Makefile.am: Add sys-utsname.c to the build.
+ * sys-utsname.c: Added; binding for uname(2).
+ * mph.h: Change definition of _mph_copy_structure_strings() so that the
+ offset array specifies whether the string is a pointer (char*) or inline
+ array (char[]) within the structure. Necessary because most bound
+ structure string members are pointers, but `struct utsname' uses arrays.
+ * fstab.c, pwd.c: Update offset array generation due to above.
+ * x-struct-str.c: Update _mph_copy_structure_strings() as above.
+
2007-11-01 Geoff Norton <gnorton@novell.com>
* stdio.c: Handle Leopards lack of L_cuserid.
View
@@ -40,6 +40,7 @@ MPH_UNIX_SOURCE = \
sys-stat.c \
sys-statvfs.c \
sys-time.c \
+ sys-utsname.c \
sys-wait.c \
sys-xattr.c \
syslog.c \
View
@@ -32,40 +32,40 @@ G_BEGIN_DECLS
typedef struct checklist mph_fstab;
-static const size_t
+static const mph_string_offset_t
fstab_offsets[] = {
- offsetof (struct checklist, fs_spec),
- offsetof (struct checklist, fs_dir),
- offsetof (struct checklist, fs_type)
+ MPH_STRING_OFFSET (struct checklist, fs_spec, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct checklist, fs_dir, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct checklist, fs_type, MPH_STRING_OFFSET_PTR)
};
-static const size_t
+static const mph_string_offset_t
mph_fstab_offsets[] = {
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_type)
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_spec, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_file, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_type, MPH_STRING_OFFSET_PTR)
};
#elif defined (HAVE_FSTAB_H)
typedef struct fstab mph_fstab;
-static const size_t
+static const mph_string_offset_t
fstab_offsets[] = {
- offsetof (struct fstab, fs_spec),
- offsetof (struct fstab, fs_file),
- offsetof (struct fstab, fs_vfstype),
- offsetof (struct fstab, fs_mntops),
- offsetof (struct fstab, fs_type)
+ MPH_STRING_OFFSET (struct fstab, fs_spec, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct fstab, fs_file, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct fstab, fs_vfstype, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct fstab, fs_mntops, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct fstab, fs_type, MPH_STRING_OFFSET_PTR)
};
-static const size_t
+static const mph_string_offset_t
mph_fstab_offsets[] = {
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_vfstype),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_mntops),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_type)
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_spec, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_file, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_vfstype, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_mntops, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_type, MPH_STRING_OFFSET_PTR)
};
#endif /* def HAVE_FSTAB_H */
@@ -110,20 +110,20 @@ copy_fstab (struct Mono_Posix_Syscall__Fstab *to, mph_fstab *from)
typedef struct vfstab mph_fstab;
-static const size_t
+static const mph_string_offset_t
vfstab_offsets[] = {
- offsetof (struct vfstab, vfs_special),
- offsetof (struct vfstab, vfs_mountp),
- offsetof (struct vfstab, vfs_fstype),
- offsetof (struct vfstab, vfs_mntopts)
+ MPH_STRING_OFFSET (struct vfstab, vfs_special, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct vfstab, vfs_mountp, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct vfstab, vfs_fstype, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct vfstab, vfs_mntopts, MPH_STRING_OFFSET_PTR)
};
-static const size_t
+static const mph_string_offset_t
mph_fstab_offsets[] = {
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_spec),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_file),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_vfstype),
- offsetof (struct Mono_Posix_Syscall__Fstab, fs_mntops)
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_spec, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_file, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_vfstype, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Fstab, fs_mntops, MPH_STRING_OFFSET_PTR)
};
/*
View
@@ -1372,6 +1372,7 @@ struct Mono_Posix_Syscall__Dirent;
struct Mono_Posix_Syscall__Fstab;
struct Mono_Posix_Syscall__Group;
struct Mono_Posix_Syscall__Passwd;
+struct Mono_Posix_Syscall__Utsname;
struct Mono_Posix_Timeval;
struct Mono_Posix_Timezone;
struct Mono_Posix_Utimbuf;
@@ -1491,6 +1492,16 @@ struct Mono_Posix_Syscall__Passwd {
void* _pw_buf_;
};
+struct Mono_Posix_Syscall__Utsname {
+ void* sysname;
+ void* nodename;
+ void* release;
+ void* version;
+ void* machine;
+ void* domainname;
+ void* _buf_;
+};
+
struct Mono_Posix_Timeval {
gint64 tv_sec; /* time_t */
gint64 tv_usec; /* suseconds_t */
@@ -1678,6 +1689,7 @@ gint64 Mono_Posix_Syscall_telldir (void* dir);
gint64 Mono_Posix_Syscall_time (gint64* t);
int Mono_Posix_Syscall_truncate (const char* path, gint64 length);
int Mono_Posix_Syscall_ttyname_r (int fd, char* buf, guint64 buflen);
+int Mono_Posix_Syscall_uname (struct Mono_Posix_Syscall__Utsname* buf);
int Mono_Posix_Syscall_utime (const char* filename, struct Mono_Posix_Utimbuf* buf, int use_buf);
int Mono_Posix_Syscall_utimes (const char* filename, struct Mono_Posix_Timeval* tvp);
int Mono_Posix_Syscall_WEXITSTATUS (int status);
View
@@ -27,6 +27,7 @@
#include <config.h>
+#include <stddef.h> /* offsetof */
#include <limits.h> /* LONG_MAX, ULONG_MAX */
#include <errno.h> /* for ERANGE */
#include <glib.h> /* for g* types, etc. */
@@ -198,10 +199,20 @@ recheck_range (int ret)
return 0;
}
+typedef unsigned int mph_string_offset_t;
+
+enum {
+ MPH_STRING_OFFSET_PTR = 0x0,
+ MPH_STRING_OFFSET_ARRAY = 0x1,
+ MPH_STRING_OFFSET_MASK = 0x1
+};
+
+#define MPH_STRING_OFFSET(type,member,kind) ((offsetof(type,member) << 1) | kind)
+
MPH_INTERNAL char*
_mph_copy_structure_strings (
- void *to, const size_t *to_offsets,
- const void *from, const size_t *from_offsets,
+ void *to, const mph_string_offset_t *to_offsets,
+ const void *from, const mph_string_offset_t *from_offsets,
size_t num_strings);
#endif /* ndef INC_mph_H */
View
@@ -18,22 +18,22 @@
G_BEGIN_DECLS
-static const size_t
+static const mph_string_offset_t
passwd_offsets[] = {
- offsetof (struct passwd, pw_name),
- offsetof (struct passwd, pw_passwd),
- offsetof (struct passwd, pw_gecos),
- offsetof (struct passwd, pw_dir),
- offsetof (struct passwd, pw_shell)
+ MPH_STRING_OFFSET (struct passwd, pw_name, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct passwd, pw_passwd, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct passwd, pw_gecos, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct passwd, pw_dir, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct passwd, pw_shell, MPH_STRING_OFFSET_PTR)
};
-static const size_t
+static const mph_string_offset_t
mph_passwd_offsets[] = {
- offsetof (struct Mono_Posix_Syscall__Passwd, pw_name),
- offsetof (struct Mono_Posix_Syscall__Passwd, pw_passwd),
- offsetof (struct Mono_Posix_Syscall__Passwd, pw_gecos),
- offsetof (struct Mono_Posix_Syscall__Passwd, pw_dir),
- offsetof (struct Mono_Posix_Syscall__Passwd, pw_shell)
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Passwd, pw_name, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Passwd, pw_passwd, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Passwd, pw_gecos, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Passwd, pw_dir, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET (struct Mono_Posix_Syscall__Passwd, pw_shell, MPH_STRING_OFFSET_PTR)
};
/*
View
@@ -0,0 +1,67 @@
+/*
+ * <sys/sendfile.h> wrapper functions.
+ *
+ * Authors:
+ * Jonathan Pryor (jonpryor@vt.edu)
+ *
+ * Copyright (C) 2004 Jonathan Pryor
+ */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include "map.h"
+#include "mph.h"
+
+#include <sys/utsname.h>
+
+G_BEGIN_DECLS
+
+static const mph_string_offset_t
+utsname_offsets[] = {
+ MPH_STRING_OFFSET(struct utsname, sysname, MPH_STRING_OFFSET_ARRAY),
+ MPH_STRING_OFFSET(struct utsname, nodename, MPH_STRING_OFFSET_ARRAY),
+ MPH_STRING_OFFSET(struct utsname, release, MPH_STRING_OFFSET_ARRAY),
+ MPH_STRING_OFFSET(struct utsname, version, MPH_STRING_OFFSET_ARRAY),
+ MPH_STRING_OFFSET(struct utsname, machine, MPH_STRING_OFFSET_ARRAY)
+};
+
+static const mph_string_offset_t
+mph_utsname_offsets[] = {
+ MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, sysname, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, nodename, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, release, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, version, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct Mono_Posix_Syscall__Utsname, machine, MPH_STRING_OFFSET_PTR)
+};
+
+int
+Mono_Posix_Syscall_uname (struct Mono_Posix_Syscall__Utsname *buf)
+{
+ struct utsname _buf;
+ int r;
+
+ if (!buf) {
+ errno = EFAULT;
+ return -1;
+ }
+
+ r = uname (&_buf);
+ if (r == 0) {
+ buf->_buf_ = _mph_copy_structure_strings (buf, mph_utsname_offsets,
+ &_buf, utsname_offsets, sizeof(utsname_offsets)/sizeof(utsname_offsets[0]));
+ buf->domainname = NULL;
+ if (!buf->_buf_) {
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+ return r;
+}
+
+G_END_DECLS
+
+/*
+ * vim: noexpandtab
+ */
View
@@ -10,12 +10,20 @@
#define MAX_OFFSETS 10
-#define str_at(p, n) (*(char**)(((char*)p)+n))
+#define OFFSET_SHIFT 1
+
+#define lstr_at(p, n) (*(char**)(((char*)(p))+(n >> OFFSET_SHIFT)))
+
+#define str_at(p, n) ( \
+ (((n) & MPH_STRING_OFFSET_MASK) == MPH_STRING_OFFSET_ARRAY) \
+ ? (char*)(p) + (n >> OFFSET_SHIFT) \
+ : lstr_at(p, n) \
+)
char* MPH_INTERNAL
_mph_copy_structure_strings (
- void *to, const size_t *to_offsets,
- const void *from, const size_t *from_offsets,
+ void *to, const mph_string_offset_t *to_offsets,
+ const void *from, const mph_string_offset_t *from_offsets,
size_t num_strings)
{
int i;
@@ -26,7 +34,7 @@ _mph_copy_structure_strings (
g_assert (num_strings < MAX_OFFSETS);
for (i = 0; i < num_strings; ++i) {
- str_at (to, to_offsets[i]) = NULL;
+ lstr_at (to, to_offsets[i]) = NULL;
}
buflen = num_strings;
@@ -45,7 +53,7 @@ _mph_copy_structure_strings (
for (i = 0; i < num_strings; ++i) {
if (len[i] > 0) {
- str_at (to, to_offsets[i]) =
+ lstr_at (to, to_offsets[i]) =
strcpy (cur, str_at (from, from_offsets[i]));
cur += (len[i] +1);
}
@@ -62,29 +70,40 @@ struct foo {
char *a;
int b;
char *c;
+ char d[10];
};
struct bar {
int b;
char *a;
double d;
char *c;
+ char *e;
};
int
main ()
{
/* test copying foo to bar */
- struct foo f = {"hello", 42, "world"};
+ struct foo f = {"hello", 42, "world", "!!"};
struct bar b;
- size_t foo_offsets[] = {offsetof(struct foo, a), offsetof(struct foo, c)};
- size_t bar_offsets[] = {offsetof(struct bar, a), offsetof(struct bar, c)};
+ mph_string_offset_t foo_offsets[] = {
+ MPH_STRING_OFFSET(struct foo, a, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct foo, c, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct foo, d, MPH_STRING_OFFSET_ARRAY)
+ };
+ mph_string_offset_t bar_offsets[] = {
+ MPH_STRING_OFFSET(struct bar, a, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct bar, c, MPH_STRING_OFFSET_PTR),
+ MPH_STRING_OFFSET(struct bar, e, MPH_STRING_OFFSET_PTR)
+ };
char *buf;
buf = _mph_copy_structure_strings (&b, bar_offsets,
- &f, foo_offsets, 2);
+ &f, foo_offsets, 3);
printf ("b.a=%s\n", b.a);
printf ("b.c=%s\n", b.c);
+ printf ("b.e=%s\n", b.e);
return 0;
}

0 comments on commit aaf6f0a

Please sign in to comment.