]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/intrinsics/ctime.c
minloc1.m4: Update copyright year and ajust headers order.
[thirdparty/gcc.git] / libgfortran / intrinsics / ctime.c
CommitLineData
35059811 1/* Implementation of the CTIME and FDATE g77 intrinsics.
36ae8a61 2 Copyright (C) 2005, 2007 Free Software Foundation, Inc.
35059811
FXC
3 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
4
5This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7Libgfortran is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public
9License as published by the Free Software Foundation; either
10version 2 of the License, or (at your option) any later version.
11
12In addition to the permissions in the GNU General Public License, the
13Free Software Foundation gives you unlimited permission to link the
14compiled version of this file into combinations with other programs,
15and to distribute those combinations without any restriction coming
16from the use of this file. (The General Public License restrictions
17do apply in other respects; for example, they cover modification of
18the file, and distribution when not linked into a combine
19executable.)
20
21Libgfortran is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public
27License along with libgfortran; see the file COPYING. If not,
28write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29Boston, MA 02110-1301, USA. */
30
35059811
FXC
31#include "libgfortran.h"
32
33#ifdef TIME_WITH_SYS_TIME
34# include <sys/time.h>
35# include <time.h>
36#else
37# if HAVE_SYS_TIME_H
38# include <sys/time.h>
39# else
40# ifdef HAVE_TIME_H
41# include <time.h>
42# endif
43# endif
44#endif
45
46#include <string.h>
47
48
49extern void fdate (char **, gfc_charlen_type *);
50export_proto(fdate);
51
52void
53fdate (char ** date, gfc_charlen_type * date_len)
54{
55#if defined(HAVE_TIME) && defined(HAVE_CTIME)
56 int i;
57 time_t now = time(NULL);
58 *date = ctime (&now);
59 if (*date != NULL)
60 {
61 *date = strdup (*date);
62 *date_len = strlen (*date);
63
64 i = 0;
65 while ((*date)[i])
66 {
67 if ((*date)[i] == '\n')
68 (*date)[i] = ' ';
69 i++;
70 }
71 return;
72 }
73#endif
74
75 *date = NULL;
76 *date_len = 0;
77}
78
79
80extern void fdate_sub (char *, gfc_charlen_type);
81export_proto(fdate_sub);
82
83void
84fdate_sub (char * date, gfc_charlen_type date_len)
85{
86#if defined(HAVE_TIME) && defined(HAVE_CTIME)
87 int i;
88 char *d;
89 time_t now = time(NULL);
90#endif
91
92 memset (date, ' ', date_len);
93#if defined(HAVE_TIME) && defined(HAVE_CTIME)
94 d = ctime (&now);
95 if (d != NULL)
96 {
97 i = 0;
98 while (*d && *d != '\n' && i < date_len)
99 date[i++] = *(d++);
100 }
101#endif
102}
103
104
105
106extern void PREFIX(ctime) (char **, gfc_charlen_type *, GFC_INTEGER_8);
107export_proto_np(PREFIX(ctime));
108
109void
110PREFIX(ctime) (char ** date, gfc_charlen_type * date_len, GFC_INTEGER_8 t)
111{
112#if defined(HAVE_CTIME)
113 time_t now = t;
114 int i;
115 *date = ctime (&now);
116 if (*date != NULL)
117 {
118 *date = strdup (*date);
119 *date_len = strlen (*date);
120
121 i = 0;
122 while ((*date)[i])
123 {
124 if ((*date)[i] == '\n')
125 (*date)[i] = ' ';
126 i++;
127 }
128 return;
129 }
130#endif
131
132 *date = NULL;
133 *date_len = 0;
134}
135
136
137extern void ctime_sub (GFC_INTEGER_8 *, char *, gfc_charlen_type);
138export_proto(ctime_sub);
139
140void
141ctime_sub (GFC_INTEGER_8 * t, char * date, gfc_charlen_type date_len)
142{
143#if defined(HAVE_CTIME)
144 int i;
145 char *d;
146 time_t now = *t;
147#endif
148
149 memset (date, ' ', date_len);
150#if defined(HAVE_CTIME)
151 d = ctime (&now);
152 if (d != NULL)
153 {
154 i = 0;
155 while (*d && *d != '\n' && i < date_len)
156 date[i++] = *(d++);
157 }
158#endif
159}