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.1 (Berkeley) 05/05/91 8 */ 9 10 #include <sys/param.h> 11 #include "saio.h" 12 13 #ifndef SMALL 14 write(fdesc, buf, count) 15 int fdesc, count; 16 char *buf; 17 { 18 register i; 19 register struct iob *file; 20 21 errno = 0; 22 if (fdesc >= 0 && fdesc <= 2) { 23 i = count; 24 while (i--) 25 putchar(*buf++); 26 return (count); 27 } 28 fdesc -= 3; 29 if (fdesc < 0 || fdesc >= SOPEN_MAX || 30 ((file = &iob[fdesc])->i_flgs&F_ALLOC) == 0) { 31 errno = EBADF; 32 return (-1); 33 } 34 if ((file->i_flgs&F_WRITE) == 0) { 35 errno = EBADF; 36 return (-1); 37 } 38 file->i_cc = count; 39 file->i_ma = buf; 40 file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE); 41 i = devwrite(file); 42 file->i_offset += count; 43 if (i < 0) 44 errno = file->i_error; 45 return (i); 46 } 47 #endif 48