]> pd.if.org Git - pdclib/blobdiff - functions/stdio/fputs.c
Intermediate stdio work.
[pdclib] / functions / stdio / fputs.c
index 748fa5aff414ed8436951c48afed57e52f9cb36b..94af1ad6a9154dd88b36a4bbbdf7bb75f90c8975 100644 (file)
@@ -16,16 +16,21 @@ int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_rest
        constraints honored?)
     */
     /* FIXME: Proper buffering handling. */
+    char written;
     while ( stream->bufidx < stream->bufsize )
     {
-        if ( ( stream->buffer[stream->bufidx++] = *(s++) ) == '\0' )
+        written = ( stream->buffer[stream->bufidx++] = *(s++) );
+        if ( ( written == '\0' ) ||
+             ( ( stream->status & _IOLBF ) && ( written == '\n' ) ) ||
+             ( stream->status & _IONBF ) )
         {
             break;
         }
     }
     fflush( stream );
-    if ( *(s-1) != '\0' )
+    if ( written != '\0' )
     {
+        /* FIXME: For _IONBF, this recurses once per character - unacceptable. */
         return fputs( s, stream );
     }
     else