Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 615 → Rev 698

/programs/develop/open watcom/trunk/clib/src/strcmp.c
File deleted
/programs/develop/open watcom/trunk/clib/src/close.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fclose.c
File deleted
/programs/develop/open watcom/trunk/clib/src/setefg.c
File deleted
/programs/develop/open watcom/trunk/clib/src/rtinit.h
File deleted
/programs/develop/open watcom/trunk/clib/src/allocfp.c
File deleted
/programs/develop/open watcom/trunk/clib/src/fstatus.inc
File deleted
/programs/develop/open watcom/trunk/clib/src/flush.c
File deleted
/programs/develop/open watcom/trunk/clib/src/mbinit.c
File deleted
/programs/develop/open watcom/trunk/clib/src/ultoa.c
File deleted
/programs/develop/open watcom/trunk/clib/src/strdup.h
File deleted
/programs/develop/open watcom/trunk/clib/src/liballoc.h
File deleted
/programs/develop/open watcom/trunk/clib/src/flush.h
File deleted
/programs/develop/open watcom/trunk/clib/src/prtscncf.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fflush.c
File deleted
/programs/develop/open watcom/trunk/clib/src/rtcheck.h
File deleted
/programs/develop/open watcom/trunk/clib/src/handleio.h
File deleted
/programs/develop/open watcom/trunk/clib/src/farfunc.h
File deleted
/programs/develop/open watcom/trunk/clib/src/widechar.h
File deleted
/programs/develop/open watcom/trunk/clib/src/hugeval.c
File deleted
/programs/develop/open watcom/trunk/clib/src/lseekwnt.c
File deleted
/programs/develop/open watcom/trunk/clib/src/riscstr.h
File deleted
/programs/develop/open watcom/trunk/clib/src/tell.c
File deleted
/programs/develop/open watcom/trunk/clib/src/mdef.inc
File deleted
/programs/develop/open watcom/trunk/clib/src/langenvd.h
File deleted
/programs/develop/open watcom/trunk/clib/src/iobaddr.c
File deleted
/programs/develop/open watcom/trunk/clib/src/fopen.c
File deleted
/programs/develop/open watcom/trunk/clib/src/flushall.c
File deleted
/programs/develop/open watcom/trunk/clib/src/struct.inc
File deleted
/programs/develop/open watcom/trunk/clib/src/prtf.c
File deleted
/programs/develop/open watcom/trunk/clib/src/tmpfname.h
File deleted
/programs/develop/open watcom/trunk/clib/src/iomode.c
File deleted
/programs/develop/open watcom/trunk/clib/src/openklbr.c
File deleted
/programs/develop/open watcom/trunk/clib/src/exitwmsg.h
File deleted
/programs/develop/open watcom/trunk/clib/src/isattwnt.c
File deleted
/programs/develop/open watcom/trunk/clib/src/myvalist.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fputc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/iomode.h
File deleted
/programs/develop/open watcom/trunk/clib/src/ioalloc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/gtchewnt.c
File deleted
/programs/develop/open watcom/trunk/clib/src/stiomode.c
File deleted
/programs/develop/open watcom/trunk/clib/src/rtdata.h
File deleted
/programs/develop/open watcom/trunk/clib/src/commode.h
File deleted
/programs/develop/open watcom/trunk/clib/src/scnf.c
File deleted
/programs/develop/open watcom/trunk/clib/src/errorno.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fileacc.h
File deleted
/programs/develop/open watcom/trunk/clib/src/saferlib.h
File deleted
/programs/develop/open watcom/trunk/clib/src/qread.c
File deleted
/programs/develop/open watcom/trunk/clib/src/exitwmsg.inc
File deleted
/programs/develop/open watcom/trunk/clib/src/fmode.h
File deleted
/programs/develop/open watcom/trunk/clib/src/scanf.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fwrite.c
File deleted
/programs/develop/open watcom/trunk/clib/src/kolibri.h
File deleted
/programs/develop/open watcom/trunk/clib/src/clibi64.h
File deleted
/programs/develop/open watcom/trunk/clib/src/seterrno.c
File deleted
/programs/develop/open watcom/trunk/clib/src/mbchar.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fputs.c
File deleted
/programs/develop/open watcom/trunk/clib/src/qread.h
File deleted
/programs/develop/open watcom/trunk/clib/src/initfile.c
File deleted
/programs/develop/open watcom/trunk/clib/src/87state.h
File deleted
/programs/develop/open watcom/trunk/clib/src/orient.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fixpoint.h
File deleted
/programs/develop/open watcom/trunk/clib/src/seterrno.h
File deleted
/programs/develop/open watcom/trunk/clib/src/freefp.c
File deleted
/programs/develop/open watcom/trunk/clib/src/vsprintf.c
File deleted
/programs/develop/open watcom/trunk/clib/src/_clsewnt.c
File deleted
/programs/develop/open watcom/trunk/clib/src/ftos.h
File deleted
/programs/develop/open watcom/trunk/clib/src/mbislead.c
File deleted
/programs/develop/open watcom/trunk/clib/src/extfunc.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fsync.c
File deleted
/programs/develop/open watcom/trunk/clib/src/farsupp.h
File deleted
/programs/develop/open watcom/trunk/clib/src/mbisdbcs.c
File deleted
/programs/develop/open watcom/trunk/clib/src/variety.h
File deleted
/programs/develop/open watcom/trunk/clib/src/rewind.c
File deleted
/programs/develop/open watcom/trunk/clib/src/comtflag.c
File deleted
/programs/develop/open watcom/trunk/clib/src/fseek.c
File deleted
/programs/develop/open watcom/trunk/clib/src/ioexit.c
File deleted
/programs/develop/open watcom/trunk/clib/src/printf.c
File deleted
/programs/develop/open watcom/trunk/clib/src/lseek.c
File deleted
/programs/develop/open watcom/trunk/clib/src/ftell.c
File deleted
/programs/develop/open watcom/trunk/clib/src/printf.h
File deleted
/programs/develop/open watcom/trunk/clib/src/mf.h
File deleted
/programs/develop/open watcom/trunk/clib/src/iomodtty.c
File deleted
/programs/develop/open watcom/trunk/clib/src/lseek.h
File deleted
/programs/develop/open watcom/trunk/clib/src/iob.c
File deleted
/programs/develop/open watcom/trunk/clib/src/openmode.h
File deleted
/programs/develop/open watcom/trunk/clib/src/qwrite.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fread.c
File deleted
/programs/develop/open watcom/trunk/clib/src/istable.c
File deleted
/programs/develop/open watcom/trunk/clib/src/fprtf.h
File deleted
/programs/develop/open watcom/trunk/clib/src/fgetc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/streamio.h
File deleted
/programs/develop/open watcom/trunk/clib/src/wctomb.c
File deleted
/programs/develop/open watcom/trunk/clib/src/mbtowc.c
File deleted
/programs/develop/open watcom/trunk/clib/src/watcom.h
File deleted
/programs/develop/open watcom/trunk/clib/src/langenv.h
File deleted
/programs/develop/open watcom/trunk/clib/src/ulltoa.c
File deleted
/programs/develop/open watcom/trunk/clib/src/hdlman.c
File deleted
/programs/develop/open watcom/trunk/clib/src/xstring.h
File deleted
/programs/develop/open watcom/trunk/clib/src/qwrit.c
File deleted
/programs/develop/open watcom/trunk/clib/src/chktty.c
File deleted
/programs/develop/open watcom/trunk/clib/h/_comdef.h
0,0 → 1,171
/*
* _comdef.h Common Macro Definitions
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* This file is automatically generated. Do not edit directly.
*
* =========================================================================
*/
#ifndef _COMDEF_H_INCLUDED
#define _COMDEF_H_INCLUDED
#if !defined(_ENABLE_AUTODEPEND)
#pragma read_only_file;
#endif
 
