[llvm-branch-commits] [libc] [libc] Annex K: strcpy_s (PR #197709)
Jeff Bailey via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jul 2 04:04:01 PDT 2026
================
@@ -0,0 +1,75 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation of strcpy_s.
+///
+//===----------------------------------------------------------------------===//
+
+#define __STDC_WANT_LIB_EXT1__ 1
+#include "hdr/stdint_proxy.h"
+#undef __STDC_WANT_LIB_EXT1__
+#include "hdr/types/constraint_handler_t.h"
+#include "hdr/types/errno_t.h"
+#include "hdr/types/rsize_t.h"
+#include "src/__support/common.h"
+#include "src/__support/constraint_handler.h"
+#include "src/__support/macros/config.h"
+#include "src/string/memory_utils/inline_memcpy.h"
+#include "src/string/strcpy_s.h"
+#include "src/string/string_utils.h"
+#include "src/string/strnlen_s.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(errno_t, strcpy_s,
+ (char *__restrict s1, rsize_t s1max,
+ const char *__restrict s2)) {
+ const char *constraint_violation_msg = 0;
+ size_t count;
+
+ if (s1 == 0) {
+ constraint_violation_msg = "strcpy_s: s1 cannot be null";
+ } else if (s2 == 0) {
+ constraint_violation_msg = "strcpy_s: s2 cannot be null";
+ } else if (s1max > RSIZE_MAX) {
+ constraint_violation_msg = "strcpy_s: s1max cannot exceed RSIZE_MAX";
+ } else if (s1max == 0) {
+ constraint_violation_msg = "strcpy_s: s1max cannot be 0";
+ } else if (count = strnlen_s(s2, s1max);
----------------
kaladron wrote:
strnlen_s is a public entrypoint, we should use the internal function instead (unless there's a reason to)
https://github.com/llvm/llvm-project/pull/197709
More information about the llvm-branch-commits
mailing list