diff options
| author | Martin Lewis <martin.lewis.x84@gmail.com> | 2019-09-15 18:13:28 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-09 14:35:55 +0200 |
| commit | dd4686128290b34d61becaaba88c54d5213f7aa5 (patch) | |
| tree | 9faef97f6325c369246524a31d1e331a38bf7b6b /libbb | |
| parent | ad27d44ebe950335616f37e36863469dc181b455 (diff) | |
| download | busybox-w32-dd4686128290b34d61becaaba88c54d5213f7aa5.tar.gz busybox-w32-dd4686128290b34d61becaaba88c54d5213f7aa5.tar.bz2 busybox-w32-dd4686128290b34d61becaaba88c54d5213f7aa5.zip | |
libbb: Converted safe_read to safe_write format
Changed safe_read to be symmetrical to safe_write, it shall
never return EINTR because it calls read multiple times,
the error is considered transient.
function old new delta
safe_read 44 57 +13
Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/read.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libbb/read.c b/libbb/read.c index 5906bc225..a342506a8 100644 --- a/libbb/read.c +++ b/libbb/read.c | |||
| @@ -12,9 +12,17 @@ ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count) | |||
| 12 | { | 12 | { |
| 13 | ssize_t n; | 13 | ssize_t n; |
| 14 | 14 | ||
| 15 | do { | 15 | for (;;) { |
| 16 | n = read(fd, buf, count); | 16 | n = read(fd, buf, count); |
| 17 | } while (n < 0 && errno == EINTR); | 17 | if (n >= 0 || errno != EINTR) |
| 18 | break; | ||
| 19 | /* Some callers set errno=0, are upset when they see EINTR. | ||
| 20 | * Returning EINTR is wrong since we retry read(), | ||
| 21 | * the "error" was transient. | ||
| 22 | */ | ||
| 23 | errno = 0; | ||
| 24 | /* repeat the read() */ | ||
| 25 | } | ||
| 18 | 26 | ||
| 19 | return n; | 27 | return n; |
| 20 | } | 28 | } |
