]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/unix/utimes.c
update
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / unix / utimes.c
1 /***********************************************************************/
2 /*                                                                     */
3 /*                           Objective Caml                            */
4 /*                                                                     */
5 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
6 /*                                                                     */
7 /*  Copyright 1996 Institut National de Recherche en Informatique et   */
8 /*  en Automatique.  All rights reserved.  This file is distributed    */
9 /*  under the terms of the GNU Library General Public License, with    */
10 /*  the special exception on linking described in file ../../LICENSE.  */
11 /*                                                                     */
12 /***********************************************************************/
13
14 /* $Id: utimes.c 6824 2005-03-24 17:20:54Z doligez $ */
15
16 #include <fail.h>
17 #include <mlvalues.h>
18 #include "unixsupport.h"
19
20 #ifdef HAS_UTIME
21
22 #include <sys/types.h>
23 #ifndef _WIN32
24 #include <utime.h>
25 #else
26 #include <sys/utime.h>
27 #endif
28
29 CAMLprim value unix_utimes(value path, value atime, value mtime)
30 {
31   struct utimbuf times, * t;
32   times.actime = Double_val(atime);
33   times.modtime = Double_val(mtime);
34   if (times.actime || times.modtime)
35     t = &times;
36   else
37     t = (struct utimbuf *) NULL;
38   if (utime(String_val(path),  t) == -1) uerror("utimes", path);
39   return Val_unit;
40 }
41
42 #else
43
44 #ifdef HAS_UTIMES
45
46 #include <sys/types.h>
47 #include <sys/time.h>
48
49 CAMLprim value unix_utimes(value path, value atime, value mtime)
50 {
51   struct timeval tv[2], * t;
52   double at = Double_val(atime);
53   double mt = Double_val(mtime);
54   tv[0].tv_sec = at;
55   tv[0].tv_usec = (at - tv[0].tv_sec) * 1000000;
56   tv[1].tv_sec = mt;
57   tv[1].tv_usec = (mt - tv[1].tv_sec) * 1000000;
58   if (tv[0].tv_sec || tv[1].tv_sec)
59     t = tv;
60   else
61     t = (struct timeval *) NULL;
62   if (utimes(String_val(path),  t) == -1) uerror("utimes", path);
63   return Val_unit;
64 }
65
66 #else
67
68 CAMLprim value unix_utimes(value path, value atime, value mtime)
69 { invalid_argument("utimes not implemented"); }
70
71 #endif
72 #endif