Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / 3rd-party / zisofs_tools / copytime.c
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* $Id: copytime.c,v 1.2 2006/07/04 04:57:42 hpa Exp $ */
14 /* ----------------------------------------------------------------------- *
15  *   
16  *   Copyright 2004 H. Peter Anvin - All Rights Reserved
17  *
18  *   This program is free software; you can redistribute it and/or modify
19  *   it under the terms of the GNU General Public License as published by
20  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
21  *   Bostom MA 02111-1307, USA; either version 2 of the License, or
22  *   (at your option) any later version; incorporated herein by reference.
23  *
24  * ----------------------------------------------------------------------- */
25
26 /*
27  * copytime.c
28  *
29  * Copy time(s) from a struct stat
30  */
31
32 #include "mkzftree.h"           /* Must be included first! */
33
34 #include <utime.h>
35 #include <sys/time.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
38
39 int copytime(const char *filename, const struct stat *st)
40 {
41 #if defined(HAVE_UTIMES) && (defined(HAVE_STRUCT_STAT_ST_MTIM_TV_USEC) || \
42                              defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC))
43   
44   struct timeval tv[2];
45   
46 # ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_USEC
47   tv[0] = st->st_atim;
48   tv[1] = st->st_mtim;
49 # else
50   tv[0].tv_sec  = st->st_atim.tv_sec;
51   tv[0].tv_usec = st->st_atim.tv_nsec / 1000;
52   tv[1].tv_sec  = st->st_mtim.tv_sec;
53   tv[1].tv_usec = st->st_mtim.tv_nsec / 1000;
54 # endif
55   return utimes(filename, tv);
56   
57 #else
58   
59   struct utimbuf ut; 
60   
61   ut.actime  = st->st_atime;
62   ut.modtime = st->st_mtime;
63   return utime(filename, &ut);
64   
65 #endif
66 }