Fixed some bugs.

svn path=/trunk/; revision=411
This commit is contained in:
Boudewijn Dekker 1999-04-23 18:43:00 +00:00
parent 98a3f0d6f5
commit 97c1f757f6
46 changed files with 1220 additions and 611 deletions

View file

@ -27,9 +27,9 @@
* DISCLAMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.4 $
* $Revision: 1.5 $
* $Author: ariadne $
* $Date: 1999/04/14 07:10:15 $
* $Date: 1999/04/23 18:43:00 $
*
*/
@ -184,6 +184,9 @@ int _fpclass (double x);
int _isnan (double x);
int _isinf (double x); // not exported
int _isnanl (long double x); // not exported
int _isinfl (long double x); // not exported
#define isnan(x) _isnan(x)
#define isinf(x) _isinf(x)

View file

@ -26,6 +26,12 @@ extern "C" {
#define _IOUNGETC 010000 /* there is an ungetc'ed character in the buffer */
#endif
// might need check for IO_APPEND aswell
#define WRITE_STREAM(f) ((((f)->_flag & _IOWRT) == _IOWRT ) || (((f)->_flag & _IORW) == _IORW ))
#define READ_STREAM(f) ((((f)->_flag & _IOREAD) == _IOREAD ) || (((f)->_flag & _IORW) == _IORW ))
int __set_errno(int err);
void *filehnd(int fn);
@ -35,7 +41,6 @@ int __fileno_alloc(void *hFile, int mode);
int _doprnt(const char *fmt, va_list args, FILE *f);
int _doscan(FILE *iop, const char *fmt, va_list argp);
int _dowscan(FILE *iop, const wchar_t *fmt, va_list argp);
int __fileno_dup2( int handle1, int handle2 );

View file

@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* @(#)quad.h 8.1 (Berkeley) 6/4/93
* $Id: quad.h,v 1.1 1999/04/17 09:11:02 ariadne Exp $
* $Id: quad.h,v 1.2 1999/04/23 18:43:00 ariadne Exp $
*/
/*
@ -58,8 +58,8 @@
typedef unsigned long long u_quad_t; /* quads */
typedef long long quad_t;
typedef unsigned long u_long;
typedef long long quad_t;
typedef unsigned long u_long;

View file

@ -18,11 +18,12 @@
* DISCLAMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.4 $
* $Revision: 1.5 $
* $Author: ariadne $
* $Date: 1999/04/17 09:11:02 $
* $Date: 1999/04/23 18:43:00 $
*
*/
// added modfl
#ifndef _MATH_H_
#define _MATH_H_
@ -103,15 +104,15 @@ double exp (double x);
double log (double x);
double log10 (double x);
double pow (double x, double y);
long double powl (long double x,long double y);
double sqrt (double x);
double ceil (double x);
long double ceill (long double x);
long double floorl (long double x);
double floor (double x);
double fabs (double x);
double ldexp (double x, int n);
double frexp (double x, int* exp);
double modf (double x, double* ip);
long double modfl (long double x,long double* ip);
long double modfl (long double x,long double* ip);
double fmod (double x, double y);

View file

@ -22,9 +22,9 @@
* DISCLAMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.8 $
* $Revision: 1.9 $
* $Author: ariadne $
* $Date: 1999/04/17 09:11:02 $
* $Date: 1999/04/23 18:43:00 $
*
*/
/* Appropriated for Reactos Crtdll by Ariadne */
@ -47,18 +47,21 @@ extern "C" {
/* Some flags for the iobuf structure provided by djgpp stdio.h */
#define _IOREAD 000010
#define _IOWRT 000020
#define _IOMYBUF 000040
#define _IOEOF 000100
#define _IOERR 000200
#define _IOSTRG 000400
#define _IORW 001000
#define _IOAPPEND 002000
#define _IORMONCL 004000 /* remove on close, for temp files */
#define _IOREAD 0x000010
#define _IOWRT 0x000020
#define _IOMYBUF 0x000040
#define _IOEOF 0x000100
#define _IOERR 0x000200
#define _IOSTRG 0x000400
#define _IORW (_IOREAD | _IOWRT)
#define _IOAPPEND 0x002000
#define _IORMONCL 0x004000 /* remove on close, for temp files */
/* if _flag & _IORMONCL, ._name_to_remove needs freeing */
#define _IOUNGETC 010000 /* there is an ungetc'ed character in the buffer */
#define _IOCOMMIT 0x4000
#define _IOUNGETC 0x010000 /* there is an ungetc'ed character in the buffer */
#define _IOCOMMIT 0x008000
#define _IODIRTY 0x000080
#define _IOAHEAD 0x000008
/*
@ -86,12 +89,11 @@ typedef struct {
int _ungotchar;
int _bufsiz;
char *_name_to_remove;
// int _fillsize;
} FILE;
#define _FILE_DEFINED
#endif
#define _fillsize _bufsiz
//#define _fillsize _bufsiz
/*
* The three standard file pointers provided by the run time library.

View file

@ -1,8 +1,13 @@
#include <crtdll/float.h>
#include <crtdll/internal/ieee.h>
//Obvious fixme
double _chgsign( double x )
double _chgsign( double __x )
{
return -1.0*x;
double_t *x = (double_t *)&x;
if ( x->sign == 1 )
x->sign = 0;
else
x->sign = 1;
return __x;
}

View file

@ -50,6 +50,13 @@ int _isinf(double __x)
return ( x->exponent == 0x7ff && ( x->mantissah == 0 && x->mantissal == 0 ));
}
int _finite( double x )
{
return !_isinf(x);
}
int _isinfl(long double __x)
{
/* Intel's extended format has the normally implicit 1 explicit

View file

@ -1,19 +1,31 @@
#include <windows.h>
#include <crtdll/io.h>
#define mode_t int
int
_chmod(const char *filename, int func)
_chmod(const char *filename, mode_t mode)
{
DWORD FileAttributes = 0;
if ( func == _S_IREAD )
FileAttributes &= FILE_ATTRIBUTE_READONLY;
if ( ((func & _S_IREAD) == _S_IREAD) && ((func & _S_IWRITE) == _S_IWRITE) )
FileAttributes &= FILE_ATTRIBUTE_NORMAL;
DWORD FileAttributes = 0;
FileAttributes = GetFileAttributes(filename);
if ( FileAttributes == -1 )
return -1;
if ( mode == 0 )
return -1;
if ( (mode & _S_IREAD) == _S_IREAD && (mode & _S_IWRITE) != _S_IWRITE)
FileAttributes &= FILE_ATTRIBUTE_READONLY;
else if ( ((mode & _S_IREAD) != _S_IREAD) && ((mode & _S_IWRITE) == _S_IWRITE) )
FileAttributes &= FILE_ATTRIBUTE_NORMAL;
else
FileAttributes &= FILE_ATTRIBUTE_NORMAL;
if ( SetFileAttributes(filename,func) == FALSE )
return -1;
if ( SetFileAttributes(filename,FileAttributes) == FALSE )
return -1;
return 1;
}
return 1;
}

View file

@ -3,9 +3,12 @@
#include <crtdll/internal/file.h>
int _close(int _fd)
int _close(int _fd)
{
CloseHandle(_get_osfhandle(_fd));
return __fileno_close(_fd);
if ( _fd == -1 )
return -1;
if ( CloseHandle(_get_osfhandle(_fd)) == FALSE )
return -1;
return __fileno_close(_fd);
}

View file

@ -7,52 +7,75 @@
int _findfirst(const char *_name, struct _finddata_t *result)
{
WIN32_FIND_DATA FindFileData;
char dir[MAX_PATH];
long hFindFile;
int len = 0;
if ( _name == NULL || _name[0] == 0 ) {
len = GetCurrentDirectory(MAX_PATH,dir);
WIN32_FIND_DATA FindFileData;
char dir[MAX_PATH];
long hFindFile;
int len = 0;
if ( _name == NULL || _name[0] == 0 ) {
len = GetCurrentDirectory(MAX_PATH-4,dir);
if (dir[len-1] != '\\') {
dir[len] = '\\';
dir[len+1] = 0;
}
strcat(dir,"*.*");
}
else
strcpy(dir,_name);
hFindFile = (long)FindFirstFileA( dir, &FindFileData );
result->attrib = FindFileData.dwFileAttributes;
dir[len] = '\\';
dir[len+1] = 0;
}
strcat(dir,"*.*");
}
else
strcpy(dir,_name);
hFindFile = (long)FindFirstFileA( dir, &FindFileData );
if ( hFindFile == -1 ) {
memset(result,0,sizeof(struct _finddata_t));
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
// result->time_create = FileTimeToUnixTime( &FindFileData.ftCreationTime,NULL);
// result->time_access = FileTimeToUnixTime( &FindFileData.ftLastAccessTime,NULL);
// result->time_write = FileTimeToUnixTime( &FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName,260);
return hFindFile;
result->time_create = FileTimeToUnixTime( &FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime( &FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime( &FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName,260);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if(!strchr(dir,'*') && !strchr(dir,'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
int _findnext(int handle, struct _finddata_t *result)
{
WIN32_FIND_DATA FindFileData;
if (handle == -1 )
return -1;
WIN32_FIND_DATA FindFileData;
// check no wildcards or invalid handle
if ( handle == 0 || handle == -1)
return 0;
if ( !FindNextFile((void *)handle, &FindFileData ) )
return -1;
result->attrib = FindFileData.dwFileAttributes;
// result->time_create = FileTimeToUnixTime( &FindFileData.ftCreationTime,NULL);
// result->time_access = FileTimeToUnixTime( &FindFileData.ftLastAccessTime,NULL);
// result->time_write = FileTimeToUnixTime( &FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName,260);
return 0;
if ( !FindNextFile((void *)handle, &FindFileData ) )
return -1;
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime( &FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime( &FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime( &FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName,260);
return 0;
}
int _findclose(int handle)
{
return FindClose((void *)handle);
// check no wildcards or invalid handle
if ( handle == 0 || handle == -1)
return 0;
return FindClose((void *)handle);
}

View file

@ -17,10 +17,6 @@
#include <crtdll/string.h>
#include <crtdll/io.h>
char* mktemp (char *_template)
{
return(_mktemp(_template));
}
char* _mktemp (char *_template)
{

View file

@ -12,11 +12,6 @@
#include <crtdll/stdio.h>
#include <crtdll/internal/file.h>
#undef setmode
int setmode(int _fd, int _newmode)
{
return _setmode(_fd, _newmode);
}
int _setmode(int _fd, int _newmode)
{

View file

@ -3,6 +3,5 @@
int _sopen(char *path,int access,int shflag,int mode)
{
return _open((path), (access)|(shflag), (mode));
}

View file

@ -1,7 +1,22 @@
#include <stdio.h>
#include <crtdll/stdio.h>
#include <crtdll/io.h>
#include <crtdll/errno.h>
#include <crtdll/sys/utime.h>
#include <crtdll/internal/file.h>
int _utime(const char* filename, struct utimbuf* buf)
int _utime(const char* filename, struct _utimbuf* buf)
{
printf("utime(filename %s, buf %x)\n",filename,buf);
return(-1);
}
int fn;
int ret;
fn = _open(filename, _O_RDWR);
if ( fn == -1 ) {
__set_errno(EBADF);
return -1;
}
ret = _futime(fn,buf);
if ( _close(fn) < 0 )
return -1;
return ret;
}

View file

@ -49,16 +49,16 @@ WCHAR_OBJECTS = wchar/wcscat.o wchar/wcschr.o wchar/wcscmp.o \
STDIO_OBJECTS = stdio/getenv.o stdio/filbuf.o \
stdio/fclose.o stdio/feof.o stdio/ferror.o stdio/fileno.o\
stdio/fflush.o stdio/fgetc.o stdio/fgetpos.o stdio/fgets.o stdio/flsbuf.o \
stdio/fopen.o stdio/fprintf.o stdio/fputc.o stdio/fputs.o \
stdio/fopen.o stdio/fprintf.o stdio/fputc.o stdio/fputs.o stdio/setvbuf.o\
stdio/fread.o stdio/freopen.o stdio/fscanf.o stdio/fseek.o \
stdio/fsetpos.o stdio/ftell.o stdio/fwalk.o stdio/fwrite.o stdio/getc.o \
stdio/getchar.o stdio/gets.o stdio/getw.o stdio/perror.o stdio/printf.o \
stdio/getchar.o stdio/gets.o stdio/getw.o stdio/perror.o \
stdio/putc.o stdio/putchar.o stdio/puts.o stdio/putw.o \
stdio/remove.o stdio/rename.o stdio/rewind.o stdio/allocfil.o\
stdio/scanf.o stdio/setbuf.o stdio/setbuffe.o stdlib/obsol.o\
stdio/setlineb.o stdio/setvbuf.o stdio/sprintf.o stdio/sscanf.o \
stdio/setbuf.o stdio/setbuffe.o stdlib/obsol.o stdio/setlineb.o\
stdio/scanf.o stdio/sscanf.o stdio/vscanf.o stdio/vsscanf.o stdio/vfscanf.o\
stdio/stdiohk.o stdio/stdhnd.o stdio/tempnam.o stdio/tmpfile.o stdio/tmpnam.o \
stdio/ungetc.o stdio/vfprintf.o stdio/vprintf.o \
stdio/ungetc.o stdio/printf.o stdio/vfprintf.o stdio/vprintf.o stdio/sprintf.o\
stdio/fdopen.o stdio/vsprintf.o stdio/frlist.o \
QUAD_OBJECTS = quad/qdivrem.o quad/divdi3.o quad/moddi3.o quad/udivdi3.o quad/umoddi3.o
@ -89,10 +89,10 @@ TCHAR_OBJECTS = tchar/strdec.o tchar/strinc.o tchar/strninc.o tchar/strncnt.o t
TIME_OBJECTS = time/ctime.o time/difftime.o time/strftime.o time/time.o time/clock.o
FLOAT_OBJECTS = float/fpreset.o float/clearfp.o float/cntrlfp.o float/statfp.o float/logb.o\
float/chgsign.o
float/chgsign.o float/fpclass.o float/isnan.o
SYS_STAT_OBJECTS = sys_stat/fstat.o sys_stat/stat.o sys_stat/futime.o
#SYS_STAT_OBJECTS = sys_stat/fstat.o sys_stat/stat.o sys_stat/futime.o
SYS_STAT_OBJECTS = sys_stat/fstat.o sys_stat/stat.o
MATH_OBJECTS = math/acos.o math/acosh.o math/asin.o math/asinh.o math/atan.o math/atan2.o\

View file

@ -1,26 +1,20 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <crtdll/math.h>
#include <crtdll/stdlib.h>
#include <crtdll/internal/ieee.h>
double
frexp(double x, int *exptr)
frexp(double __x, int *exptr)
{
union {
double d;
unsigned char c[8];
} u;
u.d = x;
/*
* The format of the number is:
* Sign, 12 exponent bits, 51 mantissa bits
* The exponent is 1023 biased and there is an implicit zero.
* We get the exponent from the upper bits and set the exponent
* to 0x3fe (1022).
*/
*exptr = (int)(((u.c[7] & 0x7f) << 4) | (u.c[6] >> 4)) - 1022;
u.c[7] &= 0x80;
u.c[7] |= 0x3f;
u.c[6] &= 0x0f;
u.c[6] |= 0xe0;
return u.d;
double_t *x = (double_t *)&__x;
if ( exptr != NULL )
*exptr = x->exponent - 0x3FE;
x->exponent = 0x3FE;
return __x;
}

View file

@ -1,17 +1,3 @@
#if 1
long double modfl(long double __x, long double *__i)
{
}
double modf(double __x, double *__i)
{
}
#else
/* @(#)s_modf.c 1.3 95/01/18 */
/*
* ====================================================
@ -24,7 +10,7 @@ double modf(double __x, double *__i)
* ====================================================
*/
#include <crtdll/float.h>
#include <crtdll/math.h>
#include <crtdll/internal/ieee.h>
@ -86,7 +72,6 @@ double modf(double __x, double *__i)
}
}
long double modfl(long double __x, long double *__i)
{
@ -145,4 +130,4 @@ long double modfl(long double __x, long double *__i)
}
}
#endif

