1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

- Added stdio thread locking functions flockfile(), funlockfile(),

and ftrylockfile().

- Modified the internal FILE structure to allow for thread locking.
  Note that this again requires that the library is rebuilt!

- Added or modified macros for getc_unlocked(), getchar_unlocked(),
  putc_unlocked() and putchar_unlocked().

- Added rand_r().

- Added flockfile()/funlockfile() wrappers around all stdio
  functions.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14841 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-02-27 18:09:12 +00:00
parent b10d1ad38c
commit c0c70bfd99
55 changed files with 1060 additions and 180 deletions

View File

@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.68k,v 1.29 2005-02-25 10:14:20 obarthel Exp $
# $Id: GNUmakefile.68k,v 1.30 2005-02-27 18:09:07 obarthel Exp $
#
# :ts=8
#
@ -130,23 +130,23 @@ C_LIB = \
ctype_isspace.o \
ctype_isupper.o \
ctype_isxdigit.o \
ctype_table.o \
ctype_tolower.o \
ctype_toupper.o \
ctype_table.o \
dirent_closedir.o \
dirent_data.o \
dirent_rewinddir.o \
dirent_opendir.o \
dirent_readdir.o \
dirent_rewinddir.o \
errno_data.o \
fcntl_close.o \
fcntl_creat.o \
fcntl_fcntl.o \
fcntl_get_default_file.o \
fcntl_lseek.o \
fcntl_open.o \
fcntl_read.o \
fcntl_write.o \
fcntl_get_default_file.o \
libgen_basename.o \
libgen_dirname.o \
locale_init_exit.o \
@ -188,13 +188,14 @@ C_LIB = \
stdio_feof.o \
stdio_ferror.o \
stdio_fflush.o \
stdio_flush.o \
stdio_fgetc.o \
stdio_fgetpos.o \
stdio_fgets.o \
stdio_filliobreadbuffer.o \
stdio_findvacantfdentry.o \
stdio_findvacantiobentry.o \
stdio_flockfile.o \
stdio_flush.o \
stdio_flushiobwritebuffer.o \
stdio_fopen.o \
stdio_fprintf.o \
@ -206,11 +207,15 @@ C_LIB = \
stdio_fseek.o \
stdio_fsetpos.o \
stdio_ftell.o \
stdio_ftrylockfile.o \
stdio_funlockfile.o \
stdio_fwrite.o \
stdio_getc.o \
stdio_getc_unlocked.o \
stdio_getchar.o \
stdio_get_file_descriptor.o \
stdio_getchar_unlocked.o \
stdio_gets.o \
stdio_get_file_descriptor.o \
stdio_growfdtable.o \
stdio_growiobtable.o \
stdio_grow_file.o \
@ -226,7 +231,9 @@ C_LIB = \
stdio_popen.o \
stdio_printf.o \
stdio_putc.o \
stdio_putc_unlocked.o \
stdio_putchar.o \
stdio_putchar_unlocked.o \
stdio_puts.o \
stdio_remove.o \
stdio_remove_fd_alias.o \
@ -243,6 +250,7 @@ C_LIB = \
stdio_tmpnam.o \
stdio_translateioerror.o \
stdio_ungetc.o \
stdio_unlockfile.o \
stdio_vasprintf.o \
stdio_vasprintf_hook_entry.o \
stdio_vfprintf.o \
@ -277,10 +285,10 @@ C_LIB = \
stdlib_dosbase.o \
stdlib_exit.o \
stdlib_free.o \
stdlib_get_errno.o \
stdlib_getdefstacksize.o \
stdlib_getenv.o \
stdlib_getsp.o \
stdlib_get_errno.o \
stdlib_init_exit.o \
stdlib_isresident.o \
stdlib_labs.o \
@ -301,11 +309,12 @@ C_LIB = \
stdlib_putenv.o \
stdlib_qsort.o \
stdlib_rand.o \
stdlib_rand_r.o \
stdlib_realloc.o \
stdlib_red_black.o \
stdlib_setenv.o \
stdlib_set_errno.o \
stdlib_setjmp.o \
stdlib_set_errno.o \
stdlib_set_process_window.o \
stdlib_shell_escape.o \
stdlib_showerror.o \
@ -318,9 +327,10 @@ C_LIB = \
stdlib_stacksize.o \
stdlib_stack_usage.o \
stdlib_startup.o \
stdlib_stdio_window_spec.o \
stdlib_strtol.o \
stdlib_strtoul.o \
stdlib_strtoll.o \
stdlib_strtoul.o \
stdlib_strtoull.o \
stdlib_swapstack.o \
stdlib_sysbase.o \
@ -332,7 +342,6 @@ C_LIB = \
stdlib_umodsi3.o \
stdlib_unsetenv.o \
stdlib_wildcard_expand.o \
stdlib_stdio_window_spec.o \
strings_strcasecmp.o \
strings_strncasecmp.o \
string_bcmp.o \

View File

