[libc-commits] [libc] [libc] improve error handling and compiler hints (PR #109026)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Sep 17 13:52:19 PDT 2024
================
@@ -9,17 +9,72 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_IO_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_IO_H
+#include "hdr/errno_macros.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/macros/config.h"
-#include "syscall.h" // For internal syscall function.
-
+#include "syscall.h" // For internal syscall function.
#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
- LIBC_NAMESPACE::syscall_impl<long>(SYS_write, 2 /* stderr */, msg.data(),
- msg.size());
+ size_t written = 0;
+ const char *msg_data = msg.data();
+ while (written != msg.size()) {
+ auto delta = LIBC_NAMESPACE::syscall_impl<long>(SYS_write, 2 /* stderr */,
+ msg_data, msg.size());
+ // If the write syscall was interrupted, try again. Otherwise, this is an
+ // error routine, we do not handle further errors.
+ if (delta == -EINTR)
+ continue;
+ if (delta < 0)
+ return;
+ written += delta;
+ msg_data += delta;
+ }
+}
+
+template <size_t N>
+LIBC_INLINE void write_all_to_stderr(const cpp::string_view (&msgs)[N]) {
----------------
michaelrj-google wrote:
I think we should consider this design carefully. If we add this function, then it needs to be added for every platform we support.
https://github.com/llvm/llvm-project/pull/109026
More information about the libc-commits
mailing list