time_r.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Reentrant time functions like localtime_r.
  2. Copyright (C) 2003, 2006-2007, 2010-2021 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, see <https://www.gnu.org/licenses/>. */
  13. /* Written by Paul Eggert. */
  14. #include <config.h>
  15. #include <time.h>
  16. static struct tm *
  17. copy_tm_result (struct tm *dest, struct tm const *src)
  18. {
  19. if (! src)
  20. return 0;
  21. *dest = *src;
  22. return dest;
  23. }
  24. struct tm *
  25. gmtime_r (time_t const * restrict t, struct tm * restrict tp)
  26. {
  27. return copy_tm_result (tp, gmtime (t));
  28. }
  29. struct tm *
  30. localtime_r (time_t const * restrict t, struct tm * restrict tp)
  31. {
  32. return copy_tm_result (tp, localtime (t));
  33. }