3 * utime.c - set the modification date of the file
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
10 #include <sys/param.h>
13 #include <proto/dos.h>
21 /****** net.lib/utime *********************************************
24 utime - set file access and modification times
29 int error = utime(const char *name, const struct utimbuf *times)
32 The access and modification times for the file 'name' are modified
33 according to the 'times'. If 'times' is NULL, the times are set to
40 'name' - the name of the file to be affected.
42 'times' - pointer to a structure containing the time values,
43 defined in <utime.h> as:
46 time_t actime; \* Access time *\
47 time_t modtime; \* Modification time *\
50 Both times are in units of seconds since Jan. 1, 1970,
53 If the 'times' is given as the NULL pointer, the current
57 Returns 0 when successful and -1 with specific error code in errno in
61 Since AmigaDOS files have only one time stamp, both access and
62 modification times cannot be supported. Since the AmigaDOS file date
63 is the modification time, only the 'modtime' field of the 'times' is
66 The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
67 done with external long __local_to_GMT, which is defined and
68 initialized by the timerinit.c module included in the net.lib.
71 dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
73 *****************************************************************************
77 extern long __local_to_GMT
; /* defined and initialized in timerinit.c */
80 utime(const char *name
, const struct utimbuf
*times
)
82 struct DateStamp stamp
;
83 unsigned long days
, secs
;
90 * AmigaDOS file date is the modification time
92 time
= times
->modtime
;
95 * Convert time (secs since 1.1.1970 GMT) to
96 * AmigaDOS DateStamp (based on 1.1.1978 local time).
98 time
-= __local_to_GMT
; /* GMT to local */
99 days
= (unsigned long)time
/ (unsigned long)(24*60*60);
100 secs
= (unsigned long)time
% (unsigned long)(24*60*60);
101 stamp
.ds_Days
= (LONG
)days
;
102 stamp
.ds_Minute
= (LONG
)(secs
/ 60);
103 stamp
.ds_Tick
= (LONG
)((secs
% 60) * TICKS_PER_SECOND
);
106 if (!SetFileDate((STRPTR
)name
, &stamp
)) {