32 lines · cpp
1//===-- Implementation of mktime 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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/time/mktime.h"10#include "src/__support/common.h"11#include "src/__support/macros/config.h"12#include "src/time/time_constants.h"13#include "src/time/time_utils.h"14 15namespace LIBC_NAMESPACE_DECL {16 17LLVM_LIBC_FUNCTION(time_t, mktime, (struct tm * tm_out)) {18 auto mktime_result = time_utils::mktime_internal(tm_out);19 if (!mktime_result)20 return time_utils::out_of_range();21 22 time_t seconds = *mktime_result;23 24 // Update the tm structure's year, month, day, etc. from seconds.25 if (time_utils::update_from_seconds(seconds, tm_out) < 0)26 return time_utils::out_of_range();27 28 return seconds;29}30 31} // namespace LIBC_NAMESPACE_DECL32