time_r.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Reentrant time functions like localtime_r.
  2. Copyright (C) 2003, 2006, 2007 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. #include <string.h>
  18. static struct tm *
  19. copy_tm_result (struct tm *dest, struct tm const *src)
  20. {
  21. if (! src)
  22. return 0;
  23. *dest = *src;
  24. return dest;
  25. }
  26. struct tm *
  27. gmtime_r (time_t const * restrict t, struct tm * restrict tp)
  28. {
  29. return copy_tm_result (tp, gmtime (t));
  30. }
  31. struct tm *
  32. localtime_r (time_t const * restrict t, struct tm * restrict tp)
  33. {
  34. return copy_tm_result (tp, localtime (t));
  35. }