#ifdef _WCDATA
#error The macro _WCDATA is reserved for use by the runtime library.
#endif
#ifdef _WCNEAR
#error The macro _WCNEAR is reserved for use by the runtime library.
#endif
#ifdef _WCFAR
#error The macro _WCFAR is reserved for use by the runtime library.
#endif
#ifdef _WCHUGE
#error The macro _WCHUGE is reserved for use by the runtime library.
#endif
#ifdef _WCI86NEAR
#error The macro _WCI86NEAR is reserved for use by the runtime library.
#endif
#ifdef _WCI86FAR
#error The macro _WCI86FAR is reserved for use by the runtime library.
#endif
#ifdef _WCI86HUGE
#error The macro _WCI86HUGE is reserved for use by the runtime library.
#endif
#ifdef _WCINTERRUPT
#error The macro _WCINTERRUPT is reserved for use by the runtime library.
#endif
#ifdef _WCUNALIGNED
#error The macro _WCUNALIGNED is reserved for use by the runtime library.
#endif
#if __WATCOMC__ > 1240
#define _WRTLCALL __declspec(__watcall)
#else
#define _WRTLCALL
#endif
#if defined(_M_IX86)
#define _WCNEAR __near
#define _WCFAR __far
#define _WCHUGE __huge
#define _WCINTERRUPT __interrupt
#define _WCUNALIGNED
#if defined(__386__)
#define _WCI86NEAR
#define _WCI86FAR
#define _WCI86HUGE
#else
#define _WCI86NEAR __near
#define _WCI86FAR __far
#define _WCI86HUGE __huge
#endif
#elif defined(__AXP__)
#define _WCNEAR
#define _WCFAR
#define _WCHUGE
#define _WCI86NEAR
#define _WCI86FAR
#define _WCI86HUGE
#define _WCINTERRUPT
#define _WCUNALIGNED __unaligned
#elif defined(__PPC__)
#define _WCNEAR
#define _WCFAR
#define _WCHUGE
#define _WCI86NEAR
#define _WCI86FAR
#define _WCI86HUGE
#define _WCINTERRUPT
#define _WCUNALIGNED __unaligned
#else
#define _WCNEAR
#define _WCFAR
#define _WCHUGE
#define _WCI86NEAR
#define _WCI86FAR
#define _WCI86HUGE
#define _WCINTERRUPT
#define _WCUNALIGNED
#endif
#if defined(M_I86HM)
#define _WCDATA _WCFAR
#elif defined(__SW_ND) || defined(__FUNCTION_DATA_ACCESS)
#define _WCDATA
#else
#define _WCDATA _WCNEAR
#endif
#if defined(__SW_BR)
#if defined(__NT__)
#define _WCRTLINK __declspec(dllimport) _WRTLCALL
#define _WCRTLINKD __declspec(dllimport)
#define _WMRTLINK __declspec(dllimport) _WRTLCALL
#define _WMRTLINKD __declspec(dllimport)
#define _WPRTLINK __declspec(dllimport) _WRTLCALL
#define _WPRTLINKD __declspec(dllimport)
#elif defined(__OS2__) && (defined(__386__) || defined(__PPC__))
#define _WCRTLINK _WRTLCALL
#define _WCRTLINKD
#define _WMRTLINK _WRTLCALL
#define _WMRTLINKD
#define _WPRTLINK _WRTLCALL
#define _WPRTLINKD
#else
#define _WCRTLINK _WRTLCALL
#define _WCRTLINKD
#define _WMRTLINK _WRTLCALL
#define _WMRTLINKD
#define _WPRTLINK _WRTLCALL
#define _WPRTLINKD
#endif
#else
#ifndef _WCRTLINK
#define _WCRTLINK _WRTLCALL
#endif
#ifndef _WCRTLINKD
#define _WCRTLINKD
#endif
#ifndef _WMRTLINK
#define _WMRTLINK _WRTLCALL
#endif
#ifndef _WMRTLINKD
#define _WMRTLINKD
#endif
#ifndef _WPRTLINK
#define _WPRTLINK _WRTLCALL
#endif
#ifndef _WPRTLINKD
#define _WPRTLINKD
#endif
#endif
/* control import modifier on intrinsic functions */
#ifndef _WCIRTLINK
#if defined(__INLINE_FUNCTIONS__)
#define _WCIRTLINK _WRTLCALL
#else
#define _WCIRTLINK _WCRTLINK
#endif
#endif
#ifndef _WMIRTLINK
#if defined(__NO_MATH_OPS) || defined(__AXP__) || defined(__PPC__)
#define _WMIRTLINK _WMRTLINK
#else
#define _WMIRTLINK _WRTLCALL
#endif
#endif
#ifndef _WPIRTLINK
#define _WPIRTLINK _WPRTLINK
#endif
/* for MS compatibility */
#ifndef _CRTAPI1
#define _CRTAPI1
#endif
#ifndef _CRTAPI2
#define _CRTAPI2
#endif
#ifndef _CRTIMP
#define _CRTIMP _WCRTLINK
#endif
#endif
/programs/develop/open watcom/trunk/clib/handleio/filelen.c
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: Implements POSIX filelength() function and Watcom
* _filelength64().
*
****************************************************************************/
 
 
#include "variety.h"
 
