Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4920 → Rev 4921

/contrib/sdk/sources/newlib/libc/sys/fload.c
File deleted
/contrib/sdk/sources/newlib/libc/sys/close.c
0,0 → 1,43
/* close.c -- close a file descriptor.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <errno.h>
#include <stdlib.h>
#include <sys/unistd.h>
#include <sys/kos_io.h>
#include "glue.h"
#include "io.h"
 
int
_DEFUN (close ,(fd),
int fd)
{
__io_handle *ioh;
 
if( (fd < 0) || (fd >=64) )
{
errno = EBADF;
return (-1);
};
 
ioh = &__io_tab[fd];
 
if( fd > STDERR_FILENO )
{
free(ioh->name);
__io_free(fd);
}
 
return (0);
}
/contrib/sdk/sources/newlib/libc/sys/errno.c
0,0 → 1,2
 
int errno;
/contrib/sdk/sources/newlib/libc/sys/fstat.c
0,0 → 1,59
/* fstat.c -- get status of a file.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <errno.h>
#include <string.h>
#include <sys/unistd.h>
#include <sys/kos_io.h>
#include <sys/stat.h>
#include "glue.h"
#include "io.h"
 
int
_DEFUN (fstat, (fd, buf),
int fd _AND
struct stat *buf)
{
fileinfo_t info;
__io_handle *ioh;
 
if( (fd < 0) || (fd >=64) )
{
errno = EBADF;
return (-1);
};
 
memset (buf, 0, sizeof (* buf));
 
if (fd <= STDERR_FILENO)
{
buf->st_mode = S_IFCHR;
buf->st_blksize = 0;
}
else
{
 
ioh = &__io_tab[fd];
get_fileinfo(ioh->name, &info);
 
buf->st_mode = S_IFREG;
buf->st_blksize = 4096;
buf->st_size = info.size;
};
 
return (0);
}
 
 
 
/contrib/sdk/sources/newlib/libc/sys/gettod.c
0,0 → 1,45
#include <_ansi.h>
#include <reent.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
int
_DEFUN (gettimeofday, (ptimeval, ptimezone),
struct timeval *ptimeval _AND
void *ptimezone)
{
unsigned int xtmp;
struct tm tmblk;
 
if( ptimeval )
{
ptimeval->tv_usec = 0;
 
__asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(3));
tmblk.tm_sec = (xtmp>>16)&0xff;
tmblk.tm_min = (xtmp>>8)&0xff;
tmblk.tm_hour = xtmp&0xff;
BCD_TO_BIN(tmblk.tm_sec);
BCD_TO_BIN(tmblk.tm_min);
BCD_TO_BIN(tmblk.tm_hour);
__asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(29));
tmblk.tm_mday = (xtmp>>16)&0xff;
tmblk.tm_mon = ((xtmp>>8)&0xff)-1;
tmblk.tm_year = ((xtmp&0xff)+2000)-1900;
tmblk.tm_wday = tmblk.tm_yday = 0;
tmblk.tm_isdst = -1;
ptimeval->tv_sec = mktime(&tmblk);
return 0;
}
else
{
errno = EINVAL;
return -1;
};
 
}
 
/contrib/sdk/sources/newlib/libc/sys/glue.h
0,0 → 1,31
/* glue.h -- common definitions for "glue" fucntions.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <_ansi.h>
 
#ifndef NULL
# define NULL 0
#endif
 
#ifdef __NO_UNDERSCORE__
# define _end end
# define _exit exit
#endif
 
extern char _end[]; /* _end is set in the linker command file */
 
/* only one prcess support, as this is OS dependant */
#define __MYPID 1
 
 
/contrib/sdk/sources/newlib/libc/sys/io.c
0,0 → 1,60
 
#include <stddef.h>
#include "io.h"
 
extern __io_handle __io_tab[64];
 
static int fake_io(const char *path, const void *buff,
size_t offset, size_t count, size_t *done)
{
*done = 0;
return 10;
};
 
