Skip to content

Commit 8ea3b4c

Browse files
jhuber6tszhin-swe
authored andcommitted
[libc] Add stubs for 'strftime' function
Summary: This patch does not actually implement the function, but provides the interface. This partially resovles #106630 as it will allow us to build libc++ with locale support (so long as you don't use it).
1 parent 560e57a commit 8ea3b4c

File tree

8 files changed

+162
-1
lines changed

8 files changed

+162
-1
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ set(TARGET_LIBC_ENTRYPOINTS
256256
libc.src.time.clock
257257
libc.src.time.clock_gettime
258258
libc.src.time.nanosleep
259+
libc.src.time.strftime
260+
libc.src.time.strftime_l
259261

260262
# wchar.h entrypoints
261263
libc.src.wchar.wctob

libc/newhdrgen/yaml/time.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ types:
88
- type_name: time_t
99
- type_name: clock_t
1010
- type_name: size_t
11+
- type_name: locale_t
1112
enums: []
1213
objects: []
1314
functions:
@@ -96,3 +97,22 @@ functions:
9697
return_type: time_t
9798
arguments:
9899
- type: time_t *
100+
- name: strftime
101+
standard:
102+
- stdc
103+
return_type: size_t
104+
arguments:
105+
- type: char *__restrict
106+
- type: size_t
107+
- type: const char *__restrict
108+
- type: const struct tm *__restrict
109+
- name: strftime_l
110+
standard:
111+
- stdc
112+
return_type: size_t
113+
arguments:
114+
- type: char *__restrict
115+
- type: size_t
116+
- type: const char *__restrict
117+
- type: const struct tm *__restrict
118+
- type: locale_t

libc/spec/stdc.td

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,7 @@ def StdC : StandardSpec<"stdc"> {
15861586
StructTimeSpec,
15871587
TimeTType,
15881588
SizeTType,
1589+
LocaleT,
15891590
],
15901591
[], // Enumerations
15911592
[
@@ -1651,6 +1652,26 @@ def StdC : StandardSpec<"stdc"> {
16511652
RetValSpec<TimeTType>,
16521653
[ArgSpec<TimeTTypePtr>]
16531654
>,
1655+
FunctionSpec<
1656+
"strftime",
1657+
RetValSpec<SizeTType>,
1658+
[
1659+
ArgSpec<CharRestrictedPtr>,
1660+
ArgSpec<SizeTType>,
1661+
ArgSpec<ConstCharRestrictedPtr>,
1662+
ArgSpec<StructTmPtr>
1663+
]
1664+
FunctionSpec<
1665+
"strftime_l",
1666+
RetValSpec<SizeTType>,
1667+
[
1668+
ArgSpec<CharRestrictedPtr>,
1669+
ArgSpec<SizeTType>,
1670+
ArgSpec<ConstCharRestrictedPtr>,
1671+
ArgSpec<StructTmPtr>,
1672+
ArgSpec<LocaleT>
1673+
]
1674+
>,
16541675
]
16551676
>;
16561677

libc/src/time/CMakeLists.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,32 @@ add_entrypoint_object(
9999
HDRS
100100
mktime.h
101101
DEPENDS
102-
.time_utils
103102
libc.include.time
104103
libc.src.errno.errno
105104
)
106105

106+
107+
add_entrypoint_object(
108+
strftime
109+
SRCS
110+
strftime.cpp
111+
HDRS
112+
strftime.h
113+
DEPENDS
114+
libc.include.time
115+
)
116+
117+
add_entrypoint_object(
118+
strftime_l
119+
SRCS
120+
strftime_l.cpp
121+
HDRS
122+
strftime_l.h
123+
DEPENDS
124+
libc.include.time
125+
libc.include.locale
126+
)
127+
107128
add_entrypoint_object(
108129
time
109130
ALIAS

libc/src/time/strftime.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Implementation of strftime 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/strftime.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
#include "src/errno/libc_errno.h"
13+
#include "src/time/time_utils.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
using LIBC_NAMESPACE::time_utils::TimeConstants;
18+
19+
LLVM_LIBC_FUNCTION(size_t, strftime,
20+
(char *__restrict, size_t, const char *__restrict,
21+
const struct tm *)) {
22+
// TODO: Implement this for the default locale.
23+
return -1;
24+
}
25+
26+
} // namespace LIBC_NAMESPACE_DECL

libc/src/time/strftime.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Implementation header of strftime -----------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_TIME_STRFTIME_H
10+
#define LLVM_LIBC_SRC_TIME_STRFTIME_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include <stddef.h>
14+
#include <time.h>
15+
16+
namespace LIBC_NAMESPACE_DECL {
17+
18+
size_t strftime(char *__restrict, size_t max, const char *__restrict format,
19+
const struct tm *timeptr);
20+
21+
} // namespace LIBC_NAMESPACE_DECL
22+
23+
#endif // LLVM_LIBC_SRC_TIME_STRFTIME_H

libc/src/time/strftime_l.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Implementation of strftime_l 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/strftime_l.h"
10+
#include "src/__support/common.h"
11+
#include "src/__support/macros/config.h"
12+
#include "src/errno/libc_errno.h"
13+
#include "src/time/time_utils.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
LLVM_LIBC_FUNCTION(size_t, strftime_l,
18+
(char *__restrict, size_t, const char *__restrict,
19+
const struct tm *, locale_t)) {
20+
// TODO: Implement this for the default locale.
21+
return -1;
22+
}
23+
24+
} // namespace LIBC_NAMESPACE_DECL

libc/src/time/strftime_l.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Implementation header of strftime_l ---------------------*- C++ -*-===//
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+
#ifndef LLVM_LIBC_SRC_TIME_STRFTIME_L_H
10+
#define LLVM_LIBC_SRC_TIME_STRFTIME_L_H
11+
12+
#include "hdr/types/locale_t.h"
13+
#include "src/__support/macros/config.h"
14+
#include <stddef.h>
15+
#include <time.h>
16+
17+
namespace LIBC_NAMESPACE_DECL {
18+
19+
size_t strftime_l(char *__restrict, size_t max, const char *__restrict format,
20+
const struct tm *timeptr, locale_t locale);
21+
22+
} // namespace LIBC_NAMESPACE_DECL
23+
24+
#endif // LLVM_LIBC_SRC_TIME_STRFTIME_L_H

0 commit comments

Comments
 (0)