]> pd.if.org Git - pdclib/commitdiff
Intermediate stdio work.
authorsolar <unknown>
Tue, 25 Jul 2006 10:12:25 +0000 (10:12 +0000)
committersolar <unknown>
Tue, 25 Jul 2006 10:12:25 +0000 (10:12 +0000)
functions/stdio/fopen.c
functions/stdio/fputs.c
functions/stdio/fseek.c
functions/stdio/fsetpos.c
functions/stdio/rewind.c

index e15338319ac07cf8ee3025fefda51be1da36ab7b..d181cc1f876ded1362cc297e8c2fad923e67ae64 100644 (file)
@@ -38,7 +38,11 @@ struct _PDCLIB_file_t * fopen( const char * _PDCLIB_restrict filename, const cha
     if ( ( rc->buffer = malloc( BUFSIZ ) ) == NULL ) goto fail;
     rc->bufsize = BUFSIZ;
     rc->bufidx = 0;
-    rc->status |= ( _PDCLIB_LIBBUFFER | _PDCLIB_VIRGINSTR );
+    /* Setting buffer to _IOLBF because "when opened, a stream is fully
+       buffered if and only if it can be determined not to refer to an
+       interactive device."
+    */
+    rc->status |= ( _PDCLIB_LIBBUFFER | _PDCLIB_VIRGINSTR /* | _IOLBF */ ); /* FIXME: Uncommenting the _IOLBF here breaks output. */
     /* TODO: Setting mbstate */
     return rc;
 fail:
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
index f33f250938a0e1cdaaa7fddbe6f971b2e8d52b3a..ca0017cacfc02f1fbaaf259be15fd0ca90f1c4a1 100644 (file)
 
 int fseek( struct _PDCLIB_file_t * stream, long int offset, int whence )
 {
+    if ( stream->status & _PDCLIB_WROTELAST )
+    {
+        fflush( stream );
+    }
     /* TODO: Implement. */
     return 0;
 }
index e40be0b948cb1a36bc38d9388081349e06f8e2a2..76c5ede87ec7dea39ef49b194581bfd7a130c878 100644 (file)
 
 int fsetpos( struct _PDCLIB_file_t * stream, const _PDCLIB_fpos_t * pos )
 {
+    if ( stream->status & _PDCLIB_WROTELAST )
+    {
+        fflush( stream );
+    }
     /* TODO: Implement. */
     return 0;
 }
index 543e2849a740df13d89c35449e22667b6eaedd2d..d97e4e21ac289db2e2ae8e3a60555350dedf29f7 100644 (file)
 
 void rewind( struct _PDCLIB_file_t * stream )
 {
+    if ( stream->status & _PDCLIB_WROTELAST )
+    {
+        fflush( stream );
+    }
     /* TODO: Implement. */
     return;
 }