/* most includes should go after this line */
#include <stdio.h>
#include <unistd.h>
#include "iomode.h"
#include "rtcheck.h"
 
typedef struct
{
char *name;
unsigned int offset;
}__file_handle;
 
typedef struct
{ DWORD attr;
DWORD flags;
DWORD cr_time;
DWORD cr_date;
DWORD acc_time;
DWORD acc_date;
DWORD mod_time;
DWORD mod_date;
DWORD size;
DWORD size_high;
} FILEINFO;
 
int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo);
 
_WCRTLINK long filelength( int handle )
{
__file_handle *fh;
FILEINFO info;
 
__handle_check( handle, -1 );
fh = (__file_handle*) __getOSHandle( handle);
get_fileinfo(fh->name,&info);
 
return( info.size );
}
 
/programs/develop/open watcom/trunk/clib/handleio/int64.h
0,0 → 1,94
/****************************************************************************
*
* 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 _INT64_H_INCLUDED
#define _INT64_H_INCLUDED
 
#include "variety.h"
 
#ifdef __WATCOM_INT64__
#define USE_INT64
#endif
#include "clibi64.h"
 
 
#ifdef __INT64__
#define INT_TYPE INT64_TYPE
#define UINT_TYPE UINT64_TYPE
#define LONG_TYPE INT64_TYPE
#define ULONG_TYPE UINT64_TYPE
#define __I64NAME(_n1,_n2) _n2
 
#if !defined(USE_INT64)
#define __int64 double
#define REAL_INT_TYPE double
 
#define GET_INT64(__d) ( *( (INT_TYPE*)(&(__d)) ) )
#define GET_UINT64(__d) ( *( (UINT_TYPE*)(&(__d)) ) )
#define GET_REALINT64(__i) ( *( (double*)(&(__i)) ) )
#define GET_REALUINT64(__i) ( *( (double*)(&(__i)) ) )
 
#define HIGHWORD(__w,__i) (__w) = (unsigned)(__i).u._32[I64HI32]
#define LOWWORD(__w,__i) (__w) = (unsigned)(__i).u._32[I64LO32]
#define MAKE_INT64(__i,__h,__l) { \
(__i).u._32[I64HI32] = (__h); \
(__i).u._32[I64LO32] = (__l); \
}
 
#define RETURN_INT64(__i) return( GET_REALINT64(__i) )
#else
#define REAL_INT_TYPE __int64
 
#define GET_INT64(__d) ( __d )
#define GET_UINT64(__d) ( __d )
#define GET_REALINT64(__i) ( __i )
#define GET_REALUINT64(__i) ( __i )
 
#define HIGHWORD(__w,__i) (__w) = (unsigned)( (__i) >> 32 )
#define LOWWORD(__w,__i) (__w) = (unsigned)(__i)
#define MAKE_INT64(__i,__h,__l) (__i) = ( ((INT_TYPE)(__h)) << 32 ) | (__l)
 
#define RETURN_INT64(__i) return( __i )
#endif
 
#else
#define INT_TYPE int
#define UINT_TYPE unsigned int
#define LONG_TYPE long
#define ULONG_TYPE unsigned long
#define __I64NAME(_n1,_n2) _n1
#endif
 
#define INTSIZE ( sizeof( INT_TYPE ) )
 
 
#endif
/programs/develop/open watcom/trunk/clib/handleio/write.c
0,0 → 1,286
/****************************************************************************
*
* 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: C Runtime write() and _lwrite() implementation.
*
****************************************************************************/
 
 
#include "variety.h"
#include "int64.h"
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <malloc.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include "iomode.h"
#include "fileacc.h"
#include "rtcheck.h"
#include "rtdata.h"
#include "seterrno.h"
#include "lseek.h"
 
