| 1 | /* Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
|
|---|
| 2 | This file is part of GNU Fortran libU77 library.
|
|---|
| 3 |
|
|---|
| 4 | This library is free software; you can redistribute it and/or modify it
|
|---|
| 5 | under the terms of the GNU Library General Public License as published
|
|---|
| 6 | by the Free Software Foundation; either version 2 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | GNU Fortran is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 12 | Library General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU Library General Public
|
|---|
| 15 | License along with GNU Fortran; see the file COPYING.LIB. If
|
|---|
| 16 | not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|---|
| 17 | Boston, MA 02111-1307, USA. */
|
|---|
| 18 |
|
|---|
| 19 | #ifdef HAVE_CONFIG_H
|
|---|
| 20 | #include "config.h"
|
|---|
| 21 | #endif
|
|---|
| 22 | #include <stdio.h>
|
|---|
| 23 | #include <sys/types.h>
|
|---|
| 24 | #if TIME_WITH_SYS_TIME
|
|---|
| 25 | # include <sys/time.h>
|
|---|
| 26 | # include <time.h>
|
|---|
| 27 | #else
|
|---|
| 28 | # if HAVE_SYS_TIME_H
|
|---|
| 29 | # include <sys/time.h>
|
|---|
| 30 | # else
|
|---|
| 31 | # include <time.h>
|
|---|
| 32 | # endif
|
|---|
| 33 | #endif
|
|---|
| 34 | #if defined (_WIN32)
|
|---|
| 35 | #include <windows.h>
|
|---|
| 36 | #undef min
|
|---|
| 37 | #undef max
|
|---|
| 38 | #endif
|
|---|
| 39 | #include "f2c.h"
|
|---|
| 40 |
|
|---|
| 41 | void s_copy (register char *a, register char *b, ftnlen la, ftnlen lb);
|
|---|
| 42 |
|
|---|
| 43 | int
|
|---|
| 44 | G77_date_and_time_0 (char *date, char *fftime, char *zone,
|
|---|
| 45 | integer * values, ftnlen date_len,
|
|---|
| 46 | ftnlen fftime_len, ftnlen zone_len)
|
|---|
| 47 | {
|
|---|
| 48 | time_t lt = time (<);
|
|---|
| 49 | struct tm ltime = *localtime (<), gtime = *gmtime (<);
|
|---|
| 50 | char dat[9], zon[6], ftim[11];
|
|---|
| 51 | int i, vals[8];
|
|---|
| 52 | #if defined (_WIN32)
|
|---|
| 53 | struct _SYSTEMTIME wdattim;
|
|---|
| 54 | GetLocalTime(&wdattim);
|
|---|
| 55 | vals[7] = wdattim.wMilliseconds;
|
|---|
| 56 | #else
|
|---|
| 57 | vals[7] = 0; /* no STDC/POSIX way to get this */
|
|---|
| 58 | /* GNUish way; maybe use `ftime' on other systems. */
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | vals[0] = 1900 + ltime.tm_year;
|
|---|
| 62 | vals[1] = 1 + ltime.tm_mon;
|
|---|
| 63 | vals[2] = ltime.tm_mday;
|
|---|
| 64 | /* fixme: year boundaries */
|
|---|
| 65 | vals[3] = (ltime.tm_min - gtime.tm_min +
|
|---|
| 66 | 60 * (ltime.tm_hour - gtime.tm_hour +
|
|---|
| 67 | 24 * (ltime.tm_yday - gtime.tm_yday)));
|
|---|
| 68 | vals[4] = ltime.tm_hour;
|
|---|
| 69 | vals[5] = ltime.tm_min;
|
|---|
| 70 | vals[6] = ltime.tm_sec;
|
|---|
| 71 | #if HAVE_GETTIMEOFDAY
|
|---|
| 72 | {
|
|---|
| 73 | struct timeval tp;
|
|---|
| 74 | # if GETTIMEOFDAY_ONE_ARGUMENT
|
|---|
| 75 | if (!gettimeofday (&tp))
|
|---|
| 76 | # else
|
|---|
| 77 | # if HAVE_STRUCT_TIMEZONE
|
|---|
| 78 | struct timezone tzp;
|
|---|
| 79 | /* Some systems such as HPUX, do have struct timezone, but
|
|---|
| 80 | gettimeofday takes void* as the 2nd arg. However, the effect
|
|---|
| 81 | of passing anything other than a null pointer is unspecified on
|
|---|
| 82 | HPUX. Configure checks if gettimeofday actually fails with a
|
|---|
| 83 | non-NULL arg and pretends that struct timezone is missing if it
|
|---|
| 84 | does fail. */
|
|---|
| 85 | if (!gettimeofday (&tp, &tzp))
|
|---|
| 86 | # else
|
|---|
| 87 | if (!gettimeofday (&tp, (void *) 0))
|
|---|
| 88 | # endif /* HAVE_STRUCT_TIMEZONE */
|
|---|
| 89 | # endif /* GETTIMEOFDAY_ONE_ARGUMENT */
|
|---|
| 90 | vals[7] = tp.tv_usec / 1000;
|
|---|
| 91 | }
|
|---|
| 92 | #endif /* HAVE_GETTIMEOFDAY */
|
|---|
| 93 | if (values) /* null pointer for missing optional */
|
|---|
| 94 | for (i = 0; i <= 7; i++)
|
|---|
| 95 | values[i] = vals[i];
|
|---|
| 96 | sprintf (dat, "%04d%02d%02d", vals[0], vals[1], vals[2]);
|
|---|
| 97 | s_copy (date, dat, date_len, 8);
|
|---|
| 98 | if (zone)
|
|---|
| 99 | {
|
|---|
| 100 | sprintf (zon, "%+03d%02d", vals[3] / 60, abs (vals[3] % 60));
|
|---|
| 101 | s_copy (zone, zon, zone_len, 5);
|
|---|
| 102 | }
|
|---|
| 103 | if (fftime)
|
|---|
| 104 | {
|
|---|
| 105 | sprintf (ftim, "%02d%02d%02d.%03d", vals[4], vals[5], vals[6], vals[7]);
|
|---|
| 106 | s_copy (fftime, ftim, fftime_len, 10);
|
|---|
| 107 | }
|
|---|
| 108 | return 0;
|
|---|
| 109 | }
|
|---|