* Copyright (c) 1985 Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
.asciz "@(#)fputs.s 5.7 (Berkeley) %G%"
#endif /* LIBC_SCCS and not lint */
* arguments: a source string and a file pointer.
* side effects: writes to the file indicated by iop using the data in
* the null-terminated source string.
* result: technically void; for compatibility we return 0 for the null
* string, non-zero otherwise. We return zero for errors too.
* For compatibility (sigh).
* For unbuffered I/O, line buffer the output line.
* Ugly but fast -- and doesn't CURRENTLY break anything (sigh).
bicw3 $~NBF,_FLAG(IOP),UNBUF
bicw2 $NBF,_FLAG(IOP) /* Clear no-buffering flag */
movl sp,_BASE(IOP) /* Create a buffer */
tstl _CNT(IOP) /* Has a buffer been allocated? */
pushl IOP /* Get _flsbuf() to do the work */
incl _CNT(IOP) /* Unput the char we sent */
* Search for the terminating null.
* We only need to look at _BUFSIZ bytes or less on each pass.
addl3 _BASE(IOP),_BUFSIZ(IOP),COUNT /* How many bytes? */
locc $0,COUNT,(S) /* Look for a null */
subl2 r0,COUNT /* Copy the data */
movc3 COUNT,(S),*_PTR(IOP)
movl r3,_PTR(IOP) /* Fix up IOP */
bitw $LBF,_FLAG(IOP) /* If line buffered... */
tstw UNBUF /* or unbuffered... */
tstl _CNT(IOP) /* or a full buffer... */
pushl IOP /* ... flush the buffer */
* Fix up buffering again.
bisw2 $NBF,_FLAG(IOP) /* Reset flag */
clrl _BASE(IOP) /* Clear data structure */
cvtbl $NL,r0 /* Compatibility hack */
* We didn't find the null -- loop.
movc3 COUNT,(S),*_PTR(IOP) /* Copy the data */
movl r3,_PTR(IOP) /* Fix up IOP */
pushl IOP /* The buffer is full -- flush it */
tstb (S) /* More data? */
* Bomb out. Return 0 (why not? that's what the old one did).