date.c 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <time.h>
  14. #include <grass/gis.h>
  15. /*!
  16. * \brief Current date and time.
  17. *
  18. * Returns a pointer to a string which is the current date and
  19. * time. The format is the same as that produced by the UNIX
  20. * <tt>date</tt> command.
  21. *
  22. * \return pointer to a string holding date/time
  23. */
  24. const char *G_date(void)
  25. {
  26. static int initialized;
  27. static char *date;
  28. time_t clock;
  29. struct tm *local;
  30. char *tdate;
  31. char *d;
  32. if (G_is_initialized(&initialized))
  33. return date;
  34. time(&clock);
  35. local = localtime(&clock);
  36. tdate = asctime(local);
  37. for (d = tdate; *d; d++)
  38. if (*d == '\n')
  39. *d = 0;
  40. date = G_store(tdate);
  41. G_initialize_done(&initialized);
  42. return date;
  43. }