mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 01:24:38 +00:00
Added various files.
--> failed to pass test printing a simple string svn path=/trunk/; revision=380
This commit is contained in:
parent
b68aceef62
commit
ed08466464
102 changed files with 3878 additions and 791 deletions
|
@ -19,8 +19,8 @@ _scan_ungetch(int c, FILE *fp)
|
|||
int
|
||||
_cscanf(const char *fmt, ...)
|
||||
{
|
||||
return(_doscan_low(NULL, _scan_getche, _scan_ungetch,
|
||||
fmt, (void **) unconst( ((&fmt)+1), char ** )));
|
||||
// return(_doscan_low(NULL, _scan_getche, _scan_ungetch,
|
||||
// fmt, (void **) unconst( ((&fmt)+1), char ** )));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,10 +38,10 @@
|
|||
-Di386 -D_WIN32 -DWIN32 -D__WIN32__ -D__MINGW32__ -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) _D_stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -Asystem(winnt) -Acpu(i386) -Amachine(i386)
|
||||
|
||||
*cross_compile:
|
||||
1
|
||||
0
|
||||
|
||||
*version:
|
||||
egcs-2.91.57
|
||||
egcs-2.8.2
|
||||
|
||||
*multilib:
|
||||
. ;
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
; DISCLAMED. This includes but is not limited to warrenties of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
;
|
||||
; $Revision: 1.6 $
|
||||
; $Author: dwelch $
|
||||
; $Date: 1999/04/14 00:51:18 $
|
||||
; $Revision: 1.7 $
|
||||
; $Author: ariadne $
|
||||
; $Date: 1999/04/14 21:26:48 $
|
||||
;
|
||||
; These three functions appear to be name mangled in some way, so GCC is
|
||||
; probably not going to be able to use them in any case.
|
||||
|
@ -35,170 +35,6 @@
|
|||
; _set_new_handler__FPFUi_i
|
||||
;
|
||||
;
|
||||
; These are functions for which I have not yet written prototypes or
|
||||
; otherwise set up (they are still included below though unlike those
|
||||
; first three).
|
||||
;
|
||||
; _CIacos
|
||||
; _CIasin
|
||||
; _CIatan
|
||||
; _CIatan2
|
||||
; _CIcos
|
||||
; _CIcosh
|
||||
; _CIexp
|
||||
; _CIfmod
|
||||
; _CIlog
|
||||
; _CIlog10
|
||||
; _CIpow
|
||||
; _CIsin
|
||||
; _CIsinh
|
||||
; _CIsqrt
|
||||
; _CItan
|
||||
; _CItanh
|
||||
; __dllonexit
|
||||
; __mb_cur_max_dll
|
||||
; __threadhandle
|
||||
; __threadid
|
||||
; _abnormal_termination
|
||||
; _acmdln_dll
|
||||
; _aexit_rtn_dll
|
||||
; _amsg_exit
|
||||
; _commit
|
||||
; _commode_dll
|
||||
; _cpumode_dll
|
||||
; _ctype
|
||||
; _daylight_dll
|
||||
; _environ_dll
|
||||
; _expand
|
||||
; _fcloseall
|
||||
; _filbuf
|
||||
; _fileinfo_dll
|
||||
; _flsbuf
|
||||
; _flushall
|
||||
; _fmode_dll
|
||||
; _fpieee_flt
|
||||
; _fsopen
|
||||
; _ftol
|
||||
; _getdiskfree
|
||||
; _getdllprocaddr
|
||||
; _getdrive
|
||||
; _getdrives
|
||||
; _getsystime
|
||||
; _getw
|
||||
; _initterm
|
||||
; _ismbbalnum
|
||||
; _ismbbalpha
|
||||
; _ismbbgraph
|
||||
; _ismbbkalnum
|
||||
; _ismbbkana
|
||||
; _ismbbkpunct
|
||||
; _ismbblead
|
||||
; _ismbbprint
|
||||
; _ismbbpunct
|
||||
; _ismbbtrail
|
||||
; _ismbcalpha
|
||||
; _ismbcdigit
|
||||
; _ismbchira
|
||||
; _ismbckata
|
||||
; _ismbcl0
|
||||
; _ismbcl1
|
||||
; _ismbcl2
|
||||
; _ismbclegal
|
||||
; _ismbclower
|
||||
; _ismbcprint
|
||||
; _ismbcspace
|
||||
; _ismbcsymbol
|
||||
; _ismbcupper
|
||||
; _ismbslead
|
||||
; _ismbstrail
|
||||
; _lfind
|
||||
; _loaddll
|
||||
; _lrotl
|
||||
; _lrotr
|
||||
; _lsearch
|
||||
; _makepath
|
||||
; _matherr
|
||||
; _mbbtombc
|
||||
; _mbbtype
|
||||
; _mbccpy
|
||||
; _mbcjistojms
|
||||
; _mbcjmstojis
|
||||
; _mbclen
|
||||
; _mbctohira
|
||||
; _mbctokata
|
||||
; _mbctolower
|
||||
; _mbctombb
|
||||
; _mbctoupper
|
||||
; _mbctype
|
||||
; _mbsbtype
|
||||
; _mbscat
|
||||
; _mbscmp
|
||||
; _mbscpy
|
||||
; _mbscspn
|
||||
; _mbsdec
|
||||
; _mbsdup
|
||||
; _mbsicmp
|
||||
; _mbsinc
|
||||
; _mbslen
|
||||
; _mbslwr
|
||||
; _mbsnbcat
|
||||
; _mbsnbcmp
|
||||
; _mbsnbcnt
|
||||
; _mbsnbcpy
|
||||
; _mbsnbicmp
|
||||
; _mbsnbset
|
||||
; _mbsnccnt
|
||||
; _mbsncmp
|
||||
; _mbsncpy
|
||||
; _mbsnextc
|
||||
; _mbsnicmp
|
||||
; _mbsninc
|
||||
; _mbsnset
|
||||
; _mbspbrk
|
||||
; _mbsrchr
|
||||
; _mbsrev
|
||||
; _mbsset
|
||||
; _mbsspn
|
||||
; _mbsspnp
|
||||
; _mbsstr
|
||||
; _mbstrlen
|
||||
; _mbsupr
|
||||
; _onexit
|
||||
; _osver_dll
|
||||
; _osversion_dll
|
||||
; _pctype_dll
|
||||
; _purecall
|
||||
; _putw
|
||||
; _pwctype_dll
|
||||
; _rmtmp
|
||||
; _rotl
|
||||
; _rotr
|
||||
; _setsystime
|
||||
; _snprintf
|
||||
; _snwprintf
|
||||
; _splitpath
|
||||
; _strdate
|
||||
; _strdec
|
||||
; _strinc
|
||||
; _strncnt
|
||||
; _strnextc
|
||||
; _strninc
|
||||
; _strspnp
|
||||
; _strtime
|
||||
; _tempnam
|
||||
; _timezone_dll
|
||||
; _tzname
|
||||
; _tzset
|
||||
; _ultoa
|
||||
; _unloaddll
|
||||
; _vsnprintf
|
||||
; _vsnwprintf
|
||||
; _winmajor_dll
|
||||
; _winminor_dll
|
||||
; _winver_dll
|
||||
; _wtoi
|
||||
; _wtol
|
||||
;
|
||||
EXPORTS
|
||||
;__builtin_new
|
||||
;__builtin_delete
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
#include <crtdll/direct.h>
|
||||
#include <windows.h>
|
||||
#include <crtdll/direct.h>
|
||||
#include <crtdll/ctype.h>
|
||||
|
||||
char _SetCurrentDirectory(char *dir);
|
||||
int _GetCurrentDirectory(int count,char *buffer);
|
||||
|
||||
#undef chdir
|
||||
int chdir( const char *_path )
|
||||
{
|
||||
return _chdir(_path);
|
||||
}
|
||||
|
||||
int _chdir( const char *_path )
|
||||
{
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
|
||||
|
||||
|
||||
#undef getcwd
|
||||
char *getcwd( char *buffer, int maxlen )
|
||||
{
|
||||
return _getcwd(buffer,maxlen);
|
||||
}
|
||||
|
||||
char *_getcwd( char *buffer, int maxlen )
|
||||
{
|
||||
char *cwd;
|
||||
|
|
22
reactos/lib/crtdll/direct/getdcwd.c
Normal file
22
reactos/lib/crtdll/direct/getdcwd.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include <direct.h>
|
||||
|
||||
char* _getdcwd (int nDrive, char* caBuffer, int nBufLen)
|
||||
{
|
||||
int i =0;
|
||||
int dr = getdrive();
|
||||
|
||||
if ( nDrive < 1 || nDrive > 26 )
|
||||
return NULL;
|
||||
|
||||
if ( dr != nDrive )
|
||||
chdrive(nDrive);
|
||||
|
||||
i = GetCurrentDirectory(nBufLen,caBuffer);
|
||||
if ( i == nBufLen )
|
||||
return NULL;
|
||||
|
||||
if ( dr != nDrive )
|
||||
chdrive(dr);
|
||||
|
||||
return caBuffer;
|
||||
}
|
|
@ -1,11 +1,7 @@
|
|||
#include <crtdll/direct.h>
|
||||
#include <windows.h>
|
||||
|
||||
#undef mkdir
|
||||
int mkdir( const char *_path )
|
||||
{
|
||||
return _mkdir(_path);
|
||||
}
|
||||
|
||||
int _mkdir( const char *_path )
|
||||
{
|
||||
if (!CreateDirectoryA(_path,NULL))
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
#include <crtdll/direct.h>
|
||||
#include <windows.h>
|
||||
|
||||
#undef rmdir
|
||||
int rmdir( const char *_path )
|
||||
{
|
||||
return _rmdir(_path);
|
||||
}
|
||||
|
||||
|
||||
int _rmdir( const char *_path )
|
||||
{
|
||||
|
|
11
reactos/lib/crtdll/except/unwind.c
Normal file
11
reactos/lib/crtdll/except/unwind.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
void _global_unwind2( PEXCEPTION_FRAME frame )
|
||||
{
|
||||
//RtlUnwind( frame, 0, NULL, 0 );
|
||||
}
|
||||
|
||||
|
||||
void _local_unwind2( PEXCEPTION_FRAME endframe, DWORD nr )
|
||||
{
|
||||
//TRACE(crtdll,"(%p,%ld)\n",endframe,nr);
|
||||
return;
|
||||
}
|
|
@ -1,12 +1,21 @@
|
|||
#include <crtdll/math.h>
|
||||
#include <crtdll/float.h>
|
||||
|
||||
int isnan(double x)
|
||||
|
||||
int _isnan(double x)
|
||||
{
|
||||
if ( x>= 0.0 && x < HUGE_VAL )
|
||||
return FALSE;
|
||||
return 0;
|
||||
else if ( x <= 0.0 && x > HUGE_VAL )
|
||||
return FALSE;
|
||||
return 0;
|
||||
|
||||
return TRUE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _isinf(double x)
|
||||
{
|
||||
if ( fabs(x) == HUGE_VAL )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -46,7 +46,7 @@ WCHAR_OBJECTS = wchar/wcscat.o wchar/wcschr.o wchar/wcscmp.o \
|
|||
wchar/wcslwr.o wchar/wcsncat.o wchar/wcsncmp.o \
|
||||
wchar/wcsncpy.o
|
||||
|
||||
STDIO_OBJECTS = stdio/getenv.o stdio/doprnt.o stdio/doscan.o stdio/filbuf.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 \
|
||||
|
@ -113,9 +113,9 @@ OLD_OBJECTS = $(MISC_OBJECTS) stdlib/malloc.o stdlib/abort.o \
|
|||
stdlib/_exit.o stdlib/atexit.o stdio/fileno.o io/fmode.o \
|
||||
float/fpreset.o stdio/stdhnd.o io/setmode.o io/open.o \
|
||||
stdio/vsprintf.o $(CTYPE_OBJECTS) stdlib/atoi.o stdlib/strtol.o \
|
||||
stdio/flsbuf.o stdio/putc.o stdio/doprnt.o $(STRING_OBJECTS)\
|
||||
stdio/flsbuf.o stdio/putc.o stdio/vfprintf.o $(STRING_OBJECTS)\
|
||||
io/write.o io/isatty.o sys_stat/fstat.o misc/dllmain.o \
|
||||
stdlib/errno.o
|
||||
stdlib/errno.o stdio/printf.o stdio/vprintf.o
|
||||
|
||||
OBJECTS = $(MISC_OBJECTS) $(STDLIB_OBJECTS) $(IO_OBJECTS) \
|
||||
$(FLOAT_OBJECTS) $(ASSERT_OBJECTS) $(PROCESS_OBJECTS) \
|
||||
|
|
|
@ -2,9 +2,20 @@
|
|||
|
||||
#include <crtdll/math.h>
|
||||
|
||||
long double modfl(long double x,long double *pint);
|
||||
|
||||
/* Slooow version. */
|
||||
|
||||
double modf(double x,double *pint)
|
||||
{
|
||||
if (x >= 0)
|
||||
*pint = floor(x);
|
||||
else
|
||||
*pint = ceil(x);
|
||||
return x - *pint;
|
||||
}
|
||||
|
||||
long double modfl(long double x,long double *pint)
|
||||
{
|
||||
if (x >= 0)
|
||||
*pint = floor(x);
|
||||
|
|
19
reactos/lib/crtdll/mbstring/hanzen.c
Normal file
19
reactos/lib/crtdll/mbstring/hanzen.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
unsigned int _mbcjistojms( unsigned int c )
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
unsigned int _mbcjmstojis( unsigned int c )
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
unsigned int _mbctohira( unsigned int c )
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
unsigned int _mbctokata( unsigned int c )
|
||||
{
|
||||
return c;
|
||||
}
|
7
reactos/lib/crtdll/mbstring/islead.c
Normal file
7
reactos/lib/crtdll/mbstring/islead.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <windows.h>
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
int isleadbyte(char *mbstr)
|
||||
{
|
||||
return IsDBCSLeadByteEx(0,*c);
|
||||
}
|
29
reactos/lib/crtdll/mbstring/ismblead.c
Normal file
29
reactos/lib/crtdll/mbstring/ismblead.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/ismblead.c
|
||||
* PURPOSE: Checks for a lead byte
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
int _ismbblead(unsigned int byte)
|
||||
{
|
||||
|
||||
return (int)IsDBCSLeadByte(byte)
|
||||
}
|
||||
|
||||
int _ismbslead( const unsigned char *str, const unsigned char *t)
|
||||
{
|
||||
char *s = str;
|
||||
while(*s != 0 && s != t)
|
||||
{
|
||||
|
||||
s+= mblen(*s);
|
||||
}
|
||||
return ismbblead( *s)
|
||||
}
|
||||
|
29
reactos/lib/crtdll/mbstring/ismbtrail.c
Normal file
29
reactos/lib/crtdll/mbstring/ismbtrail.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/ismblead.c
|
||||
* PURPOSE: Checks for a trailing byte
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
int _ismbbtrail( unsigned int b)
|
||||
{
|
||||
return ((b >= 0x40 && b <= 0x7e ) || (b >= 0x80 && b <= 0xfc ) );
|
||||
}
|
||||
|
||||
|
||||
int _ismbstrail( const unsigned char *str, const unsigned char *t)
|
||||
{
|
||||
char *s = str;
|
||||
while(*s != 0 && s != t)
|
||||
{
|
||||
|
||||
s+= mblen(*s);
|
||||
}
|
||||
|
||||
return _ismbbtrail( *s)
|
||||
}
|
29
reactos/lib/crtdll/mbstring/mbbtombc.c
Normal file
29
reactos/lib/crtdll/mbstring/mbbtombc.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/ismblead.c
|
||||
* PURPOSE: Converts a multi byte byte to a multibyte character
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
char _mbctype[256];
|
||||
|
||||
// multibyte byte to multibyte character ????
|
||||
unsigned int _mbbtombc(unsigned int c)
|
||||
{
|
||||
if (( c > = 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) {
|
||||
// convert
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
unsigned int _mbctombb( unsigned int c )
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
|
48
reactos/lib/crtdll/mbstring/mbbtype.c
Normal file
48
reactos/lib/crtdll/mbstring/mbbtype.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbbtype.c
|
||||
* PURPOSE: Determines the type of a multibyte character
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
int _mbbtype(unsigned char c , int type)
|
||||
{
|
||||
if ( type == 1 ) {
|
||||
if ((b >= 0x40 && b <= 0x7e ) || (b >= 0x80 && b <= 0xfc ) )
|
||||
{
|
||||
return _MBC_TRAIL;
|
||||
}
|
||||
else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
|
||||
( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
|
||||
return _MBC_ILLEGAL;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
else {
|
||||
if (( c > = 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) {
|
||||
return _MBC_SINGLE;
|
||||
}
|
||||
else if ( (c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC) )
|
||||
return _MBC_LEAD;
|
||||
else if else if (( c >= 0x20 && c >= 0x7E ) || ( c >= 0xA1 && c <= 0xDF ) ||
|
||||
( c >= 0x81 && c <= 0x9F ) || ( c >= 0xE0 && c <= 0xFC ) )
|
||||
return _MBC_ILLEGAL;
|
||||
else
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _mbsbtype( const unsigned char *str, size_t n )
|
||||
{
|
||||
return 0;
|
||||
}
|
9
reactos/lib/crtdll/mbstring/mbccpy.c
Normal file
9
reactos/lib/crtdll/mbstring/mbccpy.c
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <crtdll/mbstring.h>
|
||||
|
||||
void _mbccpy(unsigned char *dst, const unsigned char *src)
|
||||
{
|
||||
if (!_ismbblead(*src) )
|
||||
return;
|
||||
|
||||
memcpy(dst,src,mbclen(*src));
|
||||
}
|
19
reactos/lib/crtdll/mbstring/mbclen.c
Normal file
19
reactos/lib/crtdll/mbstring/mbclen.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
//#include <crtdll/mbstring.h>
|
||||
|
||||
#include <crtdll/stdlib.h>
|
||||
|
||||
|
||||
size_t _mbclen(const unsigned char *s)
|
||||
{
|
||||
// return _ismbblead(s) ? 2 : 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int mblen( const char *mbstr, size_t count )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
4
reactos/lib/crtdll/mbstring/mbscat.c
Normal file
4
reactos/lib/crtdll/mbstring/mbscat.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
unsigned char * _mbscat(unsigned char *dst, const unsigned char *src)
|
||||
{
|
||||
return strcat(dst,src);
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbschr.c
Normal file
4
reactos/lib/crtdll/mbstring/mbschr.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
unsigned char * _mbschr(const unsigned char *str, unsigned int c)
|
||||
{
|
||||
return strchr(str,c);
|
||||
}
|
6
reactos/lib/crtdll/mbstring/mbscmp.c
Normal file
6
reactos/lib/crtdll/mbstring/mbscmp.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <crtdll/mbstring.h>
|
||||
|
||||
int _mbscmp(const unsigned char *str1, const unsigned char *str2)
|
||||
{
|
||||
return strcmp(str1,str2);
|
||||
}
|
16
reactos/lib/crtdll/mbstring/mbscoll.c
Normal file
16
reactos/lib/crtdll/mbstring/mbscoll.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbscoll.c
|
||||
* PURPOSE:
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
int _mbscoll(const unsigned char *str1, const unsigned char *str2)
|
||||
{
|
||||
return strcoll(str1,str2);
|
||||
}
|
5
reactos/lib/crtdll/mbstring/mbscpy.c
Normal file
5
reactos/lib/crtdll/mbstring/mbscpy.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
unsigned char * _mbscpy(unsigned char *dst, const unsigned char *str)
|
||||
{
|
||||
return strcpy(dst,str);
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbscspn.c
Normal file
4
reactos/lib/crtdll/mbstring/mbscspn.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
size_t _mbscspn(const unsigned char *str, const unsigned char *set)
|
||||
{
|
||||
return strcspn(str,set);
|
||||
}
|
6
reactos/lib/crtdll/mbstring/mbsdec.c
Normal file
6
reactos/lib/crtdll/mbstring/mbsdec.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <crtdll/mbstring.h>
|
||||
|
||||
unsigned char * _mbsdec(const unsigned char *str, const unsigned char *cur)
|
||||
{
|
||||
return strdec(str,cur);
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbsdup.c
Normal file
4
reactos/lib/crtdll/mbstring/mbsdup.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
unsigned char * _mbsdup(const unsigned char *str)
|
||||
{
|
||||
return strdup(str);
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbsicmp.c
Normal file
4
reactos/lib/crtdll/mbstring/mbsicmp.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
int _mbsicmp(const unsigned char *str1, const unsigned char *str2)
|
||||
{
|
||||
return stricmp(str1,str2);
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbsicoll.c
Normal file
4
reactos/lib/crtdll/mbstring/mbsicoll.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
int _mbsicoll(const unsigned char *dest, const unsigned char *src)
|
||||
{
|
||||
return stricoll(dest,src);
|
||||
}
|
7
reactos/lib/crtdll/mbstring/mbsinc.c
Normal file
7
reactos/lib/crtdll/mbstring/mbsinc.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include <crtdll/mbstring.h>
|
||||
|
||||
unsigned char * _mbsinc(const unsigned char *s)
|
||||
{
|
||||
unsigned char *c = (unsigned char *)s;
|
||||
return c + (unsigned char *)mbclen(*c);
|
||||
}
|
11
reactos/lib/crtdll/mbstring/mbslen.c
Normal file
11
reactos/lib/crtdll/mbstring/mbslen.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
size_t _mbslen(const unsigned char *str)
|
||||
{
|
||||
int i = 0;
|
||||
unsigned char *s;
|
||||
|
||||
if (str == 0)
|
||||
return 0;
|
||||
|
||||
for (s = (unsigned char *)str; *s; s+=mbclen(*s),i++);
|
||||
return i;
|
||||
}
|
18
reactos/lib/crtdll/mbstring/mbslwr.c
Normal file
18
reactos/lib/crtdll/mbstring/mbslwr.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
unsigned int _mbctolower(unsigned int c)
|
||||
{
|
||||
if (!_ismbblead(c) )
|
||||
return tolower(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
unsigned char * _mbslwr(unsigned char *x)
|
||||
{
|
||||
char *y=x;
|
||||
|
||||
while (*y) {
|
||||
*y=_mbctolower(*y);
|
||||
y++;
|
||||
}
|
||||
return x;
|
||||
}
|
56
reactos/lib/crtdll/mbstring/mbsncat.c
Normal file
56
reactos/lib/crtdll/mbstring/mbsncat.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbsset.c
|
||||
* PURPOSE: Concatenate two multi byte string to maximum of n characters or bytes
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
|
||||
unsigned char * _mbsncat(unsigned char *dst, const unsigned char *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
const char *s = src;
|
||||
if (n != 0) {
|
||||
d = dst + strlen(dst); // get the end of string
|
||||
d += mblen(*d); // move 1 or 2 up
|
||||
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
{
|
||||
while (--n != 0)
|
||||
*d++ = 0;
|
||||
break;
|
||||
}
|
||||
if (!_ismbblead(*s1) )
|
||||
n--;
|
||||
} while (n > 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
unsigned char * _mbsnbcat(unsigned char *dst, const unsigned char *src, size_t n)
|
||||
{
|
||||
char *d;
|
||||
const char *s = src;
|
||||
if (n != 0) {
|
||||
d = dst + strlen(dst); // get the end of string
|
||||
d += mblen(*d); // move 1 or 2 up
|
||||
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
{
|
||||
while (--n != 0)
|
||||
*d++ = 0;
|
||||
break;
|
||||
}
|
||||
if ( !(n==1 && _ismbblead(*s1)) )
|
||||
n--;
|
||||
} while (n > 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
15
reactos/lib/crtdll/mbstring/mbsnccnt.c
Normal file
15
reactos/lib/crtdll/mbstring/mbsnccnt.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
size_t _mbsnccnt(const unsigned char *str, size_t n)
|
||||
{
|
||||
}
|
||||
|
||||
size_t _mbsnbcnt(const unsigned char *str, size_t n)
|
||||
{
|
||||
unsigned char *s = str;
|
||||
while(*s != 0 && n > 0)
|
||||
if (!_ismbblead(*s) )
|
||||
n--;
|
||||
s++;
|
||||
}
|
||||
|
||||
return (size_t)(s - str);
|
||||
}
|
47
reactos/lib/crtdll/mbstring/mbsncmp.c
Normal file
47
reactos/lib/crtdll/mbstring/mbsncmp.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbsncmp.c
|
||||
* PURPOSE: Compares two strings to a maximum of n bytes or characters
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
int _mbsncmp(const unsigned char *str1, const unsigned char *str2, size_t n)
|
||||
{
|
||||
unsigned char *s1;
|
||||
unsigned char *s2;
|
||||
if (n == 0)
|
||||
return 0;
|
||||
do {
|
||||
if (*s1 != *s2++)
|
||||
return *(unsigned const char *)s1 - *(unsigned const char *)--s2;
|
||||
if (*s1++ == 0)
|
||||
break;
|
||||
|
||||
if (!_ismbblead(*s1) )
|
||||
n--;
|
||||
} while (n > 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _mbsnbcmp(const unsigned char *str1, const unsigned char *str2, size_t n)
|
||||
{
|
||||
unsigned char *s1;
|
||||
unsigned char *s2;
|
||||
if (n == 0)
|
||||
return 0;
|
||||
do {
|
||||
if (*s1 != *s2++)
|
||||
return *(unsigned const char *)s1 - *(unsigned const char *)--s2;
|
||||
if (*s1++ == 0)
|
||||
break;
|
||||
|
||||
if (!(n == 1 && _ismbblead(*s)) )
|
||||
n--;
|
||||
} while (n > 0);
|
||||
return 0;
|
||||
}
|
42
reactos/lib/crtdll/mbstring/mbsncoll.c
Normal file
42
reactos/lib/crtdll/mbstring/mbsncoll.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbsncoll.c
|
||||
* PURPOSE:
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
int _mbsncoll(const unsigned char *, const unsigned char *, size_t)
|
||||
{
|
||||
int l1, l2;
|
||||
int ret;
|
||||
|
||||
l1 = mbslen(str1);
|
||||
l2 = mbslen(str2);
|
||||
ret = CompareStringA(LOCALE_USER_DEFAULT,0,str1,min(l1,n),str2,min(l2,n));
|
||||
|
||||
if ( ret != 0 )
|
||||
|
||||
return ret -2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _mbsnbcoll(const unsigned char *str1, const unsigned char *str2, size_t n)
|
||||
{
|
||||
int l1, l2;
|
||||
int ret;
|
||||
|
||||
l1 = strlen(str1);
|
||||
l2 = strlen(str2);
|
||||
ret = CompareStringA(LOCALE_USER_DEFAULT,0,str1,min(l1,n),str2,min(l2,n));
|
||||
|
||||
if ( ret != 0 )
|
||||
|
||||
return ret -2;
|
||||
|
||||
return 0;
|
||||
}
|
43
reactos/lib/crtdll/mbstring/mbsncpy.c
Normal file
43
reactos/lib/crtdll/mbstring/mbsncpy.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <crtdll/mbstring.h>
|
||||
|
||||
unsigned char * _mbsncpy(unsigned char *dst, const unsigned char *src, size_t n)
|
||||
{
|
||||
unsigned char *d = dst;
|
||||
const unsigned char *s = src;
|
||||
|
||||
if (n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
{
|
||||
while (--n != 0) {
|
||||
*d++ = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!_ismbblead(*s) )
|
||||
n--;
|
||||
} while (n > 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
unsigned char * _mbsnbcpy(unsigned char *src, const unsigned char *dst, size_t n)
|
||||
{
|
||||
unsigned char *d = dst;
|
||||
const unsigned char *s = src;
|
||||
|
||||
if (n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
{
|
||||
while (--n != 0) {
|
||||
*d++ = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!(n == 1 && _ismbblead(*s)) )
|
||||
n--;
|
||||
} while (n > 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
11
reactos/lib/crtdll/mbstring/mbsninc.c
Normal file
11
reactos/lib/crtdll/mbstring/mbsninc.c
Normal file
|
@ -0,0 +1,11 @@
|
|||
unsigned char * _mbsninc(const unsigned char *str, size_t n)
|
||||
{
|
||||
unsigned char *s = str;
|
||||
while(*s != 0 && count > 0)
|
||||
if (!_ismbblead(*s1) )
|
||||
n--;
|
||||
s++;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
66
reactos/lib/crtdll/mbstring/mbsnset.c
Normal file
66
reactos/lib/crtdll/mbstring/mbsnset.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbsset.c
|
||||
* PURPOSE: Fills a string with a multibyte character
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
unsigned char * _mbsnset(unsigned char *src, unsigned int val, size_t count)
|
||||
{
|
||||
|
||||
|
||||
unsigned char *char_s = src;
|
||||
unsigned short *short_s = src;
|
||||
|
||||
if ( c >> 8 == 0 ) {
|
||||
|
||||
while(*s != 0 && count > 0) {
|
||||
*char_src = val;
|
||||
char_src++;
|
||||
count--;
|
||||
}
|
||||
*char_src = 0;
|
||||
}
|
||||
else {
|
||||
while(*s != 0 && count > 0) {
|
||||
*short_src = val;
|
||||
short_src++;
|
||||
count-=2;
|
||||
}
|
||||
*short_src = 0;
|
||||
}
|
||||
|
||||
return src;
|
||||
|
||||
}
|
||||
|
||||
unsigned char * _mbsnbset(unsigned char *src, unsigned int val, size_t count)
|
||||
{
|
||||
|
||||
unsigned char *char_s = src;
|
||||
unsigned short *short_s = src;
|
||||
|
||||
if ( c >> 8 == 0 ) {
|
||||
|
||||
while(*s != 0 && count > 0) {
|
||||
*char_src = val;
|
||||
char_src++;
|
||||
count--;
|
||||
}
|
||||
*char_src = 0;
|
||||
}
|
||||
else {
|
||||
while(*s != 0 && count > 0) {
|
||||
*short_src = val;
|
||||
short_src++;
|
||||
count--;
|
||||
}
|
||||
*short_src = 0;
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
41
reactos/lib/crtdll/mbstring/mbsrchr.c
Normal file
41
reactos/lib/crtdll/mbstring/mbsrchr.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbsrchr.c
|
||||
* PURPOSE: Searches for a character in reverse
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
unsigned char * _mbsrchr(const unsigned char *str, unsigned int c)
|
||||
{
|
||||
|
||||
unsigned char *s = str;
|
||||
|
||||
int count = mbblen(s);
|
||||
|
||||
s += count;
|
||||
if ( c >> 8 == 0 ) {
|
||||
|
||||
while( count > 0 ) {
|
||||
if ( *s == c )
|
||||
return s;
|
||||
count--;
|
||||
s--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while( count > 0 ) {
|
||||
if ( *((short *)s) == c )
|
||||
return s;
|
||||
count--;
|
||||
s--;
|
||||
}
|
||||
}
|
||||
|
||||
return src;
|
||||
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbsrev.c
Normal file
4
reactos/lib/crtdll/mbstring/mbsrev.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
unsigned char * _mbsrev(unsigned char *str)
|
||||
{
|
||||
return strrev(str);
|
||||
}
|
35
reactos/lib/crtdll/mbstring/mbsset.c
Normal file
35
reactos/lib/crtdll/mbstring/mbsset.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/mbstring/mbsset.c
|
||||
* PURPOSE: Fills a string with a multibyte character
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 12/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/mbstring.h>
|
||||
|
||||
unsigned char * _mbsset(unsigned char *str, unsigned int c)
|
||||
{
|
||||
unsigned char *char_s = src;
|
||||
unsigned short *short_s = src;
|
||||
|
||||
if ( c >> 8 == 0 ) {
|
||||
|
||||
while(*s != 0) {
|
||||
*char_src = val;
|
||||
char_src++;
|
||||
}
|
||||
*char_src = 0;
|
||||
}
|
||||
else {
|
||||
while(*s != 0) {
|
||||
*short_src = val;
|
||||
short_src++;
|
||||
}
|
||||
*short_src = 0;
|
||||
}
|
||||
|
||||
return src;
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbsstr.c
Normal file
4
reactos/lib/crtdll/mbstring/mbsstr.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
unsigned char * _mbsstr(const unsigned char *str1, const unsigned char *str2)
|
||||
{
|
||||
return strstr(str1,str2);
|
||||
}
|
4
reactos/lib/crtdll/mbstring/mbstok.c
Normal file
4
reactos/lib/crtdll/mbstring/mbstok.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
unsigned char * _mbstok(unsigned char *x, const unsigned char *y)
|
||||
{
|
||||
return strtok(x,y);
|
||||
}
|
18
reactos/lib/crtdll/mbstring/mbsupr.c
Normal file
18
reactos/lib/crtdll/mbstring/mbsupr.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
unsigned int _mbctoupper(unsigned int c)
|
||||
{
|
||||
if (!_ismbblead(c) )
|
||||
return toupper(c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
unsigned char * _mbsupr(unsigned char *str)
|
||||
{
|
||||
char *y=x;
|
||||
|
||||
while (*y) {
|
||||
*y=_mbctoupper(*y);
|
||||
y++;
|
||||
}
|
||||
return x;
|
||||
}
|
13
reactos/lib/crtdll/misc/amsg.c
Normal file
13
reactos/lib/crtdll/misc/amsg.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
include <stdlib.h>
|
||||
|
||||
int _aexit_rtn_dll(int exitcode)
|
||||
{
|
||||
_exit(exitcode);
|
||||
}
|
||||
|
||||
void _amsg_exit (int errnum)
|
||||
{
|
||||
fprintf(stdout,strerror(errnum));
|
||||
_aexit_rtn_dll(-1);
|
||||
}
|
||||
|
7
reactos/lib/crtdll/misc/initter.c
Normal file
7
reactos/lib/crtdll/misc/initter.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
typedef void(*atexit_t)(void);
|
||||
|
||||
void _initterm(atexit_t *, atexit_t *)
|
||||
{
|
||||
return;
|
||||
}
|
21
reactos/lib/crtdll/misc/initterm.c
Normal file
21
reactos/lib/crtdll/misc/initterm.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <crtdll/stdlib.h>
|
||||
|
||||
|
||||
void _initterm (
|
||||
void (* fStart[])(void),
|
||||
void (* fEnd[])(void)
|
||||
)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
if ( fStart == NULL || fEnd == NULL )
|
||||
return;
|
||||
|
||||
while ( &fStart[i] < fEnd )
|
||||
{
|
||||
if ( fStart[i] != NULL )
|
||||
(*fStart[i])();
|
||||
i++;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ typedef int (* new_handler_t)( size_t );
|
|||
|
||||
new_handler_t new_handler;
|
||||
|
||||
#undef _set_new_handler
|
||||
new_handler_t _set_new_handler(new_handler_t hnd)
|
||||
{
|
||||
new_handler_t old = new_handler;
|
||||
|
@ -14,15 +15,15 @@ new_handler_t _set_new_handler(new_handler_t hnd)
|
|||
return old;
|
||||
}
|
||||
|
||||
#undef delete
|
||||
void operator delete(void* m)
|
||||
{
|
||||
if ( m != NULL )
|
||||
free( m );
|
||||
}
|
||||
|
||||
#undef new
|
||||
void * operator new( unsigned int s )
|
||||
{
|
||||
if ( s == 0 )
|
||||
s = 1;
|
||||
return malloc( s );
|
||||
}
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/process/dll.c
|
||||
* PURPOSE: Dll support routines
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 04/03/99: Created
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <crtdll/process.h>
|
||||
|
||||
|
|
|
@ -1,42 +1,247 @@
|
|||
#include <crtdll/process.h>
|
||||
#include <crtdll/string.h>
|
||||
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
|
||||
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
|
||||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/stdlib.h>
|
||||
#include <crtdll/string.h>
|
||||
#include <crtdll/errno.h>
|
||||
//#include <crtdll/limits.h>
|
||||
#include <crtdll/process.h>
|
||||
#include <crtdll/ctype.h>
|
||||
#include <crtdll/io.h>
|
||||
|
||||
|
||||
int _p_overlay = 2;
|
||||
#ifndef F_OK
|
||||
#define F_OK 0x01
|
||||
#endif
|
||||
#ifndef R_OK
|
||||
#define R_OK 0x02
|
||||
#endif
|
||||
#ifndef W_OK
|
||||
#define W_OK 0x04
|
||||
#endif
|
||||
#ifndef X_OK
|
||||
#define X_OK 0x08
|
||||
#endif
|
||||
#ifndef D_OK
|
||||
#define D_OK 0x10
|
||||
#endif
|
||||
|
||||
int _spawnve(int nMode, const char* szPath, char* const* szaArgv, char* const* szaEnv)
|
||||
|
||||
static int
|
||||
direct_exec_tail(const char *program, const char *args,
|
||||
char * const envp[])
|
||||
{
|
||||
|
||||
char ApplicationName[MAX_PATH];
|
||||
char CommandLine[1024];
|
||||
PROCESS_INFORMATION ProcessInformation;
|
||||
STARTUPINFO StartupInfo;
|
||||
|
||||
int i = 0;
|
||||
CommandLine[0] = 0;
|
||||
while(szaArgv[i] != NULL ) {
|
||||
strcat(CommandLine,szaArgv[i]);
|
||||
strcat(CommandLine," ");
|
||||
i++;
|
||||
}
|
||||
strcpy(ApplicationName,szaArgv[0]);
|
||||
|
||||
fflush(stdout); /* just in case */
|
||||
StartupInfo.cb = sizeof(STARTUPINFO);
|
||||
StartupInfo.lpReserved= NULL;
|
||||
StartupInfo.dwFlags = 0;
|
||||
static PROCESS_INFORMATION ProcessInformation;
|
||||
static STARTUPINFO StartupInfo;
|
||||
|
||||
StartupInfo.cb = sizeof(STARTUPINFO);
|
||||
StartupInfo.lpReserved= NULL;
|
||||
StartupInfo.dwFlags = 0;
|
||||
StartupInfo.wShowWindow = SW_SHOWDEFAULT;
|
||||
StartupInfo.lpReserved2 = NULL;
|
||||
StartupInfo.cbReserved2 = 0;
|
||||
|
||||
|
||||
if ( CreateProcessA(ApplicationName,CommandLine,NULL,NULL,TRUE,CREATE_NEW_CONSOLE|NORMAL_PRIORITY_CLASS,NULL,*szaEnv,&StartupInfo,&ProcessInformation) ) {
|
||||
return -1;
|
||||
}
|
||||
if ( CreateProcessA((char *)program,(char *)args,NULL,NULL,FALSE,0,(char **)envp,NULL,&StartupInfo,&ProcessInformation) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// if (nMode == P_OVERLAY)
|
||||
// _exit(i);
|
||||
|
||||
// _P_NOWAIT or _P_NOWAITO
|
||||
return (int )ProcessInformation.hProcess;
|
||||
return ProcessInformation.dwProcessId;
|
||||
}
|
||||
|
||||
static int vdm_exec(const char *program, char **argv, char **envp)
|
||||
{
|
||||
static char args[1024];
|
||||
int i = 0;
|
||||
args[0] = 0;
|
||||
|
||||
strcpy(args,"vdm.exe ");
|
||||
while(argv[i] != NULL ) {
|
||||
strcat(args,argv[i]);
|
||||
strcat(args," ");
|
||||
i++;
|
||||
}
|
||||
|
||||
return direct_exec_tail(program,args,envp);
|
||||
}
|
||||
|
||||
static int go32_exec(const char *program, char **argv, char **envp)
|
||||
{
|
||||
|
||||
|
||||
static char args[1024];
|
||||
int i = 0;
|
||||
|
||||
|
||||
args[0] = 0;
|
||||
|
||||
while(argv[i] != NULL ) {
|
||||
strcat(args,envp[i]);
|
||||
strcat(args," ");
|
||||
i++;
|
||||
}
|
||||
printf("%s \n %s\n",args, GetEnvironmentStrings());
|
||||
args[0] = 0;
|
||||
i = 0;
|
||||
while(argv[i] != NULL ) {
|
||||
strcat(args,argv[i]);
|
||||
strcat(args," ");
|
||||
i++;
|
||||
}
|
||||
|
||||
return direct_exec_tail(program,args,envp);
|
||||
}
|
||||
|
||||
int
|
||||
command_exec(const char *program, char **argv, char **envp)
|
||||
{
|
||||
static char args[1024];
|
||||
int i = 0;
|
||||
|
||||
|
||||
|
||||
args[0] = 0;
|
||||
|
||||
strcpy(args,"cmd.exe /c ");
|
||||
while(argv[i] != NULL ) {
|
||||
strcat(args,argv[i]);
|
||||
strcat(args," ");
|
||||
i++;
|
||||
}
|
||||
|
||||
return direct_exec_tail(program,args,envp);
|
||||
|
||||
}
|
||||
|
||||
static int script_exec(const char *program, char **argv, char **envp)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Note: the following list is not supposed to mention *every*
|
||||
possible extension of an executable file. It only mentions
|
||||
those extensions that can be *omitted* when you invoke the
|
||||
executable from one of the shells used on MSDOS. */
|
||||
static struct {
|
||||
const char *extension;
|
||||
int (*interp)(const char *, char **, char **);
|
||||
} interpreters[] = {
|
||||
{ ".com", vdm_exec },
|
||||
{ ".exe", go32_exec },
|
||||
{ ".bat", command_exec },
|
||||
{ ".btm", command_exec },
|
||||
{ ".sh", script_exec }, /* for compatibility with ms_sh */
|
||||
{ ".ksh", script_exec },
|
||||
{ ".pl", script_exec }, /* Perl */
|
||||
{ ".sed", script_exec },
|
||||
{ "", go32_exec },
|
||||
{ 0, script_exec }, /* every extension not mentioned above calls it */
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
/* This is the index into the above array of the interpreter
|
||||
which is called when the program filename has no extension. */
|
||||
#define INTERP_NO_EXT (sizeof(interpreters)/sizeof(interpreters[0]) - 3)
|
||||
|
||||
/*-------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
int _spawnve(int mode, const char *path, char *const argv[], char *const envp[])
|
||||
{
|
||||
/* This is the one that does the work! */
|
||||
union { char *const *x; char **p; } u;
|
||||
int i = -1;
|
||||
char **argvp;
|
||||
char **envpp;
|
||||
char rpath[FILENAME_MAX], *rp, *rd=0;
|
||||
int e = errno;
|
||||
int is_dir = 0;
|
||||
int found = 0;
|
||||
|
||||
if (path == 0 || argv[0] == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (strlen(path) > FILENAME_MAX - 1)
|
||||
{
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
u.x = argv; argvp = u.p;
|
||||
u.x = envp; envpp = u.p;
|
||||
|
||||
fflush(stdout); /* just in case */
|
||||
for (rp=rpath; *path; *rp++ = *path++)
|
||||
{
|
||||
if (*path == '.')
|
||||
rd = rp;
|
||||
if (*path == '\\' || *path == '/')
|
||||
rd = 0;
|
||||
}
|
||||
*rp = 0;
|
||||
|
||||
/* If LFN is supported on the volume where rpath resides, we
|
||||
might have something like foo.bar.exe or even foo.exe.com.
|
||||
If so, look for RPATH.ext before even trying RPATH itself. */
|
||||
if (!rd)
|
||||
{
|
||||
for (i=0; interpreters[i].extension; i++)
|
||||
{
|
||||
strcpy(rp, interpreters[i].extension);
|
||||
if (_access(rpath, F_OK) == 0 && !(is_dir = (_access(rpath, D_OK) == 0)))
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
const char *rpath_ext;
|
||||
|
||||
if (rd)
|
||||
{
|
||||
i = 0;
|
||||
rpath_ext = rd;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = INTERP_NO_EXT;
|
||||
rpath_ext = "";
|
||||
}
|
||||
for ( ; interpreters[i].extension; i++)
|
||||
if (_stricmp(rpath_ext, interpreters[i].extension) == 0
|
||||
&& _access(rpath, F_OK) == 0
|
||||
&& !(is_dir = (_access(rpath, D_OK) == 0)))
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
errno = is_dir ? EISDIR : ENOENT;
|
||||
return -1;
|
||||
}
|
||||
errno = e;
|
||||
i = interpreters[i].interp(rpath, argvp, envpp);
|
||||
if (mode == P_OVERLAY)
|
||||
exit(i);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
26
reactos/lib/crtdll/process/thread.c
Normal file
26
reactos/lib/crtdll/process/thread.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <windows.h>
|
||||
#include <crtdll/process.h>
|
||||
#include <crtdll/errno.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
|
||||
unsigned long
|
||||
_beginthread (void (*pfuncStart)(void *),
|
||||
unsigned unStackSize, void* pArgList)
|
||||
{
|
||||
DWORD ThreadId;
|
||||
HANDLE hThread;
|
||||
if ( pfuncStart == NULL )
|
||||
__set_errno(EINVAL);
|
||||
|
||||
hThread = CreateThread( NULL,unStackSize,(LPTHREAD_START_ROUTINE)pfuncStart,pArgList,0, &ThreadId);
|
||||
if (hThread == NULL ) {
|
||||
__set_errno(EAGAIN);
|
||||
return -1;
|
||||
}
|
||||
return (unsigned long)hThread;
|
||||
}
|
||||
void _endthread(void)
|
||||
{
|
||||
ExitThread(0);
|
||||
}
|
143
reactos/lib/crtdll/setjmp/setjmp.c
Normal file
143
reactos/lib/crtdll/setjmp/setjmp.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
/* modified by Boudewijn Dekker */
|
||||
/* ms uses a smaller jmp_buf structure */
|
||||
/* might do a realloc in setjmp */
|
||||
|
||||
typedef struct {
|
||||
unsigned int __eax, __ebx, __ecx, __edx, __esi;
|
||||
unsigned int __edi, __ebp, __esp, __eip, __eflags;
|
||||
unsigned short __cs, __ds, __es, __fs, __gs, __ss;
|
||||
unsigned long __sigmask; /* for POSIX signals only */
|
||||
unsigned long __signum; /* for expansion */
|
||||
unsigned long __exception_ptr; /* pointer to previous exception */
|
||||
unsigned char __fpu_state[108]; /* for future use */
|
||||
} jmp_buf[1];
|
||||
|
||||
|
||||
/* jumps back to position specified in jmp_buf */
|
||||
|
||||
int longjmp( jmp_buf env, int value )
|
||||
{
|
||||
//push ebp generated by the compiler
|
||||
//mov ebp, esp
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"movl 8(%ebp),%edi\n\t" /* get jmp_buf */
|
||||
"movl 12(%ebp),%eax\n\t" /* store retval in j->eax */
|
||||
"movl %eax,0(%edi)\n\t"
|
||||
|
||||
"movw 46(%edi),%fs\n\t"
|
||||
"movw 48(%edi),%gs\n\t"
|
||||
"movl 4(%edi),%ebx\n\t"
|
||||
"movl 8(%edi),%ecx\n\t"
|
||||
"movl 12(%edi),%edx\n\t"
|
||||
"movl 24(%edi),%ebp\n\t"
|
||||
|
||||
/* Now for some uglyness. The jmp_buf structure may be ABOVE the
|
||||
point on the new SS:ESP we are moving to. We don't allow overlap,
|
||||
but do force that it always be valid. We will use ES:ESI for
|
||||
our new stack before swapping to it. */
|
||||
|
||||
"movw 50(%edi),%es\n\t"
|
||||
"movl 28(%edi),%esi\n\t"
|
||||
"subl $28,%esi\n\t" /* We need 7 working longwords on stack */
|
||||
|
||||
"movl 60(%edi),%eax\n\t"
|
||||
"es\n\t"
|
||||
"movl %eax,(%esi)\n\t" /* Exception pointer */
|
||||
|
||||
"movzwl 42(%edi),%eax\n\t"
|
||||
"es\n\t"
|
||||
"movl %eax,4(%esi)\n\t" /* DS */
|
||||
|
||||
"movl 20(%edi),%eax\n\t"
|
||||
"es\n\t"
|
||||
"movl %eax,8(%esi)\n\t" /* EDI */
|
||||
|
||||
"movl 16(%edi),%eax\n\t"
|
||||
"es\n\t"
|
||||
"movl %eax,12(%esi)\n\t" /* ESI */
|
||||
|
||||
"movl 32(%edi),%eax\n\t"
|
||||
"es\n\t"
|
||||
"movl %eax,16(%esi)\n\t" /* EIP - start of IRET frame */
|
||||
|
||||
"movl 40(%edi),%eax\n\t"
|
||||
"es\n\t"
|
||||
"movl %eax,20(%esi)\n\t" /* CS */
|
||||
|
||||
"movl 36(%edi),%eax\n\t"
|
||||
"es\n\t"
|
||||
"movl %eax,24(%esi)\n\t" /* EFLAGS */
|
||||
|
||||
"movl 0(%edi),%eax\n\t"
|
||||
"movw 44(%edi),%es\n\t"
|
||||
|
||||
"movw 50(%edi),%ss\n\t"
|
||||
"movl %esi,%esp\n\t"
|
||||
|
||||
//"popl ___djgpp_exception_state_ptr\n\t"
|
||||
"popl %edi\n\t" // dummy popl instead of djgpp_exception_state_ptr
|
||||
"popl %ds\n\t"
|
||||
"popl %edi\n\t"
|
||||
"popl %esi\n\t"
|
||||
|
||||
"iret\n\t" /* actually jump to new cs:eip loading flags */
|
||||
);
|
||||
|
||||
return value; // dummy return never reached
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _setjmp( jmp_buf env )
|
||||
{
|
||||
//push ebp generated by the compiler
|
||||
//mov ebp, esp
|
||||
|
||||
__asm__ __volatile__ (
|
||||
|
||||
"pushl %edi\n\t"
|
||||
"movl 8(%ebp),%edi\n\t"
|
||||
|
||||
"movl %eax, (%edi)\n\t"
|
||||
"movl %ebx,4(%edi)\n\t"
|
||||
"movl %ecx,8(%edi)\n\t"
|
||||
"movl %edx,12(%edi)\n\t"
|
||||
"movl %esi,16(%edi)\n\t"
|
||||
|
||||
"movl -4(%ebp),%eax\n\t"
|
||||
"movl %eax,20(%edi)\n\t"
|
||||
|
||||
"movl (%ebp),%eax\n\t"
|
||||
"movl %eax,24(%edi)\n\t"
|
||||
|
||||
"movl %esp,%eax\n\t"
|
||||
"addl $12,%eax\n\t"
|
||||
"movl %eax,28(%edi)\n\t"
|
||||
|
||||
"movl 4(%ebp),%eax\n\t"
|
||||
"movl %eax,32(%edi)\n\t"
|
||||
|
||||
"pushfl\n\t"
|
||||
"popl 36(%edi)\n\t"
|
||||
|
||||
"movw %cs, 40(%edi)\n\t"
|
||||
"movw %ds, 42(%edi)\n\t"
|
||||
"movw %es, 44(%edi)\n\t"
|
||||
"movw %fs, 46(%edi)\n\t"
|
||||
"movw %gs, 48(%edi)\n\t"
|
||||
"movw %ss, 50(%edi)\n\t"
|
||||
|
||||
//movl ___djgpp_exception_state_ptr, %eax
|
||||
//movl %eax, 60(%edi)
|
||||
|
||||
"popl %edi\n\t"
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
#include <crtdll/signal.h>
|
||||
#include <crtdll/stdlib.h>
|
||||
|
||||
extern unsigned end __asm__ ("end");
|
||||
//extern unsigned end __asm__ ("end");
|
||||
|
||||
void __djgpp_traceback_exit(int);
|
||||
|
||||
|
@ -28,6 +28,7 @@ _p_sig_fn_t signal(int sig, _p_sig_fn_t func)
|
|||
int
|
||||
raise(int sig)
|
||||
{
|
||||
#if 0
|
||||
_p_sig_fn_t temp;
|
||||
|
||||
if(sig <= 0)
|
||||
|
@ -47,6 +48,8 @@ raise(int sig)
|
|||
}
|
||||
else
|
||||
temp(sig);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
10
reactos/lib/crtdll/signal/xcptfil.c
Normal file
10
reactos/lib/crtdll/signal/xcptfil.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <windows.h>
|
||||
|
||||
|
||||
int _XcptFilter (
|
||||
DWORD ExceptionCode,
|
||||
struct _EXCEPTION_POINTERS * ExceptionInfo
|
||||
)
|
||||
{
|
||||
return UnhandledExceptionFilter(ExceptionInfo);
|
||||
}
|
4
reactos/lib/crtdll/signal/xcptinfo.c
Normal file
4
reactos/lib/crtdll/signal/xcptinfo.c
Normal file
|
@ -0,0 +1,4 @@
|
|||
void **__pxcptinfoptrs (void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
|
@ -10,5 +10,9 @@ void clearerr(FILE *stream);
|
|||
void
|
||||
clearerr(FILE *f)
|
||||
{
|
||||
if (!f) {
|
||||
__set_errno (EINVAL);
|
||||
return;
|
||||
}
|
||||
f->_flag &= ~(_IOERR|_IOEOF);
|
||||
}
|
||||
|
|
|
@ -1,320 +0,0 @@
|
|||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* linux/lib/vsprintf.c
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
|
||||
/*
|
||||
* Wirzenius wrote this portably, Torvalds fucked it up :-)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Appropiated for the reactos kernel, March 1998 -- David Welch
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
//#include <crtdll/internal/debug.h>
|
||||
#include <crtdll/ctype.h>
|
||||
#include <crtdll/string.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/string.h>
|
||||
|
||||
static int skip_atoi(const char **s)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
while (isdigit(**s))
|
||||
i = i*10 + *((*s)++) - '0';
|
||||
return i;
|
||||
}
|
||||
|
||||
#define ZEROPAD 1 /* pad with zero */
|
||||
#define SIGN 2 /* unsigned/signed long */
|
||||
#define PLUS 4 /* show plus */
|
||||
#define SPACE 8 /* space if plus */
|
||||
#define LEFT 16 /* left justified */
|
||||
#define SPECIAL 32 /* 0x */
|
||||
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
|
||||
|
||||
|
||||
static int __res;
|
||||
|
||||
int do_div(int *n,int base) {
|
||||
|
||||
__res = ((unsigned long) *n) % (unsigned) base;
|
||||
*n = ((unsigned long) *n) / (unsigned) base;
|
||||
return __res;
|
||||
}
|
||||
|
||||
static char * number(FILE * f, long num, int base, int size, int precision
|
||||
,int type)
|
||||
{
|
||||
char c,sign,tmp[66];
|
||||
const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
int i;
|
||||
|
||||
if (type & LARGE)
|
||||
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
if (type & LEFT)
|
||||
type &= ~ZEROPAD;
|
||||
if (base < 2 || base > 36)
|
||||
return 0;
|
||||
c = (type & ZEROPAD) ? '0' : ' ';
|
||||
sign = 0;
|
||||
if (type & SIGN) {
|
||||
if (num < 0) {
|
||||
sign = '-';
|
||||
num = -num;
|
||||
size--;
|
||||
} else if (type & PLUS) {
|
||||
sign = '+';
|
||||
size--;
|
||||
} else if (type & SPACE) {
|
||||
sign = ' ';
|
||||
size--;
|
||||
}
|
||||
}
|
||||
if (type & SPECIAL) {
|
||||
if (base == 16)
|
||||
size -= 2;
|
||||
else if (base == 8)
|
||||
size--;
|
||||
}
|
||||
i = 0;
|
||||
if (num == 0)
|
||||
tmp[i++]='0';
|
||||
else while (num != 0)
|
||||
tmp[i++] = digits[do_div((int *)&num,base)];
|
||||
if (i > precision)
|
||||
precision = i;
|
||||
size -= precision;
|
||||
if (!(type&(ZEROPAD+LEFT)))
|
||||
while(size-->0)
|
||||
putc( ' ',f);
|
||||
if (sign)
|
||||
putc( sign,f);
|
||||
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);
|
||||
}
|
||||
while (i < precision--)
|
||||
putc( '0', f);
|
||||
while (i-- > 0)
|
||||
putc( tmp[i],f);
|
||||
while (size-- > 0)
|
||||
putc( ' ', f);
|
||||
__res = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _doprnt(const char *fmt, va_list args, FILE *f)
|
||||
{
|
||||
int len;
|
||||
unsigned long num;
|
||||
int i, base;
|
||||
|
||||
const char *s;
|
||||
const short int* sw;
|
||||
|
||||
int flags; /* flags to number() */
|
||||
|
||||
int field_width; /* width of output field */
|
||||
int precision; /* min. # of digits for integers; max
|
||||
number of chars for from string */
|
||||
int qualifier; /* 'h', 'l', or 'L' for integer fields */
|
||||
|
||||
for (; *fmt ; ++fmt) {
|
||||
if (*fmt != '%') {
|
||||
putc(*fmt,f);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* process flags */
|
||||
flags = 0;
|
||||
repeat:
|
||||
++fmt; /* this also skips first '%' */
|
||||
switch (*fmt) {
|
||||
case '-': flags |= LEFT; goto repeat;
|
||||
case '+': flags |= PLUS; goto repeat;
|
||||
case ' ': flags |= SPACE; goto repeat;
|
||||
case '#': flags |= SPECIAL; goto repeat;
|
||||
case '0': flags |= ZEROPAD; goto repeat;
|
||||
}
|
||||
|
||||
/* get field width */
|
||||
field_width = -1;
|
||||
if (isdigit(*fmt))
|
||||
field_width = skip_atoi(&fmt);
|
||||
else if (*fmt == '*') {
|
||||
++fmt;
|
||||
/* it's the next argument */
|
||||
field_width = va_arg(args, int);
|
||||
if (field_width < 0) {
|
||||
field_width = -field_width;
|
||||
flags |= LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
/* get the precision */
|
||||
precision = -1;
|
||||
if (*fmt == '.') {
|
||||
++fmt;
|
||||
if (isdigit(*fmt))
|
||||
precision = skip_atoi(&fmt);
|
||||
else if (*fmt == '*') {
|
||||
++fmt;
|
||||
/* it's the next argument */
|
||||
precision = va_arg(args, int);
|
||||
}
|
||||
if (precision < 0)
|
||||
precision = 0;
|
||||
}
|
||||
|
||||
/* get the conversion qualifier */
|
||||
qualifier = -1;
|
||||
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
|
||||
qualifier = *fmt;
|
||||
++fmt;
|
||||
}
|
||||
|
||||
/* default base */
|
||||
base = 10;
|
||||
|
||||
switch (*fmt) {
|
||||
case 'c':
|
||||
if (!(flags & LEFT))
|
||||
while (--field_width > 0)
|
||||
putc(' ',f);
|
||||
putc((unsigned char) va_arg(args, int),f);
|
||||
while (--field_width > 0)
|
||||
putc( ' ',f);
|
||||
continue;
|
||||
|
||||
case 'w':
|
||||
sw = va_arg(args,short int *);
|
||||
// DPRINT("L %x\n",sw);
|
||||
if (sw==NULL)
|
||||
{
|
||||
// CHECKPOINT;
|
||||
s = "<NULL>";
|
||||
while ((*s)!=0)
|
||||
{
|
||||
putc( *s++,f);
|
||||
}
|
||||
// CHECKPOINT;
|
||||
// DbgPrint("str %x\n",str);
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((*sw)!=0)
|
||||
{
|
||||
putc( (char)(*sw++),f);
|
||||
}
|
||||
}
|
||||
// CHECKPOINT;
|
||||
continue;
|
||||
|
||||
case 's':
|
||||
s = va_arg(args, char *);
|
||||
if (!s)
|
||||
s = "<NULL>";
|
||||
|
||||
len = strnlen(s, precision);
|
||||
|
||||
if (!(flags & LEFT))
|
||||
while (len < field_width--)
|
||||
putc( ' ', f);
|
||||
for (i = 0; i < len; ++i)
|
||||
putc( *s++,f);
|
||||
while (len < field_width--)
|
||||
putc( ' ', f);
|
||||
continue;
|
||||
|
||||
case 'p':
|
||||
if (field_width == -1) {
|
||||
field_width = 2*sizeof(void *);
|
||||
flags |= ZEROPAD;
|
||||
}
|
||||
number(f,
|
||||
(unsigned long) va_arg(args, void *), 16,
|
||||
field_width, precision, flags);
|
||||
continue;
|
||||
|
||||
|
||||
case 'n':
|
||||
if (qualifier == 'l') {
|
||||
long * ip;
|
||||
ip = va_arg(args, long *);
|
||||
//*ip = (str - buf);
|
||||
} else {
|
||||
int * ip;
|
||||
ip = va_arg(args, int *);
|
||||
//*ip = (str - buf);
|
||||
}
|
||||
continue;
|
||||
|
||||
/* integer number formats - set up the flags and "break" */
|
||||
case 'o':
|
||||
base = 8;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
base = 2;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
flags |= LARGE;
|
||||
case 'x':
|
||||
base = 16;
|
||||
break;
|
||||
case 'f':
|
||||
case 'd':
|
||||
case 'i':
|
||||
flags |= SIGN;
|
||||
case 'u':
|
||||
break;
|
||||
|
||||
default:
|
||||
if (*fmt != '%')
|
||||
putc( '%', f);
|
||||
if (*fmt)
|
||||
putc( *fmt, f);
|
||||
else
|
||||
--fmt;
|
||||
continue;
|
||||
}
|
||||
if (qualifier == 'l')
|
||||
num = va_arg(args, unsigned long);
|
||||
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
|
||||
num = va_arg(args, unsigned int);
|
||||
number(f, num, base, field_width, precision, flags);
|
||||
}
|
||||
//putc('\0',f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,18 +1,13 @@
|
|||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
//#include <crtdll/stubs.h>
|
||||
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/io.h>
|
||||
#include <crtdll/sys/types.h>
|
||||
#include <crtdll/sys/stat.h>
|
||||
#include <crtdll/stdlib.h>
|
||||
//#include <crtdll/unistd.h>
|
||||
#include <crtdll/errno.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
#if 0
|
||||
#ifndef __dj_include_stdio_h_
|
||||
#define _name_to_remove _tmpfname
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int
|
||||
fclose(FILE *f)
|
||||
|
@ -20,8 +15,12 @@ fclose(FILE *f)
|
|||
int r;
|
||||
|
||||
r = EOF;
|
||||
if (!f)
|
||||
if (!f) {
|
||||
__set_errno (EINVAL);
|
||||
return r;
|
||||
}
|
||||
// flush only if stream was opened for writing
|
||||
|
||||
if (f->_flag & (_IOREAD|_IOWRT|_IORW)
|
||||
&& !(f->_flag&_IOSTRG))
|
||||
{
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
FILE * __alloc_file(void);
|
||||
|
||||
FILE *_fdopen(int handle, char *mode)
|
||||
{
|
||||
|
|
|
@ -18,8 +18,8 @@ fgetc(FILE *f)
|
|||
return getc(f);
|
||||
}
|
||||
|
||||
int
|
||||
wint_t
|
||||
fgetwc(FILE *f)
|
||||
{
|
||||
return getc(f);
|
||||
return getwc(f);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <crtdll/string.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
#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
|
||||
|
@ -20,8 +21,7 @@
|
|||
int
|
||||
_filbuf(FILE *f)
|
||||
{
|
||||
int size =0;
|
||||
//int fillsize = 0;
|
||||
int size, fillsize;
|
||||
char c;
|
||||
|
||||
if (f->_flag & _IORW)
|
||||
|
@ -44,7 +44,7 @@ _filbuf(FILE *f)
|
|||
{
|
||||
f->_flag |= _IOMYBUF;
|
||||
f->_bufsiz = size;
|
||||
//f->_fillsize = 512;
|
||||
f->_fillsize = 512;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,22 +59,22 @@ _filbuf(FILE *f)
|
|||
}
|
||||
|
||||
/* don't read too much! */
|
||||
//if (f->_fillsize > f->_bufsiz)
|
||||
// f->_fillsize = f->_bufsiz;
|
||||
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;
|
||||
fillsize = f->_fillsize;
|
||||
if (fillsize == 1024 && f->_bufsiz >= 1536)
|
||||
fillsize = 1536;
|
||||
|
||||
f->_cnt = _read(fileno(f), f->_base,
|
||||
f->_flag & _IONBF ? 1 : size);
|
||||
f->_flag & _IONBF ? 1 : fillsize);
|
||||
|
||||
/* Read more next time, if we don't seek */
|
||||
//if (f->_fillsize < f->_bufsiz)
|
||||
// f->_fillsize *= 2;
|
||||
if (f->_fillsize < f->_bufsiz)
|
||||
f->_fillsize *= 2;
|
||||
|
||||
if(__is_text_file(f) && f->_cnt>0)
|
||||
{
|
||||
|
@ -102,3 +102,8 @@ _filbuf(FILE *f)
|
|||
}
|
||||
return *f->_ptr++ & 0377;
|
||||
}
|
||||
|
||||
wint_t _filwbuf(FILE *fp)
|
||||
{
|
||||
return (wint_t )_filbuf(fp);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
|
||||
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
|
||||
//#include <crtdll/stubs.h>
|
||||
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/sys/types.h>
|
||||
#include <crtdll/stdlib.h>
|
||||
//#include <crtdll/unistd.h>
|
||||
//#include <crtdll/go32.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
#include <crtdll/io.h>
|
||||
|
||||
int
|
||||
_flsbuf(int c, FILE *f)
|
||||
{
|
||||
char *base;
|
||||
char *base;
|
||||
int n, rn;
|
||||
char c1;
|
||||
int size;
|
||||
|
@ -29,8 +28,7 @@ _flsbuf(int c, FILE *f)
|
|||
/* if the buffer is not yet allocated, allocate it */
|
||||
if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0)
|
||||
{
|
||||
// size = _go32_info_block.size_of_transfer_buffer;
|
||||
size = 512;
|
||||
size = 512;
|
||||
if ((f->_base = base = malloc (size)) == NULL)
|
||||
{
|
||||
f->_flag |= _IONBF;
|
||||
|
@ -98,3 +96,9 @@ _flsbuf(int c, FILE *f)
|
|||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
wint_t _flswbuf(wchar_t c,FILE *fp)
|
||||
{
|
||||
return (wint_t )_flsbuf((int)c,fp);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ fprintf(register FILE *iop, const char *fmt, ...)
|
|||
iop->_flag &= ~_IONBF;
|
||||
iop->_ptr = iop->_base = localbuf;
|
||||
iop->_bufsiz = BUFSIZ;
|
||||
len = _doprnt(fmt,a, iop);
|
||||
len = vfprintf(iop,fmt,a);
|
||||
fflush(iop);
|
||||
iop->_flag |= _IONBF;
|
||||
iop->_base = NULL;
|
||||
|
@ -24,6 +24,6 @@ fprintf(register FILE *iop, const char *fmt, ...)
|
|||
iop->_cnt = 0;
|
||||
}
|
||||
else
|
||||
len = _doprnt(fmt, a, iop);
|
||||
len = vfprintf(iop, fmt, a);
|
||||
return ferror(iop) ? EOF : len;
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@ fputc(int c, FILE *fp)
|
|||
return putc(c, fp);
|
||||
}
|
||||
|
||||
int
|
||||
wint_t
|
||||
fputwc(wchar_t c, FILE *fp)
|
||||
{
|
||||
return putc(c, fp);
|
||||
{
|
||||
return fputwc(c,fp);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <crtdll/string.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
#define _fillsize _bufsiz
|
||||
|
||||
size_t
|
||||
fread(void *vptr, size_t size, size_t count, FILE *iop)
|
||||
|
|
|
@ -1,26 +1,59 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <crtdll/stdio.h>
|
||||
/* Copyright (C) 1991 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 <stdarg.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/alloc.h>
|
||||
|
||||
int
|
||||
fscanf(FILE *f, const char *fmt, ...)
|
||||
int __vfscanf (FILE *s, const char *format, va_list argptr);
|
||||
/* Read formatted input from STREAM according to the format string FORMAT. */
|
||||
/* VARARGS2 */
|
||||
int fscanf(FILE *stream,const char *format, ...)
|
||||
{
|
||||
int r;
|
||||
va_list a=0;
|
||||
va_start(a, fmt);
|
||||
r = _doscan(f, fmt, a);
|
||||
va_end(a);
|
||||
return r;
|
||||
va_list arg;
|
||||
int done;
|
||||
|
||||
va_start(arg, format);
|
||||
done = __vfscanf(stream, format, arg);
|
||||
va_end(arg);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
int
|
||||
fwscanf(FILE *f, const wchar_t *fmt, ...)
|
||||
fwscanf(FILE *stream, const wchar_t *fmt, ...)
|
||||
{
|
||||
int r;
|
||||
va_list a=0;
|
||||
va_start(a, fmt);
|
||||
r = _dowscan(f, fmt,(void *) a);
|
||||
va_end(a);
|
||||
return r;
|
||||
va_list arg;
|
||||
int done;
|
||||
char *cf;
|
||||
int i,len = wcslen(fmt);
|
||||
|
||||
cf = alloca(len+1);
|
||||
for(i=0;i<len;i++)
|
||||
cf[i] = fmt[i];
|
||||
cf[i] = 0;
|
||||
|
||||
va_start(arg, fmt);
|
||||
done = __vfscanf(stream, cf, arg);
|
||||
va_end(arg);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <crtdll/fcntl.h>
|
||||
#include <crtdll/io.h>
|
||||
|
||||
#define _fillsize _bufsiz
|
||||
|
||||
int
|
||||
fseek(FILE *f, long offset, int ptrname)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <crtdll/stdio.h>
|
||||
#include <windows.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
|
||||
|
@ -15,4 +16,25 @@ int getc(FILE *fp)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// not exported
|
||||
|
||||
wint_t getwc(FILE *fp)
|
||||
{
|
||||
|
||||
// might check on multi bytes if text mode
|
||||
|
||||
if(fp->_cnt > 0) {
|
||||
fp->_cnt -= sizeof(wchar_t);
|
||||
return (wint_t )*((wchar_t *)(fp->_ptr))++;
|
||||
}
|
||||
else {
|
||||
return _filwbuf(fp);
|
||||
}
|
||||
|
||||
// never reached
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,21 +1,41 @@
|
|||
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
|
||||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
/* Copyright (C) 1991, 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., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
|
||||
int printf(const char *fmt, ...)
|
||||
/* Write formatted output to stdout from the format string FORMAT. */
|
||||
/* VARARGS1 */
|
||||
int
|
||||
printf (const char *format, ...)
|
||||
{
|
||||
int len;
|
||||
va_list a;
|
||||
|
||||
va_start( a, fmt );
|
||||
len = _doprnt(fmt, a, stdout);
|
||||
va_list arg;
|
||||
int done;
|
||||
|
||||
/* People were confused when printf() didn't flush stdout,
|
||||
so we'll do it to reduce confusion */
|
||||
if (stdout->_flag & _IOLBF)
|
||||
fflush(stdout);
|
||||
|
||||
return ferror(stdout) ? EOF : len;
|
||||
va_start (arg, format);
|
||||
done = vprintf (format, arg);
|
||||
va_end (arg);
|
||||
return done;
|
||||
}
|
||||
|
||||
#ifdef USE_IN_LIBIO
|
||||
# undef _IO_printf
|
||||
/* This is for libg++. */
|
||||
strong_alias (printf, _IO_printf);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,20 +1,41 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <crtdll/stdio.h>
|
||||
#include <windows.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
#include <crtdll/crtdll.h>
|
||||
|
||||
int putc(int c, FILE *fp)
|
||||
{
|
||||
if (fp->_cnt > 0 )
|
||||
{
|
||||
fp->_cnt--;
|
||||
*(fp)->_ptr++ = (char)c;
|
||||
return (int)c;
|
||||
}
|
||||
else
|
||||
return _flsbuf(c,fp);
|
||||
|
||||
return -1;
|
||||
{
|
||||
if ( c == 0 )
|
||||
c = ' ';
|
||||
|
||||
if (fp->_cnt > 0 ) {
|
||||
fp->_cnt--;
|
||||
*(fp)->_ptr++ = (char)c;
|
||||
*(fp)->_ptr = 0;
|
||||
return (int)c;
|
||||
}
|
||||
else {
|
||||
return _flsbuf(c,fp);
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
wint_t putwc(wchar_t c, FILE *fp)
|
||||
{
|
||||
// might check on multi bytes if text mode
|
||||
|
||||
if (fp->_cnt > 0 ) {
|
||||
fp->_cnt-= sizeof(wchar_t);
|
||||
*((wchar_t *)(fp->_ptr))++ = c;
|
||||
return (wint_t)c;
|
||||
}
|
||||
else
|
||||
return _flswbuf(c,fp);
|
||||
|
||||
return -1;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +1,75 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <crtdll/stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
/* Copyright (C) 1991, 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 <stdarg.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/alloc.h>
|
||||
|
||||
/* The function `vscanf' is not defined in ISO C. Therefore we must
|
||||
use the protected form here. In stdio it is called `__vscanf' and
|
||||
in libio `_IO_vscanf'. */
|
||||
#ifdef USE_IN_LIBIO
|
||||
# include <libioP.h>
|
||||
# define VSCANF _IO_vscanf
|
||||
#else
|
||||
# define VSCANF __vscanf
|
||||
#endif
|
||||
|
||||
int __vscanf (const char *format, va_list arg);
|
||||
|
||||
/* Read formatted input from stdin according to the format string FORMAT. */
|
||||
/* VARARGS1 */
|
||||
int
|
||||
scanf(const char *fmt, ...)
|
||||
scanf (const char *format, ...)
|
||||
{
|
||||
int r;
|
||||
va_list a=0;
|
||||
va_start(a, fmt);
|
||||
r = _doscan(stdin, fmt, a);
|
||||
va_end(a);
|
||||
return r;
|
||||
va_list arg;
|
||||
int done;
|
||||
|
||||
va_start (arg, format);
|
||||
done = VSCANF (format, arg);
|
||||
va_end (arg);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
wscanf(const wchar_t *fmt, ...)
|
||||
{
|
||||
int r;
|
||||
va_list a=0;
|
||||
va_start(a, fmt);
|
||||
r = _dowscan(stdin, fmt, a);
|
||||
va_end(a);
|
||||
return r;
|
||||
va_list arg;
|
||||
int done;
|
||||
char *f;
|
||||
int i, len = wcslen(fmt);
|
||||
|
||||
f = alloca(len+1);
|
||||
for(i=0;i<len;i++)
|
||||
f[i] = fmt[i];
|
||||
f[i] = 0;
|
||||
va_start (arg, fmt);
|
||||
done = VSCANF (f, arg);
|
||||
va_end (arg);
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
#include <crtdll/malloc.h>
|
||||
void *alloca(size_t x)
|
||||
{
|
||||
return malloc(x);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <crtdll/io.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
#define _fillsize _bufsiz
|
||||
|
||||
int setvbuf(FILE *f, char *buf, int type, size_t len)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ sprintf(char *str, const char *fmt, ...)
|
|||
_strbuf._flag = _IOWRT|_IOSTRG;
|
||||
_strbuf._ptr = str;
|
||||
_strbuf._cnt = INT_MAX;
|
||||
len = _doprnt(fmt, a, &_strbuf);
|
||||
len = vfprintf(&_strbuf, fmt, a);
|
||||
*_strbuf._ptr = 0;
|
||||
return len;
|
||||
}
|
||||
|
|
|
@ -1,47 +1,75 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <crtdll/stdio.h>
|
||||
/* Copyright (C) 1991, 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., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
//#include <crtdll/unconst.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/alloc.h>
|
||||
|
||||
int __vsscanf (const char *s,const char *format,va_list arg);
|
||||
|
||||
/* Read formatted input from S, according to the format string FORMAT. */
|
||||
/* VARARGS2 */
|
||||
int
|
||||
sscanf(const char *str, const char *fmt, ...)
|
||||
sscanf (const char *s,const char *format, ...)
|
||||
{
|
||||
int r;
|
||||
va_list a=0;
|
||||
FILE _strbuf;
|
||||
va_list arg;
|
||||
int done;
|
||||
|
||||
va_start(a, fmt);
|
||||
va_start (arg, format);
|
||||
done = __vsscanf (s, format, arg);
|
||||
va_end (arg);
|
||||
|
||||
_strbuf._flag = _IOREAD|_IOSTRG;
|
||||
_strbuf._ptr = (char *)str;
|
||||
_strbuf._base = (char *)str;
|
||||
_strbuf._cnt = 0;
|
||||
while (*str++)
|
||||
_strbuf._cnt++;
|
||||
_strbuf._bufsiz = _strbuf._cnt;
|
||||
r = _doscan(&_strbuf, fmt, a);
|
||||
va_end(a);
|
||||
return r;
|
||||
return done;
|
||||
}
|
||||
|
||||
#ifdef USE_IN_LIBIO
|
||||
# undef _IO_sscanf
|
||||
/* This is for libg++. */
|
||||
strong_alias (sscanf, _IO_sscanf)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int
|
||||
swscanf(const wchar_t *str, const wchar_t *fmt, ...)
|
||||
{
|
||||
int r;
|
||||
va_list a=0;
|
||||
FILE _strbuf;
|
||||
va_list arg;
|
||||
int done;
|
||||
char *f , *s;
|
||||
int i,len = wcslen(fmt);
|
||||
|
||||
f = alloca(len+1);
|
||||
for(i=0;i<len;i++)
|
||||
f[i] = fmt[i];
|
||||
f[i] = 0;
|
||||
|
||||
len = wcslen(str);
|
||||
s = alloca(len+1);
|
||||
for(i=0;i<len;i++)
|
||||
s[i] = str[i];
|
||||
s[i] = 0;
|
||||
|
||||
va_start (arg, fmt);
|
||||
done = __vsscanf (s, f, arg);
|
||||
va_end (arg);
|
||||
|
||||
return done;
|
||||
|
||||
va_start(a, fmt);
|
||||
|
||||
_strbuf._flag = _IOREAD|_IOSTRG;
|
||||
_strbuf._ptr = (char *)str;
|
||||
_strbuf._base = (char *)str;
|
||||
_strbuf._cnt = 0;
|
||||
while (*str++)
|
||||
_strbuf._cnt++;
|
||||
_strbuf._bufsiz = _strbuf._cnt;
|
||||
r = _dowscan(&_strbuf, fmt, a);
|
||||
va_end(a);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -11,32 +11,34 @@ FILE _crtdll_iob[5] =
|
|||
{
|
||||
NULL, 0, NULL,
|
||||
_IOREAD | _IOLBF ,
|
||||
0, 0,0, NULL
|
||||
0, 0,0, NULL, 0
|
||||
},
|
||||
// stdout
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IOWRT | _IOLBF |_IOSTRG,
|
||||
1,0,0, NULL
|
||||
1,0,0, NULL, 0
|
||||
},
|
||||
// stderr
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IOWRT | _IONBF,
|
||||
2,0,0, NULL
|
||||
2,0,0, NULL, 0
|
||||
},
|
||||
// stdaux
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IORW | _IONBF,
|
||||
3,0,0, NULL
|
||||
3,0,0, NULL, 0
|
||||
},
|
||||
// stdprn
|
||||
{
|
||||
NULL, 0, NULL,
|
||||
_IOWRT | _IONBF,
|
||||
4, 0,0,NULL
|
||||
4, 0,0,NULL, 0
|
||||
}
|
||||
};
|
||||
|
||||
FILE (*_iob)[] = &_crtdll_iob;
|
||||
|
||||
FILE (*__imp__iob)[] = &_crtdll_iob;
|
||||
|
|
|
@ -33,8 +33,28 @@ ungetc(int c, FILE *f)
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
wint_t
|
||||
ungetwc(wchar_t c, FILE *f)
|
||||
{
|
||||
return ungetc(c,f);
|
||||
if ((char)c == EOF
|
||||
|| (f->_flag & (_IOREAD|_IORW)) == 0
|
||||
|| f->_ptr == NULL
|
||||
|| f->_base == NULL)
|
||||
return EOF;
|
||||
|
||||
if (f->_ptr == f->_base)
|
||||
{
|
||||
if (f->_cnt == 0)
|
||||
f->_ptr+=sizeof(wchar_t);
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
|
||||
f->_cnt+=sizeof(wchar_t);
|
||||
f->_ptr-=sizeof(wchar_t);
|
||||
|
||||
f->_flag |= _IOUNGETC;
|
||||
*((wchar_t *)(f->_ptr)) = c;
|
||||
|
||||
return c;
|
||||
}
|
|
@ -3,6 +3,13 @@
|
|||
#include <stdarg.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
#define isascii __isascii
|
||||
|
||||
|
||||
|
||||
int
|
||||
__vfprintf (FILE *fp, const char *fmt0, va_list argp);
|
||||
|
||||
int
|
||||
vfprintf(FILE *f, const char *fmt, va_list ap)
|
||||
{
|
||||
|
@ -14,7 +21,7 @@ vfprintf(FILE *f, const char *fmt, va_list ap)
|
|||
f->_flag &= ~_IONBF;
|
||||
f->_ptr = f->_base = localbuf;
|
||||
f->_bufsiz = BUFSIZ;
|
||||
len = _doprnt(fmt, ap, f);
|
||||
len = __vfprintf(f,fmt, ap);
|
||||
(void)fflush(f);
|
||||
f->_flag |= _IONBF;
|
||||
f->_base = NULL;
|
||||
|
@ -22,6 +29,899 @@ vfprintf(FILE *f, const char *fmt, va_list ap)
|
|||
f->_cnt = 0;
|
||||
}
|
||||
else
|
||||
len = _doprnt(fmt, ap, f);
|
||||
len = __vfprintf(f,fmt, ap);
|
||||
return (ferror(f) ? EOF : len);
|
||||
}
|
||||
|
||||
|
||||
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
|
||||
/* 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 <libc/stubs.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
//#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
//#include <libc/file.h>
|
||||
//#include <libc/stdiohk.h>
|
||||
//#include <libc/local.h>
|
||||
|
||||
static char decimal = '.';
|
||||
|
||||
/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
|
||||
#define MAXEXP 308
|
||||
#define MAXEXPLD 4952 /* this includes subnormal numbers */
|
||||
/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
|
||||
#define MAXFRACT 39
|
||||
|
||||
#define DEFPREC 6
|
||||
#define DEFLPREC 6
|
||||
|
||||
#define BUF (MAXEXPLD+MAXFRACT+1) /* + decimal point */
|
||||
|
||||
#define PUTC(ch) (void) putc(ch, fp)
|
||||
|
||||
// adjustedn llong remove from first
|
||||
#define ARG(basetype) _ulonglong = \
|
||||
flags&LONGDBL ? va_arg(argp, basetype) : \
|
||||
flags&LONGINT ? va_arg(argp, long basetype) : \
|
||||
flags&SHORTINT ? (short basetype)va_arg(argp, int) : \
|
||||
va_arg(argp, int)
|
||||
|
||||
// changed name of nan due to conflict with cygwin math header
|
||||
static int _nan = 0;
|
||||
|
||||
#define MODFL modf
|
||||
typedef double ldouble;
|
||||
typedef long llong;
|
||||
typedef unsigned long ullong;
|
||||
|
||||
ldouble modfl(ldouble x,ldouble *pint);
|
||||
|
||||
static __inline__ int todigit(char c)
|
||||
{
|
||||
if (c<='0') return 0;
|
||||
if (c>='9') return 9;
|
||||
return c-'0';
|
||||
}
|
||||
static __inline__ char tochar(int n)
|
||||
{
|
||||
if (n>=9) return '9';
|
||||
if (n<=0) return '0';
|
||||
return n+'0';
|
||||
}
|
||||
|
||||
/* have to deal with the negative buffer count kludge */
|
||||
|
||||
#define LONGINT 0x01 /* long integer */
|
||||
#define LONGDBL 0x02 /* ldouble */
|
||||
#define SHORTINT 0x04 /* short integer */
|
||||
#define ALT 0x08 /* alternate form */
|
||||
#define LADJUST 0x10 /* left adjustment */
|
||||
#define ZEROPAD 0x20 /* zero (as opposed to blank) pad */
|
||||
#define HEXPREFIX 0x40 /* add 0x or 0X prefix */
|
||||
|
||||
static int cvtl(ldouble number, int prec, int flags, char *signp,
|
||||
unsigned char fmtch, char *startp, char *endp);
|
||||
static char *roundl(ldouble fract, int *expv, char *start, char *end,
|
||||
char ch, char *signp);
|
||||
static char *exponentl(char *p, int expv, unsigned char fmtch);
|
||||
//#ifdef __GO32__
|
||||
static int isspeciall(ldouble d, char *bufp);
|
||||
//#endif
|
||||
|
||||
static char NULL_REP[] = "(null)";
|
||||
|
||||
int
|
||||
__vfprintf (FILE *fp, const char *fmt0, va_list argp)
|
||||
{
|
||||
const char *fmt; /* format string */
|
||||
int ch; /* character from fmt */
|
||||
int cnt; /* return value accumulator */
|
||||
int n; /* random handy integer */
|
||||
char *t; /* buffer pointer */
|
||||
ldouble _ldouble; /* double and ldouble precision arguments
|
||||
%L.[eEfgG] */
|
||||
ullong _ulonglong=0; /* integer arguments %[diouxX] */
|
||||
int base; /* base for [diouxX] conversion */
|
||||
int dprec; /* decimal precision in [diouxX] */
|
||||
int fieldsz; /* field size expanded by sign, etc */
|
||||
int flags; /* flags as above */
|
||||
int fpprec = 0; /* `extra' floating precision in [eEfgG] */
|
||||
int prec = 0; /* precision from format (%.3d), or -1 */
|
||||
int realsz; /* field size expanded by decimal precision */
|
||||
int size = 0; /* size of converted field or string */
|
||||
int width; /* width from format (%8d), or 0 */
|
||||
char sign; /* sign prefix (' ', '+', '-', or \0) */
|
||||
char softsign; /* temporary negative sign for floats */
|
||||
const char *digs; /* digits for [diouxX] conversion */
|
||||
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
|
||||
int neg_ldouble = 0; /* non-zero if _ldouble is negative */
|
||||
|
||||
//decimal = localeconv()->decimal_point[0];
|
||||
decimal = '.';
|
||||
|
||||
if (fp->_flag & _IORW)
|
||||
{
|
||||
fp->_flag |= _IOWRT;
|
||||
fp->_flag &= ~(_IOEOF|_IOREAD);
|
||||
}
|
||||
if ((fp->_flag & _IOWRT) == 0)
|
||||
return (EOF);
|
||||
|
||||
fmt = fmt0;
|
||||
digs = "0123456789abcdef";
|
||||
for (cnt = 0;; ++fmt)
|
||||
{
|
||||
while ((ch = *fmt) && ch != '%')
|
||||
{
|
||||
PUTC (ch);
|
||||
fmt++;
|
||||
cnt++;
|
||||
}
|
||||
if (!ch)
|
||||
return cnt;
|
||||
flags = 0; dprec = 0; fpprec = 0; width = 0;
|
||||
prec = -1;
|
||||
sign = '\0';
|
||||
rflag:
|
||||
switch (*++fmt)
|
||||
{
|
||||
case ' ':
|
||||
/*
|
||||
* ``If the space and + flags both appear, the space
|
||||
* flag will be ignored.''
|
||||
* -- ANSI X3J11
|
||||
*/
|
||||
if (!sign)
|
||||
sign = ' ';
|
||||
goto rflag;
|
||||
case '#':
|
||||
flags |= ALT;
|
||||
goto rflag;
|
||||
case '*':
|
||||
/*
|
||||
* ``A negative field width argument is taken as a
|
||||
* - flag followed by a positive field width.''
|
||||
* -- ANSI X3J11
|
||||
* They don't exclude field widths read from args.
|
||||
*/
|
||||
if ((width = va_arg(argp, int)) >= 0)
|
||||
goto rflag;
|
||||
width = -width;
|
||||
/* FALLTHROUGH */
|
||||
case '-':
|
||||
flags |= LADJUST;
|
||||
goto rflag;
|
||||
case '+':
|
||||
sign = '+';
|
||||
goto rflag;
|
||||
case '.':
|
||||
if (*++fmt == '*')
|
||||
n = va_arg(argp, int);
|
||||
else
|
||||
{
|
||||
n = 0;
|
||||
while (isascii(*fmt) && isdigit(*fmt))
|
||||
n = 10 * n + todigit(*fmt++);
|
||||
--fmt;
|
||||
}
|
||||
prec = n < 0 ? -1 : n;
|
||||
goto rflag;
|
||||
case '0':
|
||||
/*
|
||||
* ``Note that 0 is taken as a flag, not as the
|
||||
* beginning of a field width.''
|
||||
* -- ANSI X3J11
|
||||
*/
|
||||
flags |= ZEROPAD;
|
||||
goto rflag;
|
||||
case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
n = 0;
|
||||
do {
|
||||
n = 10 * n + todigit(*fmt);
|
||||
} while (isascii(*++fmt) && isdigit(*fmt));
|
||||
width = n;
|
||||
--fmt;
|
||||
goto rflag;
|
||||
case 'L':
|
||||
flags |= LONGDBL;
|
||||
goto rflag;
|
||||
case 'h':
|
||||
flags |= SHORTINT;
|
||||
goto rflag;
|
||||
case 'l':
|
||||
if (flags&LONGINT)
|
||||
flags |= LONGDBL; /* for 'll' - llong */
|
||||
else
|
||||
flags |= LONGINT;
|
||||
goto rflag;
|
||||
case 'c':
|
||||
*(t = buf) = va_arg(argp, int);
|
||||
size = 1;
|
||||
sign = '\0';
|
||||
goto pforw;
|
||||
case 'D':
|
||||
flags |= LONGINT;
|
||||
/*FALLTHROUGH*/
|
||||
case 'd':
|
||||
case 'i':
|
||||
ARG(int);
|
||||
if ((llong)_ulonglong < 0)
|
||||
{
|
||||
_ulonglong = -_ulonglong;
|
||||
sign = '-';
|
||||
}
|
||||
base = 10;
|
||||
goto number;
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (flags & LONGDBL)
|
||||
_ldouble = va_arg(argp, ldouble);
|
||||
else
|
||||
_ldouble = (ldouble)va_arg(argp, double);
|
||||
/*
|
||||
* don't do unrealistic precision; just pad it with
|
||||
* zeroes later, so buffer size stays rational.
|
||||
*/
|
||||
if (prec > MAXFRACT)
|
||||
{
|
||||
if (*fmt != 'g' && (*fmt != 'G' || (flags&ALT)))
|
||||
fpprec = prec - MAXFRACT;
|
||||
prec = MAXFRACT;
|
||||
}
|
||||
else if (prec == -1)
|
||||
{
|
||||
if (flags&LONGINT)
|
||||
prec = DEFLPREC;
|
||||
else
|
||||
prec = DEFPREC;
|
||||
}
|
||||
/*
|
||||
* softsign avoids negative 0 if _double is < 0 and
|
||||
* no significant digits will be shown
|
||||
*/
|
||||
if (_ldouble < 0)
|
||||
{
|
||||
softsign = '-';
|
||||
_ldouble = -_ldouble;
|
||||
neg_ldouble = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
softsign = 0;
|
||||
neg_ldouble = 0;
|
||||
}
|
||||
/*
|
||||
* cvt may have to round up past the "start" of the
|
||||
* buffer, i.e. ``intf("%.2f", (double)9.999);'';
|
||||
* if the first char isn't NULL, it did.
|
||||
*/
|
||||
*buf = 0;
|
||||
size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf,
|
||||
buf + sizeof(buf));
|
||||
/*
|
||||
* If the format specifier requested an explicit sign,
|
||||
* we print a negative sign even if no significant digits
|
||||
* will be shown, and we also print a sign for a NaN. In
|
||||
* other words, "%+f" might print -0.000000, +NaN and -NaN.
|
||||
*/
|
||||
if (softsign || (sign == '+' && (neg_ldouble || _nan == -1)))
|
||||
sign = '-';
|
||||
_nan = 0;
|
||||
t = *buf ? buf : buf + 1;
|
||||
goto pforw;
|
||||
case 'n':
|
||||
if (flags & LONGDBL)
|
||||
*va_arg(argp, llong *) = cnt;
|
||||
else if (flags & LONGINT)
|
||||
*va_arg(argp, long *) = cnt;
|
||||
else if (flags & SHORTINT)
|
||||
*va_arg(argp, short *) = cnt;
|
||||
else
|
||||
*va_arg(argp, int *) = cnt;
|
||||
break;
|
||||
case 'O':
|
||||
flags |= LONGINT;
|
||||
/*FALLTHROUGH*/
|
||||
case 'o':
|
||||
ARG(unsigned);
|
||||
base = 8;
|
||||
goto nosign;
|
||||
case 'p':
|
||||
/*
|
||||
* ``The argument shall be a pointer to void. The
|
||||
* value of the pointer is converted to a sequence
|
||||
* of printable characters, in an implementation-
|
||||
* defined manner.''
|
||||
* -- ANSI X3J11
|
||||
*/
|
||||
/* NOSTRICT */
|
||||
_ulonglong = (unsigned long)va_arg(argp, void *);
|
||||
base = 16;
|
||||
goto nosign;
|
||||
case 's':
|
||||
if (!(t = va_arg(argp, char *)))
|
||||
t = NULL_REP;
|
||||
if (prec >= 0)
|
||||
{
|
||||
/*
|
||||
* can't use strlen; can only look for the
|
||||
* NUL in the first `prec' characters, and
|
||||
* strlen() will go further.
|
||||
*/
|
||||
char *p /*, *memchr() */;
|
||||
|
||||
if ((p = memchr(t, 0, prec)))
|
||||
{
|
||||
size = p - t;
|
||||
if (size > prec)
|
||||
size = prec;
|
||||
}
|
||||
else
|
||||
size = prec;
|
||||
}
|
||||
else
|
||||
size = strlen(t);
|
||||
sign = '\0';
|
||||
goto pforw;
|
||||
case 'U':
|
||||
flags |= LONGINT;
|
||||
/*FALLTHROUGH*/
|
||||
case 'u':
|
||||
ARG(unsigned);
|
||||
base = 10;
|
||||
goto nosign;
|
||||
case 'X':
|
||||
digs = "0123456789ABCDEF";
|
||||
/* FALLTHROUGH */
|
||||
case 'x':
|
||||
ARG(unsigned);
|
||||
base = 16;
|
||||
/* leading 0x/X only if non-zero */
|
||||
if (flags & ALT && _ulonglong != 0)
|
||||
flags |= HEXPREFIX;
|
||||
|
||||
nosign:
|
||||
/* unsigned conversions */
|
||||
sign = '\0';
|
||||
number:
|
||||
/*
|
||||
* ``... diouXx conversions ... if a precision is
|
||||
* specified, the 0 flag will be ignored.''
|
||||
* -- ANSI X3J11
|
||||
*/
|
||||
if ((dprec = prec) >= 0)
|
||||
flags &= ~ZEROPAD;
|
||||
|
||||
/*
|
||||
* ``The result of converting a zero value with an
|
||||
* explicit precision of zero is no characters.''
|
||||
* -- ANSI X3J11
|
||||
*/
|
||||
t = buf + BUF;
|
||||
|
||||
if (_ulonglong != 0 || prec != 0)
|
||||
{
|
||||
/* conversion is done separately since operations
|
||||
with llong are much slower */
|
||||
#define CONVERT(type) \
|
||||
{ \
|
||||
register type _n = (type)_ulonglong; \
|
||||
do { \
|
||||
*--t = digs[_n % base]; \
|
||||
_n /= base; \
|
||||
} while (_n); \
|
||||
}
|
||||
if (flags&LONGDBL)
|
||||
CONVERT(ullong) /* no ; */
|
||||
else
|
||||
CONVERT(unsigned long) /* no ; */
|
||||
#undef CONVERT
|
||||
if (flags & ALT && base == 8 && *t != '0')
|
||||
*--t = '0'; /* octal leading 0 */
|
||||
}
|
||||
|
||||
digs = "0123456789abcdef";
|
||||
size = buf + BUF - t;
|
||||
|
||||
pforw:
|
||||
/*
|
||||
* All reasonable formats wind up here. At this point,
|
||||
* `t' points to a string which (if not flags&LADJUST)
|
||||
* should be padded out to `width' places. If
|
||||
* flags&ZEROPAD, it should first be prefixed by any
|
||||
* sign or other prefix; otherwise, it should be blank
|
||||
* padded before the prefix is emitted. After any
|
||||
* left-hand padding and prefixing, emit zeroes
|
||||
* required by a decimal [diouxX] precision, then print
|
||||
* the string proper, then emit zeroes required by any
|
||||
* leftover floating precision; finally, if LADJUST,
|
||||
* pad with blanks.
|
||||
*/
|
||||
|
||||
/*
|
||||
* compute actual size, so we know how much to pad
|
||||
* fieldsz excludes decimal prec; realsz includes it
|
||||
*/
|
||||
fieldsz = size + fpprec;
|
||||
realsz = dprec > fieldsz ? dprec : fieldsz;
|
||||
if (sign)
|
||||
realsz++;
|
||||
if (flags & HEXPREFIX)
|
||||
realsz += 2;
|
||||
|
||||
/* right-adjusting blank padding */
|
||||
if ((flags & (LADJUST|ZEROPAD)) == 0 && width)
|
||||
for (n = realsz; n < width; n++)
|
||||
PUTC(' ');
|
||||
/* prefix */
|
||||
if (sign)
|
||||
PUTC(sign);
|
||||
if (flags & HEXPREFIX)
|
||||
{
|
||||
PUTC('0');
|
||||
PUTC((char)*fmt);
|
||||
}
|
||||
/* right-adjusting zero padding */
|
||||
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
|
||||
for (n = realsz; n < width; n++)
|
||||
PUTC('0');
|
||||
/* leading zeroes from decimal precision */
|
||||
for (n = fieldsz; n < dprec; n++)
|
||||
PUTC('0');
|
||||
|
||||
/* the string or number proper */
|
||||
for (n = size; n > 0; n--)
|
||||
PUTC(*t++);
|
||||
/* trailing f.p. zeroes */
|
||||
while (--fpprec >= 0)
|
||||
PUTC('0');
|
||||
/* left-adjusting padding (always blank) */
|
||||
if (flags & LADJUST)
|
||||
for (n = realsz; n < width; n++)
|
||||
PUTC(' ');
|
||||
/* finally, adjust cnt */
|
||||
cnt += width > realsz ? width : realsz;
|
||||
break;
|
||||
case '\0': /* "%?" prints ?, unless ? is NULL */
|
||||
return cnt;
|
||||
default:
|
||||
PUTC((char)*fmt);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static ldouble pten[] =
|
||||
{
|
||||
1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L
|
||||
};
|
||||
|
||||
// 1e512L, 1e1024L, 1e2048L, 1e4096L
|
||||
|
||||
static ldouble ptenneg[] =
|
||||
{
|
||||
1e-1L, 1e-2L, 1e-4L, 1e-8L, 1e-16L, 1e-32L, 1e-64L, 1e-128L, 1e-256L
|
||||
};
|
||||
// 1e-512L, 1e-1024L, 1e-2048L, 1e-4096L
|
||||
|
||||
#define MAXP 4096
|
||||
#define NP 12
|
||||
#define P (4294967296.0L * 4294967296.0L * 2.0L) /* 2^65 */
|
||||
static ldouble INVPREC = P;
|
||||
static ldouble PREC = 1.0L/P;
|
||||
#undef P
|
||||
/*
|
||||
* Defining FAST_LDOUBLE_CONVERSION results in a little bit faster
|
||||
* version, which might be less accurate (about 1 bit) for long
|
||||
* double. For 'normal' double it doesn't matter.
|
||||
*/
|
||||
/* #define FAST_LDOUBLE_CONVERSION */
|
||||
|
||||
static int
|
||||
cvtl(ldouble number, int prec, int flags, char *signp, unsigned char fmtch,
|
||||
char *startp, char *endp)
|
||||
{
|
||||
char *p, *t;
|
||||
ldouble fract=0;
|
||||
int dotrim, expcnt, gformat;
|
||||
int doextradps=0; /* Do extra decimal places if the precision needs it */
|
||||
int doingzero=0; /* We're displaying 0.0 */
|
||||
ldouble integer, tmp;
|
||||
|
||||
if ((expcnt = isspeciall(number, startp)))
|
||||
return(expcnt);
|
||||
|
||||
dotrim = expcnt = gformat = 0;
|
||||
/* fract = modfl(number, &integer); */
|
||||
integer = number;
|
||||
|
||||
/* get an extra slot for rounding. */
|
||||
t = ++startp;
|
||||
|
||||
p = endp - 1;
|
||||
if (integer)
|
||||
{
|
||||
int i, lp=NP, pt=MAXP;
|
||||
#ifndef FAST_LDOUBLE_CONVERSION
|
||||
ldouble oint = integer, dd=1.0L;
|
||||
#endif
|
||||
if (integer > INVPREC)
|
||||
{
|
||||
integer *= PREC;
|
||||
while(lp >= 0) {
|
||||
if (integer >= pten[lp])
|
||||
{
|
||||
expcnt += pt;
|
||||
integer *= ptenneg[lp];
|
||||
#ifndef FAST_LDOUBLE_CONVERSION
|
||||
dd *= pten[lp];
|
||||
#endif
|
||||
}
|
||||
pt >>= 1;
|
||||
lp--;
|
||||
}
|
||||
#ifndef FAST_LDOUBLE_CONVERSION
|
||||
integer = oint/dd;
|
||||
#else
|
||||
integer *= INVPREC;
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* Do we really need this ?
|
||||
*/
|
||||
for (i = 0; i < expcnt; i++)
|
||||
*p-- = '0';
|
||||
}
|
||||
number = integer;
|
||||
fract = MODFL(number, &integer);
|
||||
/* If integer is zero then we need to look at where the sig figs are */
|
||||
if (integer<1) {
|
||||
/* If fract is zero the zero before the decimal point is a sig fig */
|
||||
if (fract==0.0) doingzero=1;
|
||||
/* If fract is non-zero all sig figs are in fractional part */
|
||||
else doextradps=1;
|
||||
}
|
||||
/*
|
||||
* get integer portion of number; put into the end of the buffer; the
|
||||
* .01 is added for modf(356.0 / 10, &integer) returning .59999999...
|
||||
*/
|
||||
for (; integer; ++expcnt)
|
||||
{
|
||||
tmp = MODFL(integer * 0.1L , &integer);
|
||||
*p-- = tochar((int)((tmp + .01L) * 10));
|
||||
}
|
||||
switch(fmtch)
|
||||
{
|
||||
case 'f':
|
||||
/* reverse integer into beginning of buffer */
|
||||
if (expcnt)
|
||||
for (; ++p < endp; *t++ = *p);
|
||||
else
|
||||
*t++ = '0';
|
||||
/*
|
||||
* if precision required or alternate flag set, add in a
|
||||
* decimal point.
|
||||
*/
|
||||
if (prec || flags&ALT)
|
||||
*t++ = decimal;
|
||||
/* if requires more precision and some fraction left */
|
||||
if (fract)
|
||||
{
|
||||
if (prec)
|
||||
do {
|
||||
fract = MODFL(fract * 10.0L, &tmp);
|
||||
*t++ = tochar((int)tmp);
|
||||
} while (--prec && fract);
|
||||
if (fract)
|
||||
startp = roundl(fract, (int *)NULL, startp,
|
||||
t - 1, (char)0, signp);
|
||||
}
|
||||
for (; prec--; *t++ = '0');
|
||||
break;
|
||||
case 'e':
|
||||
case 'E':
|
||||
eformat:
|
||||
if (expcnt)
|
||||
{
|
||||
*t++ = *++p;
|
||||
if (prec || flags&ALT)
|
||||
*t++ = decimal;
|
||||
/* if requires more precision and some integer left */
|
||||
for (; prec && ++p < endp; --prec)
|
||||
*t++ = *p;
|
||||
/*
|
||||
* if done precision and more of the integer component,
|
||||
* round using it; adjust fract so we don't re-round
|
||||
* later.
|
||||
*/
|
||||
if (!prec && ++p < endp)
|
||||
{
|
||||
fract = 0;
|
||||
startp = roundl((ldouble)0.0L, &expcnt,
|
||||
startp, t - 1, *p, signp);
|
||||
}
|
||||
/* adjust expcnt for digit in front of decimal */
|
||||
--expcnt;
|
||||
}
|
||||
/* until first fractional digit, decrement exponent */
|
||||
else if (fract)
|
||||
{
|
||||
int lp=NP, pt=MAXP;
|
||||
#ifndef FAST_LDOUBLE_CONVERSION
|
||||
ldouble ofract = fract, dd=1.0L;
|
||||
#endif
|
||||
expcnt = -1;
|
||||
if (fract < PREC)
|
||||
{
|
||||
fract *= INVPREC;
|
||||
while(lp >= 0)
|
||||
{
|
||||
if (fract <= ptenneg[lp])
|
||||
{
|
||||
expcnt -= pt;
|
||||
fract *= pten[lp];
|
||||
#ifndef FAST_LDOUBLE_CONVERSION
|
||||
dd *= pten[lp];
|
||||
#endif
|
||||
}
|
||||
pt >>= 1;
|
||||
lp--;
|
||||
}
|
||||
#ifndef FAST_LDOUBLE_CONVERSION
|
||||
fract = ofract*dd;
|
||||
#else
|
||||
fract *= PREC;
|
||||
#endif
|
||||
}
|
||||
/* adjust expcnt for digit in front of decimal */
|
||||
for ( /* expcnt = -1 */ ;; --expcnt)
|
||||
{
|
||||
fract = MODFL(fract * 10.0L, &tmp);
|
||||
if (tmp)
|
||||
break;
|
||||
}
|
||||
*t++ = tochar((int)tmp);
|
||||
if (prec || flags&ALT)
|
||||
*t++ = decimal;
|
||||
}
|
||||
else
|
||||
{
|
||||
*t++ = '0';
|
||||
if (prec || flags&ALT)
|
||||
*t++ = decimal;
|
||||
}
|
||||
/* if requires more precision and some fraction left */
|
||||
if (fract)
|
||||
{
|
||||
if (prec)
|
||||
do {
|
||||
fract = MODFL(fract * 10.0L, &tmp);
|
||||
*t++ = tochar((int)tmp);
|
||||
} while (--prec && fract);
|
||||
if (fract)
|
||||
startp = roundl(fract, &expcnt, startp,
|
||||
t - 1, (char)0, signp);
|
||||
}
|
||||
/* if requires more precision */
|
||||
for (; prec--; *t++ = '0');
|
||||
|
||||
/* unless alternate flag, trim any g/G format trailing 0's */
|
||||
if (gformat && !(flags&ALT))
|
||||
{
|
||||
while (t > startp && *--t == '0');
|
||||
if (*t == decimal)
|
||||
--t;
|
||||
++t;
|
||||
}
|
||||
t = exponentl(t, expcnt, fmtch);
|
||||
break;
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (prec) {
|
||||
/* If doing zero and precision is greater than 0 count the
|
||||
* 0 before the decimal place */
|
||||
if (doingzero) --prec;
|
||||
}
|
||||
else {
|
||||
/* a precision of 0 is treated as precision of 1 unless doing zero */
|
||||
if (!doingzero) ++prec;
|
||||
}
|
||||
/*
|
||||
* ``The style used depends on the value converted; style e
|
||||
* will be used only if the exponent resulting from the
|
||||
* conversion is less than -4 or greater than the precision.''
|
||||
* -- ANSI X3J11
|
||||
*/
|
||||
if (expcnt > prec || (!expcnt && fract && fract < .0001))
|
||||
{
|
||||
/*
|
||||
* g/G format counts "significant digits, not digits of
|
||||
* precision; for the e/E format, this just causes an
|
||||
* off-by-one problem, i.e. g/G considers the digit
|
||||
* before the decimal point significant and e/E doesn't
|
||||
* count it as precision.
|
||||
*/
|
||||
--prec;
|
||||
fmtch -= 2; /* G->E, g->e */
|
||||
gformat = 1;
|
||||
goto eformat;
|
||||
}
|
||||
/*
|
||||
* reverse integer into beginning of buffer,
|
||||
* note, decrement precision
|
||||
*/
|
||||
if (expcnt)
|
||||
for (; ++p < endp; *t++ = *p, --prec);
|
||||
else
|
||||
*t++ = '0';
|
||||
/*
|
||||
* if precision required or alternate flag set, add in a
|
||||
* decimal point. If no digits yet, add in leading 0.
|
||||
*/
|
||||
if (prec || flags&ALT)
|
||||
{
|
||||
dotrim = 1;
|
||||
*t++ = decimal;
|
||||
}
|
||||
else
|
||||
dotrim = 0;
|
||||
/* if requires more precision and some fraction left */
|
||||
while (prec && fract)
|
||||
{
|
||||
fract = MODFL(fract * 10.0L, &tmp);
|
||||
*t++ = tochar((int)tmp);
|
||||
/* If we're not adding 0s
|
||||
* or we are but they're sig figs:
|
||||
* decrement the precision */
|
||||
if ((doextradps!=1) || ((int)tmp!=0)) {
|
||||
doextradps=0;
|
||||
prec--;
|
||||
}
|
||||
}
|
||||
if (fract)
|
||||
startp = roundl(fract, (int *)NULL, startp, t - 1,
|
||||
(char)0, signp);
|
||||
/* alternate format, adds 0's for precision, else trim 0's */
|
||||
if (flags&ALT)
|
||||
for (; prec--; *t++ = '0');
|
||||
else if (dotrim)
|
||||
{
|
||||
while (t > startp && *--t == '0');
|
||||
if (*t != decimal)
|
||||
++t;
|
||||
}
|
||||
}
|
||||
return t - startp;
|
||||
}
|
||||
|
||||
static char *
|
||||
roundl(ldouble fract, int *expv, char *start, char *end, char ch,
|
||||
char *signp)
|
||||
{
|
||||
ldouble tmp;
|
||||
|
||||
if (fract)
|
||||
{
|
||||
if (fract == 0.5L)
|
||||
{
|
||||
char *e = end;
|
||||
if (*e == '.')
|
||||
e--;
|
||||
if (*e == '0' || *e == '2' || *e == '4'
|
||||
|| *e == '6' || *e == '8')
|
||||
{
|
||||
tmp = 3.0;
|
||||
goto start;
|
||||
}
|
||||
}
|
||||
(void)MODFL(fract * 10.0L, &tmp);
|
||||
}
|
||||
else
|
||||
tmp = todigit(ch);
|
||||
start:
|
||||
if (tmp > 4)
|
||||
for (;; --end)
|
||||
{
|
||||
if (*end == decimal)
|
||||
--end;
|
||||
if (++*end <= '9')
|
||||
break;
|
||||
*end = '0';
|
||||
if (end == start)
|
||||
{
|
||||
if (expv)
|
||||
{ /* e/E; increment exponent */
|
||||
*end = '1';
|
||||
++*expv;
|
||||
}
|
||||
else
|
||||
{ /* f; add extra digit */
|
||||
*--end = '1';
|
||||
--start;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* ``"%.3f", (double)-0.0004'' gives you a negative 0. */
|
||||
else if (*signp == '-')
|
||||
for (;; --end)
|
||||
{
|
||||
if (*end == decimal)
|
||||
--end;
|
||||
if (*end != '0')
|
||||
break;
|
||||
if (end == start)
|
||||
*signp = 0;
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
static char *
|
||||
exponentl(char *p, int expv, unsigned char fmtch)
|
||||
{
|
||||
char *t;
|
||||
char expbuf[MAXEXPLD];
|
||||
|
||||
*p++ = fmtch;
|
||||
if (expv < 0)
|
||||
{
|
||||
expv = -expv;
|
||||
*p++ = '-';
|
||||
}
|
||||
else
|
||||
*p++ = '+';
|
||||
t = expbuf + MAXEXPLD;
|
||||
if (expv > 9)
|
||||
{
|
||||
do {
|
||||
*--t = tochar(expv % 10);
|
||||
} while ((expv /= 10) > 9);
|
||||
*--t = tochar(expv);
|
||||
for (; t < expbuf + MAXEXPLD; *p++ = *t++);
|
||||
}
|
||||
else
|
||||
{
|
||||
*p++ = '0';
|
||||
*p++ = tochar(expv);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
isspeciall(ldouble d, char *bufp)
|
||||
{
|
||||
struct IEEExp {
|
||||
unsigned manl:32;
|
||||
unsigned manh:32;
|
||||
unsigned exp:15;
|
||||
unsigned sign:1;
|
||||
} *ip = (struct IEEExp *)&d;
|
||||
|
||||
_nan = 0; /* don't assume the static is 0 (emacs) */
|
||||
if (ip->exp != 0x7fff)
|
||||
return(0);
|
||||
if ((ip->manh & 0x7fffffff) || ip->manl)
|
||||
{
|
||||
strcpy(bufp, "NaN");
|
||||
_nan = ip->sign ? -1 : 1; /* kludge: we don't need the sign, it's not nice
|
||||
but it should work */
|
||||
}
|
||||
else
|
||||
(void)strcpy(bufp, "Inf");
|
||||
return(3);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
1081
reactos/lib/crtdll/stdio/vfscanf.c
Normal file
1081
reactos/lib/crtdll/stdio/vfscanf.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,13 +1,35 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <crtdll/stdio.h>
|
||||
/* Copyright (C) 1991, 1993, 1995 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 <stdarg.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
#undef __OPTIMIZE__ /* Avoid inline `vprintf' function. */
|
||||
#include <crtdll/stdio.h>
|
||||
|
||||
#undef vprintf
|
||||
|
||||
/* Write formatted output to stdout according to the
|
||||
format string FORMAT, using the argument list in ARG. */
|
||||
int
|
||||
vprintf(const char *fmt, va_list ap)
|
||||
vprintf (format, arg)
|
||||
const char *format;
|
||||
va_list arg;
|
||||
{
|
||||
int len;
|
||||
|
||||
len = _doprnt(fmt, ap, stdout);
|
||||
return (ferror(stdout) ? EOF : len);
|
||||
int ret = vfprintf (stdout, format, arg);
|
||||
fflush(stdout);
|
||||
return ret;
|
||||
}
|
||||
|
|
35
reactos/lib/crtdll/stdio/vscanf.c
Normal file
35
reactos/lib/crtdll/stdio/vscanf.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* Copyright (C) 1991, 1992, 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 <stdarg.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
int __vfscanf (FILE *s, const char *format, va_list argptr);
|
||||
|
||||
#undef vscanf
|
||||
|
||||
|
||||
/* Read formatted input from stdin according to the format
|
||||
string in FORMAT, using the argument list in ARG. */
|
||||
int
|
||||
__vscanf (const char *format, va_list arg)
|
||||
{
|
||||
return __vfscanf (stdin, format, arg);
|
||||
}
|
||||
//weak_alias (__vscanf, vscanf)
|
|
@ -4,6 +4,7 @@
|
|||
#include <limits.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
int
|
||||
vsprintf(char *str, const char *fmt, va_list ap)
|
||||
{
|
||||
FILE f;
|
||||
|
@ -12,7 +13,7 @@ vsprintf(char *str, const char *fmt, va_list ap)
|
|||
f._flag = _IOWRT|_IOSTRG;
|
||||
f._ptr = str;
|
||||
f._cnt = INT_MAX;
|
||||
len = _doprnt(fmt, ap, &f);
|
||||
len = vfprintf(&f,fmt, ap);
|
||||
*f._ptr = 0;
|
||||
return len;
|
||||
}
|
||||
|
|
57
reactos/lib/crtdll/stdio/vsscanf.c
Normal file
57
reactos/lib/crtdll/stdio/vsscanf.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* Copyright (C) 1991, 1992, 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 <crtdll/errno.h>
|
||||
#include <crtdll/stdarg.h>
|
||||
#include <crtdll/stdio.h>
|
||||
#include <crtdll/string.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
#undef vsscanf
|
||||
|
||||
int __vfscanf (FILE *s, const char *format, va_list argptr);
|
||||
|
||||
/* Read formatted input from S according to the format
|
||||
string FORMAT, using the argument list in ARG. */
|
||||
int
|
||||
__vsscanf (const char *s,const char *format,va_list arg)
|
||||
{
|
||||
FILE f;
|
||||
|
||||
if (s == NULL)
|
||||
{
|
||||
__set_errno (EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset ((void *) &f, 0, sizeof (f));
|
||||
|
||||
|
||||
|
||||
f._flag = _IOREAD;
|
||||
f._ptr = (char *)s;
|
||||
f._base = (char *)s;
|
||||
f._bufsiz = strlen(s);
|
||||
f._cnt = f._bufsiz;
|
||||
|
||||
|
||||
return __vfscanf (&f, format, arg);
|
||||
}
|
||||
|
||||
|
||||
//weak_alias (__vsscanf, vsscanf)
|
|
@ -1,33 +1,23 @@
|
|||
#include <windows.h>
|
||||
#include <crtdll/stdlib.h>
|
||||
//#include <crtdll/types.h>
|
||||
#include <ddk/ntddk.h>
|
||||
|
||||
|
||||
void* malloc(size_t _size)
|
||||
{
|
||||
return(HeapAlloc(GetProcessHeap(),
|
||||
0,
|
||||
_size));
|
||||
return(HeapAlloc(GetProcessHeap(),0,_size));
|
||||
}
|
||||
|
||||
void free(void* _ptr)
|
||||
{
|
||||
HeapFree(GetProcessHeap(),
|
||||
0,
|
||||
_ptr);
|
||||
HeapFree(GetProcessHeap(),0,_ptr);
|
||||
}
|
||||
|
||||
void* calloc(size_t _nmemb, size_t _size)
|
||||
{
|
||||
return(HeapAlloc(GetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
_nmemb*_size));
|
||||
return(HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, _nmemb*_size));
|
||||
}
|
||||
|
||||
void* realloc(void* _ptr, size_t _size)
|
||||
{
|
||||
return(HeapReAlloc(GetProcessHeap(),
|
||||
0,
|
||||
_ptr,
|
||||
_size));
|
||||
return(HeapReAlloc(GetProcessHeap(),0,_ptr,_size));
|
||||
}
|
||||
|
|
56
reactos/lib/crtdll/stdlib/rot.c
Normal file
56
reactos/lib/crtdll/stdlib/rot.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/crtdll/stdlib/rot.c
|
||||
* PURPOSE: Performs a bit wise rotation
|
||||
* PROGRAMER: Boudewijn Dekker
|
||||
* UPDATE HISTORY:
|
||||
* 03/04/99: Created
|
||||
*/
|
||||
|
||||
#include <crtdll/stdlib.h>
|
||||
|
||||
unsigned int _rotl( unsigned int value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned int)<<3;
|
||||
if ( shift < 0 )
|
||||
return _rotr(value,-shift);
|
||||
|
||||
if ( shift > max_bits )
|
||||
shift = shift % max_bits;
|
||||
return (value << shift) | (value >> (max_bits-shift));
|
||||
}
|
||||
|
||||
unsigned int _rotr( unsigned int value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned int)<<3;
|
||||
if ( shift < 0 )
|
||||
return _rotl(value,-shift);
|
||||
|
||||
if ( shift > max_bits<<3 )
|
||||
shift = shift % max_bits;
|
||||
return (value >> shift) | (value << (max_bits-shift));
|
||||
}
|
||||
|
||||
|
||||
unsigned long _lrotl( unsigned long value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned long)<<3;
|
||||
if ( shift < 0 )
|
||||
return _lrotr(value,-shift);
|
||||
|
||||
if ( shift > max_bits )
|
||||
shift = shift % max_bits;
|
||||
return (value << shift) | (value >> (max_bits-shift));
|
||||
}
|
||||
|
||||
unsigned long _lrotr( unsigned long value, int shift )
|
||||
{
|
||||
int max_bits = sizeof(unsigned long)<<3;
|
||||
if ( shift < 0 )
|
||||
return _lrotl(value,-shift);
|
||||
|
||||
if ( shift > max_bits )
|
||||
shift = shift % max_bits;
|
||||
return (value >> shift) | (value << (max_bits-shift));
|
||||
}
|
|
@ -1,8 +1,18 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <windows.h>
|
||||
#include <crtdll/string.h>
|
||||
|
||||
/* Compare S1 and S2, returning less than, equal to or
|
||||
greater than zero if the collated form of S1 is lexicographically
|
||||
less than, equal to or greater than the collated form of S2. */
|
||||
int
|
||||
strcoll(const char *s1, const char *s2)
|
||||
strcoll (const char *s1,const char *s2)
|
||||
{
|
||||
return strcmp(s1, s2);
|
||||
int ret = CompareStringA(LOCALE_USER_DEFAULT,0,s1,strlen(s1),s2,strlen(s2));
|
||||
if ( ret == 0 )
|
||||
return 0;
|
||||
|
||||
else
|
||||
return ret - 2;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,25 +1,16 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <windows.h>
|
||||
#include <crtdll/string.h>
|
||||
|
||||
size_t
|
||||
strxfrm(char *dst,const char *src, size_t n)
|
||||
size_t strxfrm( char *dest, const char *src, size_t n )
|
||||
{
|
||||
size_t r = 0;
|
||||
int c;
|
||||
|
||||
int ret = LCMapStringA(LOCALE_USER_DEFAULT,LCMAP_LOWERCASE,
|
||||
src, strlen(src),
|
||||
dest, strlen(dest) );
|
||||
|
||||
if (n != 0) {
|
||||
while ((c = *src++) != 0)
|
||||
{
|
||||
r++;
|
||||
if (--n == 0)
|
||||
{
|
||||
while (*src++ != 0)
|
||||
r++;
|
||||
break;
|
||||
}
|
||||
*dst++ = c;
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
if ( ret == 0 )
|
||||
return -1;
|
||||
return ret;
|
||||
|
||||
}
|
16
reactos/lib/crtdll/sys_stat/futime.c
Normal file
16
reactos/lib/crtdll/sys_stat/futime.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include <crtdll/stdlib.h>
|
||||
#include <crtdll/sys/utime.h>
|
||||
#include <crtdll/io.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) )
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -5,15 +5,15 @@
|
|||
wchar_t * wcscat(wchar_t * dest,const wchar_t * src)
|
||||
{
|
||||
|
||||
int i,j;
|
||||
j=0;
|
||||
for (i=0; dest[i]!=0; i++);
|
||||
while (src[j] != 0)
|
||||
wchar_t *d = dest;
|
||||
for (; *dest !=0; dest++);
|
||||
while (*src != 0)
|
||||
{
|
||||
dest[i+j] = src[j];
|
||||
j++;
|
||||
*dest = *src;
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
dest[i+j] = 0;
|
||||
return dest;
|
||||
*dest = 0;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,4 @@
|
|||
/*
|
||||
* The C RunTime DLL
|
||||
*
|
||||
* Implements C run-time functionality as known from UNIX.
|
||||
*
|
||||
* Copyright 1996,1998 Marcus Meissner
|
||||
* Copyright 1996 Jukka Iivonen
|
||||
* Copyright 1997 Uwe Bonnes
|
||||
*/
|
||||
|
||||
|
||||
#include <crtdll/wchar.h>
|
||||
|
||||
|
@ -15,3 +7,11 @@ int wcscoll(const wchar_t *a1,const wchar_t *a2)
|
|||
/* FIXME: handle collates */
|
||||
return wcscmp(a1,a2);
|
||||
}
|
||||
|
||||
|
||||
int _wcsicoll(const wchar_t *a1,const wchar_t *a2)
|
||||
{
|
||||
/* FIXME: handle collates */
|
||||
return wcscmp(a1,a2);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
#include <crtdll/wchar.h>
|
||||
#include <crtdll/errno.h>
|
||||
#include <crtdll/internal/file.h>
|
||||
|
||||
|
||||
wchar_t *_wcsdup(const wchar_t *ptr)
|
||||
{
|
||||
wchar_t *dup;
|
||||
dup = malloc((wcslen(ptr) + 1)*sizeof(wchar_t));
|
||||
if( dup == NULL )
|
||||
if( dup == NULL ) {
|
||||
__set_errno(ENOMEM);
|
||||
return NULL;
|
||||
}
|
||||
wcscpy(dup,ptr);
|
||||
return dup;
|
||||
}
|
||||
|
|
|
@ -19,3 +19,5 @@ size_t wstrlen(const wchar_t *s)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||
#include <crtdll/wchar.h>
|
||||
|
||||
wchar_t * wcsncat(wchar_t * dest,const wchar_t * src,size_t count)
|
||||
wchar_t *wcsncat(wchar_t *dst, const wchar_t *src, size_t n)
|
||||
{
|
||||
int i,j;
|
||||
if ( count != 0 ) {
|
||||
|
||||
for (j=0;dest[j]!=0;j++);
|
||||
if (n != 0)
|
||||
{
|
||||
wchar_t *d = dst;
|
||||
const wchar_t *s = src;
|
||||
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
dest[j+i] = src[i];
|
||||
if (src[i] == 0)
|
||||
return(dest);
|
||||
|
||||
}
|
||||
dest[j+i]=0;
|
||||
}
|
||||
return(dest);
|
||||
while (*d != 0)
|
||||
d++;
|
||||
do {
|
||||
if ((*d = *s++) == 0)
|
||||
break;
|
||||
d++;
|
||||
} while (--n != 0);
|
||||
*d = 0;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <crtdll/wchar.h>
|
||||
|
||||
wchar_t * _wcsncpy(wchar_t * dest,const wchar_t *src,size_t count)
|
||||
wchar_t * wcsncpy(wchar_t * dest,const wchar_t *src,size_t count)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
5
reactos/lib/crtdll/wchar/wcspbrk.c
Normal file
5
reactos/lib/crtdll/wchar/wcspbrk.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include <crtdll/wchar.h>
|
||||
|
||||
wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
}
|
27
reactos/lib/crtdll/wchar/wcsset.c
Normal file
27
reactos/lib/crtdll/wchar/wcsset.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#inlcude <crtdll/wchar.h>
|
||||
|
||||
wchar_t* _wcsnset (wchar_t* wsToFill, wchar_t wcFill, size_t sizeMaxFill)
|
||||
{
|
||||
wchar_t *t = wsToFill;
|
||||
int i = 0;
|
||||
while( *wsToFill != 0 && i < sizeMaxFill)
|
||||
{
|
||||
*wsToFill = wcFill;
|
||||
wsToFill++;
|
||||
i++;
|
||||
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
wchar_t* _wcsset (wchar_t* wsToFill, wchar_t wcToFill)
|
||||
{
|
||||
wchar_t *t = wsToFill;
|
||||
while( *wsToFill != 0 )
|
||||
{
|
||||
*wsToFill = wcFill;
|
||||
wsToFill++;
|
||||
|
||||
}
|
||||
return t;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#include <crtdll/wchar.h>
|
||||
|
||||
size_t _wcsspn(const wchar_t *str,const wchar_t *accept)
|
||||
size_t wcsspn(const wchar_t *str,const wchar_t *accept)
|
||||
{
|
||||
wchar_t *s;
|
||||
wchar_t *t;
|
||||
|
|
6
reactos/lib/crtdll/wchar/wcstod.c
Normal file
6
reactos/lib/crtdll/wchar/wcstod.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <crtdll/wchar.h>
|
||||
|
||||
double wcstod(const wchar_t *nptr, wchar_t **endptr)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#include <crtdll/wchar.h>
|
||||
|
||||
wchar_t *wcstok(wchar_t *s, const wchar_t *ct)
|
||||
wchar_t *_wcstok(wchar_t *s, const wchar_t *ct)
|
||||
{
|
||||
const wchar_t *spanp;
|
||||
int c, sc;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue