/contrib/sdk/sources/newlib/libc/reent/closer.c |
---|
3,7 → 3,6 |
#include <reent.h> |
#include <unistd.h> |
#include <_syslist.h> |
#include <errno.h> |
/* Some targets provides their own versions of this functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
16,6 → 15,9 |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
39,49 → 41,18 |
takes a pointer to the global data block, which holds |
<<errno>>. |
*/ |
extern unsigned __NFiles; |
#define __handle_check( __h, __r ) \ |
if( (__h) < 0 || (__h) > __NFiles ) { \ |
ptr->_errno = EBADF ; \ |
return( __r ); \ |
} |
int |
_DEFUN(_close_r, (ptr, fd), |
struct _reent *ptr _AND |
int fd) |
_close_r (ptr, fd) |
struct _reent *ptr; |
int fd; |
{ |
int ret; |
int h; |
__file_handle *fh; |
__handle_check( fd, -1 ); |
fh = (__file_handle*) __getOSHandle( fd ); |
if( fd > STDERR_FILENO ) |
{ |
_free_r(ptr, fh->name); |
_free_r(ptr, fh); |
__freePOSIXHandle( fd ); |
__SetIOMode_nogrow( fd, 0 ); |
errno = 0; |
if ((ret = _close (fd)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
return 0; |
} |
int |
_DEFUN( close,(fd), |
int fd) |
{ |
return _close_r(_REENT, fd); |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/fstatr.c |
---|
5,10 → 5,7 |
#include <unistd.h> |
#include <sys/stat.h> |
#include <_syslist.h> |
#include <errno.h> |
#include <string.h> |
/* Some targets provides their own versions of these functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
25,6 → 22,8 |
#else |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
51,70 → 50,6 |
<<errno>>. |
*/ |
#pragma pack(push, 1) |
typedef struct |
{ |
char sec; |
char min; |
char hour; |
char rsv; |
}detime_t; |
typedef struct |
{ |
char day; |
char month; |
short year; |
}dedate_t; |
typedef struct |
{ |
unsigned attr; |
unsigned flags; |
union |
{ |
detime_t ctime; |
unsigned cr_time; |
}; |
union |
{ |
dedate_t cdate; |
unsigned cr_date; |
}; |
union |
{ |
detime_t atime; |
unsigned acc_time; |
}; |
union |
{ |
dedate_t adate; |
unsigned acc_date; |
}; |
union |
{ |
detime_t mtime; |
unsigned mod_time; |
}; |
union |
{ |
dedate_t mdate; |
unsigned mod_date; |
}; |
unsigned size; |
unsigned size_high; |
} FILEINFO; |
#pragma pack(pop) |
extern unsigned __NFiles; |
#define __handle_check( __h, __r ) \ |
if( (__h) < 0 || (__h) > __NFiles ) { \ |
ptr->_errno = EBADF ; \ |
return( __r ); \ |
} |
int |
_fstat_r (ptr, fd, pstat) |
struct _reent *ptr; |
121,36 → 56,12 |
int fd; |
struct stat *pstat; |
{ |
FILEINFO info; |
int ret; |
__file_handle *fh; |
__handle_check( fd, -1 ); |
if (fd < 3) |
{ |
pstat->st_mode = S_IFCHR; |
pstat->st_blksize = 0; |
return 0; |
errno = 0; |
if ((ret = _fstat (fd, pstat)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
fh = (__file_handle*) __getOSHandle( fd ); |
get_fileinfo(fh->name, &info); |
memset (pstat, 0, sizeof (* pstat)); |
pstat->st_mode = S_IFREG; |
pstat->st_blksize = 4096; |
pstat->st_size = info.size; |
return 0; |
} |
int |
_DEFUN (fstat, (fd, pstat), |
int fd _AND |
struct stat *pstat) |
{ |
return _fstat_r (_REENT, fd, pstat); |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/getreent.c |
---|
19,7 → 19,3 |
::"r"(ent)); |
__sinit(ent); |
} |
/contrib/sdk/sources/newlib/libc/reent/gettimeofdayr.c |
---|
8,7 → 8,6 |
#include <sys/time.h> |
#include <sys/times.h> |
#include <_syslist.h> |
#include <errno.h> |
/* Some targets provides their own versions of these functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
27,7 → 26,7 |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
static int errno; |
extern int errno; |
/* |
FUNCTION |
74,40 → 73,4 |
return ret; |
} |
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10) |
int |
_gettimeofday (struct timeval *tv, void *tz) |
{ |
unsigned int xtmp; |
struct tm tmblk; |
if( tv ) |
{ |
tv->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; |
tv->tv_sec = mktime(&tmblk); |
return 0; |
} |
else |
{ |
errno = EINVAL; |
return -1; |
}; |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/isattyr.c |
---|
3,7 → 3,6 |
#include <reent.h> |
#include <unistd.h> |
#include <_syslist.h> |
#include <errno.h> |
/* Some targets provides their own versions of these functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
55,8 → 54,10 |
{ |
int ret; |
ptr->_errno = ENOTTY ; |
return 0; |
errno = 0; |
if ((ret = _isatty (fd)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/linkr.c |
---|
0,0 → 1,66 |
/* Reentrant versions of file system calls. These implementations |
just call the usual system calls. */ |
#include <reent.h> |
#include <unistd.h> |
#include <_syslist.h> |
/* Some targets provides their own versions of these functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
#ifdef _REENT_ONLY |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
#define REENTRANT_SYSCALLS_PROVIDED |
#endif |
#endif |
#ifdef REENTRANT_SYSCALLS_PROVIDED |
int _dummy_link_syscalls = 1; |
#else |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
<<_link_r>>---Reentrant version of link |
INDEX |
_link_r |
ANSI_SYNOPSIS |
#include <reent.h> |
int _link_r(struct _reent *<[ptr]>, |
const char *<[old]>, const char *<[new]>); |
TRAD_SYNOPSIS |
#include <reent.h> |
int _link_r(<[ptr]>, <[old]>, <[new]>) |
struct _reent *<[ptr]>; |
char *<[old]>; |
char *<[new]>; |
DESCRIPTION |
This is a reentrant version of <<link>>. It |
takes a pointer to the global data block, which holds |
<<errno>>. |
*/ |
int |
_DEFUN (_link_r, (ptr, old, new), |
struct _reent *ptr _AND |
_CONST char *old _AND |
_CONST char *new) |
{ |
int ret; |
errno = 0; |
if ((ret = _link (old, new)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/lseekr.c |
---|
3,7 → 3,6 |
#include <reent.h> |
#include <unistd.h> |
#include <_syslist.h> |
#include <errno.h> |
/* Some targets provides their own versions of this functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
16,72 → 15,10 |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
#pragma pack(push, 1) |
typedef struct |
{ |
char sec; |
char min; |
char hour; |
char rsv; |
}detime_t; |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
typedef struct |
{ |
char day; |
char month; |
short year; |
}dedate_t; |
typedef struct |
{ |
unsigned attr; |
unsigned flags; |
union |
{ |
detime_t ctime; |
unsigned cr_time; |
}; |
union |
{ |
dedate_t cdate; |
unsigned cr_date; |
}; |
union |
{ |
detime_t atime; |
unsigned acc_time; |
}; |
union |
{ |
dedate_t adate; |
unsigned acc_date; |
}; |
union |
{ |
detime_t mtime; |
unsigned mod_time; |
}; |
union |
{ |
dedate_t mdate; |
unsigned mod_date; |
}; |
unsigned size; |
unsigned size_high; |
} FILEINFO; |
#pragma pack(pop) |
extern unsigned __NFiles; |
#define __handle_check( __h, __r ) \ |
if( (__h) < 0 || (__h) > __NFiles ) { \ |
ptr->_errno = EBADF ; \ |
return( __r ); \ |
} |
/* |
FUNCTION |
<<_lseek_r>>---Reentrant version of lseek |
116,44 → 53,11 |
int whence) |
{ |
_off_t ret; |
__file_handle *fh; |
__handle_check( fd, -1 ); |
fh = (__file_handle*) __getOSHandle( fd ); |
switch(whence) |
{ |
case SEEK_SET: |
ret = pos; |
break; |
case SEEK_CUR: |
ret = fh->offset + pos; |
break; |
case SEEK_END: |
{ |
FILEINFO info; |
get_fileinfo(fh->name, &info); |
ret = pos + info.size; |
break; |
errno = 0; |
if ((ret = _lseek (fd, pos, whence)) == (_off_t) -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
default: |
ptr->_errno = EINVAL; |
return -1; |
}; |
fh->offset = ret; |
return( ret ); |
} |
_off_t |
_DEFUN (lseek, (fd, pos, whence), |
int fd _AND |
_off_t pos _AND |
int whence) |
{ |
return _lseek_r(_REENT, fd, pos, whence); |
}; |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/openr.c |
---|
4,11 → 4,6 |
#include <unistd.h> |
#include <fcntl.h> |
#include <_syslist.h> |
#include <sys/errno.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdarg.h> |
#include <sys/kos_io.h> |
/* Some targets provides their own versions of this functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
22,6 → 17,8 |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
49,173 → 46,20 |
<<errno>>. |
*/ |
#define NULL_HANDLE (int)-1 |
#define DUMMY_HANDLE (int)-2 |
#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 */ |
extern int _fmode; |
static inline void debug_out(const char val) |
{ |
__asm__ __volatile__( |
"int $0x40 \n\t" |
::"a"(63), "b"(1),"c"(val)); |
} |
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; |
}; |
static int __openFileHandle(const char *path, int mode, int *err) |
{ |
fileinfo_t info; |
__file_handle *handle; |
// path = getfullpath(name); |
*err = get_fileinfo(path, &info); |
if( mode & O_EXCL && mode & O_CREAT ) |
{ |
if( ! *err) |
{ |
*err = EEXIST; |
return -1; |
}; |
} |
if( *err) |
{ |
if(mode & O_CREAT) |
*err=create_file(path); |
if( *err) |
{ |
return -1; |
}; |
}; |
if( mode & O_TRUNC ) |
set_file_size(path, 0); |
if ( !(handle=(__file_handle*)malloc(sizeof( __file_handle) ))) |
{ |
*err = ENOMEM; |
return -1; |
}; |
handle->name = strdup(path); |
handle->offset = 0; |
handle->write = write_file; |
*err = 0; |
return (int)handle; |
}; |
int |
_DEFUN (_open_r, (ptr, file, flags, dmode), |
_DEFUN (_open_r, (ptr, file, flags, mode), |
struct _reent *ptr _AND |
_CONST char *file _AND |
int flags _AND |
int dmode) |
int mode) |
{ |
int hid; |
int handle; |
int err = 0; |
unsigned iomode_flags; |
int rwmode; |
/* |
if (flags & ~(O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_APPEND | O_TRUNC)) |
{ |
ptr->_errno = ENOSYS; |
return -1; |
} |
*/ |
// First try to get the required slot. |
// No point in creating a file only to not use it. JBS 99/10/26 |
hid = __allocPOSIXHandle( DUMMY_HANDLE ); |
if( hid == -1 ) |
{ |
ptr->_errno = EMFILE; |
return( -1 ); |
} |
handle = __openFileHandle( file, flags, &err); |
if( handle == -1 ) |
{ |
__freePOSIXHandle( hid ); |
ptr->_errno = err; |
return( -1 ); |
} |
__setOSHandle( hid, handle ); // JBS 99/11/01 |
rwmode = flags & ( O_RDONLY | O_WRONLY | O_RDWR | O_NOINHERIT ); |
iomode_flags = 0; |
if( rwmode == O_RDWR ) iomode_flags |= _READ | _WRITE; |
else if( rwmode == O_RDONLY) iomode_flags |= _READ; |
else if( rwmode == O_WRONLY) iomode_flags |= _WRITE; |
if( flags & O_APPEND ) iomode_flags |= _APPEND; |
if( flags & (O_BINARY|O_TEXT) ) { |
if( flags & O_BINARY ) iomode_flags |= _BINARY; |
} else { |
if( _fmode == O_BINARY ) iomode_flags |= _BINARY; |
} |
__SetIOMode( hid, iomode_flags ); |
ptr->_errno = 0; |
return (hid); |
} |
int |
_DEFUN (open, (file, flags, ...), |
const char *file _AND |
int flags _DOTS) |
{ |
va_list ap; |
int ret; |
va_start (ap, flags); |
ret = _open_r (_REENT, file, flags, va_arg (ap, int)); |
va_end (ap); |
errno = 0; |
if ((ret = _open (file, flags, mode)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/readr.c |
---|
3,7 → 3,6 |
#include <reent.h> |
#include <unistd.h> |
#include <_syslist.h> |
#include <errno.h> |
/* Some targets provides their own versions of this functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
17,6 → 16,8 |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
44,30 → 45,7 |
<<errno>>. |
*/ |
extern unsigned __NFiles; |
#define _READ 0x0001 /* file opened for reading */ |
#define _BINARY 0x0040 /* file is binary, skip CRLF processing */ |
#define _ISTTY 0x2000 /* is console device */ |
#define __handle_check( __h, __r ) \ |
if( (__h) < 0 || (__h) > __NFiles ) { \ |
ptr->_errno = EBADF; \ |
return( __r ); \ |
} |
_ssize_t |
_DEFUN (_read, (fd, buf, cnt), |
int fd _AND |
_PTR buf _AND |
size_t cnt) |
{ |
return _read_r( _REENT, fd, buf, cnt); |
} |
_ssize_t |
_DEFUN (_read_r, (ptr, fd, buf, cnt), |
struct _reent *ptr _AND |
int fd _AND |
76,93 → 54,10 |
{ |
_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; |
__file_handle *fh; |
__handle_check( fd, -1 ); |
__ChkTTYIOMode( fd ); |
iomode_flags = __GetIOMode( fd ); |
if( iomode_flags == 0 ) |
{ |
ptr->_errno = EBADF; |
return( -1 ); |
errno = 0; |
if ((ret = (_ssize_t)_read (fd, buf, cnt)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
if( !(iomode_flags & _READ) ) |
{ |
ptr->_errno = EACCES; /* changed from EBADF to EACCES 23-feb-89 */ |
return( -1 ); |
} |
fh = (__file_handle*) __getOSHandle( fd ); |
if( iomode_flags & _BINARY ) /* if binary mode */ |
{ |
err = read_file(fh->name, buffer, fh->offset, cnt, &amount_read); |
fh->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(fh->name,buffer, fh->offset, cnt, &amount_read); |
fh->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_r(ptr, 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; /* 04-feb-88, FWC */ |
} |
} while( read_len != 0 ); |
} |
return( total_len ); |
} |
_ssize_t |
_DEFUN (read, (fd, buf, cnt), |
int fd _AND |
_PTR buf _AND |
size_t cnt) |
{ |
return _read_r(_REENT, fd, buf, cnt); |
}; |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/renamer.c |
---|
0,0 → 1,74 |
/* Reentrant version of rename system call. */ |
#include <reent.h> |
#include <stdio.h> |
#include <unistd.h> |
#include <sys/stat.h> |
#include <_syslist.h> |
/* Some targets provides their own versions of these functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
#ifdef _REENT_ONLY |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
#define REENTRANT_SYSCALLS_PROVIDED |
#endif |
#endif |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
<<_rename_r>>---Reentrant version of rename |
INDEX |
_rename_r |
ANSI_SYNOPSIS |
#include <reent.h> |
int _rename_r(struct _reent *<[ptr]>, |
const char *<[old]>, const char *<[new]>); |
TRAD_SYNOPSIS |
#include <reent.h> |
int _rename_r(<[ptr]>, <[old]>, <[new]>) |
struct _reent *<[ptr]>; |
char *<[old]>; |
char *<[new]>; |
DESCRIPTION |
This is a reentrant version of <<rename>>. It |
takes a pointer to the global data block, which holds |
<<errno>>. |
*/ |
int |
_DEFUN (_rename_r, (ptr, old, new), |
struct _reent *ptr _AND |
_CONST char *old _AND |
_CONST char *new) |
{ |
int ret = 0; |
#ifdef HAVE_RENAME |
errno = 0; |
if ((ret = _rename (old, new)) == -1 && errno != 0) |
ptr->_errno = errno; |
#else |
if (_link_r (ptr, old, new) == -1) |
return -1; |
if (_unlink_r (ptr, old) == -1) |
{ |
/* ??? Should we unlink new? (rhetorical question) */ |
return -1; |
} |
#endif |
return ret; |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/timesr.c |
---|
0,0 → 1,63 |
/* Reentrant versions of times system calls */ |
#include <reent.h> |
#include <time.h> |
#include <sys/time.h> |
#include <sys/times.h> |
#include <_syslist.h> |
/* Some targets provides their own versions of these functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
#ifdef _REENT_ONLY |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
#define REENTRANT_SYSCALLS_PROVIDED |
#endif |
#endif |
#ifdef REENTRANT_SYSCALLS_PROVIDED |
int _dummy_times_syscalls = 1; |
#else |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
<<_times_r>>---Reentrant version of times |
INDEX |
_times_r |
ANSI_SYNOPSIS |
#include <reent.h> |
#include <sys/times.h> |
clock_t _times_r(struct _reent *<[ptr]>, struct tms *<[ptms]>); |
TRAD_SYNOPSIS |
#include <reent.h> |
#include <sys/times.h> |
clock_t _times_r(<[ptr]>, <[ptms]>) |
struct _reent *<[ptr]>; |
struct tms *<[ptms]>; |
DESCRIPTION |
This is a reentrant version of <<times>>. It |
takes a pointer to the global data block, which holds |
<<errno>>. |
*/ |
clock_t |
_DEFUN (_times_r, (ptr, ptms), |
struct _reent *ptr _AND |
struct tms *ptms) |
{ |
clock_t ret; |
ret = _times (ptms); |
return ret; |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/unlinkr.c |
---|
0,0 → 1,59 |
/* Reentrant versions of file system calls. These implementations |
just call the usual system calls. */ |
#include <reent.h> |
#include <unistd.h> |
#include <_syslist.h> |
/* Some targets provides their own versions of these functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
#ifdef _REENT_ONLY |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
#define REENTRANT_SYSCALLS_PROVIDED |
#endif |
#endif |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
<<_unlink_r>>---Reentrant version of unlink |
INDEX |
_unlink_r |
ANSI_SYNOPSIS |
#include <reent.h> |
int _unlink_r(struct _reent *<[ptr]>, const char *<[file]>); |
TRAD_SYNOPSIS |
#include <reent.h> |
int _unlink_r(<[ptr]>, <[file]>) |
struct _reent *<[ptr]>; |
char *<[file]>; |
DESCRIPTION |
This is a reentrant version of <<unlink>>. It |
takes a pointer to the global data block, which holds |
<<errno>>. |
*/ |
int |
_DEFUN (_unlink_r, (ptr, file), |
struct _reent *ptr _AND |
_CONST char *file) |
{ |
int ret; |
errno = 0; |
if ((ret = _unlink (file)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
/contrib/sdk/sources/newlib/libc/reent/writer.c |
---|
3,11 → 3,7 |
#include <reent.h> |
#include <unistd.h> |
#include <_syslist.h> |
#include <alloca.h> |
#include <errno.h> |
#include <string.h> |
/* Some targets provides their own versions of this functions. Those |
targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
20,6 → 16,8 |
#ifndef REENTRANT_SYSCALLS_PROVIDED |
/* We use the errno variable used by the system dependent layer. */ |
#undef errno |
extern int errno; |
/* |
FUNCTION |
47,211 → 45,19 |
<<errno>>. |
*/ |
#define _WRITE 0x0002 /* file opened for writing */ |
#define _APPEND 0x0080 /* file opened for append */ |
#define _BINARY 0x0040 /* file is binary, skip CRLF processing */ |
#define _ISTTY 0x2000 /* is console device */ |
#define _FILEEXT 0x8000 /* lseek with positive offset has been done */ |
#define __handle_check( __h, __r ) \ |
if( (__h) < 0 || (__h) > __NFiles ) { \ |
ptr->_errno = EBADF; \ |
return( __r ); \ |
} |
extern unsigned __NFiles; |
#define PAD_SIZE 512 |
static int zero_pad(struct _reent *ptr, 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_r( ptr, handle, 0L, SEEK_CUR ); /* current offset */ |
if( curPos == -1 ) |
return( -1 ); |
eodPos = _lseek_r( ptr, 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 */ |
} |
static int os_write(struct _reent *ptr, int handle, |
const void *buffer, unsigned len, unsigned *amt ) |
/********************************************************************************/ |
{ |
__file_handle *fh; |
int rc; |
rc = 0; |
*amt = 0; |
fh = (__file_handle*) __getOSHandle( handle ); |
rc = fh->write(fh->name,buffer,fh->offset,len,amt); |
fh->offset+= *amt; |
if( *amt != len ) |
{ |
rc = ENOSPC; |
ptr->_errno = ENOSPC; |
} |
return( rc ); |
} |
_ssize_t |
_DEFUN (_write_r, (ptr, fd, buffer, cnt), |
_DEFUN (_write_r, (ptr, fd, buf, cnt), |
struct _reent *ptr _AND |
int fd _AND |
_CONST _PTR buffer _AND |
_CONST _PTR buf _AND |
size_t cnt) |
{ |
_ssize_t ret; |
unsigned int iomode_flags; |
unsigned len_written, i, j; |
int rc2; |
char *buf; |
__file_handle *fh; |
__handle_check( fd, -1 ); |
iomode_flags = __GetIOMode( fd ); |
if( iomode_flags == 0 ) |
{ |
ptr->_errno = EBADF; |
return( -1 ); |
errno = 0; |
if ((ret = (_ssize_t)_write (fd, buf, cnt)) == -1 && errno != 0) |
ptr->_errno = errno; |
return ret; |
} |
if( !(iomode_flags & _WRITE) ) { |
ptr->_errno = EACCES ; /* changed from EBADF to EACCES 23-feb-89 */ |
return( -1 ); |
} |
if( (iomode_flags & _APPEND) && !(iomode_flags & _ISTTY) ) |
{ |
fh->offset = _lseek_r(ptr, 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 |
__SetIOMode_nogrow( fd, 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(ptr, 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(ptr, 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(ptr, 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(ptr, 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 ); |
} |
} |
_ssize_t |
_DEFUN (write, ( fd, buffer, cnt), |
int fd _AND |
_CONST _PTR buffer _AND |
size_t cnt) |
{ |
return _write_r(_REENT, fd, buffer, cnt); |
} |
#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |