tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / netlib / utime.c
blobe0a0ee48d2ecca494fb6f8227717f1f1ae4bbf3e
1 /* $Id$
3 * utime.c - set the modification date of the file
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
7 * All rights reserved.
8 */
10 #include <sys/param.h>
11 #include <sys/time.h>
12 #include <dos/dos.h>
13 #include <proto/dos.h>
14 #include <utime.h>
15 #include <errno.h>
17 #include <syslog.h>
19 #include "netlib.h"
21 /****** net.lib/utime *********************************************
23 NAME
24 utime - set file access and modification times
26 SYNOPSIS
27 #include <utime.h>
29 int error = utime(const char *name, const struct utimbuf *times)
31 FUNCTION
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
34 systems current time.
36 PORTABILITY
37 UNIX
39 INPUTS
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:
45 struct utimbuf {
46 time_t actime; \* Access time *\
47 time_t modtime; \* Modification time *\
50 Both times are in units of seconds since Jan. 1, 1970,
51 Greenwich Mean Time.
53 If the 'times' is given as the NULL pointer, the current
54 time is used.
56 RESULT
57 Returns 0 when successful and -1 with specific error code in errno in
58 case of an error.
60 NOTES
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
64 used.
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.
70 SEE ALSO
71 dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
73 *****************************************************************************
77 extern long __local_to_GMT; /* defined and initialized in timerinit.c */
79 int
80 utime(const char *name, const struct utimbuf *times)
82 struct DateStamp stamp;
83 unsigned long days, secs;
84 time_t time;
86 if (times == NULL)
87 DateStamp(&stamp);
88 else {
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)) {
107 set_errno(IoErr());
108 return -1;
111 return 0;