update dev300-m58
[ooovba.git] / dmake / unix / bsd43 / utime.c
blob6531968919cf3ca6518b5f1d43e5c00bb564d6c3
1 /* RCS $Id: utime.c,v 1.1.1.1 2000-09-22 15:33:34 hr Exp $
2 --
3 -- SYNOPSIS
4 -- utime
5 --
6 -- DESCRIPTION
7 -- Provide our own utime function.
8 --
9 -- AUTHOR
10 -- Dennis Vadura, dvadura@dmake.wticorp.com
12 -- WWW
13 -- http://dmake.wticorp.com/
15 -- COPYRIGHT
16 -- Copyright (c) 1996,1997 by WTI Corp. All rights reserved.
17 --
18 -- This program is NOT free software; you can redistribute it and/or
19 -- modify it under the terms of the Software License Agreement Provided
20 -- in the file <distribution-root>/readme/license.txt.
22 -- LOG
23 -- Use cvs log to obtain detailed change logs.
26 #include <sys/types.h>
27 #include <sys/time.h>
28 #include <sys/stat.h>
29 #include <sys/file.h>
31 int
32 utime(name, timep)
33 char* name;
34 time_t timep[2];
36 struct timeval tv[2], *tvp;
37 struct stat buf;
38 int fil;
39 char data;
41 if (timep!=0)
43 tvp = tv, tv[0].tv_sec = timep[0], tv[1].tv_sec = timep[1];
44 if (utimes(name, tvp)==0)
45 return (0);
48 if (stat(name, &buf) != 0)
49 return (-1);
50 if (buf.st_size != 0) {
51 if ((fil = open(name, O_RDWR, 0666)) < 0)
52 return (-1);
53 if (read(fil, &data, 1) < 1) {
54 close(fil);
55 return (-1);
57 lseek(fil, 0L, 0);
58 if (write(fil, &data, 1) < 1) {
59 close(fil);
60 return (-1);
62 close(fil);
63 return (0);
64 } else if ((fil = creat(name, 0666)) < 0) {
65 return (-1);
66 } else {
67 close(fil);
68 return (0);