149151Sbostic /*- 2*63370Sbostic * Copyright (c) 1982, 1988, 1993 3*63370Sbostic * The Regents of the University of California. All rights reserved. 449151Sbostic * 549151Sbostic * %sccs.include.proprietary.c% 649151Sbostic * 7*63370Sbostic * @(#)write.c 8.1 (Berkeley) 06/11/93 849151Sbostic */ 949151Sbostic 1049151Sbostic #include <sys/param.h> 1149151Sbostic 1260328Smckusick #include <stand.att/saio.h> 1356509Sbostic 1449151Sbostic #ifndef SMALL write(fdesc,buf,count)1549151Sbosticwrite(fdesc, buf, count) 1649151Sbostic int fdesc, count; 1749151Sbostic char *buf; 1849151Sbostic { 1949151Sbostic register i; 2049151Sbostic register struct iob *file; 2149151Sbostic 2249151Sbostic errno = 0; 2349151Sbostic if (fdesc >= 0 && fdesc <= 2) { 2449151Sbostic i = count; 2549151Sbostic while (i--) 2649151Sbostic putchar(*buf++); 2749151Sbostic return (count); 2849151Sbostic } 2949151Sbostic fdesc -= 3; 3049151Sbostic if (fdesc < 0 || fdesc >= SOPEN_MAX || 3149151Sbostic ((file = &iob[fdesc])->i_flgs&F_ALLOC) == 0) { 3249151Sbostic errno = EBADF; 3349151Sbostic return (-1); 3449151Sbostic } 3549151Sbostic if ((file->i_flgs&F_WRITE) == 0) { 3649151Sbostic errno = EBADF; 3749151Sbostic return (-1); 3849151Sbostic } 3949151Sbostic file->i_cc = count; 4049151Sbostic file->i_ma = buf; 4149151Sbostic file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE); 4249151Sbostic i = devwrite(file); 4349151Sbostic file->i_offset += count; 4449151Sbostic if (i < 0) 4549151Sbostic errno = file->i_error; 4649151Sbostic return (i); 4749151Sbostic } 4849151Sbostic #endif 49