瀏覽代碼

Mac OS X and BSD portability fixes. MonoPosixHelper should now cleanly
compile on Darwin.

svn path=/trunk/mono/; revision=35725

Jonathan Pryor 21 年之前
父節點
當前提交
9cb7cfc014
共有 11 個文件被更改,包括 86 次插入12 次删除
  1. 19 9
      ChangeLog
  2. 4 0
      support/dirent.c
  3. 5 1
      support/fcntl.c
  4. 6 0
      support/grp.c
  5. 4 0
      support/mph.h
  6. 3 0
      support/old-map.c
  7. 2 0
      support/pwd.c
  8. 26 1
      support/sys-mount.c
  9. 7 1
      support/sys-sendfile.c
  10. 2 0
      support/time.c
  11. 8 0
      support/unistd.c

+ 19 - 9
ChangeLog

@@ -11,26 +11,36 @@
 	* support/Makefile.am: Add new INCLUDE directives (for glib headers),
 	  source; bump library version (so we don't clobber previous versions of
 	  libMonoPosixHelper.so).
-	* support/dirent.c: New file; <dirent.h> wrapper functions
+	* support/dirent.c: New file; <dirent.h> wrapper functions; 
+	  BSD portability fixes.
 	* support/errno.c: New file; <errno.h> wrapper functions
-	* support/fcntl.c: New file; <fcntl.h> wrapper functions
-	* support/grp.c: New file; <grp.h> wrapper functions
+	* support/fcntl.c: New file; <fcntl.h> wrapper functions;
+	  BSD portability fixes.
+	* support/grp.c: New file; <grp.h> wrapper functions;
+	  BSD portability fixes.
 	* support/map.c: Updated macro mapping functions (more enums mapped, more
 	  error checking, etc.).
 	* support/map.h: Updated macro mapping functions
 	* support/old-map.c: Previous map.c implementation, for backward compatibility
+	  Remove spurious warning about redefining _GNU_SOURCE.
 	* support/old-map.h: Previous map.h implementation, for backward compatibility
-	* support/mph.h: New file; Utility types, macros
-	* support/pwd.c: New file; <pwd.h> wrapper functions
+	* support/mph.h: New file; Utility types, macros;
+	  BSD portability fixes.
+	* support/pwd.c: New file; <pwd.h> wrapper functions;
+	  BSD portability fixes.
 	* support/stdio.c: New file; <stdio.h> wrapper functions
 	* support/stdlib.c: New file; <stdlib.h> wrapper functions
 	* support/sys-mman.c: New file; <sys/mman.h> wrapper functions
-	* support/sys-mount.c: New file; <sys/mount.h> wrapper functions
-	* support/sys-sendfile.c: New file; <sys/sendfile.h> wrapper functions
+	* support/sys-mount.c: New file; <sys/mount.h> wrapper functions;
+	  BSD portability fixes.
+	* support/sys-sendfile.c: New file; <sys/sendfile.h> wrapper functions;
+	  BSD portability fixes.
 	* support/sys-stat.c: New file; <sys/stat.h> wrapper functions
 	* support/sys-wait.c: New file; <sys/wait.h> wrapper functions
-	* support/time.c: New file; <time.h> wrapper functions
-	* support/unistd.c: New file; <unistd.h> wrapper functions
+	* support/time.c: New file; <time.h> wrapper functions;
+	  BSD portability fixes.
+	* support/unistd.c: New file; <unistd.h> wrapper functions;
+	  BSD portability fixes.
 
 2004-10-31  Zoltan Varga  <[email protected]>
 

+ 4 - 0
support/dirent.c

