summaryrefslogtreecommitdiffstats
path: root/otherlibs/unix
diff options
context:
space:
mode:
Diffstat (limited to 'otherlibs/unix')
-rw-r--r--otherlibs/unix/gmtime.c35
-rw-r--r--otherlibs/unix/rewinddir.c8
-rw-r--r--otherlibs/unix/unix.ml1
-rw-r--r--otherlibs/unix/unix.mli5
-rw-r--r--otherlibs/unix/wait.c6
5 files changed, 54 insertions, 1 deletions
diff --git a/otherlibs/unix/gmtime.c b/otherlibs/unix/gmtime.c
index d7c251c54..0a101b5c5 100644
--- a/otherlibs/unix/gmtime.c
+++ b/otherlibs/unix/gmtime.c
@@ -13,6 +13,7 @@
#include <mlvalues.h>
#include <alloc.h>
+#include <memory.h>
#include "unix.h"
#include <time.h>
@@ -48,3 +49,37 @@ value unix_localtime(t) /* ML */
clock = Long_val(t);
return alloc_tm(localtime(&clock));
}
+
+#ifdef HAS_MKTIME
+
+value unix_mktime(t) /* ML */
+ value t;
+{
+ struct tm tm;
+ time_t clock;
+ value res;
+ Push_roots(r, 1);
+
+ tm.tm_sec = Int_val(Field(t, 0));
+ tm.tm_min = Int_val(Field(t, 1));
+ tm.tm_hour = Int_val(Field(t, 2));
+ tm.tm_mday = Int_val(Field(t, 3));
+ tm.tm_mon = Int_val(Field(t, 4));
+ tm.tm_year = Int_val(Field(t, 5));
+ tm.tm_wday = Int_val(Field(t, 6));
+ tm.tm_yday = Int_val(Field(t, 7));
+ tm.tm_isdst = Bool_val(Field(t, 8));
+ clock = mktime(&tm);
+ r[0] = alloc_tm(&tm);
+ res = alloc_tuple(2);
+ Field(res, 0) = Val_long(clock);
+ Field(res, 1) = r[0];
+ Pop_roots();
+ return res;
+}
+
+#else
+
+value unix_mktime() { invalid_argument("mktime not implemented"); }
+
+#endif
diff --git a/otherlibs/unix/rewinddir.c b/otherlibs/unix/rewinddir.c
index a523f5553..bfe3b77b2 100644
--- a/otherlibs/unix/rewinddir.c
+++ b/otherlibs/unix/rewinddir.c
@@ -20,9 +20,17 @@
#include <sys/dir.h>
#endif
+#ifdef HAS_REWINDDIR
+
value unix_rewinddir(d) /* ML */
value d;
{
rewinddir((DIR *) d);
return Val_unit;
}
+
+#else
+
+value unix_rewinddir() { invalid_argument("rewinddir not implemented"); }
+
+#endif
diff --git a/otherlibs/unix/unix.ml b/otherlibs/unix/unix.ml
index b3c2d0072..b2d7d124b 100644
--- a/otherlibs/unix/unix.ml
+++ b/otherlibs/unix/unix.ml
@@ -277,6 +277,7 @@ external time : unit -> int = "unix_time"
external gettimeofday : unit -> float = "unix_gettimeofday"
external gmtime : int -> tm = "unix_gmtime"
external localtime : int -> tm = "unix_localtime"
+external mktime : tm -> int * tm = "unix_mktime"
external alarm : int -> int = "unix_alarm"
external sleep : int -> unit = "unix_sleep"
external times : unit -> process_times =
diff --git a/otherlibs/unix/unix.mli b/otherlibs/unix/unix.mli
index f2f87624f..01875b497 100644
--- a/otherlibs/unix/unix.mli
+++ b/otherlibs/unix/unix.mli
@@ -506,6 +506,11 @@ external gmtime : int -> tm = "unix_gmtime"
external localtime : int -> tm = "unix_localtime"
(* Convert a time in seconds, as returned by [time], into a date and
a time. Assumes the local time zone. *)
+external mktime : tm -> int * tm = "unix_mktime"
+ (* Convert a date and time, specified by the [tm] argument, into
+ a time in seconds, as returned by [time]. Also return a normalized
+ copy of the given [tm] record, with the [tm_wday] and [tm_yday]
+ recomputed from the other fields. *)
external alarm : int -> int = "unix_alarm"
(* Schedule a [SIGALRM] signals after the given number of seconds. *)
external sleep : int -> unit = "unix_sleep"
diff --git a/otherlibs/unix/wait.c b/otherlibs/unix/wait.c
index d449a9e71..fcac90e43 100644
--- a/otherlibs/unix/wait.c
+++ b/otherlibs/unix/wait.c
@@ -63,7 +63,11 @@ value unix_wait() /* ML */
return alloc_process_status(pid, status);
}
-#ifdef HAS_WAITPID
+#if defined(HAS_WAITPID) || defined(HAS_WAIT4)
+
+#ifndef HAS_WAITPID
+#define waitpid(pid,status,opts) wait4(pid,status,opts,NULL)
+#endif
static int wait_flag_table[] = {
WNOHANG, WUNTRACED