1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00
Files
amiga-clib2/library/stdio_headers.h
Olaf Barthel 7492d108a3 c.lib 1.184 (28.11.2004)
- Added asctime_r(), ctime_r(), gmtime_r(), localtime_r() and strtok_r().

- Added stubs for the Rexx Variables Interface code that used to
  be part of amiga.lib. While comparable functionality is available
  in rexxsyslib.library V45, the new stubs might be helpful during
  porting. Care must be taken since these functions don't work
  exactly like the originals.

- Integrated strlcpy() and strlcat() which are intended to be safer
  replacements for strncpy() and strncat().

- The program's task priority is now configurable through an external
  variable '__priority'.

- The process name to be used when detaching can be configured through
  the new '__process_name' variable.

- The minimum required operating system version can be configured
  through the new '__minimum_os_lib_version' variable; a matching
  error message can be provided through the new '__minimum_os_lib_error'
  variable.

- The default console window specification can be overriden through
  the new '__stdio_window_specification' variable.

- The socket initialization code did not set up a reference to the
  'h_errno' variable correctly. This had the effect of making name
  and address resolution errors trash the 'errno' variable instead
  and leaving 'h_errno' always set to 0. Fixed.

- For sockets, ioctl() and fcntl() now interact on the FIONBIO/FIOASYNC
  requests (ioctl) and the O_NOBLOCK/O_ASYNC flags (fcntl).

- popen() now accepts "rb" and "wb" as mode parameters. However, "r+",
  "w+" and variants thereof are still unsupported due to the
  unidirectional pipe support in the standard "PIPE:" device.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14777 87f5fb63-7c3d-0410-a384-fd976d0f7a62
2004-11-28 10:01:26 +00:00

418 lines
15 KiB
C

/*
* $Id: stdio_headers.h,v 1.5 2004-11-28 10:01:26 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2004 by Olaf Barthel <olsen@sourcery.han.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of Olaf Barthel nor the names of contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _STDIO_HEADERS_H
#define _STDIO_HEADERS_H
/****************************************************************************/
#include <exec/libraries.h>
#include <exec/memory.h>
#include <devices/timer.h>
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include <dos/dosasl.h>
#include <dos/record.h>
#include <libraries/locale.h>
#include <utility/hooks.h>
/****************************************************************************/
#include <clib/alib_protos.h>
/****************************************************************************/
#include <proto/exec.h>
#include <proto/dos.h>
/****************************************************************************/
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
/****************************************************************************/
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <utime.h>
#include <fcntl.h>
#include <dos.h>
/****************************************************************************/
#ifndef _STDLIB_LOCALE_UTILITY_H
#include "stdlib_locale_utility.h"
#endif /* _STDLIB_LOCALE_UTILITY_H */
/****************************************************************************/
#ifndef _MATH_FP_SUPPORT_H
#include "math_fp_support.h"
#endif /* _MATH_FP_SUPPORT_H */
/****************************************************************************/
#if defined(FLOATING_POINT_SUPPORT)
#include <math.h>
#endif /* FLOATING_POINT_SUPPORT */
/****************************************************************************/
#include "macros.h"
#include "debug.h"
/****************************************************************************/
/* The directory entry type a socket is identified with (in a FileInfoBlock). */
#define ST_SOCKET (31082002)
/****************************************************************************/
/* The three file buffering modes supported. */
#define IOBF_BUFFER_MODE_FULL _IOFBF /* Buffer is flushed when it fills up */
#define IOBF_BUFFER_MODE_LINE _IOLBF /* Buffer is flushed when it fills up
or when a line end character is sent
to it */
#define IOBF_BUFFER_MODE_NONE _IONBF /* The buffer is never used */
/****************************************************************************/
/* CAREFUL: these mask/flag definitions must match the public definitions
in <stdio.h> or there will be trouble! */
#define IOBF_BUFFER_MODE 3 /* This is actually a mask which covers
the first two bits, both of which
contain the buffering mode to use. */
#define IOBF_EOF_REACHED (1<<2) /* If this flag is set, then the end of
the file was reached while reading
from it. */
#define IOBF_READ (1<<3) /* If this flag is set then data can
be read from this file. */
#define IOBF_WRITE (1<<4) /* If this flag is set then data can be
written to this file. */
#define IOBF_IN_USE (1<<5) /* If this flag is set then this file
is not available for allocation */
#define IOBF_ERROR (1<<6) /* An error was generated by an I/O
operation. */
#define IOBF_TEMP (1<<7) /* If this flag is set then the file will
be deleted after it has been closed */
#define IOBF_NO_NUL (1<<8) /* Don't NUL-terminate strings written to
this stream. */
#define IOBF_INTERNAL (1<<9) /* Not a regular file, but a buffered
file handle made up on the spot in
vsprintf(), etc. */
/****************************************************************************/
/* Each file handle is represented by the following structure. Note that this
must match the layout of the public 'FILE' structure in <stdio.h> or
things will take a turn for the worse! */
struct iob
{
ULONG iob_Flags; /* Properties and options
associated with this file */
UBYTE * iob_Buffer; /* Points to the file buffer */
LONG iob_BufferSize; /* Size of the buffer in bytes */
LONG iob_BufferPosition; /* Current read position
in the buffer (grows when any
data is read from the buffer) */
LONG iob_BufferReadBytes; /* Number of bytes available for
reading (shrinks when any data
is read from the buffer) */
LONG iob_BufferWriteBytes; /* Number of bytes written to the
buffer which still need to be
flushed to disk (grows when any
data is written to the buffer) */
/************************************************************************/
/* Public portion ends here */
/************************************************************************/
struct Hook * iob_Hook; /* The hook to invoke for file
operations, such as read,
write and seek. */
int iob_SlotNumber; /* Points back to the iob table
entry number. */
int iob_Descriptor; /* Associated file descriptor */
STRPTR iob_String; /* Alternative source of data;
a pointer to a string */
LONG iob_StringSize; /* Number of bytes that may be
stored in the string */
LONG iob_StringPosition; /* Current read/write position
in the string */
LONG iob_StringLength; /* Number of characters stored
in the string */
char * iob_File; /* For access tracking with the
memory allocator. */
int iob_Line;
struct Hook iob_DefaultHook; /* Static hook */
APTR iob_CustomBuffer; /* A custom buffer allocated
by setvbuf() */
char * iob_TempFileName; /* If this is a temporary
file, this is its name */
BPTR iob_TempFileLock; /* The directory in which this
temporary file is stored */
UBYTE iob_SingleByte; /* Fall-back buffer for 'unbuffered'
files */
};
/****************************************************************************/
#define __getc(f) \
((((struct iob *)(f))->iob_BufferPosition < ((struct iob *)(f))->iob_BufferReadBytes) ? \
((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferPosition++] : \
__fgetc((FILE *)(f)))
#define __putc(c,f,m) \
(((((struct iob *)(f))->iob_BufferWriteBytes < ((struct iob *)(f))->iob_BufferSize)) ? \
(((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes++] = (c), \
(((m) == IOBF_BUFFER_MODE_LINE && \
((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes-1] == '\n') ? \
__flush(f) : \
(((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes-1]))) : \
__fputc((c),(f),(m)))
#define __putc_fully_buffered(c,f) \
(((((struct iob *)(f))->iob_BufferWriteBytes < ((struct iob *)(f))->iob_BufferSize)) ? \
(((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes++] = (c)) : \
__fputc((c),(f),IOBF_BUFFER_MODE_FULL))
#define __putc_line_buffered(c,f) \
(((((struct iob *)(f))->iob_BufferWriteBytes < ((struct iob *)(f))->iob_BufferSize)) ? \
(((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes++] = (c), \
(((c) == '\n') ? \