Skip to content

Commit 28fcfb3

Browse files
[arch] Handle partial writes for stackTrace.cpp
aswrite issues calls to write() which may perform a partial write. The change here checks the number of bytes written and writes any remaining data
1 parent 287357f commit 28fcfb3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pxr/base/arch/stackTrace.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272

7373
#if defined(ARCH_OS_WINDOWS)
7474
#define getpid() _getpid()
75-
#define write(fd_, data_, size_) _write(fd_, data_, size_)
7675
#define strdup(str_) _strdup(str_)
7776
#endif
7877

@@ -491,7 +490,23 @@ char* asitoa(char* s, long x)
491490
void aswrite(int fd, const char* msg)
492491
{
493492
int saved = errno;
494-
write(fd, msg, asstrlen(msg));
493+
size_t len = asstrlen(msg);
494+
size_t written = 0;
495+
while (written < len) {
496+
#if defined(ARCH_OS_WINDOWS)
497+
int n = _write(fd, msg + written, len - written);
498+
#else
499+
ssize_t n = write(fd, msg + written, len - written);
500+
#endif
501+
if (n < 0) {
502+
// retry if the write is interrupted by a signal.
503+
if (errno == EINTR)
504+
continue;
505+
// Fail on any other error.
506+
break;
507+
}
508+
written += n;
509+
}
495510
errno = saved;
496511
}
497512

0 commit comments

Comments
 (0)