forked from KolibriOS/kolibrios
update CLib
git-svn-id: svn://kolibrios.org@614 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
52facee6d5
commit
3be3768ce0
74
programs/develop/open watcom/trunk/clib/direct/gtcwdwnt.c
Normal file
74
programs/develop/open watcom/trunk/clib/direct/gtcwdwnt.c
Normal file
@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <dos.h>
|
||||
#include <direct.h>
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "liballoc.h"
|
||||
|
||||
int _stdcall sys_getcwd(char *buf, size_t size);
|
||||
|
||||
_WCRTLINK CHAR_TYPE *__F_NAME(getcwd,_wgetcwd)( CHAR_TYPE *buf, size_t size )
|
||||
{
|
||||
char path[1024];
|
||||
size_t realsize;
|
||||
|
||||
/*** Get the current directory ***/
|
||||
realsize = sys_getcwd( path, 1024 );
|
||||
|
||||
if( realsize == 0 ) {
|
||||
return( NULL );
|
||||
}
|
||||
if( buf == NULL ) {
|
||||
buf = lib_malloc( max(size,realsize) * CHARSIZE );
|
||||
if( buf == NULL ) {
|
||||
__set_errno( ENOMEM );
|
||||
return( NULL );
|
||||
}
|
||||
} else {
|
||||
if( realsize > size ) {
|
||||
__set_errno( ERANGE );
|
||||
return( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
memcpy( buf, path, realsize*CHARSIZE );
|
||||
return( buf );
|
||||
}
|
69
programs/develop/open watcom/trunk/clib/environ/clearenv.c
Normal file
69
programs/develop/open watcom/trunk/clib/environ/clearenv.c
Normal file
@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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 clearenv() - clear the environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdlib.h>
|
||||
#include <env.h>
|
||||
#include "liballoc.h"
|
||||
#include "rtdata.h"
|
||||
|
||||
/* Note - clearenv() is always called at library exit */
|
||||
|
||||
_WCRTLINK int (clearenv)( void )
|
||||
{
|
||||
#ifndef __NETWARE__
|
||||
char **envp;
|
||||
char *env_str;
|
||||
int index;
|
||||
|
||||
if( _RWD_environ != NULL ) {
|
||||
for( envp = _RWD_environ; env_str = *envp; ++envp ) {
|
||||
if( _RWD_env_mask != NULL ) {
|
||||
index = envp - _RWD_environ;
|
||||
if( _RWD_env_mask[ index ] != 0 ) {
|
||||
lib_free( (void *)env_str );
|
||||
}
|
||||
*envp = NULL;
|
||||
}
|
||||
}
|
||||
if( _RWD_env_mask != NULL ) {
|
||||
lib_free( _RWD_environ );
|
||||
}
|
||||
envp = lib_malloc( sizeof(char *) + sizeof(char) );
|
||||
if( envp == NULL ) return( -1 );
|
||||
_RWD_environ = envp;
|
||||
*_RWD_environ = NULL;
|
||||
_RWD_env_mask = ((char *)envp) + sizeof(char *);
|
||||
*_RWD_env_mask = 0;
|
||||
}
|
||||
#endif
|
||||
return( 0 ); /* success */
|
||||
}
|
51
programs/develop/open watcom/trunk/clib/environ/environ.c
Normal file
51
programs/develop/open watcom/trunk/clib/environ/environ.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: Environment pointers.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdlib.h>
|
||||
#include "rtdata.h"
|
||||
#include "rtinit.h"
|
||||
|
||||
_WCRTLINKD char ** _WCNEAR environ; /* pointer to environment table */
|
||||
_WCRTLINKD wchar_t ** _WCNEAR _wenviron; /* pointer to wide char environment */
|
||||
char * _WCNEAR __env_mask; /* ptr to char array of flags */
|
||||
|
||||
extern void __setenvp( void );
|
||||
|
||||
AXI( __setenvp, INIT_PRIORITY_LIBRARY )
|
||||
|
||||
#if !defined(__NETWARE__) && !defined(__LINUX__)
|
||||
/* Environment needs to be freed after files are shut down; __MkTmpFile()
|
||||
* is used to delete temp files and needs access to environment.
|
||||
*/
|
||||
extern void __freeenvp( void );
|
||||
AYI( __freeenvp, INIT_PRIORITY_LIBRARY - 1 )
|
||||
#endif
|
54
programs/develop/open watcom/trunk/clib/environ/filestr.h
Normal file
54
programs/develop/open watcom/trunk/clib/environ/filestr.h
Normal file
@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef _FILNMTYP_H_INCLUDED
|
||||
#define _FILNMTYP_H_INCLUDED
|
||||
|
||||
#include "variety.h"
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
_WCRTLINK extern char * __FormPosixHandleStr( void );
|
||||
_WCRTLINK extern void __ParsePosixHandleStr( void );
|
||||
|
||||
_WCRTLINK extern wchar_t * __wFormPosixHandleStr( void );
|
||||
_WCRTLINK extern void __wParsePosixHandleStr( void );
|
||||
|
||||
|
||||
#ifdef __NT__
|
||||
#define __USE_POSIX_HANDLE_STRINGS
|
||||
#else
|
||||
#undef __USE_POSIX_HANDLE_STRINGS
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
111
programs/develop/open watcom/trunk/clib/environ/getenv.c
Normal file
111
programs/develop/open watcom/trunk/clib/environ/getenv.c
Normal file
@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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 getenv().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include <mbstring.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "rtdata.h"
|
||||
#ifdef __WIDECHAR__
|
||||
#include "wenviron.h"
|
||||
#endif
|
||||
|
||||
#if defined(__UNIX__)
|
||||
#ifdef __WIDECHAR__
|
||||
#define CMP_FUNC wcsncmp
|
||||
#else
|
||||
#define CMP_FUNC strncmp
|
||||
#endif
|
||||
#else
|
||||
#define CMP_FUNC _wcsnicmp
|
||||
#endif
|
||||
|
||||
#if !defined(__UNIX__) && !defined(__WIDECHAR__) && !defined(__NETWARE__)
|
||||
|
||||
_WCRTLINK char *getenv( const char *name )
|
||||
{
|
||||
char **envp;
|
||||
char *p;
|
||||
|
||||
/*** Find the environment string ***/
|
||||
__ptr_check( name, 0 );
|
||||
envp = _RWD_environ;
|
||||
if( (envp != NULL) && (name != NULL) ) {
|
||||
for( ; p = *envp; ++envp ) {
|
||||
const char *s = name;
|
||||
|
||||
while( *p != '\0' ) { /* simple check is sufficient for p, not s */
|
||||
if ( _mbterm( s ) ) {
|
||||
if( *p == '=' ) return( p + 1 );
|
||||
break;
|
||||
}
|
||||
if ( _mbctoupper( _mbsnextc( p ) ) != _mbctoupper( _mbsnextc( s ) ) )
|
||||
break;
|
||||
p = _mbsinc( p ); /* skip over character */
|
||||
s = _mbsinc( s ); /* skip over character */
|
||||
}
|
||||
}
|
||||
}
|
||||
return( NULL ); /* not found */
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
_WCRTLINK CHAR_TYPE *__F_NAME(getenv,_wgetenv)( const CHAR_TYPE *name )
|
||||
{
|
||||
#ifdef __NETWARE__
|
||||
name = name;
|
||||
#else
|
||||
CHAR_TYPE **envp;
|
||||
CHAR_TYPE *p;
|
||||
int len;
|
||||
|
||||
#ifdef __WIDECHAR__
|
||||
if( _RWD_wenviron == NULL ) __create_wide_environment();
|
||||
#endif
|
||||
|
||||
/*** Find the environment string ***/
|
||||
__ptr_check( name, 0 );
|
||||
envp = __F_NAME(_RWD_environ,_RWD_wenviron);
|
||||
if( (envp != NULL) && (name != NULL) ) {
|
||||
len = __F_NAME(strlen,wcslen)( name );
|
||||
for( ; p = *envp; ++envp ) {
|
||||
if( CMP_FUNC( p, name, len ) == 0 ) {
|
||||
if( p[len] == __F_NAME('=',L'=') ) return( &p[len+1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return( NULL ); /* not found */
|
||||
}
|
||||
|
||||
#endif
|
85
programs/develop/open watcom/trunk/clib/environ/gtcmd.c
Normal file
85
programs/develop/open watcom/trunk/clib/environ/gtcmd.c
Normal file
@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: Multi-platform implementation of getcmd() and _bgetcmd().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#if defined(__NT__)
|
||||
#elif defined(__OS2__)
|
||||
#endif
|
||||
|
||||
#if !defined( __NETWARE__ ) || defined( _NETWARE_LIBC )
|
||||
#include <process.h>
|
||||
#endif
|
||||
|
||||
extern char *_LpCmdLine;
|
||||
|
||||
_WCRTLINK int _bgetcmd( char *buffer, int len )
|
||||
{
|
||||
int cmdlen;
|
||||
char *cmd;
|
||||
char *tmp;
|
||||
|
||||
if( buffer && (len > 0) )
|
||||
*buffer = '\0';
|
||||
|
||||
cmd = _LpCmdLine;
|
||||
if( !cmd )
|
||||
return( 0 );
|
||||
|
||||
while( *cmd == ' ' || *cmd == '\t' )
|
||||
++cmd;
|
||||
|
||||
for( cmdlen = 0, tmp = cmd; *tmp; ++tmp, ++cmdlen )
|
||||
;
|
||||
|
||||
if( !buffer || (len <= 0) )
|
||||
return( cmdlen );
|
||||
|
||||
len--;
|
||||
len = (len < cmdlen) ? len : cmdlen;
|
||||
|
||||
while( len ) {
|
||||
*buffer++ = *cmd++;
|
||||
--len;
|
||||
}
|
||||
buffer[len] = '\0';
|
||||
|
||||
return( cmdlen );
|
||||
} /* _bgetcmd() */
|
||||
|
||||
|
||||
_WCRTLINK char *getcmd( char *buffer )
|
||||
{
|
||||
_bgetcmd( buffer, INT_MAX );
|
||||
return( buffer );
|
||||
} /* getcmd() */
|
151
programs/develop/open watcom/trunk/clib/environ/searchen.c
Normal file
151
programs/develop/open watcom/trunk/clib/environ/searchen.c
Normal file
@ -0,0 +1,151 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: This function searches for the specified file in the
|
||||
* 1) current directory or, failing that,
|
||||
* 2) the paths listed in the specified environment variable
|
||||
* until it finds the first occurrence of the file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#undef __INLINE_FUNCTIONS__
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#ifndef __UNIX__
|
||||
#include <direct.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#ifdef __WIDECHAR__
|
||||
#include "wenviron.h"
|
||||
#endif
|
||||
|
||||
#if defined(__UNIX__)
|
||||
#ifdef __WIDECHAR__
|
||||
#define PATH_SEPARATOR L'/'
|
||||
#define LIST_SEPARATOR L':'
|
||||
#else
|
||||
#define PATH_SEPARATOR '/'
|
||||
#define LIST_SEPARATOR ':'
|
||||
#endif
|
||||
#else
|
||||
#ifdef __WIDECHAR__
|
||||
#define PATH_SEPARATOR L'\\'
|
||||
#define LIST_SEPARATOR L';'
|
||||
#else
|
||||
#define PATH_SEPARATOR '\\'
|
||||
#define LIST_SEPARATOR ';'
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
_WCRTLINK void __F_NAME(_searchenv,_wsearchenv)( const CHAR_TYPE *name, const CHAR_TYPE *env_var, CHAR_TYPE *buffer )
|
||||
{
|
||||
CHAR_TYPE *p, *p2;
|
||||
int prev_errno;
|
||||
size_t len;
|
||||
|
||||
#ifdef __WIDECHAR__
|
||||
if( _RWD_wenviron == NULL ) __create_wide_environment();
|
||||
#endif
|
||||
|
||||
prev_errno = _RWD_errno;
|
||||
if( __F_NAME(access,_waccess)( name, F_OK ) == 0 ) {
|
||||
p = buffer; /* JBS 90/3/30 */
|
||||
len = 0; /* JBS 04/1/06 */
|
||||
for( ;; ) {
|
||||
if( name[0] == PATH_SEPARATOR ) break;
|
||||
if( name[0] == __F_NAME('.',L'.') ) break;
|
||||
#ifndef __UNIX__
|
||||
if( name[0] == __F_NAME('/',L'/') ) break;
|
||||
if( (name[0] != __F_NAME('\0',L'\0')) && (name[1] == __F_NAME(':',L':')) ) break;
|
||||
#endif
|
||||
__F_NAME(getcwd,_wgetcwd)( buffer, _MAX_PATH );
|
||||
len = __F_NAME(strlen,wcslen)( buffer );
|
||||
p = &buffer[ len ];
|
||||
if( p[-1] != PATH_SEPARATOR ) {
|
||||
if( len < (_MAX_PATH - 1) ) {
|
||||
*p++ = PATH_SEPARATOR;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
*p = __F_NAME('\0',L'\0');
|
||||
__F_NAME(strncat,wcsncat)( p, name, (_MAX_PATH - 1) - len );
|
||||
return;
|
||||
}
|
||||
p = __F_NAME(getenv,_wgetenv)( env_var );
|
||||
if( p != NULL ) {
|
||||
for( ;; ) {
|
||||
if( *p == __F_NAME('\0',L'\0') ) break;
|
||||
p2 = buffer;
|
||||
len = 0; /* JBS 04/1/06 */
|
||||
while( *p ) {
|
||||
if( *p == LIST_SEPARATOR ) break;
|
||||
if( *p != __F_NAME('"',L'"') ) {
|
||||
if( len < (_MAX_PATH-1) ) {
|
||||
*p2++ = *p; /* JBS 00/9/29 */
|
||||
len++;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
/* check for zero-length prefix which represents CWD */
|
||||
if( p2 != buffer ) { /* JBS 90/3/30 */
|
||||
if( p2[-1] != PATH_SEPARATOR
|
||||
#ifndef __UNIX__
|
||||
&& p2[-1] != __F_NAME('/','/')
|
||||
&& p2[-1] != __F_NAME(':',':')
|
||||
#endif
|
||||
) {
|
||||
if( len < (_MAX_PATH - 1) ) {
|
||||
*p2++ = PATH_SEPARATOR;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
*p2 = __F_NAME('\0',L'\0');
|
||||
len += __F_NAME(strlen,wcslen)( name );/* JBS 04/12/23 */
|
||||
if( len < _MAX_PATH ) {
|
||||
__F_NAME(strcat,wcscat)( p2, name );
|
||||
/* check to see if file exists */
|
||||
if( __F_NAME(access,_waccess)( buffer, 0 ) == 0 ) {
|
||||
__set_errno( prev_errno );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( *p == '\0' ) break;
|
||||
++p;
|
||||
}
|
||||
}
|
||||
buffer[0] = __F_NAME( '\0',L'\0' );
|
||||
}
|
127
programs/develop/open watcom/trunk/clib/environ/setenvp.c
Normal file
127
programs/develop/open watcom/trunk/clib/environ/setenvp.c
Normal file
@ -0,0 +1,127 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: Routines to create/destroy clib copy of OS environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <env.h>
|
||||
#include "liballoc.h"
|
||||
#include <string.h>
|
||||
#include "filestr.h"
|
||||
#include "rtdata.h"
|
||||
|
||||
extern char _WCI86FAR *_Envptr;
|
||||
|
||||
static char *_free_ep;
|
||||
|
||||
#define allocate lib_malloc
|
||||
|
||||
void __setenvp( void )
|
||||
{
|
||||
#if defined(__NETWARE__)
|
||||
// no environment support
|
||||
#elif defined(__LINUX__)
|
||||
#else
|
||||
char _WCI86FAR *startp;
|
||||
char _WCI86FAR *p;
|
||||
char *ep;
|
||||
char *my_env_mask;
|
||||
char **my_environ;
|
||||
int count;
|
||||
size_t ep_size;
|
||||
size_t env_size;
|
||||
|
||||
/* if we are already initialized, then return */
|
||||
if( _RWD_environ != NULL ) return; /* 10-jun-90 */
|
||||
|
||||
// env_size = sys_get_environ(0,0)+1;
|
||||
// _Envptr = lib_malloc(env_size);
|
||||
// sys_get_environ(_Envptr, env_size)
|
||||
|
||||
startp = _Envptr;
|
||||
|
||||
count = 0;
|
||||
p = startp;
|
||||
while( *p ) {
|
||||
while( *++p );
|
||||
++count;
|
||||
++p;
|
||||
}
|
||||
ep_size = p - startp;
|
||||
if( ep_size == 0 ) {
|
||||
ep_size = 1;
|
||||
}
|
||||
ep = (char *)allocate( ep_size );
|
||||
if( ep ) {
|
||||
env_size = (count + 1) * sizeof(char *) + count * sizeof(char);
|
||||
my_environ = (char **)allocate( env_size );
|
||||
if( my_environ ) {
|
||||
_RWD_environ = my_environ;
|
||||
p = startp;
|
||||
_free_ep = ep;
|
||||
while( *p ) {
|
||||
*my_environ++ = ep;
|
||||
while( *ep++ = *p++ )
|
||||
;
|
||||
}
|
||||
*my_environ++ = NULL;
|
||||
_RWD_env_mask = my_env_mask = (char *) my_environ;
|
||||
for( ; count; count-- )
|
||||
*my_env_mask++ = 0;
|
||||
} else {
|
||||
lib_free( ep );
|
||||
}
|
||||
}
|
||||
|
||||
/*** Handle the C_FILE_INFO entry ***/
|
||||
#ifdef __USE_POSIX_HANDLE_STRINGS
|
||||
// __ParsePosixHandleStr();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(__NETWARE__) && !defined(__LINUX__)
|
||||
|
||||
void __freeenvp( void )
|
||||
{
|
||||
clearenv();
|
||||
if( _RWD_environ ) {
|
||||
lib_free( _RWD_environ );
|
||||
_RWD_environ = NULL;
|
||||
}
|
||||
if( _free_ep ) {
|
||||
lib_free( _free_ep );
|
||||
_free_ep = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
48
programs/develop/open watcom/trunk/clib/file/remove.c
Normal file
48
programs/develop/open watcom/trunk/clib/file/remove.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#ifndef __UNIX__
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#ifdef __UNIX__
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
_WCRTLINK int __F_NAME(remove,_wremove)( CHAR_TYPE const *filename )
|
||||
{
|
||||
__ptr_check( filename, 0 );
|
||||
return( __F_NAME(unlink,_wunlink)( filename ) );
|
||||
}
|
50
programs/develop/open watcom/trunk/clib/handleio/close.c
Normal file
50
programs/develop/open watcom/trunk/clib/handleio/close.c
Normal file
@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "rtdata.h"
|
||||
#include "rtcheck.h"
|
||||
#include "seterrno.h"
|
||||
#include <unistd.h>
|
||||
#include "close.h"
|
||||
|
||||
_WCRTLINK int close( int handle )
|
||||
{
|
||||
int rc;
|
||||
|
||||
__handle_check( handle, -1 );
|
||||
|
||||
rc = __close( handle );
|
||||
return( rc );
|
||||
}
|
135
programs/develop/open watcom/trunk/clib/handleio/read.c
Normal file
135
programs/develop/open watcom/trunk/clib/handleio/read.c
Normal file
@ -0,0 +1,135 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include "iomode.h"
|
||||
#include "fileacc.h"
|
||||
#include "rtcheck.h"
|
||||
#include "rtdata.h"
|
||||
#include "seterrno.h"
|
||||
#include "lseek.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
unsigned int offset;
|
||||
}__file_handle;
|
||||
|
||||
|
||||
int _stdcall read_file (const char *name,char *buff,unsigned offset, unsigned count,unsigned *reads);
|
||||
|
||||
_WCRTLINK int read( int handle, void *buf, unsigned len )
|
||||
{
|
||||
unsigned read_len, total_len;
|
||||
unsigned reduce_idx, finish_idx;
|
||||
unsigned iomode_flags;
|
||||
char *buffer = buf;
|
||||
BOOL rc;
|
||||
HANDLE h;
|
||||
unsigned amount_read;
|
||||
__file_handle *fh;
|
||||
|
||||
__handle_check( handle, -1 );
|
||||
__ChkTTYIOMode( handle );
|
||||
iomode_flags = __GetIOMode( handle );
|
||||
if( iomode_flags == 0 )
|
||||
{
|
||||
__set_errno( EBADF );
|
||||
return( -1 );
|
||||
}
|
||||
if( !(iomode_flags & _READ) )
|
||||
{
|
||||
__set_errno( EACCES ); /* changed from EBADF to EACCES 23-feb-89 */
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
|
||||
fh = (__file_handle*) __getOSHandle( handle );
|
||||
|
||||
if( iomode_flags & _BINARY ) /* if binary mode */
|
||||
{
|
||||
|
||||
if(read_file(fh->name,buffer,fh->offset,len,&amount_read))
|
||||
{
|
||||
if ( amount_read == 0)
|
||||
return (-1);
|
||||
}
|
||||
fh->offset+=amount_read;
|
||||
total_len = amount_read;
|
||||
}
|
||||
else
|
||||
{
|
||||
total_len = 0;
|
||||
read_len = len;
|
||||
do
|
||||
{
|
||||
if(read_file(fh->name,buffer,fh->offset,len,&amount_read))
|
||||
{
|
||||
if( amount_read == 0 )
|
||||
{ /* EOF */
|
||||
break;
|
||||
}
|
||||
}
|
||||
reduce_idx = 0;
|
||||
finish_idx = reduce_idx;
|
||||
for( ; reduce_idx < amount_read; ++reduce_idx )
|
||||
{
|
||||
if( buffer[ reduce_idx ] == 0x1a ) /* EOF */
|
||||
{
|
||||
__lseek( handle,
|
||||
((long)reduce_idx - (long)amount_read)+1L,
|
||||
SEEK_CUR );
|
||||
total_len += finish_idx;
|
||||
return( total_len );
|
||||
}
|
||||
if( buffer[ reduce_idx ] != '\r' )
|
||||
{
|
||||
buffer[ finish_idx++ ] = buffer[ reduce_idx ];
|
||||
};
|
||||
}
|
||||
|
||||
total_len += finish_idx;
|
||||
buffer += finish_idx;
|
||||
read_len -= finish_idx;
|
||||
if( iomode_flags & _ISTTY )
|
||||
{
|
||||
break; /* 04-feb-88, FWC */
|
||||
}
|
||||
} while( read_len != 0 );
|
||||
}
|
||||
return( total_len );
|
||||
}
|
||||
|
46
programs/develop/open watcom/trunk/clib/handleio/unlnkwnt.c
Normal file
46
programs/develop/open watcom/trunk/clib/handleio/unlnkwnt.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include "widechar.h"
|
||||
#include "seterrno.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int _stdcall sys_delete_file(const CHAR_TYPE *filename);
|
||||
|
||||
_WCRTLINK int __F_NAME(unlink,_wunlink)( const CHAR_TYPE *filename )
|
||||
{
|
||||
if( sys_delete_file( filename )) {
|
||||
return( -1 );
|
||||
}
|
||||
return( 0 );
|
||||
}
|
41
programs/develop/open watcom/trunk/clib/kanji/mbdtoupp.c
Normal file
41
programs/develop/open watcom/trunk/clib/kanji/mbdtoupp.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <mbctype.h>
|
||||
#include <mbstring.h>
|
||||
|
||||
|
||||
_WCRTLINK unsigned int _mbdtoupper( unsigned int ch )
|
||||
{
|
||||
return( ch >= 0x8281 && ch <= 0x829A ? ( ch - 0x21 ) : ch );
|
||||
}
|
52
programs/develop/open watcom/trunk/clib/mbyte/mbcupper.c
Normal file
52
programs/develop/open watcom/trunk/clib/mbyte/mbcupper.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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
|
||||
* DESCRIBE IT HERE!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <ctype.h>
|
||||
#include "mbchar.h"
|
||||
#include <mbstring.h>
|
||||
|
||||
/**
|
||||
* Convert a single character to uppercase. Equivalent to toupper().
|
||||
*/
|
||||
|
||||
_WCRTLINK unsigned int _mbctoupper( unsigned int ch )
|
||||
{
|
||||
if( ch & 0xFF00 ) {
|
||||
if( __MBCodePage == 932 ) {
|
||||
return( _mbdtoupper( ch ) );
|
||||
}
|
||||
return( ch ); // we don't know what to do - just return it
|
||||
} else {
|
||||
return( toupper( ch ) );
|
||||
}
|
||||
}
|
49
programs/develop/open watcom/trunk/clib/mbyte/mbsinc.c
Normal file
49
programs/develop/open watcom/trunk/clib/mbyte/mbsinc.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <mbstring.h>
|
||||
#include "farfunc.h"
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Return the address of the next character in a string.
|
||||
****/
|
||||
|
||||
_WCRTLINK unsigned char _FFAR *_NEARFAR((_mbsinc),(_fmbsinc))( const unsigned char _FFAR *string )
|
||||
{
|
||||
if( _ismbblead(*string) && *(string+1)!='\0' ) /* valid DBCS char? */
|
||||
return( (unsigned char _FFAR*) (string+2) );/* yes, skip two bytes */
|
||||
else
|
||||
return( (unsigned char _FFAR*) (string+1) );/* no, just skip one */
|
||||
}
|
43
programs/develop/open watcom/trunk/clib/mbyte/mbsnextc.c
Normal file
43
programs/develop/open watcom/trunk/clib/mbyte/mbsnextc.c
Normal file
@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: Return the value of the next character in the string.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <mbstring.h>
|
||||
#include "farfunc.h"
|
||||
|
||||
|
||||
_WCRTLINK unsigned int _NEARFAR(_mbsnextc,_fmbsnextc)( const unsigned char _FFAR *string )
|
||||
{
|
||||
unsigned int retval = string[0];
|
||||
if( _ismbblead(retval) )
|
||||
retval = (retval << 8) | string[1];
|
||||
return( retval );
|
||||
}
|
50
programs/develop/open watcom/trunk/clib/mbyte/mbterm.c
Normal file
50
programs/develop/open watcom/trunk/clib/mbyte/mbterm.c
Normal file
@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <mbstring.h>
|
||||
#include "farfunc.h"
|
||||
|
||||
|
||||
|
||||
/****
|
||||
***** Return true if *ch=='\0' or if *ch is a lead byte and *(ch+1)=='\0'.
|
||||
***** If ch points to a single-byte character or a valid DBCS character,
|
||||
***** returns false.
|
||||
****/
|
||||
|
||||
_WCRTLINK int _NEARFAR(_mbterm,_fmbterm)( const unsigned char _FFAR *ch )
|
||||
{
|
||||
if( *ch == '\0' ) return( 1 );
|
||||
if( _ismbblead(*ch) && *(ch+1)=='\0' ) return( 2 );
|
||||
return( 0 );
|
||||
}
|
55
programs/develop/open watcom/trunk/clib/mbyte/setmbcp.c
Normal file
55
programs/develop/open watcom/trunk/clib/mbyte/setmbcp.c
Normal file
@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#include <mbctype.h>
|
||||
#include "mbchar.h"
|
||||
|
||||
|
||||
_WCRTLINK int _setmbcp( int i )
|
||||
{
|
||||
if( i == _MB_CP_ANSI ) {
|
||||
i = _MBINIT_CP_ANSI;
|
||||
} else if( i == _MB_CP_OEM ) {
|
||||
i = _MBINIT_CP_OEM;
|
||||
} else if( i == _MB_CP_SBCS ) {
|
||||
i = _MBINIT_CP_SBCS;
|
||||
} else if( i == 932 ) {
|
||||
i = _MBINIT_CP_932;
|
||||
}
|
||||
|
||||
if( __mbinit( i ) == 0 ) {
|
||||
return( 0 ); /* success */
|
||||
} else {
|
||||
return( -1 ); /* failure */
|
||||
}
|
||||
}
|
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 );
|
||||
}
|
34
programs/develop/open watcom/trunk/clib/time/_time.h
Normal file
34
programs/develop/open watcom/trunk/clib/time/_time.h
Normal file
@ -0,0 +1,34 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: prototypes for internal time related functions
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
extern int __DontCacheOSTZ( void );
|
||||
extern int __CacheOSTZ( void );
|
||||
extern void __parse_tz( char * tz );
|
141
programs/develop/open watcom/trunk/clib/time/gmtime.c
Normal file
141
programs/develop/open watcom/trunk/clib/time/gmtime.c
Normal file
@ -0,0 +1,141 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: __brktime() is an internal function to convert time to struct tm
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <time.h>
|
||||
#include "thetime.h"
|
||||
#include "timedata.h"
|
||||
|
||||
// #define DAYS_IN_4_YRS ( 365 + 365 + 365 + 366 )
|
||||
// #define DAYS_IN_400_YRS ( ( 100 * DAYS_IN_4_YRS ) - 3 )
|
||||
|
||||
// #define SECONDS_PER_DAY ( 24 * 60 * 60 )
|
||||
// extern short __diyr[], __dilyr[];
|
||||
|
||||
/*
|
||||
The number of leap years from year 1 to year 1900 is 460.
|
||||
The number of leap years from year 1 to current year is
|
||||
expressed by "years/4 - years/100 + years/400". To determine
|
||||
the number of leap years from current year to 1900, we subtract
|
||||
460 from the formula result. We do this since "days" is the
|
||||
number of days since 1900.
|
||||
*/
|
||||
|
||||
static unsigned long __DaysToJan1( unsigned year )
|
||||
{
|
||||
unsigned years = 1900 + year - 1;
|
||||
unsigned leap_days = years / 4 - years / 100 + years / 400 - 460;
|
||||
|
||||
return( year * 365UL + leap_days );
|
||||
}
|
||||
|
||||
/* __brktime breaks down a calendar time (clock) into a struct tm t */
|
||||
|
||||
struct tm *__brktime( unsigned long days,
|
||||
time_t wallclock,
|
||||
long gmtdelta, // localtime - gmtime
|
||||
struct tm *t )
|
||||
{
|
||||
unsigned long secs;
|
||||
unsigned year;
|
||||
int day_of_year;
|
||||
int month;
|
||||
short const *month_start;
|
||||
|
||||
/*
|
||||
If date is Jan 1, 1970 0:00 to 12:00 UTC and we are west of UTC
|
||||
then add a day to wallclock, subtract the gmtdelta value, and
|
||||
decrement the calculated days. This prevents local times
|
||||
such as "Wed Dec 31 19:00:00 1969 (EST)" from being
|
||||
erroneously reported as "Sun Feb 6 01:28:16 2106 (EST)"
|
||||
since (wallclock - gmtdelta) wraps (i.e., wallclock < gmtdelta).
|
||||
*/
|
||||
if( wallclock < 12 * 60 * 60UL && gmtdelta > 0 )
|
||||
wallclock += SECONDS_PER_DAY, days--; /* days compensated for wallclock one day ahead */
|
||||
wallclock -= ( time_t ) gmtdelta;
|
||||
days += wallclock / SECONDS_PER_DAY;
|
||||
secs = wallclock % SECONDS_PER_DAY;
|
||||
t->tm_hour = ( int ) ( secs / 3600 ) ;
|
||||
secs = secs % 3600;
|
||||
t->tm_min = ( int ) ( secs / 60 );
|
||||
t->tm_sec = secs % 60;
|
||||
|
||||
// The following two lines are not needed in the current implementation
|
||||
// because the range of values for days does not exceed DAYS_IN_400_YRS.
|
||||
// Even if it did, the algorithm still computes the correct values.
|
||||
//
|
||||
// unsigned year400s;
|
||||
//
|
||||
// year400s = (days / DAYS_IN_400_YRS) * 400;
|
||||
// days %= DAYS_IN_400_YRS;
|
||||
//
|
||||
// It is OK to reduce days to a value less than DAYS_IN_400_YRS, because
|
||||
// DAYS_IN_400_YRS is exactly divisible by 7. If it wasn't divisible by 7,
|
||||
// then the following line which appears at the bottom, should be computed
|
||||
// before the value of days is range reduced.
|
||||
// t->tm_wday = (days + 1) % 7; /* 24-sep-92 */
|
||||
//
|
||||
year = days / 365;
|
||||
day_of_year = ( int ) ( days - __DaysToJan1( year ) );
|
||||
while( day_of_year < 0 ) {
|
||||
--year;
|
||||
day_of_year += __leapyear( year + 1900 ) + 365;
|
||||
}
|
||||
// year += year400s;
|
||||
|
||||
t->tm_yday = day_of_year;
|
||||
t->tm_year = ( int ) year;
|
||||
month_start = __diyr;
|
||||
if( __leapyear( year + 1900 ) )
|
||||
month_start = __dilyr;
|
||||
month = day_of_year / 31; /* approximate month */
|
||||
if( day_of_year >= month_start[month + 1] )
|
||||
++month;
|
||||
t->tm_mon = month;
|
||||
t->tm_mday = day_of_year - month_start[month] + 1;
|
||||
|
||||
/* Calculate the day of the week */
|
||||
/* Jan 1,1900 is a Monday */
|
||||
|
||||
t->tm_wday = ( days + 1 ) % 7; /* 24-sep-92 */
|
||||
return( t );
|
||||
}
|
||||
|
||||
_WCRTLINK struct tm *_gmtime( const time_t *timer, struct tm *tm )
|
||||
{
|
||||
tm->tm_isdst = 0; /* assume not */
|
||||
return __brktime( DAYS_FROM_1900_TO_1970, *timer, 0L, tm );
|
||||
}
|
||||
|
||||
_WCRTLINK struct tm *gmtime( const time_t *timer )
|
||||
{
|
||||
_INITTHETIME;
|
||||
return( _gmtime( timer, &_THE_TIME ) );
|
||||
}
|
77
programs/develop/open watcom/trunk/clib/time/leapyear.c
Normal file
77
programs/develop/open watcom/trunk/clib/time/leapyear.c
Normal file
@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: Check if a year is a leap year + associated arrays
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <time.h>
|
||||
#include "rtdata.h"
|
||||
#include "timedata.h"
|
||||
|
||||
short const __based(__segname("_CONST")) __diyr[] = { /* days in normal year array */
|
||||
0, /* Jan */
|
||||
31, /* Feb */
|
||||
31 + 28, /* Mar */
|
||||
31 + 28 + 31, /* Apr */
|
||||
31 + 28 + 31 + 30, /* May */
|
||||
31 + 28 + 31 + 30 + 31, /* Jun */
|
||||
31 + 28 + 31 + 30 + 31 + 30, /* Jul */
|
||||
31 + 28 + 31 + 30 + 31 + 30 + 31, /* Aug */
|
||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, /* Sep */
|
||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, /* Oct */
|
||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, /* Nov */
|
||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, /* Dec */
|
||||
31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 /* Jan, next year */
|
||||
};
|
||||
|
||||
short const __based(__segname("_CONST")) __dilyr[] = { /* days in leap year array */
|
||||
0, /* Jan */
|
||||
31, /* Feb */
|
||||
31 + 29, /* Mar */
|
||||
31 + 29 + 31, /* Apr */
|
||||
31 + 29 + 31 + 30, /* May */
|
||||
31 + 29 + 31 + 30 + 31, /* Jun */
|
||||
31 + 29 + 31 + 30 + 31 + 30, /* Jul */
|
||||
31 + 29 + 31 + 30 + 31 + 30 + 31, /* Aug */
|
||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31, /* Sep */
|
||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30, /* Oct */
|
||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, /* Nov */
|
||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, /* Dec */
|
||||
31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 /* Jan, next year */
|
||||
};
|
||||
|
||||
int __leapyear( unsigned year )
|
||||
{
|
||||
if( year & 3 )
|
||||
return( 0 );
|
||||
if( ( year % 100 ) != 0 )
|
||||
return( 1 );
|
||||
if( ( year % 400 ) == 0 )
|
||||
return( 1 );
|
||||
return( 0 );
|
||||
}
|
59
programs/develop/open watcom/trunk/clib/time/localtim.c
Normal file
59
programs/develop/open watcom/trunk/clib/time/localtim.c
Normal file
@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: _localtime() converts time_t to struct tm
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <time.h>
|
||||
#include "rtdata.h"
|
||||
#include "thetime.h"
|
||||
#include "timedata.h"
|
||||
|
||||
_WCRTLINK struct tm *_localtime( const time_t *timer, struct tm *t )
|
||||
{
|
||||
time_t tod;
|
||||
|
||||
tzset();
|
||||
tod = *timer;
|
||||
t->tm_isdst = -1;
|
||||
#ifdef __LINUX__
|
||||
__check_tzfile( tod, t );
|
||||
#endif
|
||||
__brktime( DAYS_FROM_1900_TO_1970, tod, _RWD_timezone, t );
|
||||
|
||||
if( __isindst( t ) )
|
||||
__brktime( DAYS_FROM_1900_TO_1970, tod,
|
||||
_RWD_timezone - _RWD_dst_adjust, t );
|
||||
return( t );
|
||||
}
|
||||
|
||||
_WCRTLINK struct tm *localtime( const time_t *timer )
|
||||
{
|
||||
_INITTHETIME;
|
||||
return _localtime( timer, &_THE_TIME );
|
||||
}
|
103
programs/develop/open watcom/trunk/clib/time/locmktim.c
Normal file
103
programs/develop/open watcom/trunk/clib/time/locmktim.c
Normal file
@ -0,0 +1,103 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: mktime() without timezone and struct tm fields adjustment.
|
||||
* used by mktime() and DOS clock()
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include "rtdata.h"
|
||||
#include "timedata.h"
|
||||
|
||||
#define MONTH_YR ( 12 )
|
||||
#define DAY_YR ( 365 )
|
||||
#define HOUR_YR ( DAY_YR * 24 )
|
||||
#define MINUTE_YR ( HOUR_YR * 60 )
|
||||
#define SECOND_YR ( MINUTE_YR * 60 )
|
||||
#define __MONTHS ( INT_MIN / MONTH_YR )
|
||||
#define __DAYS ( INT_MIN / DAY_YR )
|
||||
|
||||
// these ones can underflow in 16bit environments,
|
||||
// so check the relative values first
|
||||
#if ( HOUR_YR ) < ( INT_MAX / 60 )
|
||||
#define __MINUTES ( INT_MIN / MINUTE_YR )
|
||||
#if ( MINUTE_YR ) < ( INT_MAX / 60 )
|
||||
#define __SECONDS ( INT_MIN / SECOND_YR )
|
||||
#else
|
||||
#define __SECONDS ( 0 )
|
||||
#endif
|
||||
#else
|
||||
#define __MINUTES ( 0 )
|
||||
#define __SECONDS ( 0 )
|
||||
#endif
|
||||
|
||||
#define SMALLEST_YEAR_VALUE ( __MONTHS + __DAYS + __MINUTES + __SECONDS )
|
||||
|
||||
time_t __local_mktime( const struct tm *t, long *pdays, long *pseconds )
|
||||
{
|
||||
int month;
|
||||
int year;
|
||||
long days;
|
||||
long seconds;
|
||||
short const *month_start;
|
||||
|
||||
month_start = __diyr;
|
||||
month = t->tm_mon % 12; /* put tm_mon into range */
|
||||
year = t->tm_year;
|
||||
if( year < SMALLEST_YEAR_VALUE )
|
||||
return( ( time_t ) -1 );
|
||||
year += t->tm_mon / 12;
|
||||
while( month < 0 )
|
||||
--year, month += 12;
|
||||
if( year < 0 )
|
||||
return( ( time_t ) -1 );
|
||||
if( __leapyear( ( unsigned ) ( year + 1900 ) ) )
|
||||
month_start = __dilyr;
|
||||
days = year * 365L /* # of days in the years */
|
||||
+ ( ( year + 3 ) / 4 ) /* add # of leap years before year */
|
||||
- ( ( year + 99 ) / 100 ) /* sub # of leap centuries */
|
||||
+ ( ( year + 399 - 100 ) / 400 ) /* add # of leap 4 centuries */
|
||||
/* adjust for 1900 offset */
|
||||
/* note: -100 == 300 (mod 400) */
|
||||
+ month_start[month] /* # of days to 1st of month*/
|
||||
+ t->tm_mday - 1; /* day of the month */
|
||||
seconds = ( ( ( long ) ( t->tm_hour ) ) *60L + ( long ) ( t->tm_min ) ) *60L + t->tm_sec;
|
||||
/* seconds needs to be positive for __brktime */
|
||||
while( seconds < 0 )
|
||||
days -= 1, seconds += ( long ) SECONDS_PER_DAY;
|
||||
while( seconds >= ( long ) SECONDS_PER_DAY )
|
||||
days += 1, seconds -= ( long ) SECONDS_PER_DAY;
|
||||
if( days < ( DAYS_FROM_1900_TO_1970 - 1 ) )
|
||||
return( ( time_t ) -1 );
|
||||
if ( pdays ) *pdays = days;
|
||||
if ( pseconds ) *pseconds = seconds;
|
||||
return( seconds + ( days - DAYS_FROM_1900_TO_1970 ) * ( long ) SECONDS_PER_DAY );
|
||||
}
|
69
programs/develop/open watcom/trunk/clib/time/mktime.c
Normal file
69
programs/develop/open watcom/trunk/clib/time/mktime.c
Normal file
@ -0,0 +1,69 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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 mktime() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include "rtdata.h"
|
||||
#include "timedata.h"
|
||||
|
||||
_WCRTLINK time_t mktime( struct tm *t )
|
||||
{
|
||||
long days;
|
||||
long seconds;
|
||||
long day_seconds;
|
||||
|
||||
seconds = __local_mktime( t, &days, &day_seconds );
|
||||
__brktime( (unsigned long) days, (time_t) day_seconds, 0L, t );
|
||||
tzset();
|
||||
seconds += _RWD_timezone; /* add in seconds from GMT */
|
||||
#ifdef __LINUX__
|
||||
if( t->tm_isdst < 0 )
|
||||
__check_tzfile( seconds, t );
|
||||
#endif
|
||||
/* if we are in d.s.t. then subtract __dst_adjust from seconds */
|
||||
if( __isindst( t ) ) /* - determine if we are in d.s.t. */
|
||||
seconds -= _RWD_dst_adjust;
|
||||
#ifdef __UNIX__ /* time_t is signed */
|
||||
if( seconds < 0 )
|
||||
return( ( time_t ) -1 );
|
||||
#else /* time_t is unsigned, special day check needed for 31 dec 1969 */
|
||||
/* check for overflow; days == 75277 && seconds == 23296 returns 0, but
|
||||
adjusted for dst may still be fine */
|
||||
if( days >= 75279 ||
|
||||
( seconds >= 0 && days >= 75276 ) ||
|
||||
( seconds < 0 && days <= DAYS_FROM_1900_TO_1970 ) )
|
||||
return( (time_t) -1 );
|
||||
/* 0 is year = 206, mon = 1, mday = 7, hour = 6, min = 28, sec = 16 */
|
||||
#endif
|
||||
return( ( time_t ) seconds );
|
||||
}
|
59
programs/develop/open watcom/trunk/clib/time/thetime.h
Normal file
59
programs/develop/open watcom/trunk/clib/time/thetime.h
Normal file
@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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!
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include "variety.h"
|
||||
#if defined(__OS2__) || defined(__NT__)
|
||||
// the OS/2 and NT files are identical
|
||||
#if defined(__SW_BM)
|
||||
|
||||
#include "thread.h"
|
||||
|
||||
#define _INITTHETIME
|
||||
#define _THE_TIME (__THREADDATAPTR->__The_timeP)
|
||||
|
||||
#else
|
||||
|
||||
static struct tm The_time;
|
||||
#define _INITTHETIME
|
||||
#define _THE_TIME The_time
|
||||
|
||||
#endif
|
||||
#else
|
||||
#ifdef __NETWARE__
|
||||
#define _INITTHETIME
|
||||
#define _THE_TIME (__THREADDATAPTR->__The_timeP)
|
||||
#else
|
||||
#define _INITTHETIME
|
||||
static struct tm The_time;
|
||||
#define _THE_TIME The_time
|
||||
#endif
|
||||
#endif
|
49
programs/develop/open watcom/trunk/clib/time/time.c
Normal file
49
programs/develop/open watcom/trunk/clib/time/time.c
Normal file
@ -0,0 +1,49 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: time() returns current time and date
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "timedata.h"
|
||||
|
||||
_WCRTLINK time_t time( time_t *timer )
|
||||
{
|
||||
auto struct tm t;
|
||||
time_t seconds;
|
||||
int milliseconds;
|
||||
|
||||
milliseconds = __getctime( &t ); /* get raw time and date */
|
||||
if( milliseconds >= 500 )
|
||||
t.tm_sec++;
|
||||
seconds = mktime( &t );
|
||||
if( timer != NULL )
|
||||
*timer = seconds;
|
||||
return( seconds );
|
||||
}
|
56
programs/develop/open watcom/trunk/clib/time/timedata.h
Normal file
56
programs/develop/open watcom/trunk/clib/time/timedata.h
Normal file
@ -0,0 +1,56 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: Specification of <time.h> internal interfaces.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef TIMEDATA_H_INCLUDED
|
||||
#define TIMEDATA_H_INCLUDED
|
||||
|
||||
#include "variety.h"
|
||||
#include <time.h>
|
||||
|
||||
extern int __dst_adjust;
|
||||
extern struct tm __start_dst; /* start of daylight savings */
|
||||
extern struct tm __end_dst; /* end of daylight savings */
|
||||
|
||||
#define SECONDS_FROM_1900_TO_1970 2208988800UL
|
||||
#define SECONDS_PER_DAY ( 24 * 60 * 60UL )
|
||||
#define DAYS_FROM_1900_TO_1970 ( ( long ) ( SECONDS_FROM_1900_TO_1970 / SECONDS_PER_DAY ) )
|
||||
|
||||
extern struct tm *__brktime( unsigned long, time_t, long, struct tm * );
|
||||
extern time_t __local_mktime( const struct tm *, long *, long * );
|
||||
extern int __leapyear( unsigned );
|
||||
extern int __isindst( struct tm * );
|
||||
extern int __getctime( struct tm * );
|
||||
extern int __read_tzfile( const char *tz );
|
||||
extern void __check_tzfile( time_t t, struct tm *timep );
|
||||
|
||||
extern short const __based(__segname("_CONST")) __diyr[]; /* days in normal year array */
|
||||
extern short const __based(__segname("_CONST")) __dilyr[]; /* days in leap year array */
|
||||
|
||||
#endif
|
250
programs/develop/open watcom/trunk/clib/time/timeutil.c
Normal file
250
programs/develop/open watcom/trunk/clib/time/timeutil.c
Normal file
@ -0,0 +1,250 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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: time utility functions
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <time.h>
|
||||
#include "rtdata.h"
|
||||
#include "timedata.h"
|
||||
|
||||
static int time_less( const struct tm *t1, const struct tm *t2 );
|
||||
|
||||
static int calc_yday( const struct tm *timetm, int year )
|
||||
{
|
||||
struct tm tmptm;
|
||||
int month_days;
|
||||
int first_wday;
|
||||
int nth_week;
|
||||
short const *diyr;
|
||||
|
||||
if( timetm->tm_isdst == 0 ) { // M.m.n.d form
|
||||
diyr = ( __leapyear( ( unsigned ) year + 1900 ) ) ? __dilyr : __diyr;
|
||||
month_days = diyr[timetm->tm_mon + 1] - diyr[timetm->tm_mon];
|
||||
tmptm.tm_sec = 0;
|
||||
tmptm.tm_min = 0;
|
||||
tmptm.tm_hour = 0;
|
||||
tmptm.tm_mday = 1;
|
||||
tmptm.tm_mon = timetm->tm_mon;
|
||||
tmptm.tm_year = year;
|
||||
tmptm.tm_isdst = 0;
|
||||
( void ) mktime( &tmptm );
|
||||
first_wday = ( timetm->tm_wday - tmptm.tm_wday + 7 ) % 7;
|
||||
if( timetm->tm_mday == 5 ) {
|
||||
if( ( 1 + first_wday + ( timetm->tm_mday - 1 ) * 7 ) > month_days )
|
||||
nth_week = timetm->tm_mday - 2; // fifth req. weekday does not exist
|
||||
else
|
||||
nth_week = timetm->tm_mday - 1;
|
||||
} else
|
||||
nth_week = timetm->tm_mday - 1;
|
||||
return( tmptm.tm_yday + first_wday + nth_week * 7 );
|
||||
}
|
||||
if( timetm->tm_isdst == 1 ) /* if Jn form */
|
||||
return( timetm->tm_yday - 1 );
|
||||
return( timetm->tm_yday );
|
||||
}
|
||||
|
||||
/* determine if in souther hemisphere -> start is after end */
|
||||
static int check_order( const struct tm *start, const struct tm *end, int year )
|
||||
{
|
||||
int start_day;
|
||||
int end_day;
|
||||
|
||||
/* these quick checks should always be enough */
|
||||
if( ( start->tm_isdst == 0 ) && ( end->tm_isdst == 0 ) ) { // M.m.n.d form
|
||||
if( start->tm_mon > end->tm_mon )
|
||||
return( 1 );
|
||||
if( start->tm_mon < end->tm_mon )
|
||||
return( 0 );
|
||||
}
|
||||
/* start/end of daylight savings time is in the same month (rare case) */
|
||||
/* these are *expensive* calculations under NT since 2 TZ checks must be done */
|
||||
start_day = calc_yday( start, year );
|
||||
end_day = calc_yday( end, year );
|
||||
if( start_day > end_day )
|
||||
return( 1 );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* determine if daylight savings time */
|
||||
int __isindst( struct tm *t )
|
||||
{
|
||||
int month;
|
||||
int dst;
|
||||
int n1;
|
||||
int n2;
|
||||
int month_days;
|
||||
int time_check;
|
||||
int south;
|
||||
struct tm const *start;
|
||||
struct tm const *end;
|
||||
short const *diyr;
|
||||
|
||||
// already determined -- if we are sure
|
||||
if( t->tm_isdst >= 0 )
|
||||
return( t->tm_isdst );
|
||||
dst = 0;
|
||||
// if zone doesn't have a daylight savings period
|
||||
if( _RWD_daylight == 0 )
|
||||
return( t->tm_isdst = dst );
|
||||
// // check for no daylight savings time rule
|
||||
// if( tzname[1][0] == '\0' ) { // doesn't work since Win32 says
|
||||
// return( t->tm_isdst = dst );// daylight zone name = standard zone name
|
||||
// }
|
||||
|
||||
south = check_order( &_RWD_start_dst, &_RWD_end_dst, t->tm_year );
|
||||
if( south ) {
|
||||
// if southern hemisphere
|
||||
// invert start and end dates and then invert return value
|
||||
start = &_RWD_end_dst;
|
||||
end = &_RWD_start_dst;
|
||||
} else {
|
||||
start = &_RWD_start_dst;
|
||||
end = &_RWD_end_dst;
|
||||
}
|
||||
month = t->tm_mon;
|
||||
diyr = ( __leapyear( ( unsigned ) t->tm_year + 1900 ) ) ? __dilyr : __diyr;
|
||||
month_days = diyr[month + 1] - diyr[month];
|
||||
time_check = 0;
|
||||
/*
|
||||
* M.m.n.d form
|
||||
* m = start->tm_mon (month 0-11)
|
||||
* n = start->tm_mday (n'th week day 1-5)
|
||||
* d = start->tm_wday (week day 0-6)
|
||||
*/
|
||||
if( start->tm_isdst == 0 ) { /* if Mm.n.d form */
|
||||
if( month > start->tm_mon )
|
||||
dst = 1; /* assume dst for now */
|
||||
else if( month == start->tm_mon ) {
|
||||
/* calculate for current day */
|
||||
n1 = t->tm_mday - ( t->tm_wday + 7 - start->tm_wday ) % 7;
|
||||
/* calculate for previous day */
|
||||
n2 = t->tm_mday - 1 - ( t->tm_wday - 1 + 7 - start->tm_wday ) % 7;
|
||||
// n_ stands for the day of the month that is past &&
|
||||
// is closest to today && is the required weekday
|
||||
if( start->tm_mday == 5 ) {
|
||||
if( n1 > month_days - 7 ) {
|
||||
dst = 1; /* assume dst for now */
|
||||
if( n2 <= month_days - 7 )
|
||||
time_check = 1;
|
||||
}
|
||||
} else {
|
||||
if( n1 >= 7 * ( start->tm_mday - 1 ) + 1 ) {
|
||||
dst = 1; /* assume dst for now */
|
||||
if( n2 < 7 * ( start->tm_mday - 1 ) + 1 )
|
||||
time_check = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
n1 = start->tm_yday;
|
||||
if( start->tm_isdst == 1 ) { /* if Jn form */
|
||||
if( __leapyear( ( unsigned ) t->tm_year + 1900 ) ) {
|
||||
if( n1 > __diyr[2] )
|
||||
n1++; /* past Feb 28 */
|
||||
}
|
||||
n1--;
|
||||
}
|
||||
if( t->tm_yday >= n1 ) {
|
||||
dst = 1; /* assume dst for now */
|
||||
if( t->tm_yday == n1 )
|
||||
time_check = 1;
|
||||
}
|
||||
}
|
||||
/* if it is the day for a switch-over then check the time too */
|
||||
if( time_check )
|
||||
dst = !time_less( t, start );
|
||||
|
||||
/* if we are certain that it is before daylight saving then return */
|
||||
if( dst == 0 ) {
|
||||
if( south )
|
||||
dst = south - dst; /* invert value of dst */
|
||||
return( t->tm_isdst = dst );
|
||||
}
|
||||
|
||||
/* now see if it is after daylight saving */
|
||||
time_check = 0;
|
||||
if( end->tm_isdst == 0 ) { /* if Mm.n.d form */
|
||||
if( month > end->tm_mon )
|
||||
dst = 0; /* not dst */
|
||||
else if( month == end->tm_mon ) {
|
||||
dst = 0;
|
||||
/* calculate for current day */
|
||||
n1 = t->tm_mday - ( t->tm_wday + 7 - end->tm_wday ) % 7;
|
||||
/* calculate for previous day */
|
||||
n2 = t->tm_mday - 1 -
|
||||
( t->tm_wday - 1 + 7 - end->tm_wday ) % 7;
|
||||
if( end->tm_mday == 5 ) {
|
||||
if( n1 <= month_days - 7 )
|
||||
dst = 1;
|
||||
else if( n2 <= month_days - 7 )
|
||||
time_check = 1;
|
||||
} else {
|
||||
if( n1 < 7 * ( end->tm_mday - 1 ) + 1 )
|
||||
dst = 1;
|
||||
else if( n2 < 7 * ( end->tm_mday - 1 ) + 1 )
|
||||
time_check = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
n1 = end->tm_yday;
|
||||
if( end->tm_isdst == 1 ) { /* if Jn form */
|
||||
if( __leapyear( ( unsigned ) t->tm_year + 1900 ) ) {
|
||||
if( n1 > __diyr[2] )
|
||||
n1++; /* past Feb 28 */
|
||||
}
|
||||
n1--;
|
||||
}
|
||||
if( t->tm_yday >= n1 ) {
|
||||
dst = 0;
|
||||
if( t->tm_yday == n1 )
|
||||
time_check = 1;
|
||||
}
|
||||
}
|
||||
/* if it is the day for a switch-over then check the time too */
|
||||
if( time_check )
|
||||
dst = time_less( t, end );
|
||||
if( south )
|
||||
dst = south - dst; /* invert value of dst */
|
||||
return( t->tm_isdst = dst );
|
||||
}
|
||||
|
||||
static int time_less( const struct tm *t1, const struct tm *t2 )
|
||||
{
|
||||
int before;
|
||||
|
||||
before = 0;
|
||||
if( t1->tm_hour < t2->tm_hour )
|
||||
before = 1;
|
||||
else if( t1->tm_hour == t2->tm_hour ) {
|
||||
if( t1->tm_min < t2->tm_min
|
||||
|| t1->tm_min == t2->tm_min && t1->tm_sec < t2->tm_sec )
|
||||
before = 1;
|
||||
}
|
||||
return( before );
|
||||
}
|
285
programs/develop/open watcom/trunk/clib/time/tzset.c
Normal file
285
programs/develop/open watcom/trunk/clib/time/tzset.c
Normal file
@ -0,0 +1,285 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* 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 tzset() implementation.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "variety.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
#include "rtdata.h"
|
||||
#include "timedata.h"
|
||||
#include "exitwmsg.h"
|
||||
#include "_time.h"
|
||||
|
||||
/*
|
||||
* TZSET - sets the values of the variables 'timezone', 'daylight'
|
||||
* and 'tzname' according to the setting of the environment
|
||||
* variable "TZ". The "TZ" variable has the format
|
||||
* :characters
|
||||
* or
|
||||
* <std><offset>[<dst>[<offset>]][,<start>[/<time>],<end>[/<time>]]]
|
||||
*/
|
||||
|
||||
//#define TZNAME_MAX 128 /* defined in <limits.h> */
|
||||
|
||||
struct tm __start_dst = { /* start of daylight savings */
|
||||
0, 0, 2, /* M4.1.0/02:00:00 default */
|
||||
1, 3, 0, /* i.e., 1st Sunday of Apr */
|
||||
0, 0, 0
|
||||
};
|
||||
|
||||
struct tm __end_dst = { /* end of daylight savings */
|
||||
0, 0, 1, /* M10.5.0/02:00:00 default */
|
||||
5, 9, 0, /* i.e., last Sunday of Oct */
|
||||
0, 0, 0 /* note that this is specified*/
|
||||
}; /* in terms of EST */
|
||||
/* i.e. 02:00 EDT == 01:00 EST*/
|
||||
|
||||
static char stzone[TZNAME_MAX + 1] = "EST"; /* place to store names */
|
||||
static char dtzone[TZNAME_MAX + 1] = "EDT"; /* place to store names */
|
||||
|
||||
_WCRTLINKD char *tzname[2] = { stzone, dtzone };
|
||||
|
||||
_WCRTLINKD long timezone = 5L * 60L * 60L; /* seconds from GMT */
|
||||
_WCRTLINKD int daylight = 1; /* d.s.t. indicator */
|
||||
int __dst_adjust = 60 * 60; /* daylight adjustment */
|
||||
|
||||
static struct {
|
||||
unsigned cache_OS_TZ : 1;
|
||||
unsigned have_OS_TZ : 1;
|
||||
} tzFlag = { 1, 0 };
|
||||
|
||||
int __DontCacheOSTZ( void )
|
||||
/*************************/
|
||||
{
|
||||
int old_flag;
|
||||
|
||||
old_flag = tzFlag.cache_OS_TZ;
|
||||
tzFlag.cache_OS_TZ = 0;
|
||||
tzFlag.have_OS_TZ = 0;
|
||||
return( old_flag );
|
||||
}
|
||||
|
||||
int __CacheOSTZ( void )
|
||||
/*********************/
|
||||
{
|
||||
int old_flag;
|
||||
|
||||
old_flag = tzFlag.cache_OS_TZ;
|
||||
tzFlag.cache_OS_TZ = 1;
|
||||
tzFlag.have_OS_TZ = 0;
|
||||
return( old_flag );
|
||||
}
|
||||
|
||||
static char *parse_time( char *tz, int *val )
|
||||
/*******************************************/
|
||||
{
|
||||
int value;
|
||||
|
||||
value = 0;
|
||||
while( *tz >= '0' && *tz <= '9' ) {
|
||||
value = value * 10 + *tz - '0';
|
||||
++tz;
|
||||
}
|
||||
*val = value;
|
||||
return( tz );
|
||||
}
|
||||
|
||||
static char *parse_offset( char *tz, char *name, long *offset )
|
||||
/*************************************************************/
|
||||
{
|
||||
int hours;
|
||||
int minutes;
|
||||
int seconds;
|
||||
int neg;
|
||||
int len;
|
||||
char ch;
|
||||
char const *tzstart;
|
||||
|
||||
if( *tz == ':' )
|
||||
tz++;
|
||||
/* remember where time zone name string begins */
|
||||
tzstart = tz;
|
||||
/* parse time zone name (should be 3 or more characters) */
|
||||
/* examples: PST8, EDT+6, Central Standard Time+7:00:00 */
|
||||
for( ;; ) {
|
||||
ch = *tz;
|
||||
if( ch == '\0' )
|
||||
break;
|
||||
if( ch == ',' )
|
||||
break;
|
||||
if( ch == '-' )
|
||||
break;
|
||||
if( ch == '+' )
|
||||
break;
|
||||
if( ch >= '0' && ch <= '9' )
|
||||
break;
|
||||
++tz;
|
||||
}
|
||||
len = tz - tzstart;
|
||||
if( len > TZNAME_MAX )
|
||||
len = TZNAME_MAX;
|
||||
memcpy( name, tzstart, ( size_t ) len );
|
||||
name[len] = '\0';
|
||||
|
||||
neg = 0;
|
||||
if( ch == '-' ) {
|
||||
neg = 1;
|
||||
++tz;
|
||||
} else if( ch == '+' )
|
||||
++tz;
|
||||
ch = *tz;
|
||||
if( ch >= '0' && ch <= '9' ) {
|
||||
hours = minutes = seconds = 0;
|
||||
tz = parse_time( tz, &hours );
|
||||
if( *tz == ':' ) {
|
||||
tz = parse_time( tz + 1, &minutes );
|
||||
if( *tz == ':' )
|
||||
tz = parse_time( tz + 1, &seconds );
|
||||
}
|
||||
*offset = seconds + ( ( minutes + ( hours * 60 ) ) * 60L );
|
||||
if( neg )
|
||||
*offset = -*offset;
|
||||
}
|
||||
return( tz );
|
||||
}
|
||||
|
||||
static char *parse_rule( char *tz, struct tm *timeptr )
|
||||
/*****************************************************/
|
||||
{
|
||||
int date_form;
|
||||
int days;
|
||||
int hours;
|
||||
int minutes;
|
||||
int seconds;
|
||||
|
||||
date_form = -1; /* n 0-365 */
|
||||
if( *tz == 'J' ) { /* Jn 1-365 (no leap days) */
|
||||
date_form = 1;
|
||||
tz++;
|
||||
}
|
||||
if( *tz == 'M' ) { /* Mm.n.d n'th day of month */
|
||||
date_form = 0;
|
||||
tz++;
|
||||
}
|
||||
timeptr->tm_isdst = date_form;
|
||||
tz = parse_time( tz, &days );
|
||||
if( date_form != 0 )
|
||||
timeptr->tm_yday = days;
|
||||
else {
|
||||
timeptr->tm_mon = days - 1; /* 1-12 for M form */
|
||||
if( *tz == '.' ) {
|
||||
tz = parse_time( tz + 1, &days ); /* 1-5 for M form */
|
||||
timeptr->tm_mday = days;
|
||||
if( *tz == '.' ) {
|
||||
tz = parse_time( tz + 1, &days );/* 0-6 for M form */
|
||||
timeptr->tm_wday = days;
|
||||
}
|
||||
}
|
||||
timeptr->tm_yday = 0;
|
||||
}
|
||||
|
||||
hours = 2;
|
||||
minutes = seconds = 0;
|
||||
if( *tz == '/' ) {
|
||||
tz = parse_time( tz + 1, &hours );
|
||||
if( *tz == ':' ) {
|
||||
tz = parse_time( tz + 1, &minutes );
|
||||
if( *tz == ':' )
|
||||
tz = parse_time( tz + 1, &seconds );
|
||||
}
|
||||
}
|
||||
timeptr->tm_sec = seconds;
|
||||
timeptr->tm_min = minutes;
|
||||
timeptr->tm_hour = hours;
|
||||
return( tz );
|
||||
}
|
||||
|
||||
void __parse_tz( char * tz )
|
||||
/**************************/
|
||||
{
|
||||
long dayzone;
|
||||
|
||||
_RWD_daylight = 0;
|
||||
tz = parse_offset( tz, stzone, &_RWD_timezone );
|
||||
if( *tz == '\0' ) {
|
||||
dtzone[0] = '\0';
|
||||
return;
|
||||
}
|
||||
_RWD_daylight = 1;
|
||||
dayzone = _RWD_timezone - ( 60*60 ); /* 16-aug-91 */
|
||||
tz = parse_offset( tz, dtzone, &dayzone );
|
||||
_RWD_dst_adjust = _RWD_timezone - dayzone;
|
||||
|
||||
/* parse daylight changing rules */
|
||||
if( *tz == ',' )
|
||||
tz = parse_rule( tz + 1, &__start_dst );
|
||||
if( *tz == ',' ) {
|
||||
tz = parse_rule( tz + 1, &__end_dst );
|
||||
/* convert rule to be in terms of Standard Time */
|
||||
/* rather than Daylight Time */
|
||||
__end_dst.tm_hour -= _RWD_dst_adjust / 3600;
|
||||
__end_dst.tm_min -= ( _RWD_dst_adjust / 60 ) % 60;
|
||||
__end_dst.tm_sec -= _RWD_dst_adjust % 60;
|
||||
}
|
||||
}
|
||||
|
||||
static int tryOSTimeZone( const char *tz )
|
||||
/****************************************/
|
||||
{
|
||||
if( tz == NULL ) {
|
||||
/* calling OS can be expensive; many programs don't care */
|
||||
if( tzFlag.cache_OS_TZ && tzFlag.have_OS_TZ )
|
||||
return( 1 );
|
||||
/* Assume that even if we end up not getting the TZ from OS,
|
||||
we won't have any better luck if we try later. */
|
||||
tzFlag.have_OS_TZ = 1;
|
||||
} else {
|
||||
tzFlag.have_OS_TZ = 0;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
// assume Eastern (North America) time zone
|
||||
_RWD_timezone = 5L * 60L * 60L;
|
||||
_RWD_dst_adjust = 60L * 60L;
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
_WCRTLINK void tzset( void )
|
||||
/**************************/
|
||||
{
|
||||
#ifndef __NETWARE__
|
||||
char *tz;
|
||||
|
||||
tz = getenv( "TZ" );
|
||||
if( !tryOSTimeZone( tz ) && tz != NULL )
|
||||
__parse_tz( tz );
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue
Block a user