View file

@ -78,3 +78,8 @@ double pow (double __x, double __y)
return __value;
}
long double powl (long double __x,long double __y)
{
return pow(__x,__y/2)*pow(__x,__y/2);
}

View file

@ -19,9 +19,9 @@
* DISCLAMED. This includes but is not limited to warrenties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.2 $
* $Revision: 1.3 $
* $Author: ariadne $
* $Date: 1999/04/02 21:43:55 $
* $Date: 1999/04/23 18:42:21 $
*
*/
@ -49,7 +49,7 @@ extern int main(int, char**, char**);
extern unsigned int _CRT_fmode;
void
_mingw32_init_fmode ()
_mingw32_init_fmode (void)
{
/* Don't set the file mode if the user hasn't set any value for it. */
if (_CRT_fmode)
@ -83,7 +83,7 @@ _mingw32_init_fmode ()
* The function mainCRTStartup is the entry point for all console programs.
*/
int
mainCRTStartup ()
mainCRTStartup (void)
{
int nRet;
@ -139,14 +139,13 @@ mainCRTStartup ()
* to find WinMainCRTStartup when linking GUI applications.
*/
int
WinMainCRTStartup ()
WinMainCRTStartup (void)
{
return mainCRTStartup();
}
/* With the EGCS build from Mumit Khan (or apparently b19 from Cygnus) this
* is no longer necessary. */
#if 0
#ifdef __GNUC__
/*
* This section terminates the list of imports under GCC. If you do not
@ -155,5 +154,4 @@ WinMainCRTStartup ()
*/
asm (".section .idata$3\n" ".long 0,0,0,0,0,0,0,0");
#endif
#endif

View file

@ -17,14 +17,15 @@
* DISCLAMED. This includes but is not limited to warrenties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.2 $
* $Author: dwelch $
* $Date: 1999/04/14 00:51:19 $
* $Revision: 1.3 $
* $Author: ariadne $
* $Date: 1999/04/23 18:42:21 $
*
*/
#include <windows.h>
#include <stdarg.h>
#include <string.h>
void debug_printf(char* fmt, ...)
{

View file

@ -19,9 +19,9 @@
* DISCLAMED. This includes but is not limited to warrenties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.2 $
* $Revision: 1.3 $
* $Author: ariadne $
* $Date: 1999/04/02 21:43:56 $
* $Date: 1999/04/23 18:42:21 $
*
*/
@ -56,7 +56,7 @@ extern void __GetMainArgs(int *, char***, char***, int);
* Initialize the _argc, _argv and environ variables.
*/
static void
_mingw32_init_mainargs ()
_mingw32_init_mainargs (void)
{
/* The environ variable is provided directly in stdlib.h through
* a dll function call. */

View file

@ -8,33 +8,38 @@
#include <crtdll/errno.h>
#include <crtdll/internal/file.h>
// changed check for writable stream
int
fclose(FILE *f)
{
int r;
int r = 0;
r = EOF;
if (!f) {
if (f == NULL) {
__set_errno (EINVAL);
return r;
return EOF;
}
// flush only if stream was opened for writing
if (f->_flag & (_IOREAD|_IOWRT|_IORW)
&& !(f->_flag&_IOSTRG))
{
r = fflush(f);
if (_close(fileno(f)) < 0)
r = EOF;
if (f->_flag&_IOMYBUF)
free(f->_base);
}
if (f->_flag & _IORMONCL && f->_name_to_remove)
{
remove(f->_name_to_remove);
free(f->_name_to_remove);
f->_name_to_remove = 0;
// flush only if stream was opened for writing
if ( !(f->_flag&_IOSTRG) ) {
if ( WRITE_STREAM(f) )
r = fflush(f);
if (_close(fileno(f)) < 0)
r = EOF;
if (f->_flag&_IOMYBUF)
free(f->_base);
// Kernel might do this later
if (f->_flag & _IORMONCL && f->_name_to_remove)
{
remove(f->_name_to_remove);
free(f->_name_to_remove);
f->_name_to_remove = 0;
}
}
f->_cnt = 0;
f->_base = 0;

View file

@ -1,5 +1,6 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <crtdll/stdio.h>
#include <crtdll/errno.h>
#include <crtdll/internal/file.h>
#ifdef feof
@ -9,5 +10,10 @@ int feof(FILE *stream);
int feof(FILE *stream)
{
if (stream == NULL) {
__set_errno (EINVAL);
return EOF;
}
return stream->_flag & _IOEOF;
}

View file

@ -13,45 +13,65 @@
int fflush(FILE *f)
{
char *base;
int n, rn;
if (f == NULL)
{
int e = errno;
__set_errno(0);
_fwalk((void (*)(FILE *))fflush);
if (_errno)
return EOF;
__set_errno(e);
return 0;
}
f->_flag &= ~_IOUNGETC;
if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
&& (base = f->_base) != NULL
&& (rn = n = f->_ptr - base) > 0)
{
f->_ptr = base;
f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
do
{
n = _write(fileno(f), base, rn);
if (n <= 0)
{
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
} while (rn > 0);
}
if (f->_flag & _IORW)
{
f->_cnt = 0;
f->_flag &= ~(_IOWRT|_IOREAD);
f->_ptr = f->_base;
}
return 0;
char *base;
int n, rn;
if (f == NULL)
{
int e = errno;
__set_errno(0);
_fwalk((void (*)(FILE *))fflush);
if (_errno)
return EOF;
__set_errno(e);
return 0;
}
// nothing to do if stream can not be written to
//if ( !WRITE_STREAM(f) )
// return 0;
f->_flag &= ~_IOUNGETC;
// if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
// && (base = f->_base) != NULL
// && (rn = n = f->_ptr - base) > 0)
if ((f->_flag&(_IODIRTY|_IONBF))==_IODIRTY
&& (base = f->_base) != NULL
&& (rn = n = f->_ptr - base) > 0)
{
f->_ptr = base;
if ((f->_flag & _IOFBF) == _IOFBF) {
if ( (f->_flag & _IOAHEAD) == _IOAHEAD )
_lseek(fileno(f),-(rn+f->_cnt), SEEK_CUR);
}
f->_flag &= ~_IOAHEAD;
f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
f->_flag &= ~_IODIRTY;
do {
n = _write(fileno(f), base, rn);
if (n <= 0) {
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
} while (rn > 0);
}
if (f->_flag & _IORW)
{
f->_cnt = 0;
//f->_flag &= ~(_IOWRT|_IOREAD);
f->_ptr = f->_base;
}
return 0;
}

View file

@ -10,86 +10,26 @@
#include <crtdll/io.h>
#include <crtdll/wchar.h>
/*
* Note: We set _fillsize to 512, and use that for reading instead of
* _bufsize, for performance reasons. We double _fillsize each time
* we read here, and reset it to 512 each time we call fseek. That
* way, we don't waste time reading data we won't use, or doing lots
* of small reads we could optimize. If we do lots of seeking, we'll
* end up maintaining small read sizes, but if we don't seek, we'll
* eventually read blocks as large as the transfer buffer.
*/
int _readcnv(int fn, void *buf, size_t siz );
int _filbuf(FILE *f)
int
_filbuf(FILE *f)
{
int size, fillsize;
int size;
char c;
if (f->_flag & _IORW)
f->_flag |= _IOREAD;
if ((f->_flag&_IOREAD) == 0)
return EOF;
if (f->_flag&(_IOSTRG|_IOEOF))
return EOF;
f->_flag &= ~_IOUNGETC;
if (f->_base==NULL && (f->_flag&_IONBF)==0)
{
size = 512;
if ((f->_base = malloc(size)) == NULL)
{
f->_flag |= _IONBF;
f->_flag &= ~(_IOFBF|_IOLBF);
}
else
{
f->_flag |= _IOMYBUF;
f->_bufsiz = size;
//f->_fillsize = 512;
}
}
if (f->_flag&_IONBF)
f->_base = &c;
if (f == stdin)
{
if (stdout->_flag&_IOLBF)
fflush(stdout);
if (stderr->_flag&_IOLBF)
fflush(stderr);
}
/* don't read too much! */
//if (f->_fillsize > f->_bufsiz)
// f->_fillsize = f->_bufsiz;
/* This next bit makes it so that the cumulative amount read always
aligns with file cluster boundaries; i.e. 512, then 2048
(512+1536), then 4096 (2048+2048) etc. */
//fillsize = f->_fillsize;
//if (fillsize == 1024 && f->_bufsiz >= 1536)
// fillsize = 1536;
if (f->_flag & _IONBF)
{
f->_cnt = read(fileno(f), f->_base, 1);
}
else
{
f->_cnt = read(fileno(f), f->_base, size);
}
// if ( !READ_STREAM(f))
// return EOF;
if ((f->_flag&_IOREAD) == 0)
return EOF;
if (f->_flag&(_IOSTRG|_IOEOF))
return EOF;
f->_flag &= ~_IOUNGETC;
if (f->_base==NULL && (f->_flag&_IONBF)==0) {
size = 512;
if ((f->_base = malloc(size)) == NULL)
size = 4096;
if ((f->_base = malloc(size+1)) == NULL)
{
f->_flag |= _IONBF;
f->_flag &= ~(_IOFBF|_IOLBF);
@ -98,7 +38,6 @@ int _filbuf(FILE *f)
{
f->_flag |= _IOMYBUF;
f->_bufsiz = size;
f->_fillsize = 512;
}
}
@ -112,23 +51,15 @@ int _filbuf(FILE *f)
fflush(stderr);
}
/* don't read too much! */
if (f->_fillsize > f->_bufsiz)
f->_fillsize = f->_bufsiz;
// if(__is_text_file(f))
// f->_cnt = _readcnv(fileno(f), f->_base,
// f->_flag & _IONBF ? 1 : f->_bufsiz );
// else
/* This next bit makes it so that the cumulative amount read always
aligns with file cluster boundaries; i.e. 512, then 2048
(512+1536), then 4096 (2048+2048) etc. */
fillsize = f->_fillsize;
if (fillsize == 1024 && f->_bufsiz >= 1536)
fillsize = 1536;
f->_cnt = _read(fileno(f), f->_base,
f->_flag & _IONBF ? 1 : fillsize);
/* Read more next time, if we don't seek */
if (f->_fillsize < f->_bufsiz)
f->_fillsize *= 2;
f->_cnt = _read(fileno(f), f->_base,
f->_flag & _IONBF ? 1 : f->_bufsiz );
f->_flag |= _IOAHEAD;
if(__is_text_file(f) && f->_cnt>0)
{
@ -142,18 +73,20 @@ int _filbuf(FILE *f)
}
}
f->_ptr = f->_base;
if (f->_flag & _IONBF)
f->_base = NULL;
if (f->_flag & _IONBF)
f->_base = NULL; // statically allocated buffer for sprintf
if (--f->_cnt < 0) {
if (f->_cnt == -1) {
f->_flag |= _IOEOF;
if (f->_flag & _IORW)
f->_flag &= ~_IOREAD;
//if (f->_flag & _IORW)
//f->_flag &= ~_IOREAD;
} else
f->_flag |= _IOERR;
f->_cnt = 0;
return EOF;
}
return *f->_ptr++ & 0377;
}
@ -161,3 +94,26 @@ wint_t _filwbuf(FILE *fp)
{
return (wint_t )_filbuf(fp);
}
// convert the carriage return line feed pairs
int _readcnv(int fn, void *buf, size_t siz )
{
char *bufp = (char *)buf;
int _bufsiz = siz;
int cr = 0;
int n;
n = _read(fn, buf, siz );
while (_bufsiz > 0) {
if (*bufp == '\r')
cr++;
else if ( cr != 0 )
*bufp = *(bufp + cr);
bufp++;
_bufsiz--;
}
return n + cr;
}

View file

@ -8,6 +8,10 @@
#include <crtdll/internal/file.h>
#include <crtdll/io.h>
int cntcr(char *bufp, int bufsiz);
int convert(char *endp, int bufsiz,int n);
int _writecnv(int fn, void *buf, size_t bufsiz);
int
_flsbuf(int c, FILE *f)
{
@ -16,19 +20,15 @@ _flsbuf(int c, FILE *f)
char c1;
int size;
if (f->_flag & _IORW)
{
f->_flag |= _IOWRT;
f->_flag &= ~(_IOEOF|_IOREAD);
}
if ((f->_flag&_IOWRT)==0)
return EOF;
// if (!WRITE_STREAM(f))
// return EOF;
/* if the buffer is not yet allocated, allocate it */
if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0)
{
size = 512;
size = 4096;
if ((f->_base = base = malloc (size)) == NULL)
{
f->_flag |= _IONBF;
@ -76,11 +76,21 @@ _flsbuf(int c, FILE *f)
{
rn = f->_ptr - base;
f->_ptr = base;
if ( (f->_flag & _IOAHEAD) == _IOAHEAD )
_lseek(fileno(f),-(rn+f->_cnt), SEEK_CUR);
f->_cnt = f->_bufsiz;
f->_flag &= ~_IOAHEAD;
}
f->_flag &= ~_IODIRTY;
while (rn > 0)
{
n = _write(fileno(f), base, rn);
// if(__is_text_file(f) )
// n = _writecnv(fileno(f), base, rn);
// else
n = _write(fileno(f), base, rn);
if (n <= 0)
{
f->_flag |= _IOERR;
@ -89,6 +99,8 @@ _flsbuf(int c, FILE *f)
rn -= n;
base += n;
}
if ((f->_flag&(_IOLBF|_IONBF)) == 0)
{
f->_cnt--;
@ -102,3 +114,60 @@ wint_t _flswbuf(wchar_t c,FILE *fp)
return (wint_t )_flsbuf((int)c,fp);
}
int _writecnv(int fn, void *buf, size_t siz)
{
char *bufp = (char *)buf;
int bufsiz = siz;
char *tmp;
int cr1 = 0;
int cr2 = 0;
int n;
cr1 = cntcr(bufp,bufsiz);
tmp = malloc(cr1);
memcpy(tmp,bufp+bufsiz-cr1,cr1);
cr2 = cntcr(tmp,cr1);
convert(bufp,bufsiz-cr2,cr1-cr2);
n = _write(fn, bufp, bufsiz + cr1);
convert(tmp,cr1,cr2);
n += _write(fn, tmp, cr1 + cr2);
free(tmp);
return n;
}
int convert(char *endp, int bufsiz,int n)
{
endp = endp + bufsiz + n;
while (bufsiz > 0) {
*endp = *(endp - n);
if (*endp == '\n') {
*endp--;
n--;
*endp = '\r';
}
endp--;
bufsiz--;
}
return n;
}
int cntcr(char *bufp, int bufsiz)
{
int cr = 0;
while (bufsiz > 0) {
if (*bufp == '\n')
cr++;
bufp++;
bufsiz--;
}
return cr;
}

View file

@ -7,7 +7,7 @@
int
fputs(const char *s, FILE *f)
{
/*
int r = 0;
int c;
int unbuffered;
@ -34,10 +34,5 @@ fputs(const char *s, FILE *f)
}
return(r);
*/
int r = 0;
if ( !WriteFile(_get_osfhandle(f->_file),s,strlen(s),&r,NULL) )
return -1;
return r;
}

View file

@ -1,93 +1,74 @@
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <crtdll/stdio.h>
#include <crtdll/stdlib.h>
#include <crtdll/string.h>
#include <crtdll/errno.h>
#include <crtdll/internal/file.h>
size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
// carriage return line feed conversion is done in filbuf and flsbuf
#if 0
size_t
fread(void *p, size_t size, size_t count, FILE *iop)
{
char *ptr = (char *)vptr;
int s;
int c;
/*
* grow if we know we're asking for a lot, even if it's in the
* buffer, since we'll probably read chunks this size for a while
*/
while (size*count > iop->_fillsize
&& iop->_fillsize < iop->_bufsiz)
{
if (iop->_fillsize < 512)
iop->_fillsize = 512;
iop->_fillsize *= 2;
}
char *ptr = (char *)p;
int to_read;
to_read = size * count;
s = size * count;
if(!__is_text_file(iop))
{
while (s > 0)
{
if (iop->_cnt < s)
{
if (iop->_cnt > 0)
{
memcpy(ptr, iop->_ptr, iop->_cnt);
ptr += iop->_cnt;
s -= iop->_cnt;
}
/*
* filbuf clobbers _cnt & _ptr,
* so don't waste time setting them.
*/
if ((c = _filbuf(iop)) == EOF)
break;
*ptr++ = c;
s--;
}
if (iop->_cnt >= s)
{
memcpy(ptr, iop->_ptr, s);
iop->_ptr += s;
iop->_cnt -= s;
return count;
}
}
}
else
{
while (s > 0) {
if (iop->_cnt < s) {
while (iop->_cnt > 0) {
if ((c = *iop->_ptr++) != '\r')
{
*ptr++ = c;
s--;
}
iop->_cnt--;
}
if ((c = _filbuf(iop)) == EOF)
break;
if (c != '\r')
{
*ptr++ = c;
s--;
}
}
if (iop->_cnt >= s) {
while (s > 0 && iop->_cnt > 0) {
if ((c = *iop->_ptr++) != '\r')
{
*ptr++ = c;
s--;
}
iop->_cnt--;
}
}
} /* end while */
while ( to_read > 0 ) {
*ptr = getc(iop) ;
if ( *ptr == EOF )
break;
to_read--;
ptr++;
}
return size != 0 ? count - ((s + size - 1) / size) : 0;
return count- (to_read/size);
}
#else
size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
{
char *ptr = (char *)vptr;
size_t to_read ,n_read;
to_read = size * count;
//if (!READ_STREAM(iop))
//{
// __set_errno (EINVAL);
// return 0;
//}
if (iop == NULL )
{
__set_errno (EINVAL);
return 0;
}
if (feof (iop) || ferror (iop))
return 0;
if (vptr == NULL || to_read == 0)
return 0;
while(iop->_cnt > 0) {
to_read--;
*ptr++ = getc(iop);
}
// check to see if this will work with in combination with ungetc
n_read = _read(fileno(iop), ptr, to_read);
if ( n_read != -1 )
to_read -= n_read;
return count- (to_read/size);
}
#endif

View file

@ -3,6 +3,7 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <crtdll/stdio.h>
#include <crtdll/errno.h>
#include <crtdll/internal/file.h>
#include <crtdll/fcntl.h>
#include <crtdll/io.h>
@ -10,48 +11,48 @@
int fseek(FILE *f, long offset, int ptrname)
{
long p = -1; /* can't happen? */
/* See comment in filbuf.c */
f->_fillsize = 512;
long p = -1; /* can't happen? */
if ( f == NULL ) {
__set_errno (EINVAL);
return -1;
}
f->_flag &= ~_IOEOF;
if (!WRITE_STREAM(f))
{
if (f->_base && !(f->_flag & _IONBF))
{
p = ftell(f);
if (ptrname == SEEK_CUR)
{
offset += p;
ptrname = SEEK_SET;
}
/* check if the target position is in the buffer and
optimize seek by moving inside the buffer */
if (ptrname == SEEK_SET && (f->_flag & (_IOUNGETC|_IORW)) == 0
&& p-offset <= f->_ptr-f->_base && offset-p <= f->_cnt)
{
f->_ptr+=offset-p;
f->_cnt+=p-offset;
return 0;
}
}
// if (f->_flag & _IORW)
// f->_flag &= ~_IOREAD;
p = lseek(fileno(f), offset, ptrname);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~_IOUNGETC;
}
else
{
p = fflush(f);
return lseek(fileno(f), offset, ptrname) == -1 || p == EOF ?
-1 : 0;
}
return p==-1 ? -1 : 0;
f->_flag &= ~_IOEOF;
if (f->_flag & _IOREAD)
{
if (f->_base && !(f->_flag & _IONBF))
{
p = ftell(f);
if (ptrname == SEEK_CUR)
{
offset += p;
ptrname = SEEK_SET;
}
/* check if the target position is in the buffer and
optimize seek by moving inside the buffer */
if (ptrname == SEEK_SET && (f->_flag & (_IOUNGETC|_IORW)) == 0
&& p-offset <= f->_ptr-f->_base && offset-p <= f->_cnt)
{
f->_ptr+=offset-p;
f->_cnt+=p-offset;
return 0;
}
}
if (f->_flag & _IORW)
f->_flag &= ~_IOREAD;
p = lseek(fileno(f), offset, ptrname);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~_IOUNGETC;
}
else if (f->_flag & (_IOWRT|_IORW))
{
p = fflush(f);
f->_cnt = 0;
f->_ptr = f->_base = NULL;
f->_flag &= ~_IOUNGETC;
return lseek(fileno(f), offset, ptrname) == -1 || p == EOF ? -1 : 0;
}
return p==-1 ? -1 : 0;
}

View file

@ -16,7 +16,8 @@ ftell(FILE *f)
if (f->_cnt < 0)
f->_cnt = 0;
if (f->_flag&_IOREAD)
else if (f->_flag&_IOREAD)
{
adjust = - f->_cnt;
}
@ -25,11 +26,15 @@ ftell(FILE *f)
if (f->_flag&_IOWRT && f->_base && (f->_flag&_IONBF)==0)
adjust = f->_ptr - f->_base;
}
else
return -1;
tres = lseek(fileno(f), 0L, 1);
tres = lseek(fileno(f), 0L, SEEK_CUR);
if (tres<0)
return tres;
tres += adjust;
//f->_cnt = f->_bufsiz - tres;
//f->_ptr = f->_base + tres;
return tres;
}

View file

@ -1,88 +1,75 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <crtdll/stdio.h>
#include <crtdll/stdlib.h>
#include <crtdll/string.h>
#include <crtdll/errno.h>
#include <crtdll/internal/file.h>
#if 0
size_t
fwrite(const void *vptr, size_t size, size_t count, FILE *f)
fwrite(const void *p, size_t size, size_t count, FILE *iop)
{
const char *ptr = (const char *)vptr;
register int s;
char *ptr = (char *)p;
size_t to_write;
s = size * count;
if(!__is_text_file(f))
{
if (f->_flag & _IOLBF)
while (s > 0) {
if (--f->_cnt > -f->_bufsiz && *(const char *)ptr != '\n')
*f->_ptr++ = *(const char *)ptr++;
else if (_flsbuf(*(const char *)ptr++, f) == EOF)
break;
s--;
}
else while (s > 0) {
if (f->_cnt < s) {
if (f->_cnt > 0) {
memcpy(f->_ptr, ptr, f->_cnt);
ptr += f->_cnt;
f->_ptr += f->_cnt;
s -= f->_cnt;
}
if (_flsbuf(*(const unsigned char *)ptr++, f) == EOF)
break;
s--;
}
if (f->_cnt >= s) {
memcpy(f->_ptr, ptr, s);
f->_ptr += s;
f->_cnt -= s;
return count;
}
}
to_write = size * count;
while ( to_write > 0 ) {
if ( putc(*ptr,iop) == EOF )
break;
to_write--;
ptr++;
}
else
{
if (f->_flag & _IOLBF)
{
while (s > 0) {
if (*ptr=='\n')
{
if (--f->_cnt > -f->_bufsiz)
*f->_ptr++ = '\r';
else
if (_flsbuf('\r', f) == EOF)
break;
}
if (--f->_cnt > -f->_bufsiz && *ptr != '\n')
*f->_ptr++ = *ptr++;
else if (_flsbuf(*(const unsigned char *)ptr++, f) == EOF)
break;
s--;
}
}
else
{
while (s > 0)
{
if (*ptr == '\n')
{
if(--f->_cnt >= 0)
*f->_ptr++ = '\r';
else
if (_flsbuf('\r', f) == EOF)
break;
}
if (--f->_cnt >= 0)
*f->_ptr++ = *ptr++;
else
if (_flsbuf(*(const unsigned char *)ptr++, f) == EOF)
break;
s--;
}
}
}
return size != 0 ? count - ((s + size - 1) / size) : 0;
return count -to_write/size;
}
#else
size_t fwrite(const void *vptr, size_t size, size_t count, FILE *iop)
{
size_t to_write, n_written;
char *ptr = (char *)vptr;
to_write = size*count;
//if (!WRITE_STREAM(iop) )
//{
// __set_errno (EINVAL);
// return 0;
//}
if (iop == NULL )
{
__set_errno (EINVAL);
return 0;
}
if (ferror (iop))
return 0;
if (vptr == NULL || to_write == 0)
return 0;
while(iop->_cnt > 0 ) {
to_write--;
putc(*ptr++,iop);
}
n_written = _write(fileno(iop), ptr,to_write);
if ( n_written != -1 )
to_write -= n_written;
// check to see if this will work with in combination with ungetc
return count - (to_write/size);
}
#endif

View file

@ -16,10 +16,10 @@ int getc(FILE *fp)
}
// check for read access on stream
// if ( (fp->_flag & _IOREAD) != _IOREAD ) {
// __set_errno(EINVAL);
// return -1;
// }
//if ( !READ_STREAM(fp) ) {
// __set_errno(EINVAL);
// return -1;
//}
if(fp->_cnt > 0) {
fp->_cnt--;

View file

@ -24,3 +24,84 @@ gets(char *s)
*cs++ = '\0';
return s;
}
#if 0
/* Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <errno.h>
#include <string.h>
link_warning (gets, "the `gets' function is dangerous and should not be used.")
/* Read a newline-terminated multibyte string from stdin into S,
removing the trailing newline. Return S or NULL. */
char *
gets (s)
char *s;
{
register char *p = s;
register int c;
FILE *stream = stdin;
int l;
if (!__validfp (stream) || p == NULL)
{
__set_errno (EINVAL);
return NULL;
}
if (feof (stream) || ferror (stream))
return NULL;
while ((c = getc(stdin)) != EOF) {
if (c == '\n')
break;
if ( isascii(c) )
*cs++ = c;
#ifdef _MULTIBYTE
else if ( isleadbyte(c) ) {
l = mblen(c);
while(l > 0 ) {
c = getchar();
if ( isleadbyte(c) || c == EOF )
return NULL; // encoding error
*cs++ = c;
l--;
}
}
#endif
else
return NULL; // suspicious input
}
*p = '\0';
/* Return null if we had an error, or if we got EOF
before writing any characters. */
if (ferror (stream) || (feof (stream) && p == s))
return NULL;
return s;
}
#endif

View file

@ -7,22 +7,23 @@
int putc(int c, FILE *fp)
{
if ( c == 0 )
c = ' ';
// check for fp == NULL and for putc(fp,c)
if ( (int)fp < 256 ) {
// valid stream macro should check that fp
// is dword aligned
if ( fp == NULL ) {
__set_errno(EINVAL);
return -1;
}
// check for write access on fp
// if ( (fp->_flag & _IOWRT) != _IOWRT ) {
// __set_errno(EINVAL);
// return -1;
// }
//if ( !WRITE_STREAM(fp) ) {
// __set_errno(EINVAL);
// return -1;
//}
fp->_flag |= _IODIRTY;
if (fp->_cnt > 0 ) {
fp->_cnt--;
*(fp)->_ptr++ = (char)c;

View file

@ -8,16 +8,10 @@
int
puts(const char *s)
{
/*
int c;
while ((c = *s++))
putchar(c);
return putchar('\n');
*/
int r = 0;
if ( !WriteFile(_get_osfhandle(stdout->_file),s,strlen(s),&r,NULL) )
return -1;
return putchar('\n');
}

View file

@ -11,7 +11,6 @@ void rewind(FILE *f)
lseek(fileno(f), 0L, SEEK_SET);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~(_IOERR|_IOEOF);
if (f->_flag & _IORW)
f->_flag &= ~(_IOREAD|_IOWRT);
f->_flag &= ~(_IOERR|_IOEOF|_IOAHEAD);
}

View file

@ -21,13 +21,6 @@ Cambridge, MA 02139, USA. */
#include <crtdll/wchar.h>
#include <crtdll/alloc.h>
#if 1
int scanf (const char *format, ...)
{
}
#else
/* The function `vscanf' is not defined in ISO C. Therefore we must
use the protected form here. In stdio it is called `__vscanf' and
@ -56,6 +49,7 @@ int scanf (const char *format, ...)
}
#if 0
int
wscanf(const wchar_t *fmt, ...)
{
@ -75,10 +69,4 @@ wscanf(const wchar_t *fmt, ...)
return done;
}
#include <crtdll/malloc.h>
void *alloca(size_t x)
{
return malloc(x);
}
#endif

View file

@ -26,7 +26,6 @@ int setvbuf(FILE *f, char *buf, int type, size_t len)
return -1;
mine = 1;
}
f->_fillsize = len; /* make it read in `len'-byte chunks */
/* FALLTHROUGH */
case _IONBF:
if (f->_base != NULL && f->_flag & _IOMYBUF)

View file

@ -21,13 +21,6 @@
#include <crtdll/wchar.h>
#include <crtdll/alloc.h>
#if 1
int sscanf (const char *s,const char *format, ...)
{
}
#else
int __vsscanf (const char *s,const char *format,va_list arg);
@ -52,6 +45,7 @@ strong_alias (sscanf, _IO_sscanf)
#endif
#if 0
int
swscanf(const wchar_t *str, const wchar_t *fmt, ...)
@ -81,4 +75,5 @@ swscanf(const wchar_t *str, const wchar_t *fmt, ...)
}
#endif
#endif

View file

@ -5,13 +5,17 @@
char *_tempnam(const char *dir,const char *prefix )
{
char *TempFileName;
TempFileName = malloc(MAX_PATH);
GetTempFileName(
dir,
prefix,
98,
TempFileName
);
char *TempFileName = malloc(MAX_PATH);
char *d;
if ( dir == NULL )
d = getenv("TMP");
else
d = (char *)dir;
if ( GetTempFileNameA(d, prefix, 0, TempFileName ) == 0 ) {
free(TempFileName);
return NULL;
}
return TempFileName;
}

View file

@ -1,9 +1,11 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <crtdll/stdio.h>
#include <stdarg.h>
#include <crtdll/stdarg.h>
#include <crtdll/malloc.h>
#include <crtdll/internal/file.h>
int _isnanl(double x);
int _isinfl(double x);
@ -61,8 +63,9 @@ vfprintf(FILE *f, const char *fmt, va_list ap)
#include <crtdll/string.h>
#include <crtdll/stdio.h>
#include <crtdll/string.h>
#include <crtdll/math.h>
#include <crtdll/internal/ieee.h>
//#undef isdigit
size_t strnlen( const char *string, size_t count );
@ -83,11 +86,11 @@ static int skip_atoi(const char **s)
#define LEFT 16 /* left justified */
#define SPECIAL 32 /* 0x */
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
#define ZEROTRUNC 128 /* truncate zero 's */
static int __res;
int do_div(int *n,int base) {
int do_div(long *n,int base) {
__res = ((unsigned long) *n) % (unsigned) base;
*n = ((unsigned long) *n) / (unsigned) base;
@ -141,13 +144,15 @@ static char * number(FILE * f, long num, int base, int size, int precision
putc( ' ',f);
if (sign)
putc( sign,f);
if (type & SPECIAL)
if (base==8)
if (type & SPECIAL) {
if (base==8) {
putc( '0',f);
}
else if (base==16) {
putc( '0', f);
putc( digits[33],f);
}
}
if (!(type & LEFT))
while (size-- > 0)
putc( c,f);
@ -161,13 +166,210 @@ static char * number(FILE * f, long num, int base, int size, int precision
return 0;
}
void numberf(FILE * f, long double __n, char exp_sign, int size, int precision, int type)
{
long double exponent = 0.0;
long double e;
long ie;
//int x;
char *buf, *tmp;
int i = 0;
int j = 0;
//int k = 0;
long double frac, intr;
long double p;
char sign;
char c;
char ro;
long_double_t *n = (long_double_t *)&__n;
if ( exp_sign == 'g' || exp_sign == 'G' || exp_sign == 'e' || exp_sign == 'E' ) {
ie = ((unsigned int)n->exponent - (unsigned int)0x3fff);
exponent = ie/3.321928;
}
if ( exp_sign == 'g' || exp_sign == 'G' ) {
type |= ZEROTRUNC;
if ( exponent < -4 || fabs(exponent) >= precision )
exp_sign -= 2; // g -> e and G -> E
}
if ( exp_sign == 'e' || exp_sign == 'E' ) {
frac = modfl(exponent,&e);
if ( frac > 0.5 )
e++;
else if ( frac < -0.5 )
e--;
numberf(f,__n/powl(10.0L,e),'f',size-4, precision, type);
putc( exp_sign,f);
size--;
ie = (long)e;
type = LEFT | PLUS;
if ( ie < 0 )
type |= SIGN;
number(f,ie, 10,2, 2,type );
return;
}
if ( exp_sign == 'f' ) {
buf = alloca(4096);
if (type & LEFT) {
type &= ~ZEROPAD;
}
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0;
if (type & SIGN) {
if (__n < 0) {
sign = '-';
__n = fabs(__n);
size--;
} else if (type & PLUS) {
sign = '+';
size--;
} else if (type & SPACE) {
sign = ' ';
size--;
}
}
frac = modfl(__n,&intr);
// # flags forces a . and prevents trucation of trailing zero's
if ( precision > 0 ) {
frac = modfl(__n,&intr);
i = precision-1;
while ( i >= 0 ) {
frac*=10.0L;
frac = modfl((long double)frac, &p);
buf[i] = (int)p + '0';
i--;
}
i = precision;
size -= precision;
ro = 0;
if ( frac > 0.5 ) {
ro = 1;
}
if ( precision >= 1 || type & SPECIAL) {
buf[i++] = '.';
size--;
}
}
if ( intr == 0.0 ) {
buf[i++] = '0';
size--;
}
else {
while ( intr > 0.0 ) {
intr/=10.0L;
p = modfl(intr, &intr);
p *=10;
buf[i++] = (int)p + '0';
size--;
}
}
j = 0;
while ( j < i && ro == 1) {
if ( buf[j] >= '0' && buf[j] <= '8' ) {
buf[j]++;
ro = 0;
}
else if ( buf[j] == '9' ) {
buf[j] = '0';
}
j++;
}
if ( ro == 1 )
buf[i++] = '1';
buf[i] = 0;
size -= precision;
if (!(type&(ZEROPAD+LEFT)))
while(size-->0)
putc( ' ',f);
if (sign)
putc( sign,f);
if (!(type&(ZEROPAD+LEFT)))
while(size-->0)
putc( ' ',f);
if (type & SPECIAL) {
}
if (!(type & LEFT))
while (size-- > 0)
putc( c,f);
tmp = buf;
if ( type & ZEROTRUNC && ((type & SPECIAL) != SPECIAL) ) {
j = 0;
while ( j < i && ( *tmp == '0' || *tmp == '.' )) {
tmp++;
i--;
}
}
// else
// while (i < precision--)
// putc( '0', f);
while (i-- > 0)
putc( tmp[i],f);
while (size-- > 0)
putc( ' ', f);
}
}
int
__vfprintf(FILE *f, const char *fmt, va_list args)
{
int len;
unsigned long num;
int i, base;
long double _ldouble;
const char *s;
const short int* sw;
@ -226,10 +428,32 @@ __vfprintf(FILE *f, const char *fmt, va_list args)
}
/* get the conversion qualifier */
qualifier = -1;
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
// %Z can be just stand alone or as size_t qualifier
if ( *fmt == 'Z' ) {
qualifier = *fmt;
++fmt;
switch ( *(fmt+1)) {
case 'o':
case 'b':
case 'X':
case 'x':
case 'd':
case 'i':
case 'u':
++fmt;
break;
default:
break;
}
}
else if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' ) {
qualifier = *fmt;
++fmt;
}
// go fine with ll instead of L
if ( *fmt == 'l' ) {
++fmt;
qualifier = 'L';
}
/* default base */
@ -268,7 +492,49 @@ __vfprintf(FILE *f, const char *fmt, va_list args)
}
// CHECKPOINT;
continue;
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
if (qualifier == 'l' || qualifier == 'L' )
_ldouble = va_arg(args, long double);
else
_ldouble = (long double)va_arg(args, double);
if ( _isnanl(_ldouble) ) {
s = "Nan";
len = 3;
while ( len > 0 ) {
putc(*s++,f);
len --;
}
}
else if ( _isinfl(_ldouble) < 0 ) {
s = "-Inf";
len = 4;
while ( len > 0 ) {
putc(*s++,f);
len --;
}
}
else if ( _isinfl(_ldouble) > 0 ) {
s = "+Inf";
len = 4;
while ( len > 0 ) {
putc(*s++,f);
len --;
}
}
else {
if ( precision == -1 )
precision = 6;
numberf(f,_ldouble,*fmt,field_width,precision,flags);
}
continue;
case 's':
s = va_arg(args, char *);
if (!s)
@ -299,10 +565,10 @@ __vfprintf(FILE *f, const char *fmt, va_list args)
case 'n':
if (qualifier == 'l') {
long * ip = va_arg(args, long *);
//*ip = (str - buf);
*ip = 0;
} else {
int * ip = va_arg(args, int *);
//*ip = (str - buf);
*ip = 0;
}
continue;
@ -338,11 +604,12 @@ __vfprintf(FILE *f, const char *fmt, va_list args)
}
if (qualifier == 'l')
num = va_arg(args, unsigned long);
else if (qualifier == 'h')
else if (qualifier == 'h') {
if (flags & SIGN)
num = va_arg(args, short);
else
num = va_arg(args, unsigned short);
}
else if (flags & SIGN)
num = va_arg(args, int);
else
@ -356,3 +623,12 @@ __vfprintf(FILE *f, const char *fmt, va_list args)

View file

@ -60,7 +60,6 @@ unsigned long int __strtoul_internal (const char *__nptr, char **__endptr, int
# define TYPEMOD (LONG|LONGDBL|SHORT)
# define ungetc(c, s) ((void) (c != EOF && --read_in), ungetc (c, s))
# define inchar() ((c = getc (s)), (void) (c != EOF && ++read_in), c)
# define encode_error() do { \
@ -180,7 +179,8 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
if (!isascii (*f))
{
/* Non-ASCII, may be a multibyte. */
int len = mblen (f, strlen (f));
// int len = mblen (f, strlen (f));
int len =1;
if (len > 0)
{
do
@ -1055,12 +1055,124 @@ double __strtod_internal (const char *__nptr,char **__endptr, int __group)
}
float __strtof_internal (const char *__nptr, char **__endptr,int __group)
{
return strtod(__nptr,__endptr);
return (float)strtod(__nptr,__endptr);
}
long double __strtold_internal (const char *__nptr,char **__endptr, int __group)
static double powten[] =
{
return strtod(__nptr,__endptr);
// return strtold(__nptr,__endptr);
1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L,
1e512L, 1e512L*1e512L, 1e2048L, 1e4096L
};
long double __strtold_internal (const char *s,char **sret, int __group)
{
long double r; /* result */
int e, ne; /* exponent */
int sign; /* +- 1.0 */
int esign;
int flags=0;
int l2powm1;
r = 0.0L;
sign = 1;
e = ne = 0;
esign = 1;
while(*s && isspace(*s))
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
sign = -1;
s++;
}
while ((*s >= '0') && (*s <= '9'))
{
flags |= 1;
r *= 10.0L;
r += *s - '0';
s++;
}
if (*s == '.')
{
s++;
while ((*s >= '0') && (*s <= '9'))
{
flags |= 2;
r *= 10.0L;
r += *s - '0';
s++;
ne++;
}
}
if (flags == 0)
{
if (sret)
*sret = (char *)s;
return 0.0L;
}
if ((*s == 'e') || (*s == 'E'))
{
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
s++;
esign = -1;
}
while ((*s >= '0') && (*s <= '9'))
{
e *= 10;
e += *s - '0';
s++;
}
}
if (esign < 0)
{
esign = -esign;
e = -e;
}
e = e - ne;
if (e < -4096)
{
/* possibly subnormal number, 10^e would overflow */
r *= 1.0e-2048L;
e += 2048;
}
if (e < 0)
{
e = -e;
esign = -esign;
}
if (e >= 8192)
e = 8191;
if (e)
{
double d = 1.0L;
l2powm1 = 0;
while (e)
{
if (e & 1)
d *= powten[l2powm1];
e >>= 1;
l2powm1++;
}
if (esign > 0)
r *= d;
else
r /= d;
}
if (sret)
*sret = (char *)s;
return r * sign;
return 0;
}
long int __strtol_internal (const char *__nptr, char **__endptr, int __base, int __group)
{

View file

@ -23,7 +23,7 @@ void exit(int status)
djgpp_first_dtor[i]();
*/
/* in case the program set it this way */
setmode(0, O_TEXT);
_setmode(0, O_TEXT);
_exit(status);
for(;;);
}

View file

@ -21,3 +21,69 @@ void* realloc(void* _ptr, size_t _size)
{
return(HeapReAlloc(GetProcessHeap(),0,_ptr,_size));
}
#undef alloca
void *alloca(size_t s)
{
register unsigned int as = s;
// alloca(0) should not return the stack pointer
if ( s == 0 )
return NULL;
if ( (s & 0xfffffffc) != 0 )
as += 4;
as &= 0xfffffffc;
__asm__ __volatile__(
"mov %0, %%edx \n"
"popl %%ebx \n"
"popl %%esi \n"
"leave \n"
"popl %%ecx \n"
"subl %%edx, %%esp \n"
"movl %%esp, %%eax \n"
"addl $4, %%eax \n"
"push %%ecx \n"
"ret \n"
:
:"g" ( as)
);
return NULL;
}
void *_alloca(size_t s)
{
register unsigned int as = s;
// alloca(0) should not return the stack pointer
if ( s == 0 )
return NULL;
if ( (s & 0xfffffffc) != 0 )
as += 4;
as &= 0xfffffffc;
__asm__ __volatile__(
"mov %0, %%edx \n"
"popl %%ebx \n"
"popl %%esi \n"
"leave \n"
"popl %%ecx \n"
"subl %%edx, %%esp \n"
"movl %%esp, %%eax \n"
"addl $4, %%eax \n"
"push %%ecx \n"
"ret \n"
:
:"g" ( as)
);
return NULL;
}

View file

@ -6,13 +6,12 @@
static double powten[] =
{
1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L
//1e512L, 1e512L*1e512L, 1e2048L, 1e4096L
1e512L, 1e512L*1e512L, 1e2048L, 1e4096L
};
double
long double
_strtold(const char *s, char **sret)
{
#if 0
{
double r; /* result */
int e, ne; /* exponent */
int sign; /* +- 1.0 */
@ -119,6 +118,5 @@ _strtold(const char *s, char **sret)
*sret = (char *)s;
return r * sign;
#endif
return 0;
}

View file

@ -1,16 +1,38 @@
#include <crtdll/alloc.h>
#include <crtdll/stdlib.h>
#include <crtdll/sys/utime.h>
#include <crtdll/io.h>
#include <crtdll/errno.h>
#include <crtdll/internal/file.h>
int _futime (int nHandle, struct _utimbuf *pTimes)
{
FILETIME LastAccessTime;
FILETIME LastWriteTime;
UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0);
UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0);
if ( !SetFileTime(_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime) )
FILETIME LastAccessTime;
FILETIME LastWriteTime;
// check for stdin / stdout handles ??
if ( nHandle == -1 ) {
__set_errno(EBADF);
return -1;
}
if ( pTimes == NULL ) {
pTimes = alloca(sizeof(struct _utimbuf));
time(pTimes->actime);
time(pTimes->modtime);
}
if ( pTimes->actime < pTimes->modtime ) {
__set_errno(EINVAL);
return -1;
}
UnixTimeToFileTime(pTimes->actime,&LastAccessTime,0);
UnixTimeToFileTime(pTimes->modtime,&LastWriteTime,0);
if ( !SetFileTime(_get_osfhandle(nHandle),NULL, &LastAccessTime, &LastWriteTime) ) {
__set_errno(EBADF);
return -1;
}
return 0;
return 0;
}