/* See setvbuf(), third argument */
/* Fully buffered - transmit block-wise */
-#define _IOFBF 1
+#define _IOFBF 2
/* Line buffered - transmit line-wise */
-#define _IOLBF 2
+#define _IOLBF 1
/* Not buffered - transmit immediately */
-#define _IONBF 4
+#define _IONBF 0
-/* See setbuf(). Minimum 256. */
-#define BUFSIZ 1024
-
-/* Internal-only flags for representing mode */
-#define _PDCLIB_FREAD 1
-#define _PDCLIB_FWRITE 2
-#define _PDCLIB_FAPPEND 4
-#define _PDCLIB_FRW 8
-#define _PDCLIB_FBIN 16
-
-typedef struct _PDCLIB_file_t FILE;
+/* The following are platform-dependant, and defined in _PDCLIB_config.h. */
typedef _PDCLIB_fpos_t fpos_t;
-
-/* Must be integer and of negative value */
+typedef struct _PDCLIB_file_t FILE;
#define EOF -1
-
-/* Maximum number of files this implementation can open simultaneously. Minimum 8. */
-#define FOPEN_MAX 1
-
-/* Maximum file name length (plus terminating \0) this implementation does
- guarantee can be opened. If there is no limit on the length of filenames,
- this should be a recommended size for filename buffers.
-*/
-#define FILENAME_MAX 1024
-
-/* Buffer size for tmpnam() */
-#define L_tmpnam 1024
-
-/* Number of distinct file names that can be generated by tmpnam(). */
-#define TMP_MAX 50
+#define BUFSIZ _PDCLIB_BUFSIZ
+#define FOPEN_MAX _PDCLIB_FOPEN_MAX
+#define FILENAME_MAX _PDCLIB_FILENAME_MAX
+#define L_tmpnam _PDCLIB_L_tmpnam
+#define TMP_MAX _PDCLIB_TMP_MAX
/* See fseek(), third argument */
#define SEEK_CUR 1
#define SEEK_END 2
#define SEEK_SET 4
-typedef struct
-{
- _PDCLIB_fd_t handle; /* OS-specific file descriptor */
- _PDCLIB_fpos_t position; /* file position indicator */
- void * buffer; /* file buffer */
- size_t bufsize; /* size of buffer */
- int status; /* misc. status bits */
- /*mbstate_t mbstate;*//* multibyte parse state */ /* TODO: Unmask. */
- FILE * next; /* provisions for linked list handling */
-} FILE;
-
/* Text-mode I/O is at liberty to skip non-printing characters and trailing spaces.
Binary I/O is at liberty to add trailing zero bytes.
First operation decides "orientation" of the stream (wide / byte).
*/
/* Operations on files */
+
+/* Remove the given file. Returns zero if successful, non-zero otherwise. If
+ the file is open, this implementation does flush its buffer and closes the
+ file before removing it. (It might be still accessible by another hard link
+ etc.
+*/
int remove( const char * filename );
+
+/* Rename the given old file to the given new name. Returns zero if successful,
+ non-zero otherwise. If successful, the file can no longer be accessed under
+ its old name. If the file is open, this implementation does flush its buffer
+ and closes the file before renaming it.
+*/
int rename( const char * old, const char * new );
-FILE * tmpfile( void ); /* TODO: Implement. */
-char * tmpnam( char * s ); /* TODO: Implement. */
+
+/* Opens a temporary file with mode "wb+", i.e. binary, update. The file will
+ be removed when it is closed or the process exits normally. Returns a pointer
+ to a FILE handle for this file. This implementation does not remove temporary
+ files if the process aborts abnormally (e.g. abort()).
+*/
+FILE * tmpfile( void );
+
+/* Generates a file name that is not equal to any existing filename AT THE TIME
+ OF GENERATION. It generates a different name each time it is called. If s is
+ a NULL pointer, the name is stored in an internal static array, and a pointer
+ to that array is returned. (This is not thread-safe!) If s is not a NULL
+ pointer, it is assumed to point to an array of at least L_tmpnam characters.
+ The generated name is then stored in s, and s is returned. If tmpnam() is
+ unable to generate a suitable name (because all possible variations do exist
+ already or the function has been called TMP_MAX times already), NULL is
+ returned.
+ Note that this implementation cannot guarantee a file of this name is not
+ generated between the call to tmpnam() and a subsequent fopen().
+*/
+char * tmpnam( char * s );
/* File access functions */
int fclose( FILE * stream );
#define _PDCLIB_INTMAX_C( value ) concat( value, _PDCLIB_INTMAX_LITERAL )
#define _PDCLIB_UINTMAX_C( value ) concat( value, concat( u, _PDCLIB_INTMAX_LITERAL ) )
+/* -------------------------------------------------------------------------- */
+/* Various <stdio.h> internals */
+/* -------------------------------------------------------------------------- */
+
+/* Flags for representing mode (see fopen()). */
+#define _PDCLIB_FREAD 1
+#define _PDCLIB_FWRITE 2
+#define _PDCLIB_FAPPEND 4
+#define _PDCLIB_FRW 8
+#define _PDCLIB_FBIN 16
+
+struct
+{
+ _PDCLIB_fd_t handle; /* OS-specific file descriptor */
+ _PDCLIB_fpos_t position; /* file position indicator */
+ void * buffer; /* file buffer */
+ size_t bufsize; /* size of buffer */
+ int status; /* misc. status bits */
+ /*mbstate_t mbstate;*//* multibyte parse state */ /* TODO: Unmask. */
+ FILE * next; /* provisions for linked list handling */
+} _PDCLIB_file_t;
+
/* -------------------------------------------------------------------------- */
/* Declaration of helper functions (implemented in functions/_PDCLIB). */
/* -------------------------------------------------------------------------- */
/* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */
/* -------------------------------------------------------------------------- */
-/* Memory management */
+/* Memory management -------------------------------------------------------- */
/* Set this to the page size of your OS. If your OS does not support paging, set
to an appropriate value. (Too small, and malloc() will call the kernel too
*/
#define _PDCLIB_MINALLOC 8
-/* I/O */
+/* I/O ---------------------------------------------------------------------- */
/* The unique file descriptor returned by _PDCLIB_open(). */
typedef int _PDCLIB_fd_t;
int parse_state;
} _PDCLIB_fpos_t;
-/* The mode flags used in calls to _PDCLIB_open(). */
-enum _PDCLIB_iomode_e
-{
- _PDCLIB_io_read = 1,
- _PDCLIB_io_write = 2,
- _PDCLIB_io_append = 4,
- _PDCLIB_io_create = 8,
- _PDCLIB_io_truncate = 16,
-};
+/* The default size for file buffers. Must be at least 256. */
+#define _PDCLIB_BUFSIZ 1024
+
+/* The minimum number of files the implementation can open simultaneously. Must
+ be at least 8.
+*/
+#define _PDCLIB_FOPEN_MAX 8
+
+/* Length of the longest filename the implementation guarantees to support. */
+#define _PDCLIB_FILENAME_MAX 128
+
+/* Buffer size for tmpnam(). */
+#define _PDCLIB_L_tmpnam 100
+
+/* Number of distinct file names that can be generated by tmpnam(). */
+#define _PDCLIB_TMP_MAX 50