summaryrefslogtreecommitdiff
path: root/otherlibs/unix
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>1998-06-09 15:06:39 +0000
committerXavier Leroy <xavier.leroy@inria.fr>1998-06-09 15:06:39 +0000
commit5c8f53d793d7a9a9cc0e5e7efc9a386e343ca76b (patch)
tree1f8956bdb171e318135c26904b0f7a63e5401cac /otherlibs/unix
parent4542b86635e065b813b0b5b19bf9bc5bf0b00b25 (diff)
downloadocaml-5c8f53d793d7a9a9cc0e5e7efc9a386e343ca76b.tar.gz
Probleme de l'an 2004: utilisation du type float a la place du type int pour representer les dates Unix
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1981 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/unix')
-rw-r--r--otherlibs/unix/gmtime.c11
-rw-r--r--otherlibs/unix/stat.c35
-rw-r--r--otherlibs/unix/time.c3
-rw-r--r--otherlibs/unix/unix.ml16
-rw-r--r--otherlibs/unix/unix.mli16
-rw-r--r--otherlibs/unix/utimes.c16
6 files changed, 54 insertions, 43 deletions
diff --git a/otherlibs/unix/gmtime.c b/otherlibs/unix/gmtime.c
index c1c0459db2..bbab949a5b 100644
--- a/otherlibs/unix/gmtime.c
+++ b/otherlibs/unix/gmtime.c
@@ -36,14 +36,14 @@ static value alloc_tm(struct tm *tm)
value unix_gmtime(value t) /* ML */
{
time_t clock;
- clock = Long_val(t);
+ clock = (time_t) Double_val(t);
return alloc_tm(gmtime(&clock));
}
value unix_localtime(value t) /* ML */
{
time_t clock;
- clock = Long_val(t);
+ clock = (time_t) Double_val(t);
return alloc_tm(localtime(&clock));
}
@@ -54,9 +54,9 @@ value unix_mktime(value t) /* ML */
struct tm tm;
time_t clock;
value res;
- value tmval = Val_unit;
+ value tmval = Val_unit, clkval = Val_unit;
- Begin_root (tmval);
+ Begin_roots2(tmval, clkval);
tm.tm_sec = Int_val(Field(t, 0));
tm.tm_min = Int_val(Field(t, 1));
tm.tm_hour = Int_val(Field(t, 2));
@@ -68,8 +68,9 @@ value unix_mktime(value t) /* ML */
tm.tm_isdst = -1; /* tm.tm_isdst = Bool_val(Field(t, 8)); */
clock = mktime(&tm);
tmval = alloc_tm(&tm);
+ clkval = copy_double((double) clock);
res = alloc_tuple(2);
- Field(res, 0) = Val_long(clock);
+ Field(res, 0) = clkval;
Field(res, 1) = tmval;
End_roots ();
return res;
diff --git a/otherlibs/unix/stat.c b/otherlibs/unix/stat.c
index da5da047e3..628bd4c1ab 100644
--- a/otherlibs/unix/stat.c
+++ b/otherlibs/unix/stat.c
@@ -12,6 +12,7 @@
/* $Id$ */
#include <mlvalues.h>
+#include <memory.h>
#include <alloc.h>
#include "unixsupport.h"
#include "cst2constr.h"
@@ -38,21 +39,27 @@ static int file_kind_table[] = {
static value stat_aux(struct stat *buf)
{
value v;
+ value atime = Val_unit, mtime = Val_unit, ctime = Val_unit;
- v = alloc_tuple(12);
- Field (v, 0) = Val_int (buf->st_dev);
- Field (v, 1) = Val_int (buf->st_ino);
- Field (v, 2) = cst_to_constr(buf->st_mode & S_IFMT, file_kind_table,
- sizeof(file_kind_table) / sizeof(int), 0);
- Field (v, 3) = Val_int(buf->st_mode & 07777);
- Field (v, 4) = Val_int (buf->st_nlink);
- Field (v, 5) = Val_int (buf->st_uid);
- Field (v, 6) = Val_int (buf->st_gid);
- Field (v, 7) = Val_int (buf->st_rdev);
- Field (v, 8) = Val_int (buf->st_size);
- Field (v, 9) = Val_int (buf->st_atime);
- Field (v, 10) = Val_int (buf->st_mtime);
- Field (v, 11) = Val_int (buf->st_ctime);
+ Begin_roots3(atime,mtime,ctime)
+ atime = copy_double((double) buf->st_atime);
+ mtime = copy_double((double) buf->st_mtime);
+ ctime = copy_double((double) buf->st_ctime);
+ v = alloc_tuple(12);
+ Field (v, 0) = Val_int (buf->st_dev);
+ Field (v, 1) = Val_int (buf->st_ino);
+ Field (v, 2) = cst_to_constr(buf->st_mode & S_IFMT, file_kind_table,
+ sizeof(file_kind_table) / sizeof(int), 0);
+ Field (v, 3) = Val_int(buf->st_mode & 07777);
+ Field (v, 4) = Val_int (buf->st_nlink);
+ Field (v, 5) = Val_int (buf->st_uid);
+ Field (v, 6) = Val_int (buf->st_gid);
+ Field (v, 7) = Val_int (buf->st_rdev);
+ Field (v, 8) = Val_int (buf->st_size);
+ Field (v, 9) = atime;
+ Field (v, 10) = ctime;
+ Field (v, 11) = mtime;
+ End_roots();
return v;
}
diff --git a/otherlibs/unix/time.c b/otherlibs/unix/time.c
index 4278053fb7..43c204c1c4 100644
--- a/otherlibs/unix/time.c
+++ b/otherlibs/unix/time.c
@@ -13,9 +13,10 @@
#include <time.h>
#include <mlvalues.h>
+#include <alloc.h>
#include "unixsupport.h"
value unix_time(void) /* ML */
{
- return Val_long(time((time_t *) NULL));
+ return copy_double((double) time((time_t *) NULL));
}
diff --git a/otherlibs/unix/unix.ml b/otherlibs/unix/unix.ml
index 6e90f65681..e72bcc9449 100644
--- a/otherlibs/unix/unix.ml
+++ b/otherlibs/unix/unix.ml
@@ -204,9 +204,9 @@ type stats =
st_gid : int;
st_rdev : int;
st_size : int;
- st_atime : int;
- st_mtime : int;
- st_ctime : int }
+ st_atime : float;
+ st_mtime : float;
+ st_ctime : float }
external stat : string -> stats = "unix_stat"
external lstat : string -> stats = "unix_lstat"
@@ -282,15 +282,15 @@ type tm =
tm_yday : int;
tm_isdst : bool }
-external time : unit -> int = "unix_time"
+external time : unit -> float = "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 gmtime : float -> tm = "unix_gmtime"
+external localtime : float -> tm = "unix_localtime"
+external mktime : tm -> float * tm = "unix_mktime"
external alarm : int -> int = "unix_alarm"
external sleep : int -> unit = "unix_sleep"
external times : unit -> process_times = "unix_times"
-external utimes : string -> int -> int -> unit = "unix_utimes"
+external utimes : string -> float -> float -> unit = "unix_utimes"
type interval_timer =
ITIMER_REAL
diff --git a/otherlibs/unix/unix.mli b/otherlibs/unix/unix.mli
index 73e5079cea..a113d8edf4 100644
--- a/otherlibs/unix/unix.mli
+++ b/otherlibs/unix/unix.mli
@@ -291,9 +291,9 @@ type stats =
st_gid : int; (* Group id of the owner *)
st_rdev : int; (* Device minor number *)
st_size : int; (* Size in bytes *)
- st_atime : int; (* Last access time *)
- st_mtime : int; (* Last modification time *)
- st_ctime : int } (* Last status change time *)
+ st_atime : float; (* Last access time *)
+ st_mtime : float; (* Last modification time *)
+ st_ctime : float } (* Last status change time *)
(* The informations returned by the [stat] calls. *)
@@ -525,18 +525,18 @@ type tm =
(* The type representing wallclock time and calendar date. *)
-val time : unit -> int
+val time : unit -> float
(* Return the current time since 00:00:00 GMT, Jan. 1, 1970,
in seconds. *)
val gettimeofday : unit -> float
(* Same as [time], but with resolution better than 1 second. *)
-val gmtime : int -> tm
+val gmtime : float -> tm
(* Convert a time in seconds, as returned by [time], into a date and
a time. Assumes Greenwich meridian time zone, also known as UTC. *)
-val localtime : int -> tm
+val localtime : float -> tm
(* Convert a time in seconds, as returned by [time], into a date and
a time. Assumes the local time zone. *)
-val mktime : tm -> int * tm
+val mktime : tm -> float * tm
(* 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], [tm_yday],
@@ -548,7 +548,7 @@ val sleep : int -> unit
(* Stop execution for the given number of seconds. *)
val times : unit -> process_times
(* Return the execution times of the process. *)
-val utimes : string -> int -> int -> unit
+val utimes : string -> float -> float -> unit
(* Set the last access time (second arg) and last modification time
(third arg) for a file. Times are expressed in seconds from
00:00:00 GMT, Jan. 1, 1970. *)
diff --git a/otherlibs/unix/utimes.c b/otherlibs/unix/utimes.c
index 371144aec9..336b09b550 100644
--- a/otherlibs/unix/utimes.c
+++ b/otherlibs/unix/utimes.c
@@ -26,8 +26,8 @@
value unix_utimes(value path, value atime, value mtime) /* ML */
{
struct utimbuf times, * t;
- times.actime = Int_val(atime);
- times.modtime = Int_val(mtime);
+ times.actime = Double_val(atime);
+ times.modtime = Double_val(mtime);
if (times.actime || times.modtime)
t = &times;
else
@@ -46,15 +46,17 @@ value unix_utimes(value path, value atime, value mtime) /* ML */
value unix_utimes(value path, value atime, value mtime) /* ML */
{
struct timeval tv[2], * t;
- tv[0].tv_sec = Int_val(atime);
- tv[0].tv_usec = 0;
- tv[1].tv_sec = Int_val(mtime);
- tv[1].tv_usec = 0;
+ double at = Double_val(atime);
+ double mt = Double_val(mtime);
+ tv[0].tv_sec = at;
+ tv[0].tv_usec = (at - tv[0].tv_sec) * 1000000;
+ tv[1].tv_sec = mt;
+ tv[1].tv_usec = (mt - tv[1].tv_sec) * 1000000;
if (tv[0].tv_sec || tv[1].tv_sec)
t = tv;
else
t = (struct timeval *) NULL;
- if (utimes(String_val(path), t) == -1) uerror("utime", path);
+ if (utimes(String_val(path), t) == -1) uerror("utimes", path);
return Val_unit;
}