@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.os4,v 1.29 2005-02-25 10:14:20 obarthel Exp $
# $Id: GNUmakefile.os4,v 1.30 2005-02-27 18:09:10 obarthel Exp $
#
# :ts=8
#
@ -134,23 +134,23 @@ C_LIB = \
ctype_isspace.o \
ctype_isupper.o \
ctype_isxdigit.o \
ctype_table.o \
ctype_tolower.o \
ctype_toupper.o \
ctype_table.o \
dirent_closedir.o \
dirent_data.o \
dirent_rewinddir.o \
dirent_opendir.o \
dirent_readdir.o \
dirent_rewinddir.o \
errno_data.o \
fcntl_close.o \
fcntl_creat.o \
fcntl_fcntl.o \
fcntl_get_default_file.o \
fcntl_lseek.o \
fcntl_open.o \
fcntl_read.o \
fcntl_write.o \
fcntl_get_default_file.o \
libgen_basename.o \
libgen_dirname.o \
locale_init_exit.o \
@ -192,13 +192,14 @@ C_LIB = \
stdio_feof.o \
stdio_ferror.o \
stdio_fflush.o \
stdio_flush.o \
stdio_fgetc.o \
stdio_fgetpos.o \
stdio_fgets.o \
stdio_filliobreadbuffer.o \
stdio_findvacantfdentry.o \
stdio_findvacantiobentry.o \
stdio_flockfile.o \
stdio_flush.o \
stdio_flushiobwritebuffer.o \
stdio_fopen.o \
stdio_fprintf.o \
@ -210,11 +211,15 @@ C_LIB = \
stdio_fseek.o \
stdio_fsetpos.o \
stdio_ftell.o \
stdio_ftrylockfile.o \
stdio_funlockfile.o \
stdio_fwrite.o \
stdio_getc.o \
stdio_getc_unlocked.o \
stdio_getchar.o \
stdio_get_file_descriptor.o \
stdio_getchar_unlocked.o \
stdio_gets.o \
stdio_get_file_descriptor.o \
stdio_growfdtable.o \
stdio_growiobtable.o \
stdio_grow_file.o \
@ -230,7 +235,9 @@ C_LIB = \
stdio_popen.o \
stdio_printf.o \
stdio_putc.o \
stdio_putc_unlocked.o \
stdio_putchar.o \
stdio_putchar_unlocked.o \
stdio_puts.o \
stdio_remove.o \
stdio_remove_fd_alias.o \
@ -247,6 +254,7 @@ C_LIB = \
stdio_tmpnam.o \
stdio_translateioerror.o \
stdio_ungetc.o \
stdio_unlockfile.o \
stdio_vasprintf.o \
stdio_vasprintf_hook_entry.o \
stdio_vfprintf.o \
@ -282,9 +290,9 @@ C_LIB = \
stdlib_exit.o \
stdlib_free.o \
stdlib_getdefstacksize.o \
stdlib_get_errno.o \
stdlib_getenv.o \
stdlib_getsp.o \
stdlib_get_errno.o \
stdlib_init_exit.o \
stdlib_isresident.o \
stdlib_labs.o \
@ -305,11 +313,12 @@ C_LIB = \
stdlib_putenv.o \
stdlib_qsort.o \
stdlib_rand.o \
stdlib_rand_r.o \
stdlib_realloc.o \
stdlib_red_black.o \
stdlib_set_errno.o \
stdlib_setenv.o \
stdlib_setjmp.o \
stdlib_set_errno.o \
stdlib_set_process_window.o \
stdlib_shell_escape.o \
stdlib_showerror.o \
@ -322,9 +331,10 @@ C_LIB = \
stdlib_stacksize.o \
stdlib_stack_usage.o \
stdlib_startup.o \
stdlib_stdio_window_spec.o \
stdlib_strtol.o \
stdlib_strtoul.o \
stdlib_strtoll.o \
stdlib_strtoul.o \
stdlib_strtoull.o \
stdlib_swapstack.o \
stdlib_sysbase.o \
@ -336,7 +346,6 @@ C_LIB = \
stdlib_umodsi3.o \
stdlib_unsetenv.o \
stdlib_wildcard_expand.o \
stdlib_stdio_window_spec.o \
strings_strcasecmp.o \
strings_strncasecmp.o \
string_bcmp.o \

View File

