time_r.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Reentrant time functions like localtime_r.
  2. Copyright (C) 2003, 2006-2007, 2010-2023 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along 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. }