diff options
author | van Hauser <vh@thc.org> | 2022-04-25 10:14:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-25 10:14:19 +0200 |
commit | c7bb0a9638a8929a5b664f16032c23a55a84be70 (patch) | |
tree | 2fb8cee9897c46a53e756e898de732c63f2a8842 /include/debug.h | |
parent | ac80678592ea4a790ab2eedccfec4e3bc9f96447 (diff) | |
parent | ee409d18a6678c3f5948f51db8964148cae021dc (diff) | |
download | afl++-c7bb0a9638a8929a5b664f16032c23a55a84be70.tar.gz |
Merge pull request #1392 from AFLplusplus/dev
push to stable
Diffstat (limited to 'include/debug.h')
-rw-r--r-- | include/debug.h | 47 |
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) \ |