@ -48,6 +48,20 @@
qualifier. This was done in preparation for changes that will
deal with global and local data and the issue of thread safety.
- Added stdio thread locking functions flockfile(), funlockfile(),
and ftrylockfile().
- Modified the internal FILE structure to allow for thread locking.
Note that this again requires that the library is rebuilt!
- Added or modified macros for getc_unlocked(), getchar_unlocked(),
putc_unlocked() and putchar_unlocked().
- Added rand_r().
- Added flockfile()/funlockfile() wrappers around all stdio
functions.
c.lib 1.188 (7.2.2005)

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio.h,v 1.5 2005-01-02 09:07:21 obarthel Exp $
* $Id: stdio.h,v 1.6 2005-02-27 18:09:12 obarthel Exp $
*
* :ts=4
*
@ -200,6 +200,21 @@ extern int putchar(int c);
/****************************************************************************/
/* The following four functions are not part of ISO 'C' (1994). */
/****************************************************************************/
extern int getc_unlocked(FILE *stream);
extern int getchar_unlocked(void);
extern int putc_unlocked(int c,FILE *stream);
extern int putchar_unlocked(int c);
/****************************************************************************/
/* ISO 'C' (1994) functions continue below. */
/****************************************************************************/
extern char *fgets(char *s,int n,FILE *stream);
extern char *gets(char *s);
@ -252,30 +267,40 @@ extern char *tmpnam(char *buf);
/*
* A special buffer flush routine which returns the last character written
* in case of success and EOF in case of failure. This is used by the
* putc() macro defined below.
* putc_unlocked() macro defined below.
*/
extern int __flush(FILE *stream);
/****************************************************************************/
/*
* A special function which returns the input character. This is used by
* the getc() macro defined below.
*/
extern int __unlockfile(FILE *stream,int c);
/****************************************************************************/
/*
* fgetc() implemented as a "simple" macro; note that fgetc() does much more than
* can be conveniently expressed as a macro!
*/
#define getc(f) \
#define __getc_unlocked(f) \
(((((FILE *)(f))->flags & (__FILE_IN_USE|__FILE_READABLE|__FILE_EOF)) == (__FILE_IN_USE|__FILE_READABLE) && \
(((FILE *)(f))->flags & __FILE_BUFFER_MASK) != _IONBF && \
((FILE *)(f))->position < ((FILE *)(f))->num_read_bytes) ? \
((FILE *)(f))->buffer[((FILE *)(f))->position++] : \
fgetc(f))
#define getc_unlocked(f)
/****************************************************************************/
/*
* fputc() implemented as a "simple" macro; note that fputc() does much more than
* can be conveniently expressed as a macro!
*/
#define putc(c,f) \
#define __putc_unlocked(c,f) \
(((((FILE *)(f))->flags & (__FILE_IN_USE|__FILE_WRITABLE)) == (__FILE_IN_USE|__FILE_WRITABLE) && \
(((FILE *)(f))->flags & __FILE_BUFFER_MASK) != _IONBF && \
(((FILE *)(f))->num_write_bytes < ((FILE *)(f))->size)) ? \
@ -286,6 +311,20 @@ extern int __flush(FILE *stream);
(((FILE *)(f))->buffer[((FILE *)(f))->num_write_bytes-1]))) : \
fputc((c),(f)))
#define putc_unlocked(c,f) __putc((c),(f))
/****************************************************************************/
#define getchar_unlocked() __getc_unlocked(stdin)
#define putchar_unlocked(c) __putc_unlocked((c),stdout)
/****************************************************************************/
#define getc(f) (flockfile(f), __unlockfile((f),__getc_unlocked(f)))
#define putc(c,f) (flockfile(f), __unlockfile((f),__putc_unlocked((c),(f))))
#define getchar() getc(stdin)
#define putchar(c) putc((c),stdout)
/****************************************************************************/
/*
@ -296,8 +335,6 @@ extern int __flush(FILE *stream);
/****************************************************************************/
#define getchar() getc(stdin)
#define putchar(c) putc((c),stdout)
#define clearerr(file) ((void)((file)->flags &= ~(__FILE_EOF|__FILE_ERROR)))
#define feof(file) (((file)->flags & __FILE_EOF) != 0)
#define ferror(file) (((file)->flags & __FILE_ERROR) != 0)
@ -326,6 +363,12 @@ extern FILE * popen(const char *command, const char *type);
/****************************************************************************/
extern void flockfile(FILE * file);
extern void funlockfile(FILE * file);
extern int ftrylockfile(FILE * file);
/****************************************************************************/
extern int vasprintf(char **ret,const char *format,va_list arg);
#ifdef __MEM_DEBUG

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib.h,v 1.6 2005-01-30 09:48:06 obarthel Exp $
* $Id: stdlib.h,v 1.7 2005-02-27 18:09:12 obarthel Exp $
*
* :ts=4
*
@ -149,6 +149,10 @@ extern long atol(const char *str);
/****************************************************************************/
extern int rand_r(unsigned int * seed);
/****************************************************************************/
/* These two functions are unavailable under SAS/C for lack of a
"long long" data type. */
#if ! defined(__SASC)

View File