static int fake_io_read(const char *path, void *buff,
size_t offset, size_t count, size_t *done) __attribute__ ((alias("fake_io")));
 
static int fake_io_write(const char *path, const void *buff,
size_t offset, size_t count, size_t *done) __attribute__ ((alias("fake_io")));
 
static inline void debug_out(const char val)
{
__asm__ __volatile__(
"int $0x40 \n\t"
::"a"(63), "b"(1),"c"(val));
}
 
static int debugwrite(const char *path, const void *buff,
size_t offset, size_t count, size_t *writes)
{
int ret = count;
const char *p = buff;
 
while (count--)
{
debug_out(*p++);
};
*writes = ret;
return ret;
};
 
void init_stdio()
{
__io_handle *ioh;
 
ioh = &__io_tab[__io_alloc()];
ioh->mode = _READ|_ISTTY;
ioh->read = &fake_io_read;
ioh->write = &fake_io_write;
 
ioh = &__io_tab[__io_alloc()];
ioh->mode = _WRITE|_ISTTY;
ioh->read = &fake_io_read;
ioh->write = &debugwrite;
 
ioh = &__io_tab[__io_alloc()];
ioh->mode = _WRITE|_ISTTY;
ioh->read = &fake_io_read;
ioh->write = &debugwrite;
 
}
/contrib/sdk/sources/newlib/libc/sys/io.h
0,0 → 1,32
 
#define _READ 0x0001 /* file opened for reading */
#define _WRITE 0x0002 /* file opened for writing */
#define _UNGET 0x0004 /* ungetc has been done */
#define _BIGBUF 0x0008 /* big buffer allocated */
#define _EOF 0x0010 /* EOF has occurred */
#define _SFERR 0x0020 /* error has occurred on this file */
#define _APPEND 0x0080 /* file opened for append */
#define _BINARY 0x0040 /* file is binary, skip CRLF processing */
#define _TMPFIL 0x0800 /* this is a temporary file */
#define _DIRTY 0x1000 /* buffer has been modified */
#define _ISTTY 0x2000 /* is console device */
#define _DYNAMIC 0x4000 /* FILE is dynamically allocated */
#define _FILEEXT 0x8000 /* lseek with positive offset has been done */
#define _COMMIT 0x0001 /* extended flag: commit OS buffers on flush */
 
typedef struct
{
char *name;
unsigned int offset;
int mode;
int lock;
int (*read)(const char *, void *, size_t, size_t, size_t *);
int (*write)(const char*, const void *, size_t, size_t, size_t*);
}__io_handle;
 
extern __io_handle __io_tab[64];
 
int __io_alloc();
void __io_free(int handle);
 
 
/contrib/sdk/sources/newlib/libc/sys/io_alloc.S
0,0 → 1,50
 
.section .text
 
.global ___io_alloc
.global ___io_free
.global ___io_tab
 
.align 8
___io_alloc:
pushl $__io_mutex
call ___mutex_lock
popl %eax
 
xorl %ecx, %ecx
bsfl __io_map, %eax
jnz .done
 
movl $32, %ecx
bsfl __io_map+4, %eax
jnz .done
 
xorl %eax, %eax
mov %eax, __io_mutex
notl %eax
ret
 
.done:
addl %ecx, %eax
btrl %eax, __io_map
movl $0, __io_mutex
ret
 
.align 8
___io_free:
movl 4(%esp), %eax
bts %eax, __io_map
ret
 
.section .data
 
__io_map: .long(0xFFFFFFFF)
.long(0xFFFFFFFF)
 
.section .bss
 
.align 16
 
___io_tab: .space 64*24
__io_mutex: .space 4
 
/contrib/sdk/sources/newlib/libc/sys/ioread.c
0,0 → 1,31
 
#include <sys/types.h>
#include <sys/kos_io.h>
 
