]> pd.if.org Git - pdclib/commitdiff
restrict keyword cleanup.
authorsolar <unknown>
Mon, 26 Oct 2009 22:27:59 +0000 (22:27 +0000)
committersolar <unknown>
Mon, 26 Oct 2009 22:27:59 +0000 (22:27 +0000)
functions/stdio/fgets.c
functions/stdio/fputs.c
functions/stdio/freopen.c
functions/stdio/fscanf.c
functions/stdio/fseek.c
functions/stdio/ungetc.c
functions/stdio/vsnprintf.c
functions/stdio/vsprintf.c

index a82818ad23542f9eaef5a14abc1883913b1024a5..f763e3333f18f5bc222044a19a02b330d4c4c3fb 100644 (file)
@@ -13,7 +13,7 @@
 #define _PDCLIB_GLUE_H _PDCLIB_GLUE_H
 #include <_PDCLIB_glue.h>
 
-char * fgets( char * s, int size, struct _PDCLIB_file_t * stream )
+char * fgets( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
     if ( size <= 1 )
     {
index 7a62d03de2ff5178b624c68b5fc0c381c407309a..3dfe2d3a0781b6dfb52371d453311035c7cbf0bb 100644 (file)
@@ -11,7 +11,7 @@
 #ifndef REGTEST
 #include <_PDCLIB_glue.h>
 
-int fputs( const char * s, struct _PDCLIB_file_t * stream )
+int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
     if ( _PDCLIB_prepwrite( stream ) == EOF )
     {
index e8cc72a1f2924cba8e56c8acc5947ff2525ed7bf..906096f4a5cfbc57e6ab28770b9e2bc7dfd67f3c 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$ */
 
-/* freopen( const char *, const char * )
+/* freopen( const char *, const char *, FILE * )
 
    This file is part of the Public Domain C Library (PDCLib).
    Permission is granted to use, modify, and / or redistribute at will.
@@ -21,7 +21,7 @@
    (Primary use of this function is to redirect stdin, stdout, and stderr.)
 */
 
-struct _PDCLIB_file_t * freopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, struct _PDCLIB_file_t * stream )
+struct _PDCLIB_file_t * freopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
 {
     /* FIXME: This is ad-hoc (to make the vprintf() testdriver work), and must be checked. */
     /* FIXME: If filename is NULL, change mode. */
index 6ea4866452bebfa70c0b7c8aa13768257edbfbc5..17b0dca4c9add00de4e45f667628696d137f3c5e 100644 (file)
@@ -26,27 +26,55 @@ int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format
 #ifdef TEST
 #include <_PDCLIB_test.h>
 
-#include <limits.h>
 #include <string.h>
 
-int main( void )
+char scanstring[] = "  1 23\00045\000\00067 ";
+
+void scantest( int testnr, FILE * fh, size_t position, char const * format, 
+               int expected_fscan_rc, char const * expected_fscan_output, size_t expected_fscan_length, 
+               int expected_sscan_rc, char const * expected_sscan_output, size_t expected_sscan_length )
 {
-    char teststring1[] = "  1 23\045\0\067 ";
     char buffer[15];
+    printf( "Test %d\n", testnr );
+    TESTCASE( memset( buffer, -1, 15 ) == buffer );
+    TESTCASE( fseek( fh, position, SEEK_SET ) == 0 );
+    TESTCASE( fscanf( fh, format, buffer ) == expected_fscan_rc );
+    TESTCASE( memcmp( buffer, expected_fscan_output, expected_fscan_length ) == 0 );
+    TESTCASE( memset( buffer, -1, 15 ) == buffer );
+    TESTCASE( sscanf( scanstring + position, format, buffer ) == expected_sscan_rc );
+    TESTCASE( memcmp( buffer, expected_sscan_output, expected_sscan_length ) == 0 );
+}
+
+int main( void )
+{
     FILE * fh;
     TESTCASE( ( fh = fopen( "testfile", "w+" ) ) != NULL );
-    TESTCASE( fwrite( teststring1, 15, 1, fh ) == 1 );
+    TESTCASE( fwrite( scanstring, 14, 1, fh ) == 1 );
     rewind( fh );
-    /* */
-    TESTCASE( memset( buffer, CHAR_MAX, 15 ) == buffer ); \
-    TESTCASE( fseek( fh, 0, SEEK_SET ) == 0 ); \
-    TESTCASE( fscanf( fh, "%14c", buffer ) == 1 ); \
-    TESTCASE( memcmp( buffer, teststring1 + 0, 14 ) == 0 ); \
-    TESTCASE( buffer[ 14 ] == CHAR_MAX ); \
-    TESTCASE( memset( buffer, CHAR_MAX, 15 ) == buffer ); \
-    TESTCASE( sscanf( teststring1 + 14, "%14c", buffer ) ); \
-    TESTCASE( memcmp( buffer, teststring1 + 0, 14 ) == 0 ); \
-    TESTCASE( buffer[ 14 ] == CHAR_MAX );
+
+    /* %14c - full scan */
+    scantest( 1, fh, 0, "%14c",
+              1, "  1 23\00045\000\00067 \377", 15,
+              1, "  1 23\377", 7 );
+
+    /* %c - default to one, reading whitespace */
+    scantest( 2, fh, 0, "%c",
+              1, " \377", 2,
+              1, " \377", 2 );
+
+    /* %1c - reading zero byte */
+    scantest( 3, fh, 9, "%1c",
+              1, "\000\377", 2,
+              -1, "\377", 1 );
+
+    /* %0c - NOT reading EOF */
+    scantest( 4, fh, 13, "%0c",
+              0, "\377", 1,
+              0, "\377", 1 );
+              
+    TESTCASE( fclose( fh ) == 0 );
+    //TESTCASE( remove( "testfile" ) == 0 );
+
     return TEST_RESULTS;
 }
 
index 43789c8a71b6cca2cf43ffab38ccd22260bc0c26..9a945477445c4642291748ba17cd86cd97fe4855 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <_PDCLIB_glue.h>
 
-int fseek( struct _PDCLIB_file_t * _PDCLIB_restrict stream, long offset, int whence )
+int fseek( struct _PDCLIB_file_t * stream, long offset, int whence )
 {
     if ( stream->status & _PDCLIB_FWRITE )
     {
index f85ca9ce96344f423a096807ce6a42cbafc22acc..001735b533c04361648b2c3eb5475cdced99faac 100644 (file)
@@ -10,7 +10,7 @@
 
 #ifndef REGTEST
 
-int ungetc( int c, struct _PDCLIB_file_t * _PDCLIB_restrict stream )
+int ungetc( int c, struct _PDCLIB_file_t * stream )
 {
     if ( c == EOF || stream->ungetidx == _PDCLIB_UNGETCBUFSIZE )
     {
index 9c9ab591f0993c2f5e78a2278fc8e283e56c9427..21e76b1439e4e65ab29c5f194e1a75927792abd1 100644 (file)
@@ -11,7 +11,7 @@
 
 #ifndef REGTEST
 
-int vsnprintf( char * s, size_t n, const char * format, _PDCLIB_va_list arg )
+int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg )
 {
     /* TODO: This function should interpret format as multibyte characters.  */
     /* Members: base, flags, n, i, this, s, width, prec, stream, arg         */
index 308b71051456e751b2211cb05b614946932b8a70..9f6cdd2a7d1a33f51336242209009baa43b00298 100644 (file)
@@ -12,9 +12,9 @@
 
 #ifndef REGTEST
 
-int vsprintf( char * str, const char * format, va_list arg )
+int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, va_list arg )
 {
-    return vsnprintf( str, SIZE_MAX, format, arg ); /* TODO: Replace with a non-checking call */
+    return vsnprintf( s, SIZE_MAX, format, arg ); /* TODO: Replace with a non-checking call */
 }
 
 #endif