@ -1,5 +1,5 @@
_#
# $Id: smakefile,v 1.23 2005-02-25 10:14:21 obarthel Exp $
# $Id: smakefile,v 1.24 2005-02-27 18:09:10 obarthel Exp $
#
# :ts=8
#
@ -292,18 +292,17 @@ STDIO_OBJ = \
stdio_examine_fh.o \
stdio_fclose.o \
stdio_fdhookentry.o \
stdio_record_locking.o \
stdio_remove_fd_alias.o \
stdio_feof.o \
stdio_ferror.o \
stdio_fflush.o \
stdio_flush.o \
stdio_fgetc.o \
stdio_fgetpos.o \
stdio_fgets.o \
stdio_filliobreadbuffer.o \
stdio_findvacantfdentry.o \
stdio_findvacantiobentry.o \
stdio_flockfile.o \
stdio_flush.o \
stdio_flushiobwritebuffer.o \
stdio_fopen.o \
stdio_fprintf.o \
@ -315,11 +314,15 @@ STDIO_OBJ = \
stdio_fseek.o \
stdio_fsetpos.o \
stdio_ftell.o \
stdio_ftrylockfile.o \
stdio_funlockfile.o \
stdio_fwrite.o \
stdio_getc.o \
stdio_getc_unlocked.o \
stdio_getchar.o \
stdio_get_file_descriptor.o \
stdio_getchar_unlocked.o \
stdio_gets.o \
stdio_get_file_descriptor.o \
stdio_growfdtable.o \
stdio_growiobtable.o \
stdio_grow_file.o \
@ -335,9 +338,13 @@ STDIO_OBJ = \
stdio_popen.o \
stdio_printf.o \
stdio_putc.o \
stdio_putc_unlocked.o \
stdio_putchar.o \
stdio_putchar_unlocked.o \
stdio_puts.o \
stdio_record_locking.o \
stdio_remove.o \
stdio_remove_fd_alias.o \
stdio_rename.o \
stdio_rewind.o \
stdio_scanf.o \
@ -351,6 +358,7 @@ STDIO_OBJ = \
stdio_tmpnam.o \
stdio_translateioerror.o \
stdio_ungetc.o \
stdio_unlockfile.o \
stdio_vasprintf.o \
stdio_vasprintf_hook_entry.o \
stdio_vfprintf.o \
@ -412,6 +420,7 @@ STDLIB_OBJ = \
stdlib_putenv.o \
stdlib_qsort.o \
stdlib_rand.o \
stdlib_rand_r.o \
stdlib_realloc.o \
stdlib_red_black.o \
stdlib_setenv.o \

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_clearerr.c,v 1.3 2005-02-03 16:56:15 obarthel Exp $
* $Id: stdio_clearerr.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -58,6 +58,9 @@ clearerr(FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -68,14 +71,15 @@ clearerr(FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
flockfile(stream);
CLEAR_FLAG(file->iob_Flags,IOBF_ERROR);
CLEAR_FLAG(file->iob_Flags,IOBF_EOF_REACHED);
funlockfile(stream);
out:
LEAVE();

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fclose.c,v 1.5 2005-02-21 10:21:44 obarthel Exp $
* $Id: stdio_fclose.c,v 1.6 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -62,6 +62,8 @@ fclose(FILE *stream)
assert( stream != NULL );
assert( file->iob_Lock == NULL || file->iob_Lock->ss_Owner == NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -139,6 +141,9 @@ fclose(FILE *stream)
if(file->iob_CustomBuffer != NULL)
free(file->iob_CustomBuffer);
/* Free the lock semaphore now. */
FreeVec(file->iob_Lock);
memset(file,0,sizeof(*file));
out:

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_feof.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_feof.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -59,6 +59,9 @@ feof(FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -74,14 +77,15 @@ feof(FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
flockfile(stream);
result = FLAG_IS_SET(file->iob_Flags,IOBF_EOF_REACHED);
funlockfile(stream);
out:
RETURN(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_ferror.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_ferror.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -59,6 +59,9 @@ ferror(FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -74,13 +77,14 @@ ferror(FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
flockfile(stream);
result = FLAG_IS_SET(file->iob_Flags,IOBF_ERROR);
funlockfile(stream);
out:
RETURN(result);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fflush.c,v 1.4 2005-02-21 10:21:48 obarthel Exp $
* $Id: stdio_fflush.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -55,6 +55,8 @@ fflush(FILE *stream)
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(UNIX_PATH_SEMANTICS)
{
/* Flush a particular stream? */
@ -114,6 +116,8 @@ fflush(FILE *stream)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fgetc.c,v 1.4 2005-02-21 10:21:48 obarthel Exp $
* $Id: stdio_fgetc.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -95,9 +95,6 @@ __fgetc_check(FILE * stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -138,6 +135,11 @@ fgetc(FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -155,5 +157,7 @@ fgetc(FILE *stream)
out:
funlockfile(stream);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fgetpos.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_fgetpos.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -56,6 +56,11 @@ fgetpos(FILE *stream, fpos_t *pos)
assert( stream != NULL && pos != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL || pos == NULL)
@ -68,9 +73,6 @@ fgetpos(FILE *stream, fpos_t *pos)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
position = ftell(stream);
if(position == -1)
{
@ -85,6 +87,8 @@ fgetpos(FILE *stream, fpos_t *pos)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fgets.c,v 1.4 2005-02-21 10:21:48 obarthel Exp $
* $Id: stdio_fgets.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -57,6 +57,11 @@ fgets(char *s,int n,FILE *stream)
assert( s != NULL && stream != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(s == NULL || stream == NULL)
@ -70,9 +75,6 @@ fgets(char *s,int n,FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
if(n <= 0)
{
SHOWMSG("no work to be done");
@ -130,6 +132,8 @@ fgets(char *s,int n,FILE *stream)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

89
library/stdio_flockfile.c Normal file
View File

@ -0,0 +1,89 @@
/*
* $Id: stdio_flockfile.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
void
flockfile(FILE *stream)
{
struct iob * file = (struct iob *)stream;
ENTER();
SHOWPOINTER(stream);
assert( stream != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
{
SHOWMSG("invalid stream parameter");
__set_errno(EFAULT);
goto out;
}
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE))
{
SHOWMSG("this file is not even in use");
__set_errno(EBADF);
goto out;
}
if(file->iob_Lock != NULL)
ObtainSemaphore(file->iob_Lock);
out:
LEAVE();
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_flush.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_flush.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -62,6 +62,11 @@ __flush(FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -74,9 +79,6 @@ __flush(FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(iob) );
assert( iob->iob_BufferWriteBytes > 0 );
assert( iob->iob_BufferSize > 0 );
@ -95,6 +97,8 @@ __flush(FILE *stream)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fopen.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_fopen.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -56,6 +56,9 @@ fopen(const char *filename, const char *mode)
assert( filename != NULL && mode != NULL );
if(__check_abort_enabled)
__check_abort();
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(filename == NULL || mode == NULL)
@ -68,9 +71,6 @@ fopen(const char *filename, const char *mode)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
slot_number = __find_vacant_iob_entry();
if(slot_number < 0)
{

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fprintf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_fprintf.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -56,6 +56,11 @@ fprintf(FILE *stream,const char *format,...)
assert( stream != NULL && format != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL || format == NULL)
@ -66,15 +71,14 @@ fprintf(FILE *stream,const char *format,...)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
va_start(arg,format);
result = vfprintf(stream,format,arg);
va_end(arg);
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fputc.c,v 1.4 2005-02-21 10:21:48 obarthel Exp $
* $Id: stdio_fputc.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -61,9 +61,6 @@ __fputc_check(FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -148,8 +145,13 @@ fputc(int c,FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
flockfile(stream);
if(__fputc_check(stream) < 0)
goto out;
@ -157,5 +159,7 @@ fputc(int c,FILE *stream)
out:
funlockfile(stream);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fputs.c,v 1.4 2005-02-21 10:21:49 obarthel Exp $
* $Id: stdio_fputs.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -58,6 +58,9 @@ fputs(const char *s, FILE *stream)
assert( s != NULL && stream != NULL );
if(__check_abort_enabled)
__check_abort();
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(s == NULL || stream == NULL)
@ -68,8 +71,7 @@ fputs(const char *s, FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
@ -105,6 +107,8 @@ fputs(const char *s, FILE *stream)
}
}
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fread.c,v 1.4 2005-02-21 10:21:49 obarthel Exp $
* $Id: stdio_fread.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -59,6 +59,11 @@ fread(void *ptr,size_t element_size,size_t count,FILE *stream)
assert( ptr != NULL && stream != NULL );
assert( (int)element_size >= 0 && (int)count >= 0 );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(ptr == NULL || stream == NULL)
@ -71,9 +76,6 @@ fread(void *ptr,size_t element_size,size_t count,FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -141,6 +143,8 @@ fread(void *ptr,size_t element_size,size_t count,FILE *stream)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fscanf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_fscanf.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -56,6 +56,11 @@ fscanf(FILE *stream, const char *format, ...)
assert(stream != NULL && format != NULL);
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL || format == NULL)
@ -68,15 +73,14 @@ fscanf(FILE *stream, const char *format, ...)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
va_start(arg,format);
result = __vfscanf(stream,format,arg);
va_end(arg);
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fseek.c,v 1.6 2005-02-21 10:21:49 obarthel Exp $
* $Id: stdio_fseek.c,v 1.7 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -57,6 +57,11 @@ fseek(FILE *stream, long int offset, int wherefrom)
assert(stream != NULL);
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -69,9 +74,6 @@ fseek(FILE *stream, long int offset, int wherefrom)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -188,6 +190,8 @@ fseek(FILE *stream, long int offset, int wherefrom)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fsetpos.c,v 1.4 2005-02-21 10:21:49 obarthel Exp $
* $Id: stdio_fsetpos.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -55,6 +55,11 @@ fsetpos(FILE *stream, fpos_t *pos)
assert( stream != NULL && pos != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL || pos == NULL)
@ -67,9 +72,6 @@ fsetpos(FILE *stream, fpos_t *pos)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
if(fseek(stream,(long int)(*pos),SEEK_SET) != 0)
{
SHOWMSG("fseek failed");
@ -80,6 +82,8 @@ fsetpos(FILE *stream, fpos_t *pos)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_ftell.c,v 1.6 2005-02-21 10:21:49 obarthel Exp $
* $Id: stdio_ftell.c,v 1.7 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -53,6 +53,11 @@ ftell(FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -63,9 +68,6 @@ ftell(FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -123,5 +125,7 @@ ftell(FILE *stream)
out:
funlockfile(stream);
return(result);
}

View File

@ -0,0 +1,93 @@
/*
* $Id: stdio_ftrylockfile.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
int
ftrylockfile(FILE *stream)
{
struct iob * file = (struct iob *)stream;
int result = -1;
ENTER();
SHOWPOINTER(stream);
assert( stream != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
{
SHOWMSG("invalid stream parameter");
__set_errno(EFAULT);
goto out;
}
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE))
{
SHOWMSG("this file is not even in use");
__set_errno(EBADF);
goto out;
}
if(file->iob_Lock != NULL && CANNOT AttemptSemaphore(file->iob_Lock))
goto out;
result = 0;
out:
RETURN(result);
return(result);
}

View File

@ -0,0 +1,89 @@
/*
* $Id: stdio_funlockfile.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
void
funlockfile(FILE *stream)
{
struct iob * file = (struct iob *)stream;
ENTER();
SHOWPOINTER(stream);
assert( stream != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
{
SHOWMSG("invalid stream parameter");
__set_errno(EFAULT);
goto out;
}
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE))
{
SHOWMSG("this file is not even in use");
__set_errno(EBADF);
goto out;
}
if(file->iob_Lock != NULL)
ReleaseSemaphore(file->iob_Lock);
out:
LEAVE();
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_fwrite.c,v 1.5 2005-02-21 10:21:49 obarthel Exp $
* $Id: stdio_fwrite.c,v 1.6 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -59,6 +59,11 @@ fwrite(const void *ptr,size_t element_size,size_t count,FILE *stream)
assert( ptr != NULL && stream != NULL );
assert( (int)element_size >= 0 && (int)count >= 0 );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(ptr == NULL || stream == NULL)
@ -71,9 +76,6 @@ fwrite(const void *ptr,size_t element_size,size_t count,FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -156,6 +158,8 @@ fwrite(const void *ptr,size_t element_size,size_t count,FILE *stream)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -0,0 +1,72 @@
/*
* $Id: stdio_getc_unlocked.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
#undef getc_unlocked
/****************************************************************************/
int
getc_unlocked(FILE *stream)
{
int result = -1;
assert( stream != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
{
__set_errno(EFAULT);
goto out;
}
}
#endif /* CHECK_FOR_NULL_POINTERS */
result = __getc_unlocked(stream);
out:
return(result);
}

View File

@ -0,0 +1,72 @@
/*
* $Id: stdio_getchar_unlocked.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
#undef getchar_unlocked
/****************************************************************************/
int
getchar_unlocked(void)
{
int result = -1;
assert( stdin != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stdin == NULL)
{
__set_errno(EFAULT);
goto out;
}
}
#endif /* CHECK_FOR_NULL_POINTERS */
result = __getc_unlocked(stdin);
out:
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_gets.c,v 1.4 2005-02-21 10:21:49 obarthel Exp $
* $Id: stdio_gets.c,v 1.5 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -55,6 +55,11 @@ gets(char *s)
assert( s != NULL && stdin != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stdin);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(s == NULL || stdin == NULL)
@ -69,9 +74,6 @@ gets(char *s)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
/* Take care of the checks and data structure changes that
* need to be handled only once for this stream.
*/
@ -118,6 +120,8 @@ gets(char *s)
out:
funlockfile(stdin);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_headers.h,v 1.15 2005-02-20 15:46:52 obarthel Exp $
* $Id: stdio_headers.h,v 1.16 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -262,6 +262,8 @@ struct iob
UBYTE iob_SingleByte; /* Fall-back buffer for 'unbuffered'
files */
struct SignalSemaphore * iob_Lock; /* For thread locking */
};
/****************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_init_exit.c,v 1.17 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_init_exit.c,v 1.18 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -111,6 +111,7 @@ __stdio_init(void)
{
const int num_standard_files = (STDERR_FILENO-STDIN_FILENO+1);
struct SignalSemaphore * lock;
BPTR default_file;
ULONG fd_flags,iob_flags;
int result = ERROR;
@ -187,6 +188,14 @@ __stdio_init(void)
if(buffer == NULL)
goto out;
/* Allocate memory for an arbitration mechanism, then
initialize it. */
lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC);
if(lock == NULL)
goto out;
InitSemaphore(lock);
/* Check if this stream is attached to a console window. */
if(default_file != ZERO)
{
@ -208,7 +217,8 @@ __stdio_init(void)
aligned_buffer,BUFSIZ,
i,
i,
iob_flags);
iob_flags,
lock);
}
/* If the program was launched from Workbench, we continue by

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_initializeiob.c,v 1.3 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_initializeiob.c,v 1.4 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -39,14 +39,15 @@
void
__initialize_iob(
struct iob * iob,
file_action_iob_t action_function,
STRPTR custom_buffer,
STRPTR buffer,
int buffer_size,
int file_descriptor,
int slot_number,
ULONG flags)
struct iob * iob,
file_action_iob_t action_function,
STRPTR custom_buffer,
STRPTR buffer,
int buffer_size,
int file_descriptor,
int slot_number,
ULONG flags,
struct SignalSemaphore * lock)
{
assert( iob != NULL && action_function != NULL );
@ -59,4 +60,5 @@ __initialize_iob(
iob->iob_SlotNumber = slot_number;
iob->iob_Flags = flags;
iob->iob_Action = action_function;
iob->iob_Lock = lock;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_openiob.c,v 1.7 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_openiob.c,v 1.8 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -46,6 +46,7 @@
int
__open_iob(const char *filename, const char *mode, int file_descriptor, int slot_number)
{
struct SignalSemaphore * lock;
ULONG file_flags;
int result = -1;
int open_mode;
@ -162,6 +163,14 @@ __open_iob(const char *filename, const char *mode, int file_descriptor, int slot
CLEAR_FLAG(fd->fd_Flags,FDF_APPEND);
}
/* Allocate memory for an arbitration mechanism, then
initialize it. */
lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC);
if(lock == NULL)
goto out;
InitSemaphore(lock);
/* Figure out the buffered file access mode by looking at the open mode. */
file_flags = IOBF_IN_USE | IOBF_NO_NUL;
@ -176,7 +185,8 @@ __open_iob(const char *filename, const char *mode, int file_descriptor, int slot
aligned_buffer,BUFSIZ,
file_descriptor,
slot_number,
file_flags);
file_flags,
lock);
buffer = NULL;

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_protos.h,v 1.7 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_protos.h,v 1.8 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
@ -103,7 +103,7 @@ extern int __find_vacant_fd_entry(void);
/****************************************************************************/
/* stdio_initializeiob.c */
extern void __initialize_iob(struct iob * iob,file_action_iob_t action_function,STRPTR custom_buffer,STRPTR buffer,int buffer_size,int file_descriptor,int slot_number,ULONG flags);
extern void __initialize_iob(struct iob * iob,file_action_iob_t action_function,STRPTR custom_buffer,STRPTR buffer,int buffer_size,int file_descriptor,int slot_number,ULONG flags,struct SignalSemaphore * lock);
/****************************************************************************/

View File

@ -0,0 +1,72 @@
/*
* $Id: stdio_putc_unlocked.c,v 1.1 2005-02-27 18:09:10 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
#undef putc_unlocked
/****************************************************************************/
int
putc_unlocked(int c,FILE *stream)
{
int result = -1;
assert( stream != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
{
__set_errno(EFAULT);
goto out;
}
}
#endif /* CHECK_FOR_NULL_POINTERS */
result = __putc_unlocked(c,stream);
out:
return(result);
}

View File

@ -0,0 +1,72 @@
/*
* $Id: stdio_putchar_unlocked.c,v 1.1 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_NULL_POINTER_CHECK_H
#include "stdlib_null_pointer_check.h"
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
/****************************************************************************/
#ifndef _STDIO_HEADERS_H
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
#undef putchar_unlocked
/****************************************************************************/
int
putchar_unlocked(int c)
{
int result = -1;
assert( stdout != NULL );
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stdout == NULL)
{
__set_errno(EFAULT);
goto out;
}
}
#endif /* CHECK_FOR_NULL_POINTERS */
result = __putc_unlocked(c,stdout);
out:
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_puts.c,v 1.5 2005-02-21 10:22:00 obarthel Exp $
* $Id: stdio_puts.c,v 1.6 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -57,6 +57,11 @@ puts(const char *s)
assert( s != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stdout);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(s == NULL)
@ -67,9 +72,6 @@ puts(const char *s)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -107,6 +109,8 @@ puts(const char *s)
}
}
funlockfile(stdout);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_rewind.c,v 1.2 2005-01-02 09:07:08 obarthel Exp $
* $Id: stdio_rewind.c,v 1.3 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -45,7 +45,11 @@ rewind(FILE *stream)
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
clearerr(stream);
fseek(stream,0,SEEK_SET);
funlockfile(stream);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_setbuf.c,v 1.3 2005-02-03 16:56:16 obarthel Exp $
* $Id: stdio_setbuf.c,v 1.4 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -53,6 +53,9 @@ setbuf(FILE *stream,char *buf)
assert(stream != NULL);
if(__check_abort_enabled)
__check_abort();
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -65,9 +68,6 @@ setbuf(FILE *stream,char *buf)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
if(buf == NULL)
setvbuf(stream,NULL,IOBF_BUFFER_MODE_NONE,0);
else

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_setvbuf.c,v 1.5 2005-02-21 10:22:00 obarthel Exp $
* $Id: stdio_setvbuf.c,v 1.6 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -65,6 +65,11 @@ setvbuf(FILE *stream,char *buf,int bufmode,size_t size)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -77,9 +82,6 @@ setvbuf(FILE *stream,char *buf,int bufmode,size_t size)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
if(bufmode < IOBF_BUFFER_MODE_FULL ||
bufmode > IOBF_BUFFER_MODE_NONE)
{
@ -188,6 +190,8 @@ setvbuf(FILE *stream,char *buf,int bufmode,size_t size)
out:
funlockfile(stream);
if(new_buffer != NULL)
free(new_buffer);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_sscanf.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_sscanf.c,v 1.5 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -78,7 +78,8 @@ sscanf(const char *s,const char *format, ...)
local_buffer,sizeof(local_buffer),
-1,
-1,
IOBF_IN_USE | IOBF_READ | IOBF_BUFFER_MODE_FULL | IOBF_INTERNAL);
IOBF_IN_USE | IOBF_READ | IOBF_BUFFER_MODE_FULL | IOBF_INTERNAL,
NULL);
string_iob.iob_String = (STRPTR)s;
string_iob.iob_StringLength = strlen(s);

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_ungetc.c,v 1.4 2005-02-21 10:22:01 obarthel Exp $
* $Id: stdio_ungetc.c,v 1.5 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -51,6 +51,11 @@ ungetc(int c,FILE *stream)
assert( stream != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL)
@ -63,9 +68,6 @@ ungetc(int c,FILE *stream)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(file) );
assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) );
assert( file->iob_BufferSize > 0 );
@ -140,5 +142,7 @@ ungetc(int c,FILE *stream)
out:
funlockfile(stream);
return(result);
}

View File

@ -0,0 +1,46 @@
/*
* $Id: stdio_unlockfile.c,v 1.1 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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
#include "stdio_headers.h"
#endif /* _STDIO_HEADERS_H */
/****************************************************************************/
int
__unlockfile(FILE *stream,int c)
{
funlockfile(stream);
return(c);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vasprintf.c,v 1.7 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_vasprintf.c,v 1.8 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -93,7 +93,8 @@ __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg)
local_buffer,sizeof(local_buffer),
-1,
-1,
IOBF_IN_USE | IOBF_WRITE | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL);
IOBF_IN_USE | IOBF_WRITE | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL,
NULL);
string_iob.iob_String = NULL;
string_iob.iob_StringSize = 0;

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vfprintf.c,v 1.11 2005-02-25 10:14:21 obarthel Exp $
* $Id: stdio_vfprintf.c,v 1.12 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -151,6 +151,11 @@ vfprintf(FILE * stream,const char * format, va_list arg)
assert( stream != NULL && format != NULL && arg != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL || format == NULL)
@ -1512,6 +1517,8 @@ vfprintf(FILE * stream,const char * format, va_list arg)
result = EOF;
}
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vfscanf.c,v 1.9 2005-02-21 10:22:01 obarthel Exp $
* $Id: stdio_vfscanf.c,v 1.10 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -88,6 +88,11 @@ __vfscanf(FILE *stream, const char *format, va_list arg)
assert( stream != NULL && format != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(stream);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(stream == NULL || format == NULL)
@ -1572,6 +1577,8 @@ __vfscanf(FILE *stream, const char *format, va_list arg)
out:
funlockfile(stream);
RETURN(result);
return(result);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vsnprintf.c,v 1.5 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_vsnprintf.c,v 1.6 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -83,7 +83,8 @@ vsnprintf(char *buffer,size_t size,const char *format,va_list arg)
local_buffer,sizeof(local_buffer),
-1,
-1,
IOBF_IN_USE | IOBF_WRITE | IOBF_NO_NUL | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL);
IOBF_IN_USE | IOBF_WRITE | IOBF_NO_NUL | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL,
NULL);
/* Store up to 'size-1' characters in the output buffer. This
does not include the terminating NUL character, which we

View File

@ -1,5 +1,5 @@
/*
* $Id: stdio_vsprintf.c,v 1.4 2005-02-20 13:19:40 obarthel Exp $
* $Id: stdio_vsprintf.c,v 1.5 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -70,7 +70,8 @@ vsprintf(char *s,const char *format,va_list arg)
buffer,sizeof(buffer),
-1,
-1,
IOBF_IN_USE | IOBF_WRITE | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL);
IOBF_IN_USE | IOBF_WRITE | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL,
NULL);
string_iob.iob_String = (STRPTR)s;

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib_headers.h,v 1.8 2005-02-25 10:14:21 obarthel Exp $
* $Id: stdlib_headers.h,v 1.9 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -194,7 +194,7 @@ struct MemoryTree
/****************************************************************************/
extern unsigned NOCOMMON __random_seed;
extern unsigned int NOCOMMON __random_seed;
/****************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib_rand.c,v 1.3 2005-01-02 09:07:18 obarthel Exp $
* $Id: stdlib_rand.c,v 1.4 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -37,34 +37,16 @@
/****************************************************************************/
/* Parameters of a pseudo-random-number generator from Knuth's
* "The Art of Computer Programming, Volume 2: Seminumerical
* Algorithms" (3rd edition), pp. 185-186.
*/
#define MM 2147483647 /* a Mersenne prime */
#define AA 48271 /* this does well in the spectral test */
#define QQ 44488 /* (long)(MM/AA) */
#define RR 3399 /* MM % AA; it is important that RR < QQ */
/****************************************************************************/
/* NOTE: for Knuth's algorithm below the seed must not be zero. */
unsigned __random_seed = 1;
unsigned int __random_seed = 1;
/****************************************************************************/
int
rand(void)
{
int X;
int result;
X = (int)__random_seed;
result = rand_r(&__random_seed);
X = AA * (X % QQ) - RR * (long)(X / QQ);
if(X < 0)
X += MM;
__random_seed = (unsigned)X;
return(X);
return(result);
}

