* map.h: Flush; add Mono_Posix_Syscall__Utsname, Mono_Posix_Syscall_uname()
authorJonathan Pryor <jpryor@novell.com>
Mon, 17 Dec 2007 22:49:20 +0000 (22:49 -0000)
committerJonathan Pryor <jpryor@novell.com>
Mon, 17 Dec 2007 22:49:20 +0000 (22:49 -0000)
  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

support/ChangeLog
support/Makefile.am
support/fstab.c
support/map.h
support/mph.h
support/pwd.c
support/sys-utsname.c [new file with mode: 0644]
support/x-struct-str.c

index c0fa91d6f54f07aad9218407517b7846cf32791e..5c0aca4ea97b187078174a070a8eb4e942298a9b 100644 (file)
@@ -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.
index 96cc2002e28dbf9eaec102311a276fddaf5e7b87..1f6a51c1a8fa6fd387193c6ad100438dcc5a6361 100644 (file)
@@ -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                                \
index e81821b18c6c11a48c8253c7646d3229aab9fcac..010342704a1cd7ce16cc7df72f63124967bc6571 100644 (file)
@@ -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)
 };
 
 /*
index 302b08d9c17f93e46bcd392c373c57e4b5981821..179defe372bfd278dd1a625362ec59e2bc9201c5 100644 (file)
@@ -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);
index daa5828d6db646818d49d1a834cbab2a4bae787d..224f01093333f715a3408958c87047673c7b07cf 100644 (file)
@@ -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 */
index e622027458dfa806dbdaf0525b27ce10484a3473..13bccef9b559a9392c6787f8dc47c19ab485296b 100644 (file)
 
 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)
 };
 
 /*
diff --git a/support/sys-utsname.c b/support/sys-utsname.c
new file mode 100644 (file)
index 0000000..deccad5
--- /dev/null
@@ -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
+ */
index 68925ed2cf87d2841509099e0457a0b73c836acd..89d5a61b120b6227f36aaad323efd33810fcf631 100644 (file)
 
 #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,6 +70,7 @@ struct foo {
        char *a;
        int   b;
        char *c;
+       char d[10];
 };
 
 struct bar {
@@ -69,22 +78,32 @@ struct bar {
        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;
 }