summaryrefslogtreecommitdiff
path: root/absl/base/internal
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-06-29 14:20:23 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-06-29 14:21:05 -0700
commitd9a01008ab5bd8b5845b4f3074b3bdb453373736 (patch)
treed2a208e732b91363b8fcd6678fe9fb03ff0027bf /absl/base/internal
parenta3020c763c12bd16bbf00804abe853afa5778174 (diff)
Use new emscripten_errn to avoid copying strings.
PiperOrigin-RevId: 544461113 Change-Id: Iafbd6daf2d03ae18a49ea449315ee7cd6a0e615e
Diffstat (limited to 'absl/base/internal')
-rw-r--r--absl/base/internal/raw_logging.cc26
1 files changed, 15 insertions, 11 deletions
diff --git a/absl/base/internal/raw_logging.cc b/absl/base/internal/raw_logging.cc
index c866d957..1904026f 100644
--- a/absl/base/internal/raw_logging.cc
+++ b/absl/base/internal/raw_logging.cc
@@ -206,27 +206,31 @@ void DefaultInternalLog(absl::LogSeverity severity, const char* file, int line,
} // namespace
void AsyncSignalSafeWriteError(const char* s, size_t len) {
+ if (!len) return;
absl::base_internal::ErrnoSaver errno_saver;
#if defined(__EMSCRIPTEN__)
// In WebAssembly, bypass filesystem emulation via fwrite.
- // TODO(b/282811932): Avoid this copy if these emscripten functions can
- // be updated to accept size directly.
+ if (s[len - 1] == '\n') {
+ // Skip a trailing newline character as emscripten_errn adds one itself.
+ len--;
+ }
+ // emscripten_errn introduced in emscripten 3.1.41
+#if ABSL_INTERNAL_EMSCRIPTEN_VERSION >= 3001041
+ emscripten_errn(s, len);
+#else
char buf[kLogBufSize];
if (len >= kLogBufSize) {
len = kLogBufSize - 1;
- size_t trunc_len = sizeof(kTruncated) - 2;
- strncpy(buf + len - trunc_len, kTruncated, trunc_len);
+ constexpr size_t trunc_len = sizeof(kTruncated) - 2;
+ memcpy(buf + len - trunc_len, kTruncated, trunc_len);
buf[len] = '\0';
len -= trunc_len;
- } else if (len && s[len - 1] == '\n') {
- len--;
- }
- strncpy(buf, s, len);
- if (len) {
+ } else {
buf[len] = '\0';
- // Skip a trailing newline character as emscripten_err adds one itself.
- _emscripten_err(buf);
}
+ memcpy(buf, s, len);
+ _emscripten_err(buf);
+#endif
#elif defined(ABSL_HAVE_SYSCALL_WRITE)
// We prefer calling write via `syscall` to minimize the risk of libc doing
// something "helpful".