@@ -53,7 +53,11 @@ copy_dirent (
 	)
 {
 	to->d_ino    = from->d_ino;
+#ifdef MPH_ON_BSD
+	to->d_off    = 0;
+#else
 	to->d_off    = from->d_off;
+#endif
 	to->d_reclen = from->d_reclen;
 	to->d_type   = from->d_type;
 	to->d_name   = strdup (from->d_name);

+ 5 - 1
support/fcntl.c

@@ -42,13 +42,13 @@ gint32
 Mono_Posix_Syscall_fcntl_arg (gint32 fd, gint32 cmd, gint64 arg)
 {
 	long _arg;
-	int _argi;
 	gint32 _cmd;
 
 	mph_return_if_long_overflow (arg);
 
 #ifdef F_NOTIFY
 	if (cmd == F_NOTIFY) {
+		int _argi;
 		if (Mono_Posix_FromDirectoryNotifyFlags (arg, &_argi) == -1) {
 			return -1;
 		}
@@ -140,6 +140,7 @@ Mono_Posix_Syscall_creat (const char *pathname, guint32 mode)
 #endif
 }
 
+#ifdef HAVE_POSIX_FADVISE
 gint32
 Mono_Posix_Syscall_posix_fadvise (gint32 fd, mph_off_t offset, mph_off_t len, 
 	gint32 advice)
@@ -156,7 +157,9 @@ Mono_Posix_Syscall_posix_fadvise (gint32 fd, mph_off_t offset, mph_off_t len,
 	return posix_fadvise (fd, (off_t) offset, (off_t) len, advice);
 #endif
 }
+#endif /* ndef HAVE_POSIX_FADVISE */
 
+#ifdef HAVE_POSIX_FALLOCATE
 gint32
 Mono_Posix_Syscall_posix_fallocate (gint32 fd, mph_off_t offset, mph_size_t len)
 {
@@ -169,6 +172,7 @@ Mono_Posix_Syscall_posix_fallocate (gint32 fd, mph_off_t offset, mph_size_t len)
 	return posix_fadvise (fd, (off_t) offset, (size_t) len);
 #endif
 }
+#endif /* ndef HAVE_POSIX_FALLOCATE */
 
 G_END_DECLS
 

+ 6 - 0
support/grp.c

@@ -7,10 +7,14 @@
  * Copyright (C) 2004 Jonathan Pryor
  */
 
+#include <sys/types.h>
+#include <sys/param.h>
 #include <grp.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
+#include <unistd.h>	/* for setgroups on Mac OS X */
 
 #include "mph.h"
 
@@ -233,6 +237,7 @@ Mono_Posix_Syscall_getgrent (struct Mono_Posix_Syscall__Group *grbuf)
 	return 0;
 }
 
+#ifdef HAVE_FGETGRENT
 gint32
 Mono_Posix_Syscall_fgetgrent (FILE *stream, struct Mono_Posix_Syscall__Group *grbuf)
 {
@@ -253,6 +258,7 @@ Mono_Posix_Syscall_fgetgrent (FILE *stream, struct Mono_Posix_Syscall__Group *gr
 	}
 	return 0;
 }
+#endif /* ndef HAVE_FGETGRENT */
 
 gint32
 Mono_Posix_Syscall_setgroups (mph_size_t size, mph_gid_t *list)

+ 4 - 0
support/mph.h

@@ -30,6 +30,10 @@
 #define MPH_USE_64_API
 #endif
 
+#if __APPLE__ || __BSD__
+#define MPH_ON_BSD
+#endif
+
 typedef    gint64 mph_blkcnt_t;
 typedef    gint64 mph_blksize_t;
 typedef   guint64 mph_dev_t;

+ 3 - 0
support/old-map.c

@@ -1,6 +1,9 @@
 /* This file was automatically generated by make-map from Mono.Posix.dll */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/wait.h>

+ 2 - 0
support/pwd.c

@@ -228,6 +228,7 @@ Mono_Posix_Syscall_getpwent (struct Mono_Posix_Syscall__Passwd *pwbuf)
 	return 0;
 }
 
+#ifdef HAVE_FGETPWENT
 gint32
 Mono_Posix_Syscall_fgetpwent (FILE *stream, struct Mono_Posix_Syscall__Passwd *pwbuf)
 {
@@ -248,6 +249,7 @@ Mono_Posix_Syscall_fgetpwent (FILE *stream, struct Mono_Posix_Syscall__Passwd *p
 	}
 	return 0;
 }
+#endif /* ndef FGETPWENT */
 
 G_END_DECLS
 

