* cppfiles.c (_cpp_execute_include): Move `len` initialisation
[official-gcc.git] / fastjar / dostime.c
blob834ef4284aaddf3c40f2edb455a1236d9ebb2659
1 /*
2 dostime.c - routines for converting UNIX time to MS-DOS time.
4 Borrowed from Info-zip's unzip
6 Copyright (C) 1999 Bryan Burns
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /* $Id: dostime.c,v 1.1 2000/12/09 03:08:23 apbianco Exp $
25 $Log: dostime.c,v $
26 Revision 1.1 2000/12/09 03:08:23 apbianco
27 2000-12-08 Alexandre Petit-Bianco <apbianco@cygnus.com>
29 * fastjar: Imported.
31 Revision 1.1.1.1 1999/12/06 03:09:12 toast
32 initial checkin..
36 Revision 1.6 1999/05/10 08:32:26 burnsbr
37 added dos2unixtime
39 Revision 1.5 1999/04/27 10:03:50 burnsbr
40 configure support
42 Revision 1.4 1999/04/26 21:55:19 burnsbr
43 switched from sys/time.h to time.h for better portability
45 Revision 1.3 1999/04/20 08:54:30 burnsbr
46 added GPL comment
48 Revision 1.2 1999/04/20 05:10:53 burnsbr
49 added RCS tags
53 #include "config.h"
55 #ifdef TM_IN_SYS_TIME
56 #include <sys/time.h>
57 #else
58 #include <time.h>
59 #endif
61 #include "dostime.h"
65 Copyright (C) 1990-1997 Mark Adler, Richard B. Wales, Jean-loup Gailly,
66 Kai Uwe Rommel, Onno van der Linden and Igor Mandrichenko.
67 Permission is granted to any individual or institution to use, copy, or
68 redistribute this software so long as all of the original files are included,
69 that it is not sold for profit, and that this copyright notice is retained.
74 time_t dos2unixtime(dostime)
75 unsigned long dostime; /* DOS time to convert */
76 /* Return the Unix time_t value (GMT/UTC time) for the DOS format (local)
77 * time dostime, where dostime is a four byte value (date in most
78 * significant word, time in least significant word), see dostime()
79 * function.
82 struct tm *t; /* argument for mktime() */
83 time_t clock = time(NULL);
85 t = localtime(&clock);
86 t->tm_isdst = -1; /* let mktime() determine if DST is in effect */
87 /* Convert DOS time to UNIX time_t format */
88 t->tm_sec = (((int)dostime) << 1) & 0x3e;
89 t->tm_min = (((int)dostime) >> 5) & 0x3f;
90 t->tm_hour = (((int)dostime) >> 11) & 0x1f;
91 t->tm_mday = (int)(dostime >> 16) & 0x1f;
92 t->tm_mon = ((int)(dostime >> 21) & 0x0f) - 1;
93 t->tm_year = ((int)(dostime >> 25) & 0x7f) + 80;
95 return mktime(t);
98 unsigned long dostime(y, n, d, h, m, s)
99 int y; /* year */
100 int n; /* month */
101 int d; /* day */
102 int h; /* hour */
103 int m; /* minute */
104 int s; /* second */
105 /* Convert the date y/n/d and time h:m:s to a four byte DOS date and
106 time (date in high two bytes, time in low two bytes allowing magnitude
107 comparison). */
109 return y < 1980 ? dostime(1980, 1, 1, 0, 0, 0) :
110 (((unsigned long)y - 1980) << 25) | ((unsigned long)n << 21) |
111 ((unsigned long)d << 16) | ((unsigned long)h << 11) |
112 ((unsigned long)m << 5) | ((unsigned long)s >> 1);
116 unsigned long unix2dostime(t)
117 time_t *t; /* unix time to convert */
118 /* Return the Unix time t in DOS format, rounded up to the next two
119 second boundary. */
121 time_t t_even;
122 struct tm *s; /* result of localtime() */
124 t_even = (*t + 1) & (~1); /* Round up to even seconds. */
125 s = localtime(&t_even); /* Use local time since MSDOS does. */
126 return dostime(s->tm_year + 1900, s->tm_mon + 1, s->tm_mday,
127 s->tm_hour, s->tm_min, s->tm_sec);