/*
The _lwrite function writes data to the specified file.
 
Note: This function is provided only for compatibility with 16-bit
versions of Windows. Win32-based applications should use the WriteFile
function.
 
UINT _lwrite(
HFILE hFile, // handle to file
LPCSTR lpBuffer, // write data buffer
UINT uBytes // number of bytes to write
);
*/
 
extern void __STKOVERFLOW();
 
/*
Win32 Note:
Note that it is not an error to set the file pointer to a position
beyond the end of the file. The size of the file does not increase
until you call the SetEndOfFile, WriteFile, or WriteFileEx function. A
write operation increases the size of the file to the file pointer
position plus the size of the buffer written, leaving the intervening
bytes uninitialized. Hence, the reason for zero-padding the file
to achieve POSIX conformance.
*/
 
/*
POSIX Note:
When writing to a file that does not support seek operations (pipe,
device, etc.), the O_APPEND flag is effectively ignored. POSIX does
not explicitly state this, but it is implied. Also, ESPIPE (illegal
seek error) is not listed for write(), only pwrite(). Hence we must
either not attempt to seek on such devices, or ignore the failures.
*/
 
#define PAD_SIZE 512
 
typedef union {
unsigned __int64 _64;
long _32[2];
} __i64;
 
static int zero_pad( int handle ) /* 09-jan-95 */
/*******************************/
{
int rc;
long curPos, eodPos;
long bytesToWrite;
unsigned writeAmt;
char zeroBuf[PAD_SIZE];
 
// Pad with zeros due to lseek() past EOF (POSIX)
curPos = __lseek( handle, 0L, SEEK_CUR ); /* current offset */
if( curPos == -1 )
return( -1 );
eodPos = __lseek( handle, 0L, SEEK_END ); /* end of data offset */
if( eodPos == -1 )
return( -1 );
 
if( curPos > eodPos ) {
bytesToWrite = curPos - eodPos; /* amount to pad by */
 
if( bytesToWrite > 0 ) { /* only write if needed */
memset( zeroBuf, 0x00, PAD_SIZE ); /* zero out a buffer */
do { /* loop until done */
if( bytesToWrite > PAD_SIZE )
writeAmt = 512;
else
writeAmt = (unsigned)bytesToWrite;
rc = write( handle, zeroBuf, writeAmt );
if( rc < 0 )
return( rc );
bytesToWrite -= writeAmt; /* more bytes written */
} while( bytesToWrite != 0 );
}
} else {
curPos = __lseek( handle, curPos, SEEK_SET );
if( curPos == -1 ) {
return( -1 );
}
}
 
return( 0 ); /* return success code */
}
 
