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