int read_file(const char *path, void *buff,
size_t offset, size_t count, size_t *reads)
{
int retval;
int d0;
__asm__ __volatile__(
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %%eax, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl %%edx \n\t"
"pushl $0 \n\t"
"pushl %%ecx \n\t"
"pushl $0 \n\t"
"movl %%esp, %%ebx \n\t"
"mov $70, %%eax \n\t"
"int $0x40 \n\t"
"testl %%esi, %%esi \n\t"
"jz 1f \n\t"
"movl %%ebx, (%%esi) \n\t"
"1:"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(reads));
return retval;
};
 
/contrib/sdk/sources/newlib/libc/sys/iowrite.c
0,0 → 1,28
#include <sys/types.h>
#include <sys/kos_io.h>
 
int write_file(const char *path,const void *buff,
size_t offset, size_t count, size_t *writes)
{
int retval;
__asm__ __volatile__(
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %%eax, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl %%edx \n\t"
"pushl $0 \n\t"
"pushl %%ecx \n\t"
"pushl $3 \n\t"
"movl %%esp, %%ebx \n\t"
"mov $70, %%eax \n\t"
"int $0x40 \n\t"
"testl %%esi, %%esi \n\t"
"jz 1f \n\t"
"movl %%ebx, (%%esi) \n\t"
"1:"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(writes));
return retval;
};
/contrib/sdk/sources/newlib/libc/sys/isatty.c
0,0 → 1,27
/* isatty.c -- chek the terminal device.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include "glue.h"
 
/*
* isatty -- returns 1 if connected to a terminal device,
* returns 0 if not. Since we're hooked up to a
* serial port, we'll say yes _AND return a 1.
*/
int
_DEFUN (isatty, (fd),
int fd)
{
return (1);
}
/contrib/sdk/sources/newlib/libc/sys/lseek.c
0,0 → 1,51
 
#include <errno.h>
#include <stdlib.h>
#include <sys/unistd.h>
#include <sys/kos_io.h>
#include "glue.h"
#include "io.h"
 
 
_off_t
_DEFUN (lseek, (fd, pos, whence),
int fd _AND
_off_t pos _AND
int whence)
 
