xref: /original-bsd/sys/stand.att/write.c (revision 4092c5cc)
1 /*-
2  * Copyright (c) 1982, 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  *
7  *	@(#)write.c	7.3 (Berkeley) 05/24/93
8  */
9 
10 #include <sys/param.h>
11 
12 #include <stand.att/saio.h>
13 
14 #ifndef SMALL
15 write(fdesc, buf, count)
16 	int fdesc, count;
17 	char *buf;
18 {
19 	register i;
20 	register struct iob *file;
21 
22 	errno = 0;
23 	if (fdesc >= 0 && fdesc <= 2) {
24 		i = count;
25 		while (i--)
26 			putchar(*buf++);
27 		return (count);
28 	}
29 	fdesc -= 3;
30 	if (fdesc < 0 || fdesc >= SOPEN_MAX ||
31 	    ((file = &iob[fdesc])->i_flgs&F_ALLOC) == 0) {
32 		errno = EBADF;
33 		return (-1);
34 	}
35 	if ((file->i_flgs&F_WRITE) == 0) {
36 		errno = EBADF;
37 		return (-1);
38 	}
39 	file->i_cc = count;
40 	file->i_ma = buf;
41 	file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE);
42 	i = devwrite(file);
43 	file->i_offset += count;
44 	if (i < 0)
45 		errno = file->i_error;
46 	return (i);
47 }
48 #endif
49