+ 26 - 1
support/sys-mount.c

@@ -10,18 +10,43 @@
 #include <sys/mount.h>
 #include <glib/gtypes.h>
 
+#include "mph.h"
 #include "map.h"
 
 G_BEGIN_DECLS
 
 gint32
 Mono_Posix_Syscall_mount (const char *source, const char *target, 
-		const char *filesystemtype, guint64 mountflags, const void *data)
+		const char *filesystemtype, guint64 mountflags, void *data)
 {
 	if (Mono_Posix_FromMountFlags (mountflags, &mountflags) == -1)
 		return -1;
 
+#ifdef MPH_ON_BSD
+	return mount (filesystemtype, target, mountflags, data);
+#else
 	return mount (source, target, filesystemtype, (unsigned long) mountflags, data);
+#endif
+}
+
+gint32
+Mono_Posix_Syscall_umount (const char *source)
+{
+#ifdef MPH_ON_BSD
+	return unmount (source, MNT_FORCE);
+#else
+	return umount (source);
+#endif
+}
+
+gint32
+Mono_Posix_Syscall_umount2 (const char *source, gint32 flags)
+{
+#ifdef MPH_ON_BSD
+	return unmount (source, flags);
+#else
+	return umount2 (source, flags);
+#endif
 }
 
 G_END_DECLS

+ 7 - 1
support/sys-sendfile.c

@@ -7,13 +7,18 @@
  * Copyright (C) 2004 Jonathan Pryor
  */
 
-#include <sys/sendfile.h>
+#include <sys/types.h>
 #include <errno.h>
 
+#ifdef HAVE_SYS_SENDFILE_H
+#include <sys/sendfile.h>
+#endif /* ndef HAVE_SYS_SENDFILE_H */
+
 #include "mph.h"
 
 G_BEGIN_DECLS
 
+#ifdef HAVE_SENDFILE
 mph_ssize_t
 Mono_Posix_Syscall_sendfile (int out_fd, int in_fd, mph_off_t *offset, mph_size_t count)
 {
@@ -29,6 +34,7 @@ Mono_Posix_Syscall_sendfile (int out_fd, int in_fd, mph_off_t *offset, mph_size_
 
 	return r;
 }
+#endif /* ndef HAVE_SENDFILE */
 
 G_END_DECLS
 

+ 2 - 0
support/time.c

@@ -16,6 +16,7 @@
 
 G_BEGIN_DECLS
 
+#ifdef HAVE_STIME
 gint32
 Mono_Posix_Syscall_stime (mph_time_t *t)
 {
@@ -28,6 +29,7 @@ Mono_Posix_Syscall_stime (mph_time_t *t)
 	_t = (time_t) *t;
 	return stime (&_t);
 }
+#endif /* ndef HAVE_STIME */
 
 mph_time_t
 Mono_Posix_Syscall_time (mph_time_t *t)

+ 8 - 0
support/unistd.c

@@ -17,6 +17,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <limits.h>
+#include <string.h>     /* for swab(3) on Mac OS X */
 
 #include <glib/gtypes.h>
 
@@ -136,12 +137,14 @@ Mono_Posix_Syscall_confstr (int name, char *buf, mph_size_t len)
 	return confstr (name, buf, (size_t) len);
 }
 
+#ifdef HAVE_TTYNAME_R
 gint32
 Mono_Posix_Syscall_ttyname_r (int fd, char *buf, mph_size_t len)
 {
 	mph_return_if_size_t_overflow (len);
 	return ttyname_r (fd, buf, (size_t) len);
 }
+#endif /* ndef HAVE_TTYNAME_R */
 
 gint32
 Mono_Posix_Syscall_readlink (const char *path, char *buf, mph_size_t len)
@@ -181,7 +184,12 @@ gint32
 Mono_Posix_Syscall_sethostid (gint64 hostid)
 {
 	mph_return_if_long_overflow (hostid);
+#ifdef MPH_ON_BSD
+	sethostid ((long) hostid);
+	return 0;
+#else
 	return sethostid ((long) hostid);
+#endif
 }
 
 gint32