[libc-commits] [libc] [libc] Add `ctime_s` (PR #110676)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Thu Jan 9 10:24:47 PST 2025
================
@@ -37,6 +37,14 @@ functions:
arguments:
- type: const time_t *
- type: char *
+ - name: ctime_s
+ standard:
+ - stdc
+ return_type: errno_t
+ arguments:
+ - type: char *
+ - type: rsize_t
+ - type: const time_t *
----------------
nickdesaulniers wrote:
Ok, so the last thing I think we should resolve before landing this is related to this problem, so "unresolving the conversation."
When you build llvm-libc in fullbuild mode, we generate `{build_dir}/build/libc/include/time.h`. It has:
```c
#ifdef __STDC_WANT_LIB_EXT1__
errno_t ctime_s(char *, rsize_t, const time_t *) __NOEXCEPT;
#endif // __STDC_WANT_LIB_EXT1__
```
Looks good, yeah? But one issue I think will be when someone does:
```c
#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
```
then they'll get some error that `errno_t` is undefined. So I think you'll need the manual inclusion of `errno.h` in libc/include/time.h.def. I guess we can make it conditional on `__STDC_WANT_LIB_EXT1__` as well.
```diff
diff --git a/libc/include/time.h.def b/libc/include/time.h.def
index 2355e8822fad..c745a4317504 100644
--- a/libc/include/time.h.def
+++ b/libc/include/time.h.def
@@ -12,6 +12,10 @@
#include "__llvm-libc-common.h"
#include "llvm-libc-macros/time-macros.h"
+#ifdef __STDC_WANT_LIB_EXT1__
+#include <errno.h> // errno_t
+#endif
+
%%public_api()
#endif // LLVM_LIBC_TIME_H
```
mind adding that to your PR?
https://github.com/llvm/llvm-project/pull/110676
More information about the libc-commits
mailing list