/*
The os_write function returns 0 meaning no error, -1 meaning error, or
ENOSPC meaning no space left on device.
*/
 
typedef struct
{
char *name;
unsigned int offset;
}__file_handle;
 
int _stdcall write_file (const char *name,const void* buff,unsigned offset, unsigned count,unsigned *reads);
 
static int os_write( int handle, const void *buffer, unsigned len, unsigned *amt )
/********************************************************************************/
{
__file_handle *fh;
int rc;
 
rc = 0;
fh = (__file_handle*) __getOSHandle( handle );
if(write_file(fh->name,buffer,fh->offset,len,amt))
{
rc = __set_errno_nt();
};
 
 
if( *amt != len )
{
rc = ENOSPC;
__set_errno( rc );
}
return( rc );
}
 
_WCRTLINK int write( int handle, const void *buffer, unsigned len )
/**********************************************************************/
{
unsigned iomode_flags;
char *buf;
unsigned buf_size;
unsigned len_written, i, j;
int rc2;
 
__file_handle *fh;
 
__handle_check( handle, -1 );
iomode_flags = __GetIOMode( handle );
if( iomode_flags == 0 )
{
__set_errno( EBADF );
return( -1 );
}
if( !(iomode_flags & _WRITE) ) {
__set_errno( EACCES ); /* changed from EBADF to EACCES 23-feb-89 */
return( -1 );
}
 
fh = (__file_handle*) __getOSHandle( handle );
 
// put a semaphore around our writes
 
_AccessFileH( handle );
if( (iomode_flags & _APPEND) && !(iomode_flags & _ISTTY) )
{
fh->offset = __lseek( handle, 0L, SEEK_END ); /* end of data offset */
}
 
len_written = 0;
rc2 = 0;
 
// Pad the file with zeros if necessary
if( iomode_flags & _FILEEXT ) {
// turn off file extended flag
__SetIOMode_nogrow( handle, iomode_flags&(~_FILEEXT) );
 
// It is not required to pad a file with zeroes on an NTFS file system;
// unfortunately it is required on FAT (and probably FAT32). (JBS)
rc2 = zero_pad( handle );
}
 
if( rc2 == 0 ) {
if( iomode_flags & _BINARY ) { /* if binary mode */
rc2 = os_write( handle, buffer, len, &len_written );
/* end of binary mode part */
} else { /* text mode */
i = stackavail();
if( i < 0x00b0 ) {
__STKOVERFLOW(); /* not enough stack space */
}
buf_size = 512;
if( i < (512 + 48) ) {
buf_size = 128;
}
 
buf = __alloca( buf_size );
j = 0;
for( i = 0; i < len; )
{
if( ((const char*)buffer)[i] == '\n' )
{
buf[j] = '\r';
++j;
if( j == buf_size )
{
rc2 = os_write( handle, buf, buf_size, &j );
if( rc2 == -1 )
break;
len_written += j;
if( rc2 == ENOSPC )
break;
len_written = i;
j = 0;
}
}
buf[j] = ((const char*)buffer)[i];
++i;
++j;
if( j == buf_size ) {
rc2 = os_write( handle, buf, buf_size, &j );
if( rc2 == -1 )
break;
len_written += j;
if( rc2 == ENOSPC )
break;
len_written = i;
j = 0;
}
}
if( j ) {
rc2 = os_write( handle, buf, j, &i );
if( rc2 == ENOSPC ) {
len_written += i;
} else {
len_written = len;
}
}
/* end of text mode part */
}
}
_ReleaseFileH( handle );
if( rc2 == -1 ) {
return( rc2 );
} else {
return( len_written );
}
}