time_r.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Reentrant time functions like localtime_r.
  2. Copyright (C) 2003, 2006-2007, 2010-2011 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation,
  13. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  14. /* Written by Paul Eggert. */
  15. #include <config.h>
  16. #include <time.h>
  17. static struct tm *
  18. copy_tm_result (struct tm *dest, struct tm const *src)
  19. {
  20. if (! src)
  21. return 0;
  22. *dest = *src;
  23. return dest;
  24. }
  25. struct tm *
  26. gmtime_r (time_t const * restrict t, struct tm * restrict tp)
  27. {
  28. return copy_tm_result (tp, gmtime (t));
  29. }
  30. struct tm *
  31. localtime_r (time_t const * restrict t, struct tm * restrict tp)
  32. {
  33. return copy_tm_result (tp, localtime (t));
  34. }