aboutsummaryrefslogtreecommitdiff
path: root/include/debug.h
diff options
context:
space:
mode:
authorlazymio <mio@lazym.io>2022-04-24 20:13:40 +0200
committerlazymio <mio@lazym.io>2022-04-24 20:13:40 +0200
commitee50f41d29ea67282e7bd2a2fc495c6e09922916 (patch)
tree346a5bd5066ee472cb329fe628eda0f53d83b20e /include/debug.h
parentaeeca164b5a01eebc9c7cb386155375980e1fdc2 (diff)
parentb2c96f66eef42a58d2b62f98a5cec6f5f483dbde (diff)
downloadafl++-ee50f41d29ea67282e7bd2a2fc495c6e09922916.tar.gz
Merge origin/dev
Diffstat (limited to 'include/debug.h')
-rw-r--r--include/debug.h47
1 files changed, 33 insertions, 14 deletions
diff --git a/include/debug.h b/include/debug.h
index 31ebd0f2..e2ee16a8 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -355,20 +355,39 @@ static inline const char *colorfilter(const char *x) {
/* Error-checking versions of read() and write() that call RPFATAL() as
appropriate. */
-#define ck_write(fd, buf, len, fn) \
- do { \
- \
- int _fd = (fd); \
- \
- s32 _len = (s32)(len); \
- s32 _res = write(_fd, (buf), _len); \
- if (_res != _len) { \
- \
- RPFATAL(_res, "Short write to %s, fd %d (%d of %d bytes)", fn, _fd, \
- _res, _len); \
- \
- } \
- \
+#define ck_write(fd, buf, len, fn) \
+ do { \
+ \
+ if (len <= 0) break; \
+ int _fd = (fd); \
+ s32 _written = 0, _off = 0, _len = (s32)(len); \
+ \
+ do { \
+ \
+ s32 _res = write(_fd, (buf) + _off, _len); \
+ if (_res != _len && (_res > 0 && _written + _res != _len)) { \
+ \
+ if (_res > 0) { \
+ \
+ _written += _res; \
+ _len -= _res; \
+ _off += _res; \
+ \
+ } else { \
+ \
+ RPFATAL(_res, "Short write to %s, fd %d (%d of %d bytes)", fn, _fd, \
+ _res, _len); \
+ \
+ } \
+ \
+ } else { \
+ \
+ break; \
+ \
+ } \
+ \
+ } while (1); \
+ \
} while (0)
#define ck_read(fd, buf, len, fn) \