mldonkey-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mldonkey-commits] Changes to mldonkey/src/config/unix/os_stubs_c.c


From: mldonkey-commits
Subject: [Mldonkey-commits] Changes to mldonkey/src/config/unix/os_stubs_c.c
Date: Tue, 26 Jul 2005 17:35:17 -0400

Index: mldonkey/src/config/unix/os_stubs_c.c
diff -u mldonkey/src/config/unix/os_stubs_c.c:1.5 
mldonkey/src/config/unix/os_stubs_c.c:1.6
--- mldonkey/src/config/unix/os_stubs_c.c:1.5   Fri Apr 16 17:14:53 2004
+++ mldonkey/src/config/unix/os_stubs_c.c       Tue Jul 26 21:35:11 2005
@@ -1,17 +1,13 @@
 
 
-
-#include "caml/mlvalues.h"
-#include "caml/fail.h"
-#include "caml/alloc.h"
-#include "caml/memory.h"
-
-
 #include <errno.h>
 #include <stdio.h>
 #include <caml/mlvalues.h>
 #include <caml/alloc.h>
 #include <caml/memory.h>
+#include <caml/custom.h>
+#include <caml/callback.h>
+#include <caml/fail.h>
 #include <signal.h>
 
 #ifdef HAS_SIGNALS_H
@@ -113,4 +109,112 @@
 void os_set_nonblock(OS_SOCKET fd)
 {
 
+}
+
+#ifdef HAVE_SYS_PARAM_H
+#  include <sys/param.h>
+#  if (defined(__FreeBSD__) && __FreeBSD_version >= 503001) || 
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+#    include <sys/mount.h>
+#    define HAVE_STATS 1
+#  endif
+#endif
+#ifdef HAVE_SYS_VFS_H
+#  include <sys/vfs.h>
+#  define HAVE_STATS 1
+#endif
+
+#ifdef HAVE_STATS
+static value
+#if ((defined (sun) || defined (__sun__)))
+copy_statfs (struct statvfs *buf)
+#else
+copy_statfs (struct statfs *buf)
+#endif
+{
+  CAMLparam0 ();
+  CAMLlocal2 (bufv, v);
+  bufv = caml_alloc (11, 0);
+#if ((defined (sun) || defined (__sun__))) || (defined(__FreeBSD__) && 
__FreeBSD_version >= 503001) || defined(__OpenBSD__) || defined(__NetBSD__)
+  v = copy_int64 (-1); caml_modify (&Field (bufv, 0), v);
+#else
+  v = copy_int64 (buf->f_type); caml_modify (&Field (bufv, 0), v);
+#endif /* ((defined (sun) || defined (__sun__))) || (defined(__FreeBSD__) && 
__FreeBSD_version >= 503001) || defined(__OpenBSD__) || defined(__NetBSD__) */
+  v = copy_int64 (buf->f_bsize); caml_modify (&Field (bufv, 1), v);
+  v = copy_int64 (buf->f_blocks); caml_modify (&Field (bufv, 2), v);
+  v = copy_int64 (buf->f_bfree); caml_modify (&Field (bufv, 3), v);
+  v = copy_int64 (buf->f_bavail); caml_modify (&Field (bufv, 4), v);
+  v = copy_int64 (buf->f_files); caml_modify (&Field (bufv, 5), v);
+  v = copy_int64 (buf->f_ffree); caml_modify (&Field (bufv, 6), v);
+#if ((defined (sun) || defined (__sun__)))
+  v = copy_int64 (-1); caml_modify (&Field (bufv, 7), v);
+  v = copy_int64 (buf->f_namemax); caml_modify (&Field (bufv, 8), v);
+  v = copy_string (buf->f_basetype); caml_modify (&Field (bufv, 9), v);
+  v = copy_int64 (buf->f_frsize); caml_modify (&Field (bufv, 10), v);
+#else
+#if (defined(__FreeBSD__) && __FreeBSD_version >= 503001) || 
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+#  if defined(__OpenBSD__) || defined(__NetBSD__)
+#    include <sys/syslimits.h>
+     v = copy_int64 (NAME_MAX); caml_modify (&Field (bufv, 8), v);
+#  else
+#    if defined(__APPLE__)
+#      include <unistd.h>
+       v = copy_int64 (_PC_NAME_MAX); caml_modify (&Field (bufv ,8 ), v);
+#    else
+       v = copy_int64 (buf->f_namemax); caml_modify (&Field (bufv, 8), v);
+#    endif /* (__APPLE__) */
+#  endif /* (__OpenBSD__) || defined(__NetBSD__) */
+  v = copy_string (buf->f_fstypename); caml_modify (&Field (bufv, 9), v);
+#else
+  v = copy_int64 (buf->f_namelen); caml_modify (&Field (bufv, 8), v);
+  v = copy_string ("-1"); caml_modify (&Field (bufv, 9), v);
+#endif /* (defined(__FreeBSD__) && __FreeBSD_version >= 503001) || 
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) */
+  caml_modify (&Field (bufv, 7), Val_unit);
+  v = copy_int64 (-1); caml_modify (&Field (bufv, 10), v);
+#endif /*  ((defined (sun) || defined (__sun__))) */
+  CAMLreturn (bufv);
+}
+#endif
+
+CAMLprim value
+statfs_statfs (value pathv)
+{
+#ifdef HAVE_STATS
+  CAMLparam1 (pathv);
+  CAMLlocal1 (bufv);
+  const char *path = String_val (pathv);
+#if ((defined (sun) || defined (__sun__)))
+  struct statvfs buf;
+  if (statvfs (path, &buf) == -1)
+#else
+  struct statfs buf;
+  if (statfs (path, &buf) == -1)
+#endif
+    raise_constant(*(value *)caml_named_value("error"));
+  bufv = copy_statfs (&buf);
+  CAMLreturn (bufv);
+#else
+  raise_constant(*(value *)caml_named_value("not supported"));
+#endif
+}
+
+CAMLprim value
+statfs_fstatfs (value fdv)
+{
+#ifdef HAVE_STATS
+  CAMLparam1 (fdv);
+  CAMLlocal1 (bufv);
+  int fd = Int_val (fdv);
+#if ((defined (sun) || defined (__sun__)))
+  struct statvfs buf;
+  if (fstatvfs (fd, &buf) == -1)
+#else
+  struct statfs buf;
+  if (fstatfs (fd, &buf) == -1)
+#endif
+    raise_constant(*(value *)caml_named_value("error"));
+  bufv = copy_statfs (&buf);
+  CAMLreturn (bufv);
+#else
+  raise_constant(*(value *)caml_named_value("not supported"));
+#endif
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]