1 //===-- Implementation of gmtime function ---------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/time/gmtime.h"
10 #include "src/__support/common.h"
11 #include "src/time/time_utils.h"
12 
13 #include <limits.h>
14 
15 namespace __llvm_libc {
16 
17 LLVM_LIBC_FUNCTION(struct tm *, gmtime, (const time_t *timer)) {
18   static struct tm tm_out;
19   time_t seconds = *timer;
20   // Update the tm structure's year, month, day, etc. from seconds.
21   if (time_utils::UpdateFromSeconds(seconds, &tm_out) < 0) {
22     time_utils::OutOfRange();
23     return nullptr;
24   }
25 
26   return &tm_out;
27 }
28 
29 } // namespace __llvm_libc
30