67
library/stdlib_rand_r.c Normal file
View File

@ -0,0 +1,67 @@
/*
* $Id: stdlib_rand_r.c,v 1.1 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 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 _STDLIB_HEADERS_H
#include "stdlib_headers.h"
#endif /* _STDLIB_HEADERS_H */
/****************************************************************************/
/* Parameters of a pseudo-random-number generator from Knuth's
"The Art of Computer Programming, Volume 2: Seminumerical Algorithms"
(3rd edition), pp. 185-186. */
#define MM 2147483647 /* a Mersenne prime */
#define AA 48271 /* this does well in the spectral test */
#define QQ 44488 /* (long)(MM/AA) */
#define RR 3399 /* MM % AA; it is important that RR < QQ */
/****************************************************************************/
int
rand_r(unsigned int * seed)
{
int X;
X = (int)((*seed) & 0x7fffffff);
if(X == 0)
X = 1; /* NOTE: for Knuth's algorithm the seed must not be zero. */
X = AA * (X % QQ) - RR * (long)(X / QQ);
if(X < 0)
X += MM;
(*seed) = (unsigned int)X;
return(X);
}

View File

@ -1,5 +1,5 @@
/*
* $Id: stdlib_srand.c,v 1.2 2005-01-02 09:07:18 obarthel Exp $
* $Id: stdlib_srand.c,v 1.3 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -40,6 +40,5 @@
void
srand(unsigned seed)
{
/* We have to make sure that the seed is never zero. */
__random_seed = (seed & 0x7FFFFFFF) | 1;
__random_seed = seed;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: unistd_fileno.c,v 1.4 2005-02-03 16:56:17 obarthel Exp $
* $Id: unistd_fileno.c,v 1.5 2005-02-27 18:09:11 obarthel Exp $
*
* :ts=4
*
@ -59,6 +59,11 @@ fileno(FILE * file)
assert( file != NULL );
if(__check_abort_enabled)
__check_abort();
flockfile(file);
#if defined(CHECK_FOR_NULL_POINTERS)
{
if(file == NULL)
@ -71,9 +76,6 @@ fileno(FILE * file)
}
#endif /* CHECK_FOR_NULL_POINTERS */
if(__check_abort_enabled)
__check_abort();
assert( __is_valid_iob(iob) );
assert( FLAG_IS_SET(iob->iob_Flags,IOBF_IN_USE) );
@ -91,6 +93,8 @@ fileno(FILE * file)
out:
funlockfile(file);
RETURN(result);
return(result);
}