]> pd.if.org Git - pdclib/blobdiff - includes/stdio.h
* Test cleanups: surround the code for all functions by #ifndef REGTEST
[pdclib] / includes / stdio.h
index b9a02249a717be07a28dd09fffdd9dd8c667de10..12b7f0aea2aa1ea51a06f4b93c7d9556735f816c 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$ */
 
-/* Input/output <stdio.h>
+/* 7.19 Input/output <stdio.h>
 
    This file is part of the Public Domain C Library (PDCLib).
    Permission is granted to use, modify, and / or redistribute at will.
@@ -8,11 +8,8 @@
 
 #ifndef _PDCLIB_STDIO_H
 #define _PDCLIB_STDIO_H _PDCLIB_STDIO_H
-
-#ifndef _PDCLIB_INT_H
-#define _PDCLIB_INT_H _PDCLIB_INT_H
 #include <_PDCLIB_int.h>
-#endif
+_PDCLIB_BEGIN_EXTERN_C
 
 #ifndef _PDCLIB_SIZE_T_DEFINED
 #define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED
@@ -39,10 +36,28 @@ typedef struct _PDCLIB_file_t FILE;
 #define L_tmpnam _PDCLIB_L_tmpnam
 #define TMP_MAX _PDCLIB_TMP_MAX
 
-/* See fseek(), third argument */
-#define SEEK_CUR _PDCLIB_SEEK_CUR
-#define SEEK_END _PDCLIB_SEEK_END
-#define SEEK_SET _PDCLIB_SEEK_SET
+/* See fseek(), third argument 
+ *
+ * Some system headers (e.g. windows) also define the SEEK_* values. Check for
+ * this and validate that they're the same value
+ */
+#if !defined(SEEK_CUR)
+    #define SEEK_CUR _PDCLIB_SEEK_CUR
+#elif SEEK_CUR != _PDCLIB_SEEK_CUR
+    #error SEEK_CUR != _PDCLIB_SEEK_CUR
+#endif
+
+#if !defined(SEEK_END)
+    #define SEEK_END _PDCLIB_SEEK_END
+#elif SEEK_END != _PDCLIB_SEEK_END
+    #error SEEK_END != _PDCLIB_SEEK_END
+#endif
+
+#if !defined(SEEK_SET)
+    #define SEEK_SET _PDCLIB_SEEK_SET
+#elif SEEK_SET != _PDCLIB_SEEK_SET
+    #error SEEK_SET != _PDCLIB_SEEK_SET
+#endif
 
 extern FILE * stdin;
 extern FILE * stdout;
@@ -65,7 +80,7 @@ int remove( const char * filename );
    If there already is a file with the new filename, behaviour is defined by
    the glue code (see functions/_PDCLIB/rename.c).
 */
-int rename( const char * old, const char * new );
+int rename( const char * old, const char * newn );
 
 /* Open a temporary file with mode "wb+", i.e. binary-update. Remove the file
    automatically if it is closed or the program exits normally (by returning
@@ -158,6 +173,11 @@ int fflush( FILE * stream );
 */
 FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode );
 
+/* Creates a stream connected to the file descriptor \p fd with mode \p mode.
+   Mode must match the mode with which the file descriptor was opened.
+*/
+FILE * _PDCLIB_fdopen( _PDCLIB_fd_t fd, int mode, const char* filename );
+
 /* Close any file currently associated with the given stream. Open the file
    identified by the given filename with the given mode (equivalent to fopen()),
    and associate it with the given stream. If filename is a NULL pointer,
@@ -654,13 +674,13 @@ int fputc( int c, FILE * stream );
 */
 int fputs( const char * _PDCLIB_restrict s, FILE * _PDCLIB_restrict stream );
 
-/* Equivalent to fgetc( stream ), but may be implemented as a macro that
+/* Equivalent to fgetc( stream ), but may be overloaded by a macro that
    evaluates its parameter more than once.
 */
-#define getc( stream ) fgetc( stream )
+int getc( FILE * stream );
 
-/* Equivalent to fgetc( stdin ), but may be implemented as a macro. */
-#define getchar() fgetc( stdin )
+/* Equivalent to fgetc( stdin ). */
+int getchar( void );
 
 /* Read characters from given stream into the array s, stopping at \n or EOF.
    The string read is terminated with \0. Returns s if successful. If EOF is
@@ -670,15 +690,15 @@ int fputs( const char * _PDCLIB_restrict s, FILE * _PDCLIB_restrict stream );
 */
 char * gets( char * s );
 
-/* Equivalent to fputc( c, stream ), but may be implemented as a macro that
+/* Equivalent to fputc( c, stream ), but may be overloaded by a macro that
    evaluates its parameter more than once.
 */
-#define putc( c, stream ) fputc( c, stream )
+int putc( int c, FILE * stream );
 
-/* Equivalent to fputc( c, stdout ), but may be implemented as a macro that
+/* Equivalent to fputc( c, stdout ), but may be overloaded by a macro that
    evaluates its parameter more than once.
 */
-#define putchar( c ) putc( c, stdout )
+int putchar( int c );
 
 /* Write the string s (not including the terminating \0) to stdout, and append
    a newline to the output. Returns a value >= 0 when successful, EOF if a
@@ -796,4 +816,5 @@ int ferror( FILE * stream );
 */
 void perror( const char * s );
 
+_PDCLIB_END_EXTERN_C
 #endif