1 /* vi: set sw=4 ts=4: */
2 /*
3  * Utility routines.
4  *
5  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8  */
9 #include "libbb.h"
10 
safe_write(int fd,const void * buf,size_t count)11 ssize_t FAST_FUNC safe_write(int fd, const void *buf, size_t count)
12 {
13 	ssize_t n;
14 
15 	for (;;) {
16 		n = write(fd, buf, count);
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 	}
26 
27 	return n;
28 }
29