GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
date.c
Go to the documentation of this file.
1 /*!
2  * \file lib/gis/date.c
3  *
4  * \brief GIS Library - Date functions.
5  *
6  * (C) 2001-2009 by the GRASS Development Team
7  *
8  * This program is free software under the GNU General Public License
9  * (>=v2). Read the file COPYING that comes with GRASS for details.
10  *
11  * \author Original author CERL
12  */
13 
14 #include <time.h>
15 #include <grass/gis.h>
16 
17 /*!
18  * \brief Current date and time.
19  *
20  * Returns a pointer to a string which is the current date and
21  * time. The format is the same as that produced by the UNIX
22  * <tt>date</tt> command.
23  *
24  * \return pointer to a string holding date/time
25  */
26 const char *G_date(void)
27 {
28  static int initialized;
29  static char *date;
30  time_t clock;
31  struct tm *local;
32  char *tdate;
33  char *d;
34 
35  if (G_is_initialized(&initialized))
36  return date;
37 
38  time(&clock);
39 
40  local = localtime(&clock);
41  tdate = asctime(local);
42  for (d = tdate; *d; d++)
43  if (*d == '\n')
44  *d = 0;
45 
46  date = G_store(tdate);
47 
48  G_initialize_done(&initialized);
49 
50  return date;
51 }
const char * G_date(void)
Current date and time.
Definition: date.c:26
struct tm * localtime()
void G_initialize_done(int *)
Definition: counter.c:76
int G_is_initialized(int *)
Definition: counter.c:59
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87