Eric Andersen | dae099b | 2003-10-09 08:35:42 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Utility routines. |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | dae099b | 2003-10-09 08:35:42 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | dae099b | 2003-10-09 08:35:42 +0000 | [diff] [blame] | 8 | */ |
Eric Andersen | dae099b | 2003-10-09 08:35:42 +0000 | [diff] [blame] | 9 | #include "libbb.h" |
| 10 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 11 | ssize_t FAST_FUNC safe_write(int fd, const void *buf, size_t count) |
Eric Andersen | dae099b | 2003-10-09 08:35:42 +0000 | [diff] [blame] | 12 | { |
| 13 | ssize_t n; |
| 14 | |
Denys Vlasenko | a03ac60 | 2017-07-14 14:22:09 +0200 | [diff] [blame] | 15 | for (;;) { |
Eric Andersen | dae099b | 2003-10-09 08:35:42 +0000 | [diff] [blame] | 16 | n = write(fd, buf, count); |
Denys Vlasenko | a03ac60 | 2017-07-14 14:22:09 +0200 | [diff] [blame] | 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 write(), |
| 21 | * the "error" was transient. |
| 22 | */ |
| 23 | errno = 0; |
| 24 | /* repeat the write() */ |
| 25 | } |
Eric Andersen | dae099b | 2003-10-09 08:35:42 +0000 | [diff] [blame] | 26 | |
| 27 | return n; |
| 28 | } |