forked from KolibriOS/kolibrios
update CLib
git-svn-id: svn://kolibrios.org@614 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
92
programs/develop/open watcom/trunk/clib/streamio/allocfp.c
Normal file
92
programs/develop/open watcom/trunk/clib/streamio/allocfp.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent __allocfp() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "liballoc.h"
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
#define KEEP_FLAGS (_READ | _WRITE | _DYNAMIC)
|
||||
|
||||
FILE *__allocfp( int handle )
|
||||
{
|
||||
FILE *end;
|
||||
FILE *fp;
|
||||
__stream_link *link;
|
||||
unsigned flags;
|
||||
|
||||
handle = handle;
|
||||
_AccessIOB();
|
||||
/* Try and take one off the recently closed list */
|
||||
link = _RWD_cstream;
|
||||
if( link != NULL ) {
|
||||
_RWD_cstream = link->next;
|
||||
fp = link->stream;
|
||||
flags = (fp->_flag & KEEP_FLAGS) | (_READ | _WRITE);
|
||||
goto got_one;
|
||||
}
|
||||
/* See if there is a static FILE structure available. */
|
||||
end = &_RWD_iob[_NFILES];
|
||||
for( fp = _RWD_iob; fp < end; ++fp ) {
|
||||
if( (fp->_flag & (_READ | _WRITE)) == 0 ) {
|
||||
link = lib_malloc( sizeof( __stream_link ) );
|
||||
if( link == NULL )
|
||||
goto no_mem;
|
||||
flags = _READ | _WRITE;
|
||||
goto got_one;
|
||||
}
|
||||
}
|
||||
/* Allocate a new dynamic structure */
|
||||
flags = _DYNAMIC | _READ | _WRITE;
|
||||
link = lib_malloc( sizeof( __stream_link ) + sizeof( FILE ) );
|
||||
if( link == NULL )
|
||||
goto no_mem;
|
||||
fp = (FILE *)(link + 1);
|
||||
got_one:
|
||||
memset( fp, 0, sizeof( *fp ) );
|
||||
fp->_flag = flags;
|
||||
link->stream = fp;
|
||||
link->stream->_link = link; /* point back to link structure */
|
||||
link->next = _RWD_ostream;
|
||||
_RWD_ostream = link;
|
||||
_ReleaseIOB();
|
||||
return( fp );
|
||||
no_mem:
|
||||
__set_errno( ENOMEM );
|
||||
_ReleaseIOB();
|
||||
return( NULL ); /* no free slots */
|
||||
}
|
52
programs/develop/open watcom/trunk/clib/streamio/chktty.c
Normal file
52
programs/develop/open watcom/trunk/clib/streamio/chktty.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of chktty() - check if stream is teletype.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include "rtdata.h"
|
||||
#include "fileacc.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
void __chktty( FILE *fp )
|
||||
{
|
||||
/* if we have not determined that we've got a tty then check for one */
|
||||
if( !(fp->_flag & _ISTTY) ) {
|
||||
if( isatty( fileno( fp ) ) ) {
|
||||
fp->_flag |= _ISTTY;
|
||||
if( ( fp->_flag & (_IONBF | _IOLBF | _IOFBF) ) == 0 ) {
|
||||
fp->_flag |= _IOLBF;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
programs/develop/open watcom/trunk/clib/streamio/clearerr.c
Normal file
45
programs/develop/open watcom/trunk/clib/streamio/clearerr.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of clearerr() - clear stream error indicator.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "variety.h"
|
||||
#include "fileacc.h"
|
||||
|
||||
|
||||
_WCRTLINK void (clearerr)( FILE *fp )
|
||||
{
|
||||
__stream_check( fp, 0 );
|
||||
_ValidFile( fp, 0 );
|
||||
_AccessFile( fp );
|
||||
fp->_flag &= ~(_SFERR | _EOF);
|
||||
_ReleaseFile( fp );
|
||||
}
|
47
programs/develop/open watcom/trunk/clib/streamio/comtflag.c
Normal file
47
programs/develop/open watcom/trunk/clib/streamio/comtflag.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Commit mode state variable and accessor.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "commode.h"
|
||||
|
||||
|
||||
int _commode = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Before changing any of this, check startup/c/commode.c!
|
||||
*/
|
||||
|
||||
_WCRTLINK void _WCI86FAR __set_commode( void )
|
||||
{
|
||||
_commode = _COMMIT;
|
||||
}
|
35
programs/develop/open watcom/trunk/clib/streamio/dsetefg.c
Normal file
35
programs/develop/open watcom/trunk/clib/streamio/dsetefg.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: DLL version of setefg module.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
// this file should remain an indirected file
|
||||
// it is done this way to support the reuse of the source file
|
||||
#define __SW_BR
|
||||
#include "setefg.c"
|
122
programs/develop/open watcom/trunk/clib/streamio/fclose.c
Normal file
122
programs/develop/open watcom/trunk/clib/streamio/fclose.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent fclose() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "liballoc.h"
|
||||
#include "mf.h"
|
||||
#include <string.h>
|
||||
#include "fileacc.h"
|
||||
#include "tmpfname.h"
|
||||
#include "rtdata.h"
|
||||
#include "lseek.h"
|
||||
#include "streamio.h"
|
||||
#include "close.h"
|
||||
#include "flush.h"
|
||||
|
||||
|
||||
#ifndef __UNIX__
|
||||
void (*__RmTmpFileFn)( FILE *fp );
|
||||
#endif
|
||||
|
||||
|
||||
int __doclose( FILE *fp, int close_handle )
|
||||
{
|
||||
int ret;
|
||||
|
||||
if( fp->_flag == 0 ) {
|
||||
return( -1 ); /* file already closed */
|
||||
}
|
||||
ret = 0;
|
||||
if( fp->_flag & _DIRTY ) {
|
||||
ret = __flush( fp );
|
||||
}
|
||||
_AccessFile( fp );
|
||||
/*
|
||||
* 02-nov-92 G.Turcotte Syncronize buffer pointer with the file pointer
|
||||
* IEEE Std 1003.1-1988 B.8.2.3.2
|
||||
* 03-nov-03 B.Oldeman Inlined ftell; we already know the buffer isn't
|
||||
* dirty (because of the flush), so only a "get" applies
|
||||
*/
|
||||
if( fp->_cnt != 0 ) { /* if something in buffer */
|
||||
__lseek( fileno( fp ), -fp->_cnt, SEEK_CUR );
|
||||
}
|
||||
|
||||
if( close_handle ) {
|
||||
#if defined( __UNIX__ ) || defined( __NETWARE__ )
|
||||
// we don't get to implement the close function on these systems
|
||||
ret |= close( fileno( fp ) );
|
||||
#else
|
||||
ret |= __close( fileno( fp ) );
|
||||
#endif
|
||||
}
|
||||
if( fp->_flag & _BIGBUF ) { /* if we allocated the buffer */
|
||||
lib_free( _FP_BASE(fp) );
|
||||
_FP_BASE(fp) = NULL;
|
||||
}
|
||||
#ifndef __UNIX__
|
||||
/* this never happens under UNIX */
|
||||
if( fp->_flag & _TMPFIL ) { /* if this is a temporary file */
|
||||
__RmTmpFileFn( fp );
|
||||
}
|
||||
#endif
|
||||
_ReleaseFile( fp );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
int __shutdown_stream( FILE *fp, int close_handle )
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = __doclose( fp, close_handle );
|
||||
__freefp( fp );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
_WCRTLINK int fclose( FILE *fp )
|
||||
{
|
||||
__stream_link *link;
|
||||
|
||||
_AccessIOB();
|
||||
link = _RWD_ostream;
|
||||
for( ;; ) {
|
||||
if( link == NULL ) {
|
||||
_ReleaseIOB();
|
||||
return( -1 ); /* file not open */
|
||||
}
|
||||
if( link->stream == fp ) break;
|
||||
link = link->next;
|
||||
}
|
||||
_ReleaseIOB();
|
||||
return( __shutdown_stream( fp, 1 ) );
|
||||
}
|
144
programs/develop/open watcom/trunk/clib/streamio/fdopen.c
Normal file
144
programs/develop/open watcom/trunk/clib/streamio/fdopen.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent fdopen() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#ifdef __WIDECHAR__
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef __NT__
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "iomode.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
extern int __F_NAME(__open_flags,__wopen_flags)( const CHAR_TYPE *, int * );
|
||||
|
||||
|
||||
#ifndef __NETWARE__
|
||||
|
||||
static int __iomode( int handle, int amode )
|
||||
{
|
||||
int flags;
|
||||
int __errno;
|
||||
|
||||
#ifdef __UNIX__
|
||||
if( (flags = fcntl( handle, F_GETFL )) == -1 ) {
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
__errno = EOK;
|
||||
if( (flags & O_APPEND) && !(amode & _APPEND) ) {
|
||||
__errno = EACCES;
|
||||
}
|
||||
if( (flags & O_ACCMODE) == O_RDONLY ) {
|
||||
if( amode & _WRITE ) {
|
||||
__errno = EACCES;
|
||||
}
|
||||
} else if( (flags & O_ACCMODE) == O_WRONLY ) {
|
||||
if( amode & _READ ) {
|
||||
__errno = EACCES;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* make sure the handle has the same text/binary mode */
|
||||
flags = __GetIOMode( handle );
|
||||
__errno = 0;
|
||||
if( (amode ^ flags) & (_BINARY | _APPEND) ) {
|
||||
__errno = EACCES;
|
||||
}
|
||||
if( ( amode & _READ ) && !(flags & _READ) ) {
|
||||
__errno = EACCES;
|
||||
}
|
||||
if( ( amode & _WRITE ) && !(flags & _WRITE) ) {
|
||||
__errno = EACCES;
|
||||
}
|
||||
#endif
|
||||
if( __errno == EACCES ) {
|
||||
__set_errno( __errno );
|
||||
return( -1 );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
_WCRTLINK FILE *__F_NAME(fdopen,_wfdopen)( int handle, const CHAR_TYPE *access_mode )
|
||||
{
|
||||
unsigned flags;
|
||||
FILE *fp;
|
||||
int extflags;
|
||||
|
||||
if( handle == -1 ) {
|
||||
__set_errno( EBADF ); /* 5-dec-90 */
|
||||
return( NULL ); /* 19-apr-90 */
|
||||
}
|
||||
flags = __F_NAME(__open_flags,__wopen_flags)( access_mode, &extflags );
|
||||
if( flags == 0 ) return( NULL );
|
||||
|
||||
#ifndef __NETWARE__
|
||||
/* make sure the handle has the same text/binary mode */
|
||||
if( __iomode( handle, flags ) == -1 ) {
|
||||
return( NULL );
|
||||
}
|
||||
#endif
|
||||
fp = __allocfp( handle ); /* JBS 30-aug-91 */
|
||||
if( fp ) {
|
||||
fp->_flag &= ~(_READ | _WRITE); /* 2-dec-90 */
|
||||
fp->_flag |= flags;
|
||||
fp->_cnt = 0;
|
||||
_FP_BASE(fp) = NULL;
|
||||
fp->_bufsize = 0; /* was BUFSIZ JBS 91/05/31 */
|
||||
#ifndef __NETWARE__
|
||||
_FP_ORIENTATION(fp) = _NOT_ORIENTED; /* initial orientation */
|
||||
_FP_EXTFLAGS(fp) = extflags;
|
||||
#endif
|
||||
#if defined( __NT__ ) || defined( __OS2__ )
|
||||
_FP_PIPEDATA(fp).isPipe = 0; /* not a pipe */
|
||||
#endif
|
||||
fp->_handle = handle; /* BJS 91-07-23 */
|
||||
if( __F_NAME(tolower,towlower)( *access_mode ) == 'a' ) {
|
||||
fseek( fp, 0, SEEK_END );
|
||||
}
|
||||
__chktty( fp ); /* JBS 31-may-91 */
|
||||
#if !defined( __UNIX__ ) && !defined( __NETWARE__ )
|
||||
__SetIOMode( handle, flags );
|
||||
#endif
|
||||
}
|
||||
return( fp );
|
||||
}
|
41
programs/develop/open watcom/trunk/clib/streamio/feof.c
Normal file
41
programs/develop/open watcom/trunk/clib/streamio/feof.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of feof() - check for stream end-of-file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "fileacc.h"
|
||||
|
||||
|
||||
_WCRTLINK int (feof)( FILE *fp )
|
||||
{
|
||||
_ValidFile( fp, 0 );
|
||||
return( fp->_flag & _EOF );
|
||||
}
|
41
programs/develop/open watcom/trunk/clib/streamio/ferror.c
Normal file
41
programs/develop/open watcom/trunk/clib/streamio/ferror.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of ferror() - check for stream error.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "fileacc.h"
|
||||
|
||||
|
||||
_WCRTLINK int (ferror)( FILE *fp )
|
||||
{
|
||||
_ValidFile( fp, 0 );
|
||||
return( fp->_flag & _SFERR );
|
||||
}
|
48
programs/develop/open watcom/trunk/clib/streamio/fflush.c
Normal file
48
programs/develop/open watcom/trunk/clib/streamio/fflush.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fflush() - flush streams.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "rtdata.h"
|
||||
#include "fileacc.h"
|
||||
#include "flush.h"
|
||||
|
||||
_WCRTLINK int fflush( FILE *fp )
|
||||
{
|
||||
if( fp == NULL ) {
|
||||
flushall();
|
||||
return( 0 );
|
||||
}
|
||||
_ValidFile( fp, EOF );
|
||||
return( __flush( fp ) );
|
||||
}
|
227
programs/develop/open watcom/trunk/clib/streamio/fgetc.c
Normal file
227
programs/develop/open watcom/trunk/clib/streamio/fgetc.c
Normal file
@@ -0,0 +1,227 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent fgetc() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#ifndef __UNIX__
|
||||
#include <conio.h>
|
||||
#endif
|
||||
#include "fileacc.h"
|
||||
#include <errno.h>
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#ifdef __WIDECHAR__
|
||||
#include <mbstring.h>
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
#include "qread.h"
|
||||
#include "orient.h"
|
||||
#include "flush.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
#define DOS_EOF_CHAR 0x1a
|
||||
|
||||
#ifdef __WIDECHAR__
|
||||
#define CHARMASK 0xffff
|
||||
#else
|
||||
#define CHARMASK 0xff
|
||||
#endif
|
||||
|
||||
int __F_NAME(__fill_buffer,__wfill_buffer)( FILE *fp )
|
||||
{
|
||||
if( _FP_BASE(fp) == NULL ) {
|
||||
__ioalloc( fp );
|
||||
}
|
||||
if( fp->_flag & _ISTTY ) { /* 20-aug-90 */
|
||||
if( fp->_flag & (_IONBF | _IOLBF) ) {
|
||||
__flushall( _ISTTY ); /* flush all TTY output */
|
||||
}
|
||||
}
|
||||
fp->_flag &= ~_UNGET; /* 10-mar-90 */
|
||||
fp->_ptr = _FP_BASE(fp);
|
||||
#ifdef __UNIX__
|
||||
fp->_cnt = __qread( fileno( fp ), fp->_ptr,
|
||||
(fp->_flag & _IONBF) ? CHARSIZE : fp->_bufsize );
|
||||
#else
|
||||
if(( fp->_flag & (_IONBF | _ISTTY)) == (_IONBF | _ISTTY) &&
|
||||
( fileno( fp ) == STDIN_FILENO ))
|
||||
{
|
||||
int c; /* JBS 31-may-91 */
|
||||
|
||||
fp->_cnt = 0;
|
||||
// c = getche();
|
||||
if( c != EOF ) {
|
||||
*(CHAR_TYPE *)fp->_ptr = c;
|
||||
fp->_cnt = CHARSIZE;
|
||||
}
|
||||
} else {
|
||||
fp->_cnt = __qread( fileno( fp ), fp->_ptr,
|
||||
(fp->_flag & _IONBF) ? CHARSIZE : fp->_bufsize );
|
||||
}
|
||||
#endif
|
||||
if( fp->_cnt <= 0 ) {
|
||||
if( fp->_cnt == 0 ) {
|
||||
fp->_flag |= _EOF;
|
||||
} else {
|
||||
fp->_flag |= _SFERR;
|
||||
fp->_cnt = 0;
|
||||
}
|
||||
}
|
||||
return( fp->_cnt );
|
||||
}
|
||||
|
||||
int __F_NAME(__filbuf,__wfilbuf)( FILE *fp )
|
||||
{
|
||||
if( __F_NAME(__fill_buffer,__wfill_buffer)( fp ) == 0 ) {
|
||||
return( EOF );
|
||||
}
|
||||
else {
|
||||
fp->_cnt -= CHARSIZE;
|
||||
fp->_ptr += CHARSIZE;
|
||||
return( *(CHAR_TYPE *)(fp->_ptr - CHARSIZE) & CHARMASK );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef __WIDECHAR__
|
||||
|
||||
_WCRTLINK int fgetc( FILE *fp )
|
||||
{
|
||||
int c;
|
||||
|
||||
_ValidFile( fp, EOF );
|
||||
_AccessFile( fp );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(fp,EOF);
|
||||
|
||||
if( (fp->_flag & _READ) == 0 ) {
|
||||
__set_errno( EBADF );
|
||||
fp->_flag |= _SFERR;
|
||||
c = EOF;
|
||||
} else {
|
||||
fp->_cnt--;
|
||||
// it is important that this remain a relative comparison
|
||||
// to ensure that the getc() macro works properly
|
||||
if( fp->_cnt < 0 ) {
|
||||
c = __F_NAME(__filbuf,__wfilbuf)( fp );
|
||||
} else {
|
||||
c = *(char *)fp->_ptr;
|
||||
fp->_ptr++;
|
||||
}
|
||||
}
|
||||
#ifndef __UNIX__
|
||||
if( !(fp->_flag & _BINARY) ) {
|
||||
if( c == '\r' ) {
|
||||
fp->_cnt--;
|
||||
// it is important that this remain a relative comparison
|
||||
// to ensure that the getc() macro works properly
|
||||
if( fp->_cnt < 0 ) {
|
||||
c = __F_NAME(__filbuf,__wfilbuf)( fp );
|
||||
} else {
|
||||
c = *(CHAR_TYPE*)fp->_ptr & CHARMASK;
|
||||
fp->_ptr += CHARSIZE;
|
||||
}
|
||||
}
|
||||
if( c == DOS_EOF_CHAR ) {
|
||||
fp->_flag |= _EOF;
|
||||
c = EOF;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
_ReleaseFile( fp );
|
||||
return( c );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int __read_wide_char( FILE *fp, wchar_t *wc )
|
||||
/**************************************************/
|
||||
{
|
||||
if( fp->_flag & _BINARY ) {
|
||||
/*** Read a wide character ***/
|
||||
return( fread( wc, sizeof( wchar_t ), 1, fp ) );
|
||||
} else {
|
||||
char mbc[MB_CUR_MAX];
|
||||
wchar_t wcTemp;
|
||||
int rc;
|
||||
|
||||
/*** Read the multibyte character ***/
|
||||
if( !fread( &mbc[0], 1, 1, fp ) )
|
||||
return( 0 );
|
||||
|
||||
if( _ismbblead( mbc[0] ) ) {
|
||||
if( !fread( &mbc[1], 1, 1, fp ) )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*** Convert it to wide form ***/
|
||||
rc = mbtowc( &wcTemp, mbc, MB_CUR_MAX );
|
||||
if( rc >= 0 ) {
|
||||
*wc = wcTemp;
|
||||
return( 1 );
|
||||
} else {
|
||||
__set_errno( EILSEQ );
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_WCRTLINK wint_t fgetwc( FILE *fp )
|
||||
{
|
||||
wchar_t c;
|
||||
|
||||
_ValidFile( fp, WEOF );
|
||||
_AccessFile( fp );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(fp,WEOF);
|
||||
|
||||
/*** Read the character ***/
|
||||
if( !__read_wide_char( fp, &c ) ) {
|
||||
_ReleaseFile( fp );
|
||||
return( WEOF );
|
||||
}
|
||||
if( !(fp->_flag & _BINARY) && (c == L'\r') ) {
|
||||
if( !__read_wide_char( fp, &c ) ) {
|
||||
_ReleaseFile( fp );
|
||||
return( WEOF );
|
||||
}
|
||||
}
|
||||
|
||||
_ReleaseFile( fp );
|
||||
return( (wint_t)c );
|
||||
}
|
||||
|
||||
#endif
|
40
programs/develop/open watcom/trunk/clib/streamio/fgetchar.c
Normal file
40
programs/develop/open watcom/trunk/clib/streamio/fgetchar.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fgetchar() - read character from stdin.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK INTCHAR_TYPE __F_NAME(fgetchar,fgetwchar)( void )
|
||||
{
|
||||
return( __F_NAME(fgetc,fgetwc)( stdin ) );
|
||||
}
|
42
programs/develop/open watcom/trunk/clib/streamio/fgetpos.c
Normal file
42
programs/develop/open watcom/trunk/clib/streamio/fgetpos.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fgetpos() - return stream position.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "fileacc.h"
|
||||
|
||||
|
||||
_WCRTLINK int fgetpos( FILE *fp, fpos_t *pos )
|
||||
{
|
||||
_ValidFile( fp, -1 );
|
||||
*pos = ftell( fp );
|
||||
return( *pos == -1L );
|
||||
}
|
65
programs/develop/open watcom/trunk/clib/streamio/fgets.c
Normal file
65
programs/develop/open watcom/trunk/clib/streamio/fgets.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fgets() - read string from stream.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include "fileacc.h"
|
||||
|
||||
|
||||
_WCRTLINK CHAR_TYPE *__F_NAME(fgets,fgetws)( CHAR_TYPE *s, int n, FILE *fp )
|
||||
{
|
||||
INTCHAR_TYPE c;
|
||||
CHAR_TYPE *cs;
|
||||
unsigned oflag;
|
||||
|
||||
_ValidFile( fp, 0 );
|
||||
_AccessFile( fp );
|
||||
|
||||
oflag = fp->_flag & (_SFERR | _EOF); /* 06-sep-91 */
|
||||
fp->_flag &= ~(_SFERR | _EOF);
|
||||
cs = s;
|
||||
|
||||
/* don't use macro version of getc: multi-threading issues */
|
||||
while( (--n > 0) && (c = __F_NAME(fgetc,fgetwc)( fp )) != __F_NAME(EOF,WEOF) ) {
|
||||
if( (*cs++ = c) == __F_NAME('\n',L'\n') )
|
||||
break;
|
||||
}
|
||||
|
||||
if( c == __F_NAME(EOF,WEOF) && (cs == s || ferror( fp )) ) {
|
||||
s = NULL;
|
||||
} else {
|
||||
*cs = NULLCHAR;
|
||||
}
|
||||
fp->_flag |= oflag; /* 06-sep-91 */
|
||||
_ReleaseFile( fp );
|
||||
return( s );
|
||||
}
|
113
programs/develop/open watcom/trunk/clib/streamio/flush.c
Normal file
113
programs/develop/open watcom/trunk/clib/streamio/flush.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fflush() helper routine.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "qwrite.h"
|
||||
#include "lseek.h"
|
||||
#include "flush.h"
|
||||
|
||||
#if defined( __NETWARE__ ) && defined( _THIN_LIB )
|
||||
|
||||
/* Take flush from LibC */
|
||||
_WCRTLINK int __flush( FILE *fp )
|
||||
{
|
||||
return( fflush( fp ) );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
_WCRTLINK int __flush( FILE *fp )
|
||||
{
|
||||
int len;
|
||||
long offset;
|
||||
int ret;
|
||||
char *ptr;
|
||||
unsigned amount;
|
||||
|
||||
ret = 0;
|
||||
_AccessFile( fp );
|
||||
if( fp->_flag & _DIRTY ) {
|
||||
fp->_flag &= ~_DIRTY;
|
||||
if( (fp->_flag & _WRITE) && (_FP_BASE(fp) != NULL) ) {
|
||||
ptr = _FP_BASE(fp);
|
||||
amount = fp->_cnt;
|
||||
while( amount != 0 && ret == 0 ) {
|
||||
len = __qwrite( fileno( fp ), ptr, amount ); /* 02-aug-90 */
|
||||
if( len == -1 ) {
|
||||
fp->_flag |= _SFERR;
|
||||
ret = EOF;
|
||||
}
|
||||
#ifndef __UNIX__
|
||||
else if( len == 0 ) {
|
||||
__set_errno( ENOSPC ); /* 12-nov-88 */
|
||||
fp->_flag |= _SFERR;
|
||||
ret = EOF;
|
||||
}
|
||||
#endif
|
||||
ptr += len;
|
||||
amount -= len;
|
||||
}
|
||||
}
|
||||
} else if( _FP_BASE(fp) != NULL ) { /* not dirty */
|
||||
/* fseek( fp, ftell(fp), SEEK_SET ); */
|
||||
fp->_flag &= ~_EOF;
|
||||
if( !(fp->_flag & _ISTTY) ) {
|
||||
offset = fp->_cnt;
|
||||
if( offset != 0 ) { /* 10-aug-89 JD */
|
||||
offset = __lseek( fileno( fp ), -offset, SEEK_CUR );
|
||||
}
|
||||
if( offset == -1 ) {
|
||||
fp->_flag |= _SFERR;
|
||||
ret = EOF;
|
||||
}
|
||||
}
|
||||
}
|
||||
fp->_ptr = _FP_BASE(fp); /* reset ptr to start of buffer */
|
||||
fp->_cnt = 0;
|
||||
#if !defined( __NETWARE__ ) && !defined( __OSI__ )
|
||||
if( ret == 0 && (_FP_EXTFLAGS(fp) & _COMMIT) ) {
|
||||
if( fsync( fileno( fp ) ) == -1 ) {
|
||||
ret = EOF;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
_ReleaseFile( fp );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif
|
65
programs/develop/open watcom/trunk/clib/streamio/flushall.c
Normal file
65
programs/develop/open watcom/trunk/clib/streamio/flushall.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of flushall() - flush all streams.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "rtdata.h"
|
||||
#include "fileacc.h"
|
||||
#include "flush.h"
|
||||
|
||||
|
||||
/* __fill_buffer calls this routine with _ISTTY mask */
|
||||
|
||||
int __flushall( int mask )
|
||||
{
|
||||
__stream_link *link;
|
||||
FILE *fp;
|
||||
int number_of_open_files;
|
||||
|
||||
_AccessIOB();
|
||||
number_of_open_files = 0;
|
||||
for( link = _RWD_ostream; link != NULL; link = link->next ) {
|
||||
fp = link->stream;
|
||||
if( fp->_flag & mask ) { /* if file is a candidate */
|
||||
++number_of_open_files;
|
||||
if( fp->_flag & _DIRTY ) {
|
||||
__flush( fp );
|
||||
}
|
||||
}
|
||||
}
|
||||
_ReleaseIOB();
|
||||
return( number_of_open_files );
|
||||
}
|
||||
|
||||
_WCRTLINK int flushall( void )
|
||||
{
|
||||
return( __flushall( ~0 ) );
|
||||
}
|
33
programs/develop/open watcom/trunk/clib/streamio/fmode.h
Normal file
33
programs/develop/open watcom/trunk/clib/streamio/fmode.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/* define _fmode to be _fmode */
|
359
programs/develop/open watcom/trunk/clib/streamio/fopen.c
Normal file
359
programs/develop/open watcom/trunk/clib/streamio/fopen.c
Normal file
@@ -0,0 +1,359 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent fopen() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#ifdef __WIDECHAR__
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include "fileacc.h"
|
||||
#include "fmode.h"
|
||||
#include "openmode.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
//#include "defwin.h"
|
||||
#include "streamio.h"
|
||||
|
||||
#ifdef __UNIX__
|
||||
#define PMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
||||
#else
|
||||
#define PMODE (S_IREAD | S_IWRITE)
|
||||
#endif
|
||||
|
||||
|
||||
int __F_NAME(__open_flags,__wopen_flags)( const CHAR_TYPE *modestr, int *extflags )
|
||||
{
|
||||
int flags;
|
||||
int alive = 1;
|
||||
int gotplus = 0;
|
||||
int gottextbin = 0;
|
||||
#ifndef __NETWARE__
|
||||
int gotcommit = 0;
|
||||
#endif
|
||||
|
||||
flags = 0;
|
||||
if( extflags != NULL ) {
|
||||
#ifdef __NETWARE__
|
||||
*extflags = 0;
|
||||
#else
|
||||
if( _commode == _COMMIT ) {
|
||||
*extflags = _COMMIT;
|
||||
} else {
|
||||
*extflags = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* The first character in modestr must be 'r', 'w', or 'a'.
|
||||
*/
|
||||
switch( *modestr ) {
|
||||
case 'r':
|
||||
flags |= _READ;
|
||||
break;
|
||||
case 'w':
|
||||
flags |= _WRITE;
|
||||
break;
|
||||
case 'a':
|
||||
flags |= _WRITE | _APPEND;
|
||||
break;
|
||||
default:
|
||||
__set_errno( EINVAL );
|
||||
return( 0 );
|
||||
}
|
||||
modestr++;
|
||||
|
||||
/*
|
||||
* Next we might have, in any order, some additional mode modifier
|
||||
* characters:
|
||||
* 1. A '+' character.
|
||||
* 2. Either a 't' or a 'b'.
|
||||
* 3. Either a 'c' or a 'n'. (Not available for Netware.)
|
||||
* For MS compatability, scanning stops when any of the three groups
|
||||
* is encountered twice; e.g., "wct+b$&!" is valid and will result in
|
||||
* a text, not binary, stream. Also for MS compatability, scanning
|
||||
* stops at any unrecognized character, without causing failure.
|
||||
*/
|
||||
while( (*modestr != NULLCHAR) && alive ) {
|
||||
switch( *modestr ) {
|
||||
case '+':
|
||||
if( gotplus ) {
|
||||
alive = 0;
|
||||
} else {
|
||||
flags |= _READ | _WRITE;
|
||||
gotplus = 1;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if( gottextbin ) {
|
||||
alive = 0;
|
||||
} else {
|
||||
gottextbin = 1;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
if( gottextbin ) {
|
||||
alive = 0;
|
||||
} else {
|
||||
#ifndef __UNIX__
|
||||
flags |= _BINARY;
|
||||
#endif
|
||||
gottextbin = 1;
|
||||
}
|
||||
break;
|
||||
#ifndef __NETWARE__
|
||||
case 'c':
|
||||
if( gotcommit ) {
|
||||
alive = 0;
|
||||
} else {
|
||||
*extflags |= _COMMIT;
|
||||
gotcommit = 1;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if( gotcommit ) {
|
||||
alive = 0;
|
||||
} else {
|
||||
*extflags &= ~_COMMIT;
|
||||
gotcommit = 1;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
modestr++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle defaults for any unspecified options.
|
||||
*/
|
||||
#ifndef __UNIX__
|
||||
if( !gottextbin ) {
|
||||
if( _RWD_fmode == O_BINARY ) flags |= _BINARY;
|
||||
}
|
||||
#endif
|
||||
|
||||
return( flags );
|
||||
}
|
||||
|
||||
|
||||
static FILE *__F_NAME(__doopen,__wdoopen)( const CHAR_TYPE *name,
|
||||
CHAR_TYPE mode,
|
||||
int file_flags,
|
||||
int extflags,
|
||||
int shflag, /* sharing flag */
|
||||
FILE * fp )
|
||||
{
|
||||
int open_mode;
|
||||
int p_mode;
|
||||
|
||||
SetupTGCSandNCS( RETURN_ARG( FILE *, 0 ) ); /* for NW386 */
|
||||
fp->_flag &= ~(_READ | _WRITE);
|
||||
fp->_flag |= file_flags;
|
||||
|
||||
/* we need the mode character to indicate if the original */
|
||||
/* intention is to open for read or for write */
|
||||
mode = __F_NAME(tolower,towlower)( mode );
|
||||
if( mode == 'r' ) {
|
||||
open_mode = O_RDONLY;
|
||||
if( file_flags & _WRITE ) { /* if "r+" mode */
|
||||
open_mode = O_RDWR;
|
||||
}
|
||||
#if defined( __NETWARE__ )
|
||||
open_mode |= O_BINARY;
|
||||
#elif defined( __UNIX__ )
|
||||
#else
|
||||
if( file_flags & _BINARY ) {
|
||||
open_mode |= O_BINARY;
|
||||
} else {
|
||||
open_mode |= O_TEXT;
|
||||
}
|
||||
#endif
|
||||
p_mode = 0;
|
||||
} else { /* mode == 'w' || mode == 'a' */
|
||||
if( file_flags & _READ ) { /* if "a+" or "w+" mode */
|
||||
open_mode = O_RDWR | O_CREAT;
|
||||
} else {
|
||||
open_mode = O_WRONLY | O_CREAT;
|
||||
}
|
||||
if( file_flags & _APPEND ) {
|
||||
open_mode |= O_APPEND;
|
||||
} else { /* mode == 'w' */
|
||||
open_mode |= O_TRUNC;
|
||||
}
|
||||
#if defined( __NETWARE__ )
|
||||
open_mode |= O_BINARY;
|
||||
#elif defined( __UNIX__ )
|
||||
#else
|
||||
if( file_flags & _BINARY ) {
|
||||
open_mode |= O_BINARY;
|
||||
} else {
|
||||
open_mode |= O_TEXT;
|
||||
}
|
||||
#endif
|
||||
p_mode = PMODE;
|
||||
}
|
||||
fp->_handle = __F_NAME(sopen,_wsopen)( name, open_mode, shflag, p_mode );
|
||||
if( fp->_handle == -1 ) {
|
||||
// since we couldn't open the file, release the FILE struct
|
||||
__freefp( fp );
|
||||
return( NULL );
|
||||
}
|
||||
fp->_cnt = 0;
|
||||
fp->_bufsize = 0; /* was BUFSIZ JBS 31-may-91 */
|
||||
#ifndef __NETWARE__
|
||||
_FP_ORIENTATION(fp) = _NOT_ORIENTED; /* initial orientation */
|
||||
_FP_EXTFLAGS(fp) = extflags;
|
||||
#endif
|
||||
#if defined( __NT__ ) || defined( __OS2__ )
|
||||
_FP_PIPEDATA(fp).isPipe = 0; /* not a pipe */
|
||||
#endif
|
||||
_FP_BASE(fp) = NULL;
|
||||
if( file_flags & _APPEND ) {
|
||||
fseek( fp, 0L, SEEK_END );
|
||||
}
|
||||
__chktty( fp ); /* JBS 28-aug-90 */
|
||||
return( fp );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK FILE *__F_NAME(_fsopen,_wfsopen)( const CHAR_TYPE *name,
|
||||
const CHAR_TYPE *access_mode, int shflag )
|
||||
{
|
||||
FILE * fp;
|
||||
int file_flags;
|
||||
int extflags;
|
||||
|
||||
/* validate access_mode */
|
||||
file_flags = __F_NAME(__open_flags,__wopen_flags)( access_mode, &extflags );
|
||||
if( file_flags == 0 ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* specify dummy handle 0 */
|
||||
fp = __allocfp( 0 ); /* JBS 30-aug-91 */
|
||||
if( fp != NULL ) {
|
||||
fp = __F_NAME(__doopen,__wdoopen)( name, *access_mode,
|
||||
file_flags, extflags,
|
||||
shflag, fp );
|
||||
}
|
||||
return( fp );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK FILE *__F_NAME(fopen,_wfopen)( const CHAR_TYPE *name, const CHAR_TYPE *access_mode )
|
||||
{
|
||||
return( __F_NAME(_fsopen,_wfsopen)( name, access_mode, OPENMODE_DENY_COMPAT ) );
|
||||
}
|
||||
|
||||
static FILE *close_file( FILE *fp )
|
||||
{
|
||||
__stream_link * link;
|
||||
__stream_link **owner;
|
||||
|
||||
_AccessIOB();
|
||||
/* See if the file pointer is a currently open file. */
|
||||
link = _RWD_ostream;
|
||||
for( ;; ) {
|
||||
if( link == NULL ) break;
|
||||
if( link->stream == fp ) {
|
||||
if( fp->_flag & (_READ|_WRITE) ) {
|
||||
__doclose( fp, 1 );
|
||||
}
|
||||
_ReleaseIOB();
|
||||
return( fp );
|
||||
}
|
||||
link = link->next;
|
||||
}
|
||||
/*
|
||||
It's not on the list of open files, so check the list of
|
||||
recently closed ones.
|
||||
*/
|
||||
owner = &_RWD_cstream;
|
||||
for( ;; ) {
|
||||
link = *owner;
|
||||
if( link == NULL ) break;
|
||||
if( link->stream == fp ) {
|
||||
/* remove from closed list and put on open */
|
||||
*owner = link->next;
|
||||
link->next = _RWD_ostream;
|
||||
_RWD_ostream = link;
|
||||
_ReleaseIOB();
|
||||
return( fp );
|
||||
}
|
||||
owner = &link->next;
|
||||
}
|
||||
/* We ain't seen that file pointer ever. Leave things be. */
|
||||
__set_errno( EBADF );
|
||||
_ReleaseIOB();
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK FILE *__F_NAME(freopen,_wfreopen)( const CHAR_TYPE *name,
|
||||
const CHAR_TYPE *access_mode, FILE *fp )
|
||||
{
|
||||
int hdl;
|
||||
int file_flags;
|
||||
int extflags;
|
||||
|
||||
_ValidFile( fp, 0 );
|
||||
|
||||
/* validate access_mode */
|
||||
file_flags = __F_NAME(__open_flags,__wopen_flags)( access_mode, &extflags );
|
||||
if( file_flags == 0 ) {
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
hdl = fileno( fp );
|
||||
_AccessFileH( hdl );
|
||||
|
||||
#ifdef DEFAULT_WINDOWING
|
||||
if( _WindowsRemoveWindowedHandle != 0 ) {
|
||||
_WindowsRemoveWindowedHandle( hdl );
|
||||
}
|
||||
#endif
|
||||
fp = close_file( fp );
|
||||
if( fp != NULL ) {
|
||||
fp->_flag &= _DYNAMIC; /* 24-jul-92 */
|
||||
fp = __F_NAME(__doopen,__wdoopen)( name, *access_mode,
|
||||
file_flags, extflags,
|
||||
0, fp );
|
||||
}
|
||||
_ReleaseFileH( hdl );
|
||||
return( fp );
|
||||
}
|
89
programs/develop/open watcom/trunk/clib/streamio/fopen_s.c
Normal file
89
programs/develop/open watcom/trunk/clib/streamio/fopen_s.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fopen_s() - safe version of fopen().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#ifdef __WIDECHAR__
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
// #include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include "fileacc.h"
|
||||
#include "fmode.h"
|
||||
#include "openmode.h"
|
||||
#include "rtdata.h"
|
||||
// #include "seterrno.h"
|
||||
// #include "defwin.h"
|
||||
|
||||
|
||||
_WCRTLINK errno_t __F_NAME(fopen_s,_wfopen_s)( FILE * __restrict * __restrict streamptr,
|
||||
const CHAR_TYPE * __restrict filename,
|
||||
const CHAR_TYPE * __restrict mode)
|
||||
/**************************************************************************************/
|
||||
{
|
||||
errno_t rc = -1;
|
||||
const char *msg;
|
||||
|
||||
/* check for runtime-constraints */
|
||||
/* streamptr not null */
|
||||
/* filename not null */
|
||||
/* mode not null */
|
||||
if( __check_constraint_nullptr_msg( msg, streamptr ) &&
|
||||
__check_constraint_nullptr_msg( msg, filename ) &&
|
||||
__check_constraint_nullptr_msg( msg, mode ) ) {
|
||||
|
||||
/* ua.. and uw.. are treated as a.. and w.. */
|
||||
if( (*mode == __F_NAME('u',L'u')) &&
|
||||
( (*(mode + 1) == __F_NAME('r',L'r')) ||
|
||||
(*(mode + 1) == __F_NAME('w',L'w')) ||
|
||||
(*(mode + 1) == __F_NAME('a',L'a'))) ) {
|
||||
mode++; /* ignore u for now */
|
||||
}
|
||||
*streamptr = __F_NAME(_fsopen,_wfsopen)( filename, mode, OPENMODE_DENY_COMPAT );
|
||||
|
||||
if( *streamptr != NULL ) { /* if open ok set rc = 0 */
|
||||
rc = 0;
|
||||
}
|
||||
} else {
|
||||
/* Runtime-constraints found, store zero in streamptr */
|
||||
if( streamptr != NULL ) {
|
||||
*streamptr = NULL;
|
||||
}
|
||||
/* Now call the handler */
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
}
|
||||
return( rc );
|
||||
}
|
47
programs/develop/open watcom/trunk/clib/streamio/fprintf.c
Normal file
47
programs/develop/open watcom/trunk/clib/streamio/fprintf.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fprintf() - formatted stream output.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "farsupp.h"
|
||||
#include "printf.h"
|
||||
#include "fprtf.h"
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(fprintf,fwprintf)( FILE *io, const CHAR_TYPE *format, ... )
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return( __F_NAME(__fprtf,__fwprtf)( io, format, args ) );
|
||||
}
|
48
programs/develop/open watcom/trunk/clib/streamio/fprntf_s.c
Normal file
48
programs/develop/open watcom/trunk/clib/streamio/fprntf_s.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fprintf_s() - safe formatted stream output.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include "fprtf_s.h"
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(fprintf_s,fwprintf_s)( FILE * __restrict io,
|
||||
const CHAR_TYPE * __restrict format, ... )
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return( __F_NAME(__fprtf_s,__fwprtf_s)( io, format, args ) );
|
||||
}
|
99
programs/develop/open watcom/trunk/clib/streamio/fprtf.c
Normal file
99
programs/develop/open watcom/trunk/clib/streamio/fprtf.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of printf() - formatted output.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "rtdata.h"
|
||||
#include "fileacc.h"
|
||||
#include "printf.h"
|
||||
#include "fprtf.h"
|
||||
#include "orient.h"
|
||||
#include "flush.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
/*
|
||||
* file_putc -- write a character to a file
|
||||
*/
|
||||
static slib_callback_t file_putc; // setup calling convention
|
||||
static void __SLIB_CALLBACK file_putc( SPECS __SLIB *specs, int op_char )
|
||||
{
|
||||
__F_NAME(fputc,fputwc)( op_char, (FILE *)specs->_dest );
|
||||
specs->_output_count++;
|
||||
}
|
||||
|
||||
|
||||
int __F_NAME(__fprtf,__fwprtf)( FILE *fp, const CHAR_TYPE *format, va_list arg )
|
||||
{
|
||||
int not_buffered;
|
||||
int amount_written;
|
||||
unsigned oflag;
|
||||
slib_callback_t *tmp;
|
||||
|
||||
_ValidFile( fp, 0 );
|
||||
_AccessFile( fp );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(fp,0);
|
||||
|
||||
oflag = fp->_flag & (_SFERR | _EOF); /* 06-sep-91 */
|
||||
fp->_flag &= ~(_SFERR | _EOF);
|
||||
|
||||
if( _FP_BASE(fp) == NULL ) {
|
||||
__ioalloc( fp ); /* allocate buffer */
|
||||
}
|
||||
not_buffered = 0;
|
||||
if( fp->_flag & _IONBF ) {
|
||||
not_buffered = 1;
|
||||
fp->_flag &= ~_IONBF;
|
||||
fp->_flag |= _IOFBF;
|
||||
}
|
||||
#if defined( __386__ ) && defined( __QNX__ )
|
||||
/* avoid some segment relocations for 32-bit QNX */
|
||||
tmp = (void (*)())file_putc;
|
||||
#else
|
||||
tmp = file_putc;
|
||||
#endif
|
||||
amount_written = __F_NAME(__prtf,__wprtf)( fp, format, arg, tmp );
|
||||
if( not_buffered ) {
|
||||
fp->_flag &= ~_IOFBF;
|
||||
fp->_flag |= _IONBF;
|
||||
__flush( fp );
|
||||
}
|
||||
if( ferror( fp ) )
|
||||
amount_written = -1; /* 06-sep-91 */
|
||||
fp->_flag |= oflag;
|
||||
|
||||
_ReleaseFile( fp );
|
||||
return( amount_written );
|
||||
}
|
108
programs/develop/open watcom/trunk/clib/streamio/fprtf_s.c
Normal file
108
programs/develop/open watcom/trunk/clib/streamio/fprtf_s.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of __fprtf_s() - safe formatted output.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "rtdata.h"
|
||||
#include "fileacc.h"
|
||||
#include "printf.h"
|
||||
#include "fprtf_s.h"
|
||||
#include "orient.h"
|
||||
|
||||
extern void __ioalloc( FILE * );
|
||||
extern int __flush( FILE * );
|
||||
|
||||
|
||||
/*
|
||||
* file_putc -- write a character to a file
|
||||
*/
|
||||
static slib_callback_t file_putc; // setup calling convention
|
||||
static void __SLIB_CALLBACK file_putc( SPECS __SLIB *specs, int op_char )
|
||||
{
|
||||
__F_NAME(fputc,fputwc)( op_char, (FILE *)specs->_dest );
|
||||
specs->_output_count++;
|
||||
}
|
||||
|
||||
|
||||
int __F_NAME(__fprtf_s,__fwprtf_s)( FILE * __restrict stream,
|
||||
const CHAR_TYPE * __restrict format, va_list arg )
|
||||
{
|
||||
int not_buffered;
|
||||
int amount_written;
|
||||
unsigned oflag;
|
||||
const char *msg = NULL; /* doubles as error indicator */
|
||||
|
||||
/* Check for runtime-constraints before grabbing file lock */
|
||||
/* stream not null */
|
||||
/* format not null */
|
||||
if( __check_constraint_nullptr_msg( msg, stream ) &&
|
||||
__check_constraint_nullptr_msg( msg, format ) ) {
|
||||
|
||||
_ValidFile( stream, 0 );
|
||||
_AccessFile( stream );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(stream,0);
|
||||
|
||||
oflag = stream->_flag & (_SFERR | _EOF);
|
||||
stream->_flag &= ~(_SFERR | _EOF);
|
||||
|
||||
if( _FP_BASE(stream) == NULL ) {
|
||||
__ioalloc( stream ); /* allocate buffer */
|
||||
}
|
||||
not_buffered = 0;
|
||||
if( stream->_flag & _IONBF ) {
|
||||
not_buffered = 1;
|
||||
stream->_flag &= ~_IONBF;
|
||||
stream->_flag |= _IOFBF;
|
||||
}
|
||||
amount_written = __F_NAME(__prtf_s,__wprtf_s)( stream, format, arg, &msg, file_putc );
|
||||
if( not_buffered ) {
|
||||
stream->_flag &= ~_IOFBF;
|
||||
stream->_flag |= _IONBF;
|
||||
__flush( stream );
|
||||
}
|
||||
if( ferror( stream ) )
|
||||
amount_written = -1;
|
||||
stream->_flag |= oflag;
|
||||
|
||||
_ReleaseFile( stream );
|
||||
}
|
||||
if( msg != NULL ) {
|
||||
/* There was a constraint violation; call the handler */
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
amount_written = -1;
|
||||
}
|
||||
return( amount_written );
|
||||
}
|
32
programs/develop/open watcom/trunk/clib/streamio/fprtf_s.h
Normal file
32
programs/develop/open watcom/trunk/clib/streamio/fprtf_s.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Prototype for __fprtf_s() internal routine.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
extern int __F_NAME(__fprtf_s,__fwprtf_s)( FILE *fp, const CHAR_TYPE *format, va_list arg );
|
145
programs/develop/open watcom/trunk/clib/streamio/fputc.c
Normal file
145
programs/develop/open watcom/trunk/clib/streamio/fputc.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent fputc() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "orient.h"
|
||||
#ifdef __WIDECHAR__
|
||||
#include <mbstring.h>
|
||||
#include <wchar.h>
|
||||
#endif
|
||||
#include "flush.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
#ifndef __WIDECHAR__
|
||||
|
||||
_WCRTLINK int fputc( int c, FILE *fp )
|
||||
{
|
||||
int flags;
|
||||
|
||||
_ValidFile( fp, EOF );
|
||||
_AccessFile( fp );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(fp,EOF);
|
||||
|
||||
if( !(fp->_flag & _WRITE) ) {
|
||||
__set_errno( EBADF );
|
||||
fp->_flag |= _SFERR;
|
||||
_ReleaseFile( fp );
|
||||
return( EOF );
|
||||
}
|
||||
if( _FP_BASE(fp) == NULL ) {
|
||||
__ioalloc( fp );
|
||||
}
|
||||
flags = _IONBF;
|
||||
if( c == '\n' ) {
|
||||
flags = _IONBF | _IOLBF;
|
||||
#ifndef __UNIX__
|
||||
if( !(fp->_flag & _BINARY) ) {
|
||||
fp->_flag |= _DIRTY;
|
||||
*(char*)fp->_ptr = '\r'; /* '\n' -> '\r''\n' */
|
||||
fp->_ptr++;
|
||||
fp->_cnt++;
|
||||
if( fp->_cnt == fp->_bufsize ) {
|
||||
if( __flush( fp ) ) {
|
||||
_ReleaseFile( fp );
|
||||
return( EOF );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
fp->_flag |= _DIRTY;
|
||||
*(char *)fp->_ptr = c;
|
||||
fp->_ptr++;
|
||||
fp->_cnt++;
|
||||
if( (fp->_flag & flags) || (fp->_cnt == fp->_bufsize) ) {
|
||||
if( __flush( fp ) ) {
|
||||
_ReleaseFile( fp );
|
||||
return( EOF );
|
||||
}
|
||||
}
|
||||
_ReleaseFile( fp );
|
||||
return( (UCHAR_TYPE)c );
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
static int __write_wide_char( FILE *fp, wchar_t wc )
|
||||
/**************************************************/
|
||||
{
|
||||
if( fp->_flag & _BINARY ) {
|
||||
/*** Dump the wide character ***/
|
||||
return( fwrite( &wc, sizeof( wchar_t ), 1, fp ) );
|
||||
} else {
|
||||
char mbc[MB_CUR_MAX];
|
||||
int rc;
|
||||
|
||||
/*** Convert the wide character to multibyte form and write it ***/
|
||||
rc = wctomb( mbc, wc );
|
||||
if( rc > 0 ) {
|
||||
return( fwrite( mbc, rc, 1, fp ) );
|
||||
} else {
|
||||
__set_errno( EILSEQ );
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK wint_t fputwc( wint_t c, FILE *fp )
|
||||
{
|
||||
_ValidFile( fp, WEOF );
|
||||
_AccessFile( fp );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(fp,WEOF);
|
||||
|
||||
/*** Write the character ***/
|
||||
if( !__write_wide_char( fp, c ) ) {
|
||||
_ReleaseFile( fp );
|
||||
return( WEOF );
|
||||
} else {
|
||||
_ReleaseFile( fp );
|
||||
return( c );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
40
programs/develop/open watcom/trunk/clib/streamio/fputchar.c
Normal file
40
programs/develop/open watcom/trunk/clib/streamio/fputchar.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fputchar() - print character to stdout.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK INTCHAR_TYPE __F_NAME(fputchar,fputwchar)( INTCHAR_TYPE c )
|
||||
{
|
||||
return( __F_NAME(fputc,fputwc)( c, stdout ) );
|
||||
}
|
91
programs/develop/open watcom/trunk/clib/streamio/fputs.c
Normal file
91
programs/develop/open watcom/trunk/clib/streamio/fputs.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fputs() - put string to stream.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "flush.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(fputs,fputws)( const CHAR_TYPE *s, FILE *fp )
|
||||
{
|
||||
const CHAR_TYPE *start;
|
||||
int c;
|
||||
int not_buffered;
|
||||
int rc;
|
||||
|
||||
_ValidFile( fp, __F_NAME(EOF,WEOF) );
|
||||
_AccessFile( fp );
|
||||
|
||||
if( _FP_BASE(fp) == NULL ) {
|
||||
__ioalloc( fp ); /* allocate buffer */
|
||||
}
|
||||
not_buffered = 0;
|
||||
if( fp->_flag & _IONBF ) {
|
||||
not_buffered = 1;
|
||||
fp->_flag &= ~_IONBF;
|
||||
fp->_flag |= _IOLBF;
|
||||
}
|
||||
rc = 0;
|
||||
start = s;
|
||||
while( c = *s ) {
|
||||
s++;
|
||||
#ifndef __WIDECHAR__
|
||||
if( (fputc)( c, fp ) == EOF ) { /* 23-oct-91 */
|
||||
rc = EOF;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if( (fputwc)( c, fp ) == WEOF ) { /* 23-oct-91 */
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if( not_buffered ) {
|
||||
fp->_flag &= ~_IOLBF;
|
||||
fp->_flag |= _IONBF;
|
||||
if( rc == 0 ) {
|
||||
rc = __flush( fp ); /* 23-oct-91 */
|
||||
}
|
||||
}
|
||||
if( rc == 0 ) {
|
||||
/* return the number of items written */
|
||||
/* this is ok by ANSI which says that success is */
|
||||
/* indicated by a non-negative return value */
|
||||
rc = s - start;
|
||||
}
|
||||
_ReleaseFile( fp );
|
||||
return( rc );
|
||||
}
|
165
programs/develop/open watcom/trunk/clib/streamio/fread.c
Normal file
165
programs/develop/open watcom/trunk/clib/streamio/fread.c
Normal file
@@ -0,0 +1,165 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fread() - read data from stream.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "fileacc.h"
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "qread.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
#define DOS_EOF_CHAR 0x1a
|
||||
|
||||
extern int __fill_buffer( FILE * ); /* located in fgetc */
|
||||
|
||||
|
||||
_WCRTLINK size_t fread( void *_buf, size_t size, size_t n, FILE *fp )
|
||||
{
|
||||
char *buf = _buf;
|
||||
size_t len_read;
|
||||
|
||||
_ValidFile( fp, 0 );
|
||||
_AccessFile( fp );
|
||||
if( (fp->_flag & _READ) == 0 ) {
|
||||
__set_errno( EBADF );
|
||||
fp->_flag |= _SFERR;
|
||||
_ReleaseFile( fp );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*** If the buffer is _DIRTY, resync it before reading ***/
|
||||
if( fp->_flag & (_WRITE | _UNGET) ) {
|
||||
if( fp->_flag & _DIRTY ) {
|
||||
fseek( fp, 0, SEEK_CUR );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
n *= size;
|
||||
if( n == 0 ) {
|
||||
_ReleaseFile( fp );
|
||||
return( n );
|
||||
}
|
||||
if( _FP_BASE(fp) == NULL ) {
|
||||
__ioalloc( fp ); /* allocate buffer */
|
||||
}
|
||||
len_read = 0;
|
||||
#if !defined( __UNIX__ )
|
||||
if( fp->_flag & _BINARY )
|
||||
#endif
|
||||
{
|
||||
size_t bytes_left = n, bytes;
|
||||
for( ;; ) {
|
||||
if( fp->_cnt != 0 ) {
|
||||
bytes = fp->_cnt;
|
||||
if( bytes > bytes_left ) {
|
||||
bytes = bytes_left;
|
||||
}
|
||||
memcpy( buf, fp->_ptr, bytes );
|
||||
fp->_ptr += bytes;
|
||||
buf += bytes;
|
||||
fp->_cnt -= bytes;
|
||||
bytes_left -= bytes;
|
||||
len_read += bytes;
|
||||
}
|
||||
if( bytes_left == 0 ) break;
|
||||
|
||||
/* if user's buffer is larger than our buffer, OR
|
||||
_IONBF is set, then read directly into user's buffer. */
|
||||
|
||||
if( (bytes_left >= fp->_bufsize) || (fp->_flag & _IONBF) ) {
|
||||
bytes = bytes_left;
|
||||
fp->_ptr = _FP_BASE(fp);
|
||||
fp->_cnt = 0;
|
||||
if( !(fp->_flag & _IONBF) ) {
|
||||
/* if more than a sector, set to multiple of sector size*/
|
||||
if( bytes > 512 ) {
|
||||
bytes &= -512;
|
||||
}
|
||||
}
|
||||
n = __qread( fileno(fp), buf, bytes );
|
||||
if( n == -1 ) {
|
||||
fp->_flag |= _SFERR;
|
||||
break;
|
||||
} else if( n == 0 ) {
|
||||
fp->_flag |= _EOF;
|
||||
break;
|
||||
}
|
||||
buf += n;
|
||||
bytes_left -= n;
|
||||
len_read += n;
|
||||
} else {
|
||||
if( __fill_buffer( fp ) == 0 ) break;
|
||||
}
|
||||
} /* end for */
|
||||
#if !defined(__UNIX__)
|
||||
} else {
|
||||
for( ;; ) {
|
||||
int c;
|
||||
|
||||
// ensure non-empty buffer
|
||||
if( fp->_cnt == 0 ) {
|
||||
if( __fill_buffer( fp ) == 0 ) break;
|
||||
}
|
||||
// get character
|
||||
--fp->_cnt;
|
||||
c = *fp->_ptr++ & 0xff;
|
||||
// perform new-line translation
|
||||
if( c == '\r' ) {
|
||||
// ensure non-empty buffer
|
||||
if( fp->_cnt == 0 ) {
|
||||
if( __fill_buffer( fp ) == 0 ) break;
|
||||
}
|
||||
// get character
|
||||
--fp->_cnt;
|
||||
c = *fp->_ptr++ & 0xff;
|
||||
}
|
||||
// check for DOS end of file marker
|
||||
if( c == DOS_EOF_CHAR ) {
|
||||
fp->_flag |= _EOF;
|
||||
break;
|
||||
}
|
||||
// store chracter
|
||||
buf[len_read] = (char)c;
|
||||
++len_read;
|
||||
if( len_read == n ) break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
_ReleaseFile( fp );
|
||||
return( len_read / size );
|
||||
}
|
92
programs/develop/open watcom/trunk/clib/streamio/freefp.c
Normal file
92
programs/develop/open watcom/trunk/clib/streamio/freefp.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent __allocfp() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "liballoc.h"
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "streamio.h"
|
||||
|
||||
#ifdef DLHEAP
|
||||
|
||||
void _cdecl dlfree(void*);
|
||||
void _cdecl mf_init();
|
||||
|
||||
#define malloc dlmalloc
|
||||
#define free dlfree
|
||||
#define realloc dlrealloc
|
||||
|
||||
#define lib_free dlfree
|
||||
#endif
|
||||
|
||||
/*
|
||||
NOTE: This routine does not actually free the link/FILE structures.
|
||||
That is because code assumes that it can fclose the file and then
|
||||
freopen is a short time later. The __purgefp routine can be called
|
||||
to actually release the storage.
|
||||
*/
|
||||
|
||||
void __freefp( FILE * fp )
|
||||
{
|
||||
__stream_link **owner;
|
||||
__stream_link *link;
|
||||
|
||||
_AccessIOB();
|
||||
owner = &_RWD_ostream;
|
||||
for( ;; ) {
|
||||
link = *owner;
|
||||
if( link == NULL )
|
||||
return;
|
||||
if( link->stream == fp )
|
||||
break;
|
||||
owner = &link->next;
|
||||
}
|
||||
fp->_flag |= _READ | _WRITE;
|
||||
(*owner) = link->next;
|
||||
link->next = _RWD_cstream;
|
||||
_RWD_cstream = link;
|
||||
_ReleaseIOB();
|
||||
}
|
||||
|
||||
|
||||
void __purgefp( void )
|
||||
{
|
||||
__stream_link *next;
|
||||
|
||||
_AccessIOB();
|
||||
while( _RWD_cstream != NULL ) {
|
||||
next = _RWD_cstream->next;
|
||||
lib_free( _RWD_cstream );
|
||||
_RWD_cstream = next;
|
||||
}
|
||||
_ReleaseIOB();
|
||||
}
|
88
programs/develop/open watcom/trunk/clib/streamio/freop_s.c
Normal file
88
programs/develop/open watcom/trunk/clib/streamio/freop_s.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of freopen_s() - safe version of freopen().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#ifdef __WIDECHAR__
|
||||
#include <wctype.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include "fileacc.h"
|
||||
#include "fmode.h"
|
||||
#include "openmode.h"
|
||||
#include "rtdata.h"
|
||||
|
||||
|
||||
_WCRTLINK errno_t __F_NAME(freopen_s,_wfreopen_s)(
|
||||
FILE * __restrict * __restrict newstreamptr,
|
||||
const CHAR_TYPE * __restrict filename,
|
||||
const CHAR_TYPE * __restrict mode,
|
||||
FILE * __restrict stream )
|
||||
/********************************************************************/
|
||||
{
|
||||
errno_t rc = -1;
|
||||
const char *msg;
|
||||
|
||||
/* check for runtime-constraints */
|
||||
/* newstreamptr not null */
|
||||
/* mode not null */
|
||||
/* stream not null */
|
||||
if( __check_constraint_nullptr_msg( msg, newstreamptr ) &&
|
||||
__check_constraint_nullptr_msg( msg, mode ) &&
|
||||
__check_constraint_nullptr_msg( msg, stream ) ) {
|
||||
|
||||
/* ua.. and uw.. are treated as a.. and w.. */
|
||||
if( (*mode == __F_NAME('u',L'u')) &&
|
||||
( (*(mode + 1) == __F_NAME('r',L'r')) ||
|
||||
(*(mode + 1) == __F_NAME('w',L'w')) ||
|
||||
(*(mode + 1) == __F_NAME('a',L'a'))) ) {
|
||||
mode++; /* ignore u for now */
|
||||
}
|
||||
*newstreamptr = __F_NAME(freopen,_wfreopen)( filename, mode, stream );
|
||||
|
||||
if( *newstreamptr != NULL ) { /* if reopen ok set rc = 0 */
|
||||
rc = 0;
|
||||
}
|
||||
} else {
|
||||
/* Runtime-constraints found, store zero in newstreamptr */
|
||||
if( newstreamptr != NULL ) {
|
||||
*newstreamptr = NULL;
|
||||
}
|
||||
/* Now call the handler */
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
}
|
||||
return( rc );
|
||||
}
|
84
programs/develop/open watcom/trunk/clib/streamio/fscanf.c
Normal file
84
programs/develop/open watcom/trunk/clib/streamio/fscanf.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fscanf() - formatted stream input.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "rtdata.h"
|
||||
#include "scanf.h"
|
||||
#include "fileacc.h"
|
||||
#include "orient.h"
|
||||
|
||||
|
||||
static int cget_file( PTR_SCNF_SPECS specs )
|
||||
{
|
||||
int c;
|
||||
|
||||
if( (c = __F_NAME(getc,getwc)( (FILE *)specs->ptr )) == __F_NAME(EOF,WEOF) ) {
|
||||
specs->eoinp = 1;
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
|
||||
|
||||
static void uncget_file( int c, PTR_SCNF_SPECS specs )
|
||||
{
|
||||
__F_NAME(ungetc,ungetwc)( c, (FILE *)specs->ptr );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(vfscanf,vfwscanf)( FILE *io, const CHAR_TYPE *format, va_list args )
|
||||
{
|
||||
int rc;
|
||||
SCNF_SPECS specs;
|
||||
|
||||
_AccessFile( io );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(io,0);
|
||||
|
||||
specs.ptr = (CHAR_TYPE *)io;
|
||||
specs.cget_rtn = cget_file;
|
||||
specs.uncget_rtn = uncget_file;
|
||||
rc = __F_NAME(__scnf,__wscnf)( (PTR_SCNF_SPECS)&specs, format, args );
|
||||
_ReleaseFile( io );
|
||||
return( rc );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(fscanf,fwscanf)( FILE *io, const CHAR_TYPE *format, ... )
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return( __F_NAME(vfscanf,vfwscanf)( io, format, args ) );
|
||||
}
|
96
programs/develop/open watcom/trunk/clib/streamio/fscanf_s.c
Normal file
96
programs/develop/open watcom/trunk/clib/streamio/fscanf_s.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fscanf_s() - safe formatted stream input.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include "rtdata.h"
|
||||
#include "scanf.h"
|
||||
#include "fileacc.h"
|
||||
#include "orient.h"
|
||||
|
||||
|
||||
static int cget_file( PTR_SCNF_SPECS specs )
|
||||
{
|
||||
int c;
|
||||
|
||||
if( (c = __F_NAME(getc,getwc)( (FILE *)specs->ptr )) == __F_NAME(EOF,WEOF) ) {
|
||||
specs->eoinp = 1;
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
|
||||
|
||||
static void uncget_file( int c, PTR_SCNF_SPECS specs )
|
||||
{
|
||||
__F_NAME(ungetc,ungetwc)( c, (FILE *)specs->ptr );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(fscanf_s,fwscanf_s)( FILE * __restrict stream,
|
||||
const CHAR_TYPE * __restrict format, ... )
|
||||
{
|
||||
va_list arg;
|
||||
SCNF_SPECS specs;
|
||||
const char *msg;
|
||||
int rc;
|
||||
|
||||
/* Basic check for null pointers to see if we can continue */
|
||||
if( __check_constraint_nullptr_msg( msg, stream )
|
||||
&& __check_constraint_nullptr_msg( msg, format ) ) {
|
||||
|
||||
_AccessFile( stream );
|
||||
|
||||
/*** Deal with stream orientation ***/
|
||||
ORIENT_STREAM(stream,0);
|
||||
|
||||
specs.ptr = (CHAR_TYPE *)stream;
|
||||
specs.cget_rtn = cget_file;
|
||||
specs.uncget_rtn = uncget_file;
|
||||
msg = NULL;
|
||||
|
||||
va_start( arg, format );
|
||||
rc = __F_NAME(__scnf_s,__wscnf_s)( (PTR_SCNF_SPECS)&specs, format, &msg, arg );
|
||||
va_end( arg );
|
||||
|
||||
_ReleaseFile( stream );
|
||||
|
||||
if( msg == NULL ) {
|
||||
/* no rt-constraint violation inside worker routine */
|
||||
return( rc );
|
||||
}
|
||||
}
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
return( __F_NAME(EOF,WEOF) );
|
||||
}
|
157
programs/develop/open watcom/trunk/clib/streamio/fseek.c
Normal file
157
programs/develop/open watcom/trunk/clib/streamio/fseek.c
Normal file
@@ -0,0 +1,157 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fseek - set stream position.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "flush.h"
|
||||
|
||||
|
||||
static int __update_buffer( long diff, FILE *fp )
|
||||
{
|
||||
/*
|
||||
diff is relative to fp->_ptr
|
||||
if diff is within the buffer update the pointers and return 0
|
||||
otherwise update the pointers and return 1
|
||||
*/
|
||||
if( diff <= fp->_cnt && diff >= (_FP_BASE(fp) - fp->_ptr) ) {
|
||||
fp->_flag &= ~(_EOF);
|
||||
fp->_ptr += diff;
|
||||
fp->_cnt -= diff;
|
||||
return( 0 );
|
||||
}
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This used to be in __update_buffer(), but we don't want to do this until
|
||||
* AFTER we've made certain that lseek() will be a successful one.
|
||||
*/
|
||||
static void __reset_buffer( FILE *fp )
|
||||
{
|
||||
fp->_flag &= ~(_EOF);
|
||||
fp->_ptr = _FP_BASE(fp);
|
||||
fp->_cnt = 0;
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK int fseek( FILE *fp, long offset, int origin )
|
||||
{
|
||||
_ValidFile( fp, -1 );
|
||||
_AccessFile( fp );
|
||||
/*
|
||||
if the file is open for any sort of writing we must ensure that
|
||||
the buffer is flushed when dirty so that the integrity of the
|
||||
data is preserved.
|
||||
if there is an ungotten character in the buffer then the data must
|
||||
be discarded to ensure the integrity of the data
|
||||
*/
|
||||
if( fp->_flag & (_WRITE | _UNGET) ) {
|
||||
if( fp->_flag & _DIRTY ) {
|
||||
/*
|
||||
the __flush routine aligns the DOS file pointer with the
|
||||
start of the resulting cleared buffer, as such, the SEEK_CUR
|
||||
code used for the non-_DIRTY buffer case is not required
|
||||
*/
|
||||
if( __flush( fp ) ) {
|
||||
// assume __flush set the errno value
|
||||
// if erroneous input, override errno value
|
||||
if( origin == SEEK_SET && offset < 0 ) {
|
||||
__set_errno( EINVAL );
|
||||
}
|
||||
_ReleaseFile( fp );
|
||||
return( -1 );
|
||||
}
|
||||
} else {
|
||||
if( origin == SEEK_CUR ) {
|
||||
offset -= fp->_cnt;
|
||||
}
|
||||
fp->_ptr = _FP_BASE(fp);
|
||||
fp->_cnt = 0;
|
||||
}
|
||||
fp->_flag &= ~(_EOF|_UNGET);
|
||||
if( lseek( fileno( fp ), offset, origin ) == -1 ) {
|
||||
_ReleaseFile( fp );
|
||||
return( -1 );
|
||||
}
|
||||
} else {
|
||||
// file is open for read only,
|
||||
// no characters have been ungotten
|
||||
// the OS file pointer is at fp->_ptr + fp->_cnt relative to the
|
||||
// FILE* buffer
|
||||
switch( origin ) {
|
||||
case SEEK_CUR:
|
||||
{ long ptr_delta = fp->_cnt;
|
||||
|
||||
if( __update_buffer( offset, fp ) ) {
|
||||
offset -= ptr_delta;
|
||||
if( lseek( fileno( fp ), offset, origin ) == -1 ) {
|
||||
_ReleaseFile( fp );
|
||||
return( -1 );
|
||||
}
|
||||
__reset_buffer(fp);
|
||||
}
|
||||
} break;
|
||||
case SEEK_SET:
|
||||
{ long file_ptr = tell( fileno( fp ) );
|
||||
|
||||
file_ptr -= fp->_cnt;
|
||||
if( __update_buffer( offset - file_ptr, fp ) ) {
|
||||
if( lseek( fileno( fp ), offset, origin ) == -1 ) {
|
||||
_ReleaseFile( fp );
|
||||
return( -1 );
|
||||
}
|
||||
__reset_buffer(fp);
|
||||
}
|
||||
} break;
|
||||
case SEEK_END:
|
||||
fp->_flag &= ~(_EOF);
|
||||
fp->_ptr = _FP_BASE(fp);
|
||||
fp->_cnt = 0;
|
||||
if( lseek( fileno( fp ), offset, origin ) == -1 ) {
|
||||
_ReleaseFile( fp );
|
||||
return( -1 );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
__set_errno( EINVAL );
|
||||
_ReleaseFile( fp );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
_ReleaseFile( fp );
|
||||
return( 0 ); /* indicate success */
|
||||
}
|
39
programs/develop/open watcom/trunk/clib/streamio/fsetpos.c
Normal file
39
programs/develop/open watcom/trunk/clib/streamio/fsetpos.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of fsetpos() - set stream position.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK int fsetpos( FILE *fp, const fpos_t *pos )
|
||||
{
|
||||
return( fseek( fp, *pos, SEEK_SET ) );
|
||||
}
|
61
programs/develop/open watcom/trunk/clib/streamio/ftell.c
Normal file
61
programs/develop/open watcom/trunk/clib/streamio/ftell.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent ftell() implementaiton.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "fileacc.h"
|
||||
|
||||
|
||||
_WCRTLINK long ftell( FILE *fp )
|
||||
{
|
||||
long pos;
|
||||
|
||||
_ValidFile( fp, -1 );
|
||||
if( fp->_flag & _APPEND && fp->_flag & _DIRTY ) {
|
||||
fflush( fp ); /* if data written in append mode, OS must know */
|
||||
}
|
||||
pos = tell( fileno( fp ) );
|
||||
if( pos == -1 ) {
|
||||
return( -1L );
|
||||
}
|
||||
_AccessFile( fp );
|
||||
if( fp->_cnt != 0 ) { /* if something in buffer */
|
||||
if( fp->_flag & _DIRTY ) { /* last operation was a put */
|
||||
pos += fp->_cnt;
|
||||
} else { /* last operation was a get */
|
||||
pos -= fp->_cnt;
|
||||
}
|
||||
}
|
||||
_ReleaseFile( fp );
|
||||
return( pos );
|
||||
}
|
62
programs/develop/open watcom/trunk/clib/streamio/fwide.c
Normal file
62
programs/develop/open watcom/trunk/clib/streamio/fwide.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent fwide() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
|
||||
|
||||
_WCRTLINK int fwide( FILE *fp, int mode )
|
||||
{
|
||||
int new_mode;
|
||||
|
||||
_ValidFile( fp, EOF );
|
||||
_AccessFile( fp );
|
||||
|
||||
#ifndef __NETWARE__
|
||||
/* Set orientation if possible */
|
||||
if( mode > 0 && _FP_ORIENTATION(fp) == _NOT_ORIENTED )
|
||||
_FP_ORIENTATION(fp) = _WIDE_ORIENTED;
|
||||
else if( mode < 0 && _FP_ORIENTATION(fp) == _NOT_ORIENTED )
|
||||
_FP_ORIENTATION(fp) = _BYTE_ORIENTED;
|
||||
|
||||
/* Find out what the current orientation is */
|
||||
new_mode = _FP_ORIENTATION(fp) == _WIDE_ORIENTED ?
|
||||
1 : (_FP_ORIENTATION(fp) == _BYTE_ORIENTED ? -1 : 0);
|
||||
#else
|
||||
new_mode = 0;
|
||||
#endif
|
||||
|
||||
_ReleaseFile( fp );
|
||||
return( new_mode );
|
||||
}
|
161
programs/develop/open watcom/trunk/clib/streamio/fwrite.c
Normal file
161
programs/develop/open watcom/trunk/clib/streamio/fwrite.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent fwrite() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "qwrite.h"
|
||||
#include "flush.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
_WCRTLINK size_t fwrite( const void *buf, size_t size, size_t n, FILE *fp )
|
||||
{
|
||||
size_t count;
|
||||
unsigned oflag;
|
||||
|
||||
_ValidFile( fp, 0 );
|
||||
_AccessFile( fp );
|
||||
if( (fp->_flag & _WRITE) == 0 ) {
|
||||
__set_errno( EBADF );
|
||||
fp->_flag |= _SFERR;
|
||||
_ReleaseFile( fp );
|
||||
return( 0 ); /* POSIX says return 0 */
|
||||
}
|
||||
n *= size;
|
||||
if( n == 0 ) {
|
||||
_ReleaseFile( fp );
|
||||
return( n );
|
||||
}
|
||||
if( _FP_BASE(fp) == NULL ) {
|
||||
__ioalloc( fp ); /* allocate buffer */
|
||||
}
|
||||
oflag = fp->_flag & (_SFERR | _EOF); /* JBS 27-jan-92 */
|
||||
fp->_flag &= ~(_SFERR | _EOF); /* JBS 27-jan-92 */
|
||||
count = 0;
|
||||
#if !defined( __UNIX__ )
|
||||
if( fp->_flag & _BINARY ) { /* binary I/O */
|
||||
#else
|
||||
{
|
||||
#endif
|
||||
size_t bytes_left = n, bytes;
|
||||
|
||||
do {
|
||||
/* if our buffer is empty, and user's buffer is larger,
|
||||
then write directly from user's buffer. 28-apr-90 */
|
||||
|
||||
if( fp->_cnt == 0 && bytes_left >= fp->_bufsize ) {
|
||||
bytes = bytes_left & -512; /* multiple of 512 */
|
||||
if( bytes == 0 ) {
|
||||
bytes = bytes_left; /* bufsize < 512 */
|
||||
}
|
||||
n = __qwrite( fileno( fp ), buf, bytes );
|
||||
if( n == -1 ) {
|
||||
fp->_flag |= _SFERR;
|
||||
}
|
||||
#if !defined( __UNIX__ )
|
||||
else if( n == 0 ) {
|
||||
_RWD_errno = ENOSPC;
|
||||
fp->_flag |= _SFERR;
|
||||
}
|
||||
#endif
|
||||
bytes = n;
|
||||
} else {
|
||||
bytes = fp->_bufsize - fp->_cnt;
|
||||
if( bytes > bytes_left ) {
|
||||
bytes = bytes_left;
|
||||
}
|
||||
memcpy( fp->_ptr, buf, bytes );
|
||||
fp->_ptr += bytes;
|
||||
fp->_cnt += bytes;
|
||||
fp->_flag |= _DIRTY;
|
||||
if( (fp->_cnt == fp->_bufsize) || (fp->_flag & _IONBF) ) {
|
||||
__flush(fp);
|
||||
}
|
||||
}
|
||||
buf = ((const char *)buf) + bytes;
|
||||
count += bytes;
|
||||
bytes_left -= bytes;
|
||||
} while( bytes_left && !ferror( fp ) );
|
||||
#if !defined( __UNIX__ )
|
||||
} else { /* text I/O */
|
||||
const char *bufptr;
|
||||
int not_buffered;
|
||||
#ifndef __NETWARE__
|
||||
int old_orientation;
|
||||
#endif
|
||||
/* temporarily enable buffering saving the previous setting */
|
||||
not_buffered = 0;
|
||||
if( fp->_flag & _IONBF ) {
|
||||
not_buffered = 1;
|
||||
fp->_flag &= ~_IONBF;
|
||||
fp->_flag |= _IOFBF;
|
||||
}
|
||||
|
||||
/*** Use fputc, and make it think the stream is byte-oriented ***/
|
||||
#ifndef __NETWARE__
|
||||
old_orientation = _FP_ORIENTATION(fp);
|
||||
_FP_ORIENTATION(fp) = _BYTE_ORIENTED;
|
||||
#endif
|
||||
bufptr = (const char *)buf;
|
||||
do {
|
||||
fputc( *(bufptr++), fp );
|
||||
if( fp->_flag & (_EOF | _SFERR) ) break;
|
||||
++count;
|
||||
} while( count != n );
|
||||
#ifndef __NETWARE__
|
||||
_FP_ORIENTATION(fp) = old_orientation;
|
||||
#endif
|
||||
|
||||
if( not_buffered ) { /* if wasn't buffered, then reset */
|
||||
fp->_flag &= ~_IOFBF;
|
||||
fp->_flag |= _IONBF;
|
||||
__flush( fp );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if( fp->_flag & _SFERR ) {
|
||||
/*
|
||||
* Quantum 11-17-92 Temporary buffering confuses the return
|
||||
* value if the call is interrupted.
|
||||
* kludge: return 0 on error
|
||||
*/
|
||||
count = 0;
|
||||
}
|
||||
fp->_flag |= oflag; /* JBS 27-jan-92 */
|
||||
_ReleaseFile( fp );
|
||||
return( count / size );
|
||||
}
|
45
programs/develop/open watcom/trunk/clib/streamio/getc.c
Normal file
45
programs/develop/open watcom/trunk/clib/streamio/getc.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of getc() - read character from stream.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK INTCHAR_TYPE __F_NAME((getc),(getwc))( FILE *fp )
|
||||
{
|
||||
__stream_check( fp, 1 );
|
||||
#if !defined( __WIDECHAR__ ) && defined( getc )
|
||||
return( getc( fp ) );
|
||||
#else
|
||||
return( __F_NAME(fgetc,fgetwc)( fp ) );
|
||||
#endif
|
||||
}
|
46
programs/develop/open watcom/trunk/clib/streamio/getchar.c
Normal file
46
programs/develop/open watcom/trunk/clib/streamio/getchar.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of getchar() - read character from stdin.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#undef getchar
|
||||
|
||||
|
||||
_WCRTLINK INTCHAR_TYPE __F_NAME(getchar,getwchar)( void )
|
||||
{
|
||||
#ifdef getc
|
||||
return( __F_NAME(getc,getwc)( stdin ) );
|
||||
#else
|
||||
return( __F_NAME(fgetc,fgetwc)( stdin ) );
|
||||
#endif
|
||||
}
|
57
programs/develop/open watcom/trunk/clib/streamio/gets.c
Normal file
57
programs/develop/open watcom/trunk/clib/streamio/gets.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of gets() - read string from stdin.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK CHAR_TYPE *__F_NAME(gets,getws)( CHAR_TYPE *s )
|
||||
{
|
||||
INTCHAR_TYPE c;
|
||||
CHAR_TYPE *cs;
|
||||
unsigned oflag;
|
||||
|
||||
oflag = stdin->_flag & (_SFERR | _EOF); /* 06-sep-91 */
|
||||
stdin->_flag &= ~(_SFERR | _EOF);
|
||||
cs = s;
|
||||
while( (c = __F_NAME((getc),(getwc))( stdin )) != __F_NAME(EOF,WEOF)
|
||||
&& (c != __F_NAME('\n',L'\n')) ) {
|
||||
*cs++ = c;
|
||||
}
|
||||
if( c == __F_NAME(EOF,WEOF) && (cs == s || ferror( stdin )) ) {
|
||||
s = NULL;
|
||||
} else {
|
||||
*cs = NULLCHAR;
|
||||
}
|
||||
stdin->_flag |= oflag; /* 06-sep-91 */
|
||||
return( s );
|
||||
}
|
106
programs/develop/open watcom/trunk/clib/streamio/gets_s.c
Normal file
106
programs/develop/open watcom/trunk/clib/streamio/gets_s.c
Normal file
@@ -0,0 +1,106 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of gets_s().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
_WCRTLINK extern char *gets_s( char *s, rsize_t n )
|
||||
/*************************************************/
|
||||
{
|
||||
int c;
|
||||
char *cs;
|
||||
rsize_t len;
|
||||
unsigned oflag;
|
||||
|
||||
/* Check runtime constraint: s shall not be a null pointer */
|
||||
if( ! __check_constraint_nullptr( s ) ) {
|
||||
/* Just trigger the constraint handler if necessary */
|
||||
}
|
||||
|
||||
/* Check runtime constraint: n shall not be zero nor
|
||||
greater than RSIZE_MAX */
|
||||
if( ! __check_constraint_zero( n )
|
||||
|| ! __check_constraint_maxsize( n ) ) {
|
||||
n = 0;
|
||||
}
|
||||
|
||||
/* Filter out stream error and EOF status during this function */
|
||||
oflag = stdin->_flag & (_SFERR | _EOF);
|
||||
stdin->_flag &= ~(_SFERR | _EOF);
|
||||
|
||||
cs = s;
|
||||
len = n;
|
||||
|
||||
/*
|
||||
Read data until any of following conditions is met:
|
||||
- Received EOF
|
||||
- Read error
|
||||
- New line character received
|
||||
*/
|
||||
while( (c = getc( stdin )) != EOF
|
||||
&& (c != '\n') ) {
|
||||
if( cs && len ) {
|
||||
*cs++ = c;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Post-process runtime constraints, return NULL when catched */
|
||||
if( s == NULL || n == 0) {
|
||||
stdin->_flag |= oflag;
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* After this point, it is assumed that s is valid and
|
||||
contains at least one character */
|
||||
|
||||
/* Catch too small buffer and I/O error */
|
||||
if( ! __check_constraint_toosmall( s, len )
|
||||
|| ferror( stdin ) ) {
|
||||
stdin->_flag |= oflag;
|
||||
*s = 0;
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Restore stream error states if they were present previously */
|
||||
stdin->_flag |= oflag;
|
||||
|
||||
/* If we got EOF and didn't get any characters, return NULL */
|
||||
if( c == EOF && cs == s ) {
|
||||
*s = 0;
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/* Terminate string */
|
||||
*cs = 0;
|
||||
|
||||
return( s );
|
||||
}
|
47
programs/develop/open watcom/trunk/clib/streamio/getw.c
Normal file
47
programs/develop/open watcom/trunk/clib/streamio/getw.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent implementation of _getw().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK int _getw( FILE *fp )
|
||||
{
|
||||
int ch;
|
||||
size_t rc;
|
||||
|
||||
rc = fread( &ch, sizeof( int ), 1, fp );
|
||||
if( rc > 0 ) {
|
||||
return( ch );
|
||||
} else {
|
||||
return( EOF );
|
||||
}
|
||||
}
|
67
programs/develop/open watcom/trunk/clib/streamio/initfile.c
Normal file
67
programs/develop/open watcom/trunk/clib/streamio/initfile.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Stream I/O initializer.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
//#include "dll.h" // needs to be first
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "liballoc.h"
|
||||
#include "mf.h"
|
||||
#include "rtdata.h"
|
||||
#include "exitwmsg.h"
|
||||
|
||||
void __InitFiles( void )
|
||||
{
|
||||
__stream_link *link;
|
||||
FILE *fp;
|
||||
|
||||
fp = _RWD_iob;
|
||||
|
||||
stderr->_flag &= ~(_IONBF | _IOLBF | _IOFBF);
|
||||
stderr->_flag |= _IONBF;
|
||||
for( fp = _RWD_iob; fp->_flag != 0; ++fp )
|
||||
{
|
||||
link = lib_malloc( sizeof( __stream_link ) );
|
||||
if( link == NULL )
|
||||
{
|
||||
__fatal_runtime_error(
|
||||
"Not enough memory to allocate file structures\r\n", 1 );
|
||||
}
|
||||
link->stream = fp;
|
||||
link->next = _RWD_ostream;
|
||||
_RWD_ostream = link;
|
||||
fp->_link = link;
|
||||
fp->_link->_base = NULL;
|
||||
fp->_link->_tmpfchar = 0;
|
||||
fp->_link->_orientation = _NOT_ORIENTED;
|
||||
}
|
||||
_RWD_cstream = NULL;
|
||||
}
|
68
programs/develop/open watcom/trunk/clib/streamio/ioalloc.c
Normal file
68
programs/develop/open watcom/trunk/clib/streamio/ioalloc.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent __ioalloc() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "liballoc.h"
|
||||
#include <unistd.h>
|
||||
#include "rtdata.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
void __ioalloc( FILE *fp )
|
||||
{
|
||||
__chktty( fp ); /* JBS 28-aug-90 */
|
||||
if( fp->_bufsize == 0 ) {
|
||||
if( fp->_flag & _IOLBF ) {
|
||||
fp->_bufsize = 134;
|
||||
} else if( fp->_flag & _IONBF ) {
|
||||
/* Use small but reasonably sized buffer; otherwise we will end
|
||||
* up calling into the OS for every character, completely killing
|
||||
* performance on unbuffered stream output through printf() etc.,
|
||||
* especially in extended DOS because of mode switches.
|
||||
*/
|
||||
fp->_bufsize = 64;
|
||||
} else {
|
||||
fp->_bufsize = BUFSIZ;
|
||||
}
|
||||
}
|
||||
_FP_BASE(fp) = lib_malloc( fp->_bufsize );
|
||||
if( _FP_BASE(fp) == NULL ) {
|
||||
fp->_flag &= ~(_IONBF | _IOLBF | _IOFBF);
|
||||
fp->_flag |= _IONBF; /* can't get big buffer */
|
||||
_FP_BASE(fp) = (char *)&(fp->_ungotten);
|
||||
fp->_bufsize = 1;
|
||||
} else {
|
||||
fp->_flag |= _BIGBUF; /* got big buffer */
|
||||
}
|
||||
fp->_ptr = _FP_BASE(fp);
|
||||
fp->_cnt = 0;
|
||||
}
|
62
programs/develop/open watcom/trunk/clib/streamio/iob.c
Normal file
62
programs/develop/open watcom/trunk/clib/streamio/iob.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Definition of __iob array.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include "rtdata.h"
|
||||
#include "rtinit.h"
|
||||
#include "tmpfname.h"
|
||||
|
||||
|
||||
_WCRTLINKD FILE _WCNEAR __iob[_NFILES] = {
|
||||
{ NULL, 0, NULL, _READ, 0, 0, 0 } /* stdin */
|
||||
,{ NULL, 0, NULL, _WRITE, 1, 0, 0 } /* stdout */
|
||||
,{ NULL, 0, NULL, _WRITE, 2, 0, 0 } /* stderr */
|
||||
#if defined( __DOS__ ) || defined( __WINDOWS__ ) || defined( __OSI__ )
|
||||
,{ NULL, 0, NULL, _READ|_WRITE, 3, 0, 0 } /* stdaux */
|
||||
,{ NULL, 0, NULL, _WRITE, 4, 0, 0 } /* stdprn */
|
||||
#endif
|
||||
};
|
||||
|
||||
__stream_link *__ClosedStreams;
|
||||
__stream_link *__OpenStreams;
|
||||
|
||||
#if !defined( __UNIX__ )
|
||||
_WCRTLINKD int _WCNEAR _fmode = O_TEXT; /* default file translation mode */
|
||||
#endif
|
||||
|
||||
extern void __InitFiles();
|
||||
extern void __full_io_exit();
|
||||
|
||||
AXI(__InitFiles,INIT_PRIORITY_LIBRARY);
|
||||
AYI(__full_io_exit,INIT_PRIORITY_LIBRARY);
|
140
programs/develop/open watcom/trunk/clib/streamio/iobaddr.c
Normal file
140
programs/develop/open watcom/trunk/clib/streamio/iobaddr.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Standard stream/file accessor routines.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "rtdata.h"
|
||||
|
||||
|
||||
#if !defined( __NETWARE__ ) && !defined( _THIN_LIB )
|
||||
|
||||
_WCRTLINK FILE *__get_std_stream( unsigned handle )
|
||||
{
|
||||
if( handle > NUM_STD_STREAMS ) {
|
||||
return( NULL );
|
||||
} else {
|
||||
return( &_RWD_iob[handle] );
|
||||
}
|
||||
}
|
||||
|
||||
_WCRTLINK FILE *__get_std_file( unsigned handle )
|
||||
{
|
||||
return( __get_std_stream( handle ) );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <io.h>
|
||||
|
||||
#if defined( _NETWARE_LIBC )
|
||||
extern FILE **___stdin ( void );
|
||||
extern FILE **___stdout( void );
|
||||
extern FILE **___stderr( void );
|
||||
extern FILE **___cin ( void );
|
||||
extern FILE **___cout ( void );
|
||||
|
||||
_WCRTLINK FILE *__get_std_stream( unsigned handle )
|
||||
{
|
||||
FILE *pFile = NULL;
|
||||
|
||||
switch( handle ) {
|
||||
case STDIN_FILENO:
|
||||
pFile = *___stdin();
|
||||
break;
|
||||
case STDOUT_FILENO:
|
||||
pFile = *___stdout();
|
||||
break;
|
||||
case STDERR_FILENO:
|
||||
pFile = *___stderr();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return( pFile );
|
||||
}
|
||||
#elif defined( _NETWARE_CLIB )
|
||||
extern FILE **__get_stdin ( void );
|
||||
extern FILE **__get_stdout( void );
|
||||
extern FILE **__get_stderr( void );
|
||||
|
||||
_WCRTLINK FILE *__get_std_stream( unsigned handle )
|
||||
{
|
||||
FILE *pFile = NULL;
|
||||
|
||||
switch( handle ) {
|
||||
case STDIN_FILENO:
|
||||
pFile = *__get_stdin();
|
||||
break;
|
||||
case STDOUT_FILENO:
|
||||
pFile = *__get_stdout();
|
||||
break;
|
||||
case STDERR_FILENO:
|
||||
pFile = *__get_stderr();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return( pFile );
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined( __NETWARE__ ) && !defined( _THIN_LIB )
|
||||
|
||||
#include <io.h>
|
||||
|
||||
FILE **__get_stdin( void )
|
||||
{
|
||||
static FILE *stdin_ptr;
|
||||
|
||||
stdin_ptr = __get_std_stream( STDIN_FILENO );
|
||||
return( &stdin_ptr );
|
||||
}
|
||||
|
||||
FILE **__get_stdout( void )
|
||||
{
|
||||
static FILE *stdout_ptr;
|
||||
|
||||
stdout_ptr = __get_std_stream( STDOUT_FILENO );
|
||||
return( &stdout_ptr );
|
||||
}
|
||||
|
||||
FILE **__get_stderr( void )
|
||||
{
|
||||
static FILE *stderr_ptr;
|
||||
|
||||
stderr_ptr = __get_std_stream( STDERR_FILENO );
|
||||
return( &stderr_ptr );
|
||||
}
|
||||
|
||||
#endif
|
40
programs/develop/open watcom/trunk/clib/streamio/iobptr.c
Normal file
40
programs/develop/open watcom/trunk/clib/streamio/iobptr.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Accessor function for __iob array.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "rtdata.h"
|
||||
|
||||
|
||||
_WCRTLINK FILE (*__get_iob_ptr( void ))[]
|
||||
{
|
||||
return( &__iob );
|
||||
}
|
46
programs/develop/open watcom/trunk/clib/streamio/noefgfmt.c
Normal file
46
programs/develop/open watcom/trunk/clib/streamio/noefgfmt.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Dummy floating-point formatting routines.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "rtdata.h"
|
||||
#include "exitwmsg.h"
|
||||
#include "ftos.h"
|
||||
#include "farsupp.h"
|
||||
|
||||
|
||||
static void _no_support_loaded( void )
|
||||
{
|
||||
__fatal_runtime_error( "Floating-point support not loaded\r\n", 1 );
|
||||
}
|
||||
|
||||
_WCRTLINK FAR_STRING (*__EFG_printf)() = (FAR_STRING (*)())_no_support_loaded;
|
||||
_WCRTLINK void (*__EFG_scanf)() = _no_support_loaded;
|
51
programs/develop/open watcom/trunk/clib/streamio/perror.c
Normal file
51
programs/develop/open watcom/trunk/clib/streamio/perror.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of perror() - print error message.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
|
||||
|
||||
_WCRTLINK void __F_NAME(perror,_wperror)( const CHAR_TYPE *s )
|
||||
{
|
||||
__null_check( s, 0 );
|
||||
if( s != NULL && *s != '\0' ) {
|
||||
__F_NAME(fputs,fputws)( s, stderr );
|
||||
__F_NAME(fputs,fputws)( __F_NAME(": ",L": "), stderr );
|
||||
}
|
||||
__F_NAME(fputs,fputws)( __F_NAME(strerror,wcserror)( _RWD_errno ), stderr );
|
||||
__F_NAME(fputc,fputwc)( '\n', stderr );
|
||||
}
|
73
programs/develop/open watcom/trunk/clib/streamio/printf.c
Normal file
73
programs/develop/open watcom/trunk/clib/streamio/printf.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of printf() - formatted output.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "farsupp.h"
|
||||
#include "printf.h"
|
||||
#include "fprtf.h"
|
||||
|
||||
void debug_out_str(const char* str);
|
||||
void _stdcall debug_out(int ch);
|
||||
|
||||
static char _dest[512];
|
||||
|
||||
_WCRTLINK int __F_NAME(printf,wprintf)( const CHAR_TYPE *format, ... )
|
||||
{
|
||||
int retval;
|
||||
auto va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
// return( __F_NAME(__fprtf,__fwprtf)( stdout, format, args ) );
|
||||
|
||||
va_start( args, format );
|
||||
#ifdef __WIDECHAR__
|
||||
retval = _vswprintf( _dest, format, args );
|
||||
#else
|
||||
retval = vsprintf( _dest, format, args );
|
||||
#endif
|
||||
debug_out_str(_dest);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void debug_out_str(const char* str)
|
||||
{
|
||||
while (*str != 0)
|
||||
{
|
||||
debug_out(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
47
programs/develop/open watcom/trunk/clib/streamio/printf_s.c
Normal file
47
programs/develop/open watcom/trunk/clib/streamio/printf_s.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of printf_s() - safe formatted output.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include "fprtf_s.h"
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(printf_s,wprintf_s)( const CHAR_TYPE * __restrict format, ... )
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return( __F_NAME(__fprtf_s,__fwprtf_s)( stdout, format, args ) );
|
||||
}
|
1100
programs/develop/open watcom/trunk/clib/streamio/prtf.c
Normal file
1100
programs/develop/open watcom/trunk/clib/streamio/prtf.c
Normal file
File diff suppressed because it is too large
Load Diff
35
programs/develop/open watcom/trunk/clib/streamio/prtf_s.c
Normal file
35
programs/develop/open watcom/trunk/clib/streamio/prtf_s.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Safe version of __prtf_s() worker routine.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
// this file should remain an indirected file
|
||||
// it is done this way to support the reuse of the source file
|
||||
#define SAFE_PRINTF
|
||||
#include "prtf.c"
|
45
programs/develop/open watcom/trunk/clib/streamio/putc.c
Normal file
45
programs/develop/open watcom/trunk/clib/streamio/putc.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent implementation of putc().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK INTCHAR_TYPE __F_NAME((putc),putwc)( INTCHAR_TYPE c, FILE *fp )
|
||||
{
|
||||
__stream_check( fp, 2 );
|
||||
#if !defined( __WIDECHAR__ ) && defined( putc )
|
||||
return( putc( c, fp ) );
|
||||
#else
|
||||
return( __F_NAME(fputc,fputwc)( c, fp ) );
|
||||
#endif
|
||||
}
|
45
programs/develop/open watcom/trunk/clib/streamio/putchar.c
Normal file
45
programs/develop/open watcom/trunk/clib/streamio/putchar.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent implementation of putchar().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#undef putchar
|
||||
|
||||
_WCRTLINK INTCHAR_TYPE __F_NAME(putchar,putwchar)( INTCHAR_TYPE c )
|
||||
{
|
||||
#ifdef putc
|
||||
return( __F_NAME(putc,putwc)( c, stdout ) );
|
||||
#else
|
||||
return( __F_NAME(fputc,fputwc)( c, stdout ) );
|
||||
#endif
|
||||
}
|
53
programs/develop/open watcom/trunk/clib/streamio/puts.c
Normal file
53
programs/develop/open watcom/trunk/clib/streamio/puts.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of puts() - put string to stdout.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(puts,putws)( const CHAR_TYPE *s )
|
||||
{
|
||||
INTCHAR_TYPE rc;
|
||||
wint_t result;
|
||||
|
||||
rc = __F_NAME(fputs,fputws)( s, stdout );
|
||||
if( rc != __F_NAME(EOF,WEOF) ) {
|
||||
/* don't use macro version of putc: multi-threading issues */
|
||||
result = __F_NAME(fputc,fputwc)( __F_NAME('\n',L'\n'), stdout );
|
||||
if( result == __F_NAME('\n',L'\n') ) {
|
||||
rc++;
|
||||
} else {
|
||||
rc = result;
|
||||
}
|
||||
}
|
||||
return( rc );
|
||||
}
|
46
programs/develop/open watcom/trunk/clib/streamio/putw.c
Normal file
46
programs/develop/open watcom/trunk/clib/streamio/putw.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent implementation of _putw().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK int _putw( int binint, FILE *fp )
|
||||
{
|
||||
size_t rc;
|
||||
|
||||
rc = fwrite( &binint, sizeof( int ), 1, fp );
|
||||
if( rc > 0 ) {
|
||||
return( binint );
|
||||
} else {
|
||||
return( EOF );
|
||||
}
|
||||
}
|
36
programs/develop/open watcom/trunk/clib/streamio/qread.h
Normal file
36
programs/develop/open watcom/trunk/clib/streamio/qread.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Prototype for __qread() internal helper.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifdef __NETWARE__
|
||||
#define __qread( h, b, l ) read( h, b, l )
|
||||
#else
|
||||
extern int __qread( int handle, void *buffer, unsigned len );
|
||||
#endif
|
36
programs/develop/open watcom/trunk/clib/streamio/qwrite.h
Normal file
36
programs/develop/open watcom/trunk/clib/streamio/qwrite.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Prototype for __qwrite() internal helper.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifdef __NETWARE__
|
||||
#define __qwrite( h, b, l ) write( h, (void *)b, l )
|
||||
#else
|
||||
extern int __qwrite( int, const void *, unsigned );
|
||||
#endif
|
41
programs/develop/open watcom/trunk/clib/streamio/rewind.c
Normal file
41
programs/develop/open watcom/trunk/clib/streamio/rewind.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent implementation of rewind().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK void rewind( FILE *fp )
|
||||
{
|
||||
__stream_check( fp, 0 );
|
||||
clearerr( fp );
|
||||
fseek( fp, 0, SEEK_SET );
|
||||
}
|
72
programs/develop/open watcom/trunk/clib/streamio/scanf.c
Normal file
72
programs/develop/open watcom/trunk/clib/streamio/scanf.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent implementation of scanf() and vscanf().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "scanf.h"
|
||||
|
||||
|
||||
static int cget_stdin( PTR_SCNF_SPECS specs )
|
||||
{
|
||||
int c;
|
||||
|
||||
if( (c = __F_NAME(getc,getwc)( stdin )) == __F_NAME(EOF,WEOF) ) {
|
||||
specs->eoinp = 1;
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
|
||||
|
||||
static void uncget_stdin( int c, PTR_SCNF_SPECS specs )
|
||||
{
|
||||
__F_NAME(ungetc,ungetwc)( c, stdin );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(vscanf,vwscanf)( const CHAR_TYPE *format, va_list args )
|
||||
{
|
||||
SCNF_SPECS specs;
|
||||
|
||||
specs.cget_rtn = cget_stdin;
|
||||
specs.uncget_rtn = uncget_stdin;
|
||||
return( __F_NAME(__scnf,__wscnf)( (PTR_SCNF_SPECS)&specs, format, args ) );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(scanf,wscanf)( const CHAR_TYPE *format, ... )
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start( args, format );
|
||||
return( __F_NAME(vscanf,vwscanf)( format, args ) );
|
||||
}
|
81
programs/develop/open watcom/trunk/clib/streamio/scanf_s.c
Normal file
81
programs/develop/open watcom/trunk/clib/streamio/scanf_s.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Implementation of scanf_s() - safe formatted stream input.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "saferlib.h"
|
||||
#include "widechar.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <wchar.h>
|
||||
#include "scanf.h"
|
||||
|
||||
|
||||
static int cget_stdin( PTR_SCNF_SPECS specs )
|
||||
{
|
||||
int c;
|
||||
|
||||
if( (c = __F_NAME(getc,getwc)( stdin )) == __F_NAME(EOF,WEOF) ) {
|
||||
specs->eoinp = 1;
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
|
||||
|
||||
static void uncget_stdin( int c, PTR_SCNF_SPECS specs )
|
||||
{
|
||||
__F_NAME(ungetc,ungetwc)( c, stdin );
|
||||
}
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(scanf_s,wscanf_s)( const CHAR_TYPE * __restrict format, ... )
|
||||
{
|
||||
va_list arg;
|
||||
SCNF_SPECS specs;
|
||||
const char *msg;
|
||||
int rc;
|
||||
|
||||
/* Basic check for null pointers to see if we can continue */
|
||||
if( __check_constraint_nullptr_msg( msg, format ) ) {
|
||||
|
||||
specs.cget_rtn = cget_stdin;
|
||||
specs.uncget_rtn = uncget_stdin;
|
||||
msg = NULL;
|
||||
va_start( arg, format );
|
||||
rc = __F_NAME(__scnf_s,__wscnf_s)( (PTR_SCNF_SPECS)&specs, format, &msg, arg );
|
||||
va_end( arg );
|
||||
if( msg == NULL ) {
|
||||
/* no rt-constraint violation inside worker routine */
|
||||
return( rc );
|
||||
}
|
||||
}
|
||||
__rtct_fail( __func__, msg, NULL );
|
||||
return( __F_NAME(EOF,WEOF) );
|
||||
}
|
1116
programs/develop/open watcom/trunk/clib/streamio/scnf.c
Normal file
1116
programs/develop/open watcom/trunk/clib/streamio/scnf.c
Normal file
File diff suppressed because it is too large
Load Diff
36
programs/develop/open watcom/trunk/clib/streamio/scnf_s.c
Normal file
36
programs/develop/open watcom/trunk/clib/streamio/scnf_s.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Safe version of scanf() worker routine.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
// this file should remain an indirected file
|
||||
// it is done this way to support the reuse of the source file
|
||||
#define SAFE_SCANF
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include "scnf.c"
|
47
programs/develop/open watcom/trunk/clib/streamio/setbuf.c
Normal file
47
programs/develop/open watcom/trunk/clib/streamio/setbuf.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent implementation of setbuf().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
_WCRTLINK void setbuf( FILE *fp, char *buf )
|
||||
{
|
||||
int mode;
|
||||
|
||||
__stream_check( fp, 1 );
|
||||
__null_check( buf, 2 );
|
||||
mode = _IOFBF;
|
||||
if( buf == NULL ) {
|
||||
mode = _IONBF;
|
||||
}
|
||||
setvbuf( fp, buf, mode, BUFSIZ );
|
||||
}
|
48
programs/develop/open watcom/trunk/clib/streamio/setefg.c
Normal file
48
programs/develop/open watcom/trunk/clib/streamio/setefg.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Routine to bring in real floating-point formatting code.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include "ftos.h"
|
||||
#include "farsupp.h"
|
||||
|
||||
/* This routine will be called by cstart if "_fltused" is referenced. */
|
||||
|
||||
void __setEFGfmt( void )
|
||||
{
|
||||
#ifdef __SW_BR
|
||||
__EFG_printf = __get_EFG_Format();
|
||||
__EFG_scanf = __get__cnvs2d(); /* 27-mar-90 */
|
||||
#else
|
||||
__EFG_printf = _EFG_Format;
|
||||
__EFG_scanf = __cnvs2d; /* 27-mar-90 */
|
||||
#endif
|
||||
}
|
79
programs/develop/open watcom/trunk/clib/streamio/setvbuf.c
Normal file
79
programs/develop/open watcom/trunk/clib/streamio/setvbuf.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent setvbuf() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include "fileacc.h"
|
||||
#include "rtdata.h"
|
||||
#include "streamio.h"
|
||||
|
||||
|
||||
extern void __full_io_exit();
|
||||
|
||||
|
||||
_WCRTLINK int setvbuf( FILE *fp, char *buf, int mode, size_t size )
|
||||
{
|
||||
__stream_check( fp, 1 );
|
||||
__null_check( buf, 2 );
|
||||
if( size > INT_MAX ) {
|
||||
/* 16-bit buffer filling code can't handle >32k (-ve size) */
|
||||
return( -1 );
|
||||
}
|
||||
/* check for allowable values for mode */
|
||||
switch( mode ) {
|
||||
case _IOFBF:
|
||||
case _IOLBF:
|
||||
case _IONBF:
|
||||
break;
|
||||
default:
|
||||
return( -1 );
|
||||
}
|
||||
if( buf != NULL && size == 0 ) { /* JBS 27-aug-90 */
|
||||
return( -1 );
|
||||
}
|
||||
_ValidFile( fp, -1 );
|
||||
_AccessFile( fp );
|
||||
__chktty( fp ); /* JBS 28-aug-90 */
|
||||
if( size != 0 ) {
|
||||
fp->_bufsize = size; /* JBS 27-aug-90 */
|
||||
}
|
||||
_FP_BASE(fp) = buf;
|
||||
fp->_ptr = buf;
|
||||
fp->_flag &= ~(_IONBF | _IOLBF | _IOFBF); /* FWC 14-jul-87 */
|
||||
fp->_flag |= mode;
|
||||
if( buf == NULL ) { /* FWC 16-mar-93 */
|
||||
__ioalloc( fp );
|
||||
}
|
||||
_ReleaseFile( fp );
|
||||
return( 0 );
|
||||
}
|
171
programs/develop/open watcom/trunk/clib/streamio/tmpfl.c
Normal file
171
programs/develop/open watcom/trunk/clib/streamio/tmpfl.c
Normal file
@@ -0,0 +1,171 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Platform independent tmpfile() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "rtinit.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <fcntl.h>
|
||||
#include <direct.h>
|
||||
#include <string.h>
|
||||
#include <process.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "rtdata.h"
|
||||
#include "tmpfname.h"
|
||||
#include "seterrno.h"
|
||||
#include "openmode.h"
|
||||
|
||||
#define OPEN_MODE (O_RDWR | O_CREAT | O_BINARY)
|
||||
#define PMODE (S_IREAD | S_IWRITE)
|
||||
|
||||
/* Netware doesn't define these */
|
||||
/* Symbolic constants for the access() function */
|
||||
|
||||
#if !defined( F_OK )
|
||||
#define R_OK 4 /* Test for read permission */
|
||||
#define W_OK 2 /* Test for write permission */
|
||||
#define X_OK 1 /* Test for execute permission */
|
||||
#define F_OK 0 /* Test for existence of file */
|
||||
#endif
|
||||
|
||||
extern void __MkTmpFile( char *buf, int num );
|
||||
extern void __RmTmpFile( FILE *fp );
|
||||
extern void (*__RmTmpFileFn)( FILE *fp );
|
||||
|
||||
char __tmpfnext = _TMP_INIT_CHAR;
|
||||
|
||||
_WCRTLINK FILE *tmpfile( void ) /* create a temporary file */
|
||||
{
|
||||
int hdl;
|
||||
int old_errno;
|
||||
int our_errno;
|
||||
char suffix1;
|
||||
char suffix2;
|
||||
FILE *fp;
|
||||
char name1[PATH_MAX + _TMPFNAME_LENGTH + 1];
|
||||
char name2[PATH_MAX + _TMPFNAME_LENGTH + 1];
|
||||
|
||||
old_errno = _RWD_errno;
|
||||
suffix1 = 0;
|
||||
for( ;; ) {
|
||||
// Part I
|
||||
for( ;; ) {
|
||||
__MkTmpFile( name1, suffix1 );
|
||||
// if a file by this name does not exist
|
||||
if( access( name1, F_OK ) != 0 ) {
|
||||
|
||||
// then let's try to create it
|
||||
hdl = sopen( name1, OPEN_MODE, OPENMODE_DENY_COMPAT, PMODE );
|
||||
|
||||
// if we created it then continue with part II
|
||||
if( hdl != -1 ) break;
|
||||
__set_errno( EAGAIN );
|
||||
}
|
||||
suffix1++;
|
||||
// give up after _TMP_INIT_CHAR tries JBS 99/10/26
|
||||
if( suffix1 >= _TMP_INIT_CHAR ) return NULL;
|
||||
}
|
||||
close( hdl );
|
||||
|
||||
// Part II
|
||||
/* we now have a empty file. Let's try to rename it
|
||||
rename should be an atomic operation in the operating system
|
||||
so if it succeeds we can be sure no one else has this file.
|
||||
Consider the following sequence:
|
||||
|
||||
task1: access x.y => file does not exist
|
||||
task2: access x.y => file does not exist
|
||||
task1: fopen x.y => succeeds
|
||||
task2: fopen x.y => succeeds (now have both tasks with x.y open)
|
||||
task1: rename x.y to y.y => succeeds, can use this file
|
||||
task2: rename x.y to y.y => fails (because x.y no longer exists)
|
||||
task2: start over again to get a new file name
|
||||
task2: succeeds second time around since no more race condition
|
||||
with task1.
|
||||
*/
|
||||
suffix2 = _RWD_tmpfnext; // only one of these per process
|
||||
for( ;; ) {
|
||||
if( suffix2 == suffix1 ) {
|
||||
suffix2++;
|
||||
}
|
||||
__MkTmpFile( name2, suffix2 );
|
||||
|
||||
if( rename( name1, name2 ) == 0 ) { // if rename worked
|
||||
|
||||
// The file is now ours. Let's try to open it.
|
||||
fp = fopen( name2, "wb+" );
|
||||
if( fp != NULL ) {
|
||||
fp->_flag |= _TMPFIL;
|
||||
_FP_TMPFCHAR(fp) = suffix2;
|
||||
__set_errno( old_errno );
|
||||
return( fp );
|
||||
}
|
||||
// We couldn't open it, probably because we have run out of handles.
|
||||
// Remove the renamed file.
|
||||
our_errno = errno;
|
||||
remove( name2 );
|
||||
__set_errno( our_errno );
|
||||
return( NULL );
|
||||
}
|
||||
// The rename didn't work or we couldn't open the renamed file.
|
||||
// One of two possibilities:
|
||||
// (1) The "to" name already exists.
|
||||
// (2) Another process renamed it away from us.
|
||||
|
||||
// Check for case (2).
|
||||
// Quit if "from" file is gone and start over.
|
||||
if( access( name1, F_OK ) != 0 ) break;
|
||||
|
||||
// Must be case (1). Try another "to" name.
|
||||
++suffix2;
|
||||
if( suffix2 == 0 ) {
|
||||
suffix2 = _TMP_INIT_CHAR;
|
||||
}
|
||||
_RWD_tmpfnext = suffix2; // update for all processes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* tmpfil() pulls in a lot of overhead that many programs do not need. But */
|
||||
/* since temp files are removed on program shutdown, the code to remove */
|
||||
/* them would always get linked in even if the program never heard of temp */
|
||||
/* files. Since we know that temporary files can _only_ be created through */
|
||||
/* tmpfile(), we can have a dummy __RmTmpFile() by default and use the */
|
||||
/* real thing only if tmpfil() was called. */
|
||||
void __Init_Tmpfl( void )
|
||||
{
|
||||
// Just assign the function address
|
||||
__RmTmpFileFn = __RmTmpFile;
|
||||
}
|
||||
|
||||
AXI( __Init_Tmpfl, INIT_PRIORITY_RUNTIME )
|
138
programs/develop/open watcom/trunk/clib/streamio/tmputil.c
Normal file
138
programs/develop/open watcom/trunk/clib/streamio/tmputil.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Open Watcom Project
|
||||
*
|
||||
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original
|
||||
* Code as defined in and that are subject to the Sybase Open Watcom
|
||||
* Public License version 1.0 (the 'License'). You may not use this file
|
||||
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
|
||||
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
|
||||
* provided with the Original Code and Modifications, and is also
|
||||
* available at www.sybase.com/developer/opensource.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
|
||||
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
|
||||
* NON-INFRINGEMENT. Please see the License for the specific language
|
||||
* governing rights and limitations under the License.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Description: Internal helper routines __MkTmpFile() and __RmTmpFile().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <direct.h>
|
||||
#include <string.h>
|
||||
#include <process.h>
|
||||
#include "rtdata.h"
|
||||
#include "tmpfname.h"
|
||||
|
||||
|
||||
static unsigned __GetTmpPath( char *buf )
|
||||
{
|
||||
#ifndef __NETWARE__
|
||||
static char *evars[] = { "TMP", "TEMP", "TMPDIR", "TEMPDIR", "" };
|
||||
char **evar;
|
||||
char *tmp;
|
||||
#endif
|
||||
unsigned i;
|
||||
|
||||
buf[0] = '\0'; // initialize path
|
||||
#ifdef __NETWARE__
|
||||
getcwd( buf, PATH_MAX ); // No environment vars on Netware
|
||||
#else
|
||||
for( evar = evars; **evar; ++evar ) {
|
||||
tmp = getenv( *evar );
|
||||
if( (tmp != NULL) && (strlen( tmp ) <= PATH_MAX) ) {
|
||||
tmp = _fullpath( buf, tmp, PATH_MAX );
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* If we didn't match on any environment vars, get current working dir
|
||||
*/
|
||||
if( buf[0] == '\0' ) {
|
||||
getcwd( buf, PATH_MAX );
|
||||
}
|
||||
#endif
|
||||
|
||||
// if last char is not a path delimiter then append one
|
||||
i = strlen( buf );
|
||||
if( i > 0 ) i--;
|
||||
if( (buf[i] != '\\') && (buf[i] != '/') ) {
|
||||
// if buf[i] is a null char then the following has no effect as planned
|
||||
i++;
|
||||
buf[i] = '\\';
|
||||
i++;
|
||||
buf[i] = '\0';
|
||||
}
|
||||
return( i );
|
||||
}
|
||||
|
||||
static char __hex( int num )
|
||||
{
|
||||
num += '0';
|
||||
if( num > '9' ) {
|
||||
num += 'a' - '0' - 10;
|
||||
}
|
||||
return( num );
|
||||
}
|
||||
|
||||
#if defined( __NETWARE__ )
|
||||
extern int GetThreadID( void );
|
||||
#define getuniqueid() GetThreadID()
|
||||
#elif defined( __NT__ )
|
||||
#define getuniqueid() ((getpid() << 12) + *_threadid)
|
||||
#elif defined( __OS2__ )
|
||||
#define getuniqueid() ((getpid() << 12) + *_threadid)
|
||||
#else
|
||||
#define getuniqueid() (getpid())
|
||||
#endif
|
||||
|
||||
void __MkTmpFile( char *buf, int num )
|
||||
{
|
||||
unsigned pid;
|
||||
unsigned i;
|
||||
char *ptr;
|
||||
|
||||
pid = getuniqueid();
|
||||
// JBS on Win32 pid's range from 0 to n where n is not very large for
|
||||
// most systems (e.g. 500 would indicate many, many processes are active).
|
||||
// #if defined(__386__) || defined(__AXP__) || defined(__PPC__)
|
||||
// // try to use more of the 32bit pid bits
|
||||
// pid |= pid >> 16;
|
||||
// #endif
|
||||
|
||||
i = __GetTmpPath( buf );
|
||||
ptr = &buf[ i ];
|
||||
ptr[0] = 't';
|
||||
for( i = 7; i != 0; i-- ) { // JBS use 7 hex digits instead of 4
|
||||
ptr[i] = __hex( pid & 0x000F );
|
||||
pid = pid >> 4;
|
||||
}
|
||||
ptr[8] = '.';
|
||||
ptr[9] = 't';
|
||||
ptr[10] = __hex( (num >> 4) & 0x000F );
|
||||
ptr[11] = __hex( num & 0x000F );
|
||||
ptr[12] = '\0';
|
||||
}
|
||||
|
||||
void __RmTmpFile( FILE *fp )
|
||||
{
|
||||
char name[PATH_MAX + _TMPFNAME_LENGTH + 1]; /* 02-aug-90 */
|
||||
|
||||
__MkTmpFile( name, _FP_TMPFCHAR(fp) );
|
||||
remove( name );
|
||||
}
|
Reference in New Issue
Block a user