File: writen.c

package info (click to toggle)
echoping 6.0.2-10
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 9,296 kB
  • ctags: 515
  • sloc: sh: 8,951; ansic: 3,352; makefile: 170
file content (32 lines) | stat: -rw-r--r-- 745 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Write "n" bytes to a descriptor. Use in place of write() when fd is a
 * stream socket. 
 */

/* Stolen from Stevens' book */

#include "echoping.h"

int
writen(fd, ptr, nbytes)
	register int    fd;
	register char  *ptr;
	register int    nbytes;
{
	int             nleft, nwritten;

	nleft = nbytes;
	while (nleft > 0) {
		nwritten = write(fd, ptr, nleft);
		if (nwritten <= 0)
			return (nwritten);	/* error */
		/* Some systems, such as Digital's OSF1 (Digital Unix) doesn't set
		 * the returned value to -1, even when interrupted by an alarm,
		 * whatever says the documentation. errno is not set. */
		if ((nwritten < nleft) && timeout_flag)
			return nwritten;
		nleft -= nwritten;
		ptr += nwritten;
	}
	return (nbytes - nleft);
}