{
fileinfo_t info;
__io_handle *ioh;
_off_t ret;
 
if( (fd < 0) || (fd >=64) )
{
errno = EBADF;
return (-1);
};
 
ioh = &__io_tab[fd];
 
switch(whence)
{
case SEEK_SET:
ret = pos;
break;
case SEEK_CUR:
ret = ioh->offset + pos;
break;
case SEEK_END:
{
get_fileinfo(ioh->name, &info);
ret = pos + info.size;
break;
}
default:
errno = EINVAL;
return (-1);
};
 
ioh->offset = ret;
 
return( ret );
};
/contrib/sdk/sources/newlib/libc/sys/open.c
0,0 → 1,104
/* open.c -- open a file.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/kos_io.h>
#include "glue.h"
#include "io.h"
 
#undef erro
extern int errno;
 
int open (const char * filename, int flags, ...)
{
__io_handle *ioh;
fileinfo_t info;
int iomode, rwmode, offset;
int hid;
int err;
 
hid = __io_alloc();
if(hid < 0)
{
errno = EMFILE;
return (-1);
};
 
// path = getfullpath(name);
 
err = get_fileinfo(filename, &info);
 
if( flags & O_EXCL &&
flags & O_CREAT )
{
if( !err )
{
errno = EEXIST;
return (-1);
};
}
 
if( err )
{
if(flags & O_CREAT)
err=create_file(filename);
if( err )
{
errno = EACCES;
return -1;
};
};
 
if( flags & O_TRUNC )
set_file_size(filename, 0);
 
ioh = &__io_tab[hid];
 
rwmode = flags & ( O_RDONLY | O_WRONLY | O_RDWR );
 
iomode = 0;
offset = 0;
 
if( rwmode == O_RDWR )
iomode |= _READ | _WRITE;
else if( rwmode == O_RDONLY)
iomode |= _READ;
else if( rwmode == O_WRONLY)
iomode |= _WRITE;
 
if( flags & O_APPEND )
{
iomode |= _APPEND;
offset = info.size;
};
 
if( flags & (O_BINARY|O_TEXT) )
{
if( flags & O_BINARY )
iomode |= _BINARY;
} else
iomode |= _BINARY;
 
ioh->name = strdup(filename);
ioh->offset = offset;
ioh->mode = iomode;
ioh->read = read_file;
ioh->write = write_file;
 
return hid;
};
 
 
/contrib/sdk/sources/newlib/libc/sys/read.c
1,31 → 1,112
 
#include <sys/types.h>
/* read.c -- read bytes from a input device.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <alloca.h>
#include <sys/kos_io.h>
#include "glue.h"
#include "io.h"
 
int read_file(const char *path, void *buff,
size_t offset, size_t count, size_t *reads)
#undef erro
extern int errno;
 
ssize_t read(int fd, void *buf, size_t cnt)
{
int retval;
int d0;
__asm__ __volatile__(
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %%eax, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl %%edx \n\t"
"pushl $0 \n\t"
"pushl %%ecx \n\t"
"pushl $0 \n\t"
"movl %%esp, %%ebx \n\t"
"mov $70, %%eax \n\t"
"int $0x40 \n\t"
"testl %%esi, %%esi \n\t"
"jz 1f \n\t"
"movl %%ebx, (%%esi) \n\t"
"1:"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(reads));
return retval;
_ssize_t ret;
 
_ssize_t read_len, total_len;
unsigned reduce_idx, finish_idx;
unsigned iomode_flags;
char *buffer = buf;
int rc;
int h;
unsigned amount_read;
int err;
 
__io_handle *ioh;
 
if( (fd < 0) || (fd >=64) )
{
errno = EBADF;
return -1;
};
 
ioh = &__io_tab[fd];
 
iomode_flags = ioh->mode;
 
if( iomode_flags == 0 )
{
errno = EBADF;
return( -1 );
}
 
if( !(iomode_flags & _READ) )
{
errno = EACCES;
return( -1 );
}
 
if( iomode_flags & _BINARY ) /* if binary mode */
{
err = read_file(ioh->name, buffer, ioh->offset, cnt, &amount_read);
ioh->offset+= amount_read;
total_len = amount_read;
 
if(err)
if ( amount_read == 0)
return (-1);
}
else
{
total_len = 0;
read_len = cnt;
do
{
err=read_file(ioh->name,buffer, ioh->offset, cnt, &amount_read);
ioh->offset+=amount_read;
 
if( amount_read == 0 )
break; /* EOF */
 
reduce_idx = 0;
finish_idx = reduce_idx;
for( ; reduce_idx < amount_read; ++reduce_idx )
{
if( buffer[ reduce_idx ] == 0x1a ) /* EOF */
{
lseek(fd, ((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;
}
} while( read_len != 0 );
}
return( total_len );
}
/contrib/sdk/sources/newlib/libc/sys/unlink.c
0,0 → 1,48
/* unlink.c -- remove a file.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
 
#include "glue.h"
 
/*
* unlink -- since we have no file system,
* we just return an error.
*/
int
_DEFUN (unlink, (path),
char * path)
{
errno = EIO;
return (-1);
}
 
int
_DEFUN(link, (old, new),
const char *old _AND
const char *new)
{
errno = EIO;
return (-1);
}
 
clock_t
times (struct tms *tp)
{
return -1;
}
 
/contrib/sdk/sources/newlib/libc/sys/write.c
1,29 → 1,217
 
#include <sys/types.h>
/* write.c -- write bytes to an output device.
*
* Copyright (c) 1995 Cygnus Support
*
* The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this
* notice is included verbatim in any distributions. No written agreement,
* license, or royalty fee is required for any of the authorized uses.
* Modifications to this software may be copyrighted by their authors
* and need not follow the licensing terms described here, provided that
* the new terms are clearly indicated on the first page of each file where
* they apply.
*/
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <alloca.h>
#include <sys/kos_io.h>
#include "glue.h"
#include "io.h"
 
int write_file(const char *path,const void *buff,
size_t offset, size_t count, size_t *writes)
#undef erro
extern int errno;
 
 
#if 0
#define PAD_SIZE 512
 
static int zero_pad(int handle ) /* 09-jan-95 */
/*******************************/
{
int retval;
__asm__ __volatile__(
"pushl $0 \n\t"
"pushl $0 \n\t"
"movl %%eax, 1(%%esp) \n\t"
"pushl %%ebx \n\t"
"pushl %%edx \n\t"
"pushl $0 \n\t"
"pushl %%ecx \n\t"
"pushl $3 \n\t"
"movl %%esp, %%ebx \n\t"
"mov $70, %%eax \n\t"
"int $0x40 \n\t"
"testl %%esi, %%esi \n\t"
"jz 1f \n\t"
"movl %%ebx, (%%esi) \n\t"
"1:"
"addl $28, %%esp \n\t"
:"=a" (retval)
:"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(writes));
return retval;
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_r(ptr, handle, zeroBuf, writeAmt );
if( rc < 0 )
return( rc );
bytesToWrite -= writeAmt; /* more bytes written */
} while( bytesToWrite != 0 );
}
} else {
curPos = _lseek_r( ptr, handle, curPos, SEEK_SET );
if( curPos == -1 ) {
return( -1 );
}
}
 
return( 0 ); /* return success code */
}
#endif
 
static int os_write(int handle, const void *buffer, unsigned len, unsigned *amt )
{
__io_handle *ioh;
int rc;
 
rc = 0;
*amt = 0;
 
ioh = &__io_tab[handle];
 
rc = ioh->write(ioh->name,(const void*)buffer,ioh->offset,len,amt);
 
ioh->offset+= *amt;
 
if( *amt != len )
{
rc = ENOSPC;
}
 
return( rc );
}
 
/*
* write -- write bytes to the serial port. Ignore fd, since
* stdout and stderr are the same. Since we have no filesystem,
* open will only return an error.
*/
ssize_t write(int fd, const void *buffer, size_t cnt)
{
_ssize_t ret;
unsigned int iomode_flags;
unsigned len_written, i, j;
int rc2;
char *buf;
 
__io_handle *ioh;
 
if( (fd < 0) || (fd >=64) )
{
errno = EBADF;
return -1;
};
 
ioh = &__io_tab[fd];
 
iomode_flags = ioh->mode;
 
if( iomode_flags == 0 )
{
errno = EBADF;
return( -1 );
}
 
if( !(iomode_flags & _WRITE) )
{
errno = EACCES ;
return( -1 );
}
 
if( (iomode_flags & _APPEND) && !(iomode_flags & _ISTTY) )
{
ioh->offset = lseek(fd, 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
ioh->mode = 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( ptr, fd );
}
 
if( rc2 == 0 )
{
if( iomode_flags & _BINARY ) { /* if binary mode */
rc2 = os_write(fd, buffer, cnt, &len_written );
/* end of binary mode part */
} else { /* text mode */
 
int buf_size = 512;
 
buf = (char*)alloca( buf_size );
 
j = 0;
for( i = 0; i < cnt; )
{
if( ((const char*)buffer)[i] == '\n' )
{
buf[j] = '\r';
++j;
if( j == buf_size )
{
rc2 = os_write(fd, 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(fd, 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(fd, buf, j, &i );
if( rc2 == ENOSPC ) {
len_written += i;
} else {
len_written = cnt;
}
}
/* end of text mode part */
}
}
 
if( rc2 == -1 ) {
return( rc2 );
} else {
return( len_written );
}
 
return 0;
}