Added missing math and stdio functions

svn path=/trunk/; revision=2041
This commit is contained in:
Eric Kohl 2001-07-06 00:58:15 +00:00
parent 3bba37d64a
commit e5e74911b3
27 changed files with 1351 additions and 97 deletions

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.14 2001/07/04 20:40:19 chorns Exp $ # $Id: Makefile,v 1.15 2001/07/06 00:58:15 ekohl Exp $
# #
# ReactOS Operating System # ReactOS Operating System
# #
@ -103,9 +103,37 @@ OBJECTS_IO = \
io/write.o io/write.o
OBJECTS_MATH = \ OBJECTS_MATH = \
math/acos.o \
math/adjust.o \ math/adjust.o \
math/asin.o \
math/atan.o \
math/atan2.o \
math/cabs.o \
math/ceil.o \
math/cos.o \
math/cosh.o \
math/exp.o \
math/fabs.o \
math/floor.o \
math/fmod.o \
math/frexp.o \
math/ftol.o \
math/huge_val.o \
math/hypot.o \
math/j0_y0.o \
math/j1_y1.o \
math/jn_yn.o \
math/ldexp.o \
math/log.o \
math/log10.o \
math/modf.o \ math/modf.o \
math/pow.o \ math/pow.o \
math/sin.o \
math/sinh.o \
math/sqrt.o \
math/stubs.o \
math/tan.o \
math/tanh.o
OBJECTS_MISC = \ OBJECTS_MISC = \
misc/amsg.o \ misc/amsg.o \
@ -127,10 +155,15 @@ OBJECTS_SIGNAL = \
OBJECTS_STDIO = \ OBJECTS_STDIO = \
stdio/allocfil.o \ stdio/allocfil.o \
stdio/clearerr.o \
stdio/fclose.o \ stdio/fclose.o \
stdio/fdopen.o \
stdio/feof.o \ stdio/feof.o \
stdio/ferror.o \ stdio/ferror.o \
stdio/fflush.o \ stdio/fflush.o \
stdio/fgetc.o \
stdio/fgetchar.o \
stdio/fgetpos.o \
stdio/fgets.o \ stdio/fgets.o \
stdio/filbuf.o \ stdio/filbuf.o \
stdio/fileno.o \ stdio/fileno.o \
@ -138,23 +171,41 @@ OBJECTS_STDIO = \
stdio/fopen.o \ stdio/fopen.o \
stdio/fprintf.o \ stdio/fprintf.o \
stdio/fputc.o \ stdio/fputc.o \
stdio/fputchar.o \
stdio/fputs.o \ stdio/fputs.o \
stdio/fread.o \ stdio/fread.o \
stdio/freopen.o \
stdio/fscanf.o \ stdio/fscanf.o \
stdio/fseek.o \
stdio/fsetpos.o \
stdio/fsopen.o \
stdio/ftell.o \
stdio/fwalk.o \ stdio/fwalk.o \
stdio/fwrite.o \ stdio/fwrite.o \
stdio/getc.o \ stdio/getc.o \
stdio/getchar.o \
stdio/gets.o \
stdio/getw.o \
stdio/perror.o \
stdio/popen.o \
stdio/printf.o \ stdio/printf.o \
stdio/putc.o \ stdio/putc.o \
stdio/putchar.o \ stdio/putchar.o \
stdio/puts.o \ stdio/puts.o \
stdio/putw.o \
stdio/remove.o \ stdio/remove.o \
stdio/rename.o \
stdio/rewind.o \
stdio/rmtmp.o \
stdio/scanf.o \ stdio/scanf.o \
stdio/setbuf.o \
stdio/setvbuf.o \ stdio/setvbuf.o \
stdio/sprintf.o \ stdio/sprintf.o \
stdio/sscanf.o \ stdio/sscanf.o \
stdio/stdhnd.o \ stdio/stdhnd.o \
stdio/tempnam.o \ stdio/tempnam.o \
stdio/tmpfile.o \
stdio/tmpnam.o \
stdio/ungetc.o \ stdio/ungetc.o \
stdio/vfprintf.o \ stdio/vfprintf.o \
stdio/vfscanf.o \ stdio/vfscanf.o \

View file

@ -1,4 +1,4 @@
; $Id: msvcrt.def,v 1.9 2001/07/04 16:39:37 ekohl Exp $ ; $Id: msvcrt.def,v 1.10 2001/07/06 00:58:15 ekohl Exp $
; ;
; ReactOS MSVCRT Compatibility Library ; ReactOS MSVCRT Compatibility Library
; ;
@ -59,28 +59,28 @@ EXPORTS
;---------------------------------------------------------------------- ;----------------------------------------------------------------------
; C Undecorated Symbols ; C Undecorated Symbols
;---------------------------------------------------------------------- ;----------------------------------------------------------------------
; _CIacos _CIacos
; _CIasin _CIasin
; _CIatan _CIatan
; _CIatan2 _CIatan2
; _CIcos _CIcos
; _CIcosh _CIcosh
; _CIexp _CIexp
; _CIfmod _CIfmod
; _CIlog _CIlog
; _CIlog10 _CIlog10
; _CIpow _CIpow
; _CIsin _CIsin
; _CIsinh _CIsinh
; _CIsqrt _CIsqrt
; _CItan _CItan
; _CItanh _CItanh
; _CxxThrowException ; _CxxThrowException
; _EH_prolog ; _EH_prolog
; _Getdays ; _Getdays
; _Getmonths ; _Getmonths
; _Gettnames ; _Gettnames
; _HUGE _HUGE DATA
; _Strftime ; _Strftime
_XcptFilter _XcptFilter
; __CxxFrameHandler ; __CxxFrameHandler
@ -178,7 +178,7 @@ _beep
_beginthread _beginthread
_beginthreadex _beginthreadex
_c_exit _c_exit
; _cabs _cabs
; _callnewh ; _callnewh
_cexit _cexit
_cgets _cgets
@ -225,9 +225,9 @@ _exit
; _expand ; _expand
_fcloseall _fcloseall
; _fcvt ; _fcvt
; _fdopen _fdopen
; _fgetchar _fgetchar
; _fgetwchar _fgetwchar
_filbuf _filbuf
; _fileinfo ; _fileinfo
_filelength _filelength
@ -245,13 +245,13 @@ _fmode DATA
_fpclass _fpclass
_fpieee_flt _fpieee_flt
_fpreset _fpreset
; _fputchar _fputchar
; _fputwchar _fputwchar
; _fsopen _fsopen
_fstat _fstat
_fstati64 _fstati64
; _ftime ; _ftime
; _ftol _ftol
_fullpath _fullpath
_futime _futime
; _gcvt ; _gcvt
@ -269,7 +269,7 @@ _getdrives
; _getmbcp ; _getmbcp
_getpid _getpid
; _getsystime ; _getsystime
; _getw _getw
; _getws ; _getws
_global_unwind2 _global_unwind2
; _heapadd ; _heapadd
@ -278,7 +278,7 @@ _global_unwind2
; _heapset ; _heapset
; _heapused ; _heapused
; _heapwalk ; _heapwalk
; _hypot _hypot
_i64toa _i64toa
_i64tow _i64tow
_initterm _initterm
@ -320,9 +320,9 @@ _isctype
_isnan _isnan
_itoa _itoa
_itow _itow
; _j0 _j0
; _j1 _j1
; _jn _jn
_kbhit _kbhit
; _lfind ; _lfind
_loaddll _loaddll
@ -407,20 +407,20 @@ _osver DATA
; _outp ; _outp
; _outpd ; _outpd
; _outpw ; _outpw
; _pclose _pclose
_pctype DATA _pctype DATA
_pgmptr DATA _pgmptr DATA
_pipe _pipe
; _popen _popen
_purecall _purecall
_putch _putch
_putenv _putenv
; _putw _putw
_putws _putws
_pwctype DATA _pwctype DATA
_read _read
_rmdir _rmdir
; _rmtmp _rmtmp
_rotl _rotl
_rotr _rotr
; _safe_fdiv ; _safe_fdiv
@ -520,14 +520,14 @@ _wcsupr
; _wexecve ; _wexecve
; _wexecvp ; _wexecvp
; _wexecvpe ; _wexecvpe
; _wfdopen _wfdopen
_wfindfirst _wfindfirst
_wfindfirsti64 _wfindfirsti64
_wfindnext _wfindnext
_wfindnexti64 _wfindnexti64
; _wfopen _wfopen
; _wfreopen _wfreopen
; _wfsopen _wfsopen
_wfullpath _wfullpath
_wgetcwd _wgetcwd
_wgetdcwd _wgetdcwd
@ -539,12 +539,12 @@ _wmakepath
_wmkdir _wmkdir
; _wmktemp ; _wmktemp
_wopen _wopen
; _wperror _wperror
; _wpgmptr DATA ; _wpgmptr DATA
; _wpopen _wpopen
_wputenv _wputenv
_wremove _wremove
; _wrename _wrename
_write _write
_wrmdir _wrmdir
_wsearchenv _wsearchenv
@ -564,51 +564,51 @@ _wstati64
; _wstrdate ; _wstrdate
; _wstrtime ; _wstrtime
; _wsystem ; _wsystem
; _wtempnam _wtempnam
; _wtmpnam _wtmpnam
_wtoi _wtoi
_wtoi64 _wtoi64
_wtol _wtol
_wunlink _wunlink
_wutime _wutime
; _y0 _y0
; _y1 _y1
; _yn _yn
abort abort
abs abs
; acos acos
asctime asctime
; asin asin
; atan atan
; atan2 atan2
atexit atexit
atof atof
atoi atoi
atol atol
bsearch bsearch
calloc calloc
; ceil ceil
; clearerr clearerr
; clock ; clock
; cos cos
; cosh cosh
ctime ctime
; difftime ; difftime
div div
exit exit
; exp exp
; fabs fabs
fclose fclose
feof feof
ferror ferror
fflush fflush
; fgetc fgetc
; fgetpos fgetpos
fgets fgets
; fgetwc fgetwc
; fgetws ; fgetws
; floor floor
; fmod fmod
fopen fopen
fprintf fprintf
fputc fputc
@ -617,19 +617,19 @@ fputwc
; fputws ; fputws
fread fread
free free
; freopen freopen
; frexp frexp
fscanf fscanf
; fseek fseek
; fsetpos fsetpos
; ftell ftell
fwprintf fwprintf
fwrite fwrite
fwscanf fwscanf
getc getc
; getchar getchar
getenv getenv
; gets gets
getwc getwc
; getwchar ; getwchar
gmtime gmtime
@ -660,12 +660,12 @@ iswupper
iswxdigit iswxdigit
isxdigit isxdigit
labs labs
; ldexp ldexp
ldiv ldiv
; localeconv ; localeconv
localtime localtime
; log log
; log10 log10
; longjmp ; longjmp
malloc malloc
; mblen ; mblen
@ -678,7 +678,7 @@ memmove
memset memset
mktime mktime
modf modf
; perror perror
pow pow
printf printf
putc putc
@ -688,21 +688,21 @@ putwc
putwchar putwchar
qsort qsort
raise raise
; rand rand
realloc realloc
remove remove
; rename rename
; rewind rewind
scanf scanf
; setbuf setbuf
; setlocale ; setlocale
setvbuf setvbuf
signal signal
; sin sin
; sinh sinh
sprintf sprintf
; sqrt sqrt
; srand srand
sscanf sscanf
strcat strcat
strchr strchr
@ -728,11 +728,11 @@ strxfrm
swprintf swprintf
swscanf swscanf
; system ; system
; tan tan
; tanh tanh
time time
; tmpfile tmpfile
; tmpnam tmpnam
tolower tolower
toupper toupper
towlower towlower

View file

@ -0,0 +1,19 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/errno.h>
#include <msvcrt/internal/file.h>
#ifdef clearerr
#undef clearerr
void clearerr(FILE *stream);
#endif
void
clearerr(FILE *f)
{
if (!__validfp (f)) {
__set_errno (EINVAL);
return;
}
f->_flag &= ~(_IOERR|_IOEOF);
}

View file

@ -0,0 +1,102 @@
#include <msvcrt/stdio.h>
#include <msvcrt/internal/file.h>
FILE * __alloc_file(void);
FILE *_fdopen(int handle, char *mode)
{
FILE *file;
int rw;
if (handle == 0)
return stdin;
if (handle == 1)
return stdout;
if (handle == 2)
return stderr;
if (handle == 3)
return stdaux;
if (handle == 4)
return stdprn;
file = __alloc_file();
if (file == NULL)
return NULL;
file->_file = handle;
rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
if (*mode == 'a')
_lseek(handle, 0, SEEK_END);
file->_cnt = 0;
file->_file = handle;
file->_bufsiz = 0;
// The mode of the stream must be compatible with the mode of the file descriptor.
// this should be checked.
if (rw)
file->_flag = _IOREAD | _IOWRT;
else if (*mode == 'r')
file->_flag = _IOREAD;
else
file->_flag = _IOWRT;
file->_base = file->_ptr = NULL;
return file;
}
FILE *_wfdopen(int handle, wchar_t *mode)
{
FILE *file;
int rw;
if (handle == 0)
return stdin;
if (handle == 1)
return stdout;
if (handle == 2)
return stderr;
if (handle == 3)
return stdaux;
if (handle == 4)
return stdprn;
file = __alloc_file();
if (file == NULL)
return NULL;
file->_file = handle;
rw = (mode[1] == L'+') || (mode[1] && (mode[2] == L'+'));
if (*mode == L'a')
_lseek(handle, 0, SEEK_END);
file->_cnt = 0;
file->_file = handle;
file->_bufsiz = 0;
// The mode of the stream must be compatible with the mode of the file descriptor.
// this should be checked.
if (rw)
file->_flag = _IOREAD | _IOWRT;
else if (*mode == L'r')
file->_flag = _IOREAD;
else
file->_flag = _IOWRT;
file->_base = file->_ptr = NULL;
return file;
}

View file

@ -0,0 +1,23 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/stdio/fgetc.c
* PURPOSE: Get a character string from stdin
* PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY:
* 28/12/98: Appropriated for Reactos
25/02/99: Added fgetwc
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/internal/file.h>
int fgetc(FILE *f)
{
return getc(f);
}
wint_t fgetwc(FILE *f)
{
return getwc(f);
}

View file

@ -0,0 +1,12 @@
#include <msvcrt/stdio.h>
#include <msvcrt/conio.h>
int _fgetchar(void)
{
return _getch();
}
int _fgetwchar(void)
{
return _getch();
}

View file

@ -0,0 +1,14 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/errno.h>
int fgetpos(FILE *stream, fpos_t *pos)
{
if (stream && pos)
{
*pos = (fpos_t)ftell(stream);
return 0;
}
//errno = EFAULT;
return 1;
}

View file

@ -78,3 +78,68 @@ FILE* fopen(const char *file, const char *mode)
f->_base = f->_ptr = NULL; f->_base = f->_ptr = NULL;
return f; return f;
} }
FILE* _wfopen(const wchar_t *file, const wchar_t *mode)
{
FILE *f;
int fd, rw, oflags = 0;
wchar_t tbchar;
if (file == 0)
return 0;
if (mode == 0)
return 0;
f = __alloc_file();
if (f == NULL)
return NULL;
rw = (mode[1] == L'+') || (mode[1] && (mode[2] == L'+'));
switch (*mode)
{
case L'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case L'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case L'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return (NULL);
}
if (mode[1] == L'+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == L't')
oflags |= O_TEXT;
else if (tbchar == L'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
fd = _wopen(file, oflags, 0);
if (fd < 0)
return NULL;
// ms crtdll ensures that writes will end up at the end of file in append mode
// we just move the file pointer to the end of file initially
if (*mode == L'a')
lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (*mode == L'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
f->_base = f->_ptr = NULL;
return f;
}

View file

@ -0,0 +1,14 @@
#include <msvcrt/stdio.h>
#include <msvcrt/conio.h>
int _fputchar(int c)
{
return _putch(c);
}
int _fputwchar(wchar_t c)
{
//return _putch(c);
return 0;
}

View file

@ -0,0 +1,122 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/sys/types.h>
#include <msvcrt/stdio.h>
#include <msvcrt/fcntl.h>
#include <msvcrt/io.h>
#include <msvcrt/internal/file.h>
FILE *freopen(const char *file, const char *mode, FILE *f)
{
int fd, rw, oflags=0;
char tbchar;
if (file == 0 || mode == 0 || f == 0)
return 0;
rw = (mode[1] == '+');
fclose(f);
switch (*mode) {
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return NULL;
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
fd = _open(file, oflags, 0666);
if (fd < 0)
return NULL;
if (*mode == 'a')
lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
f->_base = f->_ptr = NULL;
return f;
}
FILE *_wfreopen(const wchar_t *file, const wchar_t *mode, FILE *f)
{
int fd, rw, oflags=0;
wchar_t tbchar;
if (file == 0 || mode == 0 || f == 0)
return 0;
rw = (mode[1] == L'+');
fclose(f);
switch (*mode) {
case L'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case L'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case L'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return NULL;
}
if (mode[1] == L'+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == L't')
oflags |= O_TEXT;
else if (tbchar == L'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
fd = _wopen(file, oflags, 0666);
if (fd < 0)
return NULL;
if (*mode == L'a')
lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (*mode == L'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
f->_base = f->_ptr = NULL;
return f;
}

View file

@ -0,0 +1,54 @@
/* Copyright (C) 1997 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 <msvcrt/stdio.h>
#include <msvcrt/errno.h>
#include <msvcrt/fcntl.h>
#include <msvcrt/io.h>
#include <msvcrt/internal/file.h>
int fseek(FILE *f, long offset, int ptrname)
{
long p = -1; /* can't happen? */
if ( f == NULL ) {
__set_errno (EINVAL);
return -1;
}
f->_flag &= ~_IOEOF;
if (!OPEN4WRITING(f))
{
if (f->_base && !(f->_flag & _IONBF))
{
p = ftell(f);
if (ptrname == SEEK_CUR)
{
offset += p;
ptrname = SEEK_SET;
}
/* check if the target position is in the buffer and
optimize seek by moving inside the buffer */
if (ptrname == SEEK_SET && (f->_flag & (_IOUNGETC|_IOREAD|_IOWRT )) == 0
&& p-offset <= f->_ptr-f->_base && offset-p <= f->_cnt)
{
f->_ptr+=offset-p;
f->_cnt+=p-offset;
return 0;
}
}
p = lseek(fileno(f), offset, ptrname);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~_IOUNGETC;
}
else
{
p = fflush(f);
return lseek(fileno(f), offset, ptrname) == -1 || p == EOF ?
-1 : 0;
}
return p==-1 ? -1 : 0;
}

View file

@ -0,0 +1,15 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/errno.h>
#include <msvcrt/internal/file.h>
int fsetpos(FILE *stream,const fpos_t *pos)
{
if (stream && pos)
{
fseek(stream, (long)(*pos), SEEK_SET);
return 0;
}
__set_errno(EFAULT);
return -1;
}

View file

@ -0,0 +1,177 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/conio/kbhit.c
* PURPOSE: Checks for keyboard hits
* PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY:
* 28/12/98: Created
*/
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/sys/types.h>
#include <msvcrt/stdio.h>
#include <msvcrt/io.h>
#include <msvcrt/fcntl.h>
#include <msvcrt/share.h>
#include <msvcrt/internal/file.h>
FILE * __alloc_file(void);
FILE* _fsopen(const char *file, const char *mode, int shflag)
{
FILE *f;
int fd, rw, oflags = 0;
char tbchar;
int shf;
if (file == 0)
return 0;
if (mode == 0)
return 0;
f = __alloc_file();
if (f == NULL)
return NULL;
rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
switch (*mode)
{
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return (NULL);
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
if ( shflag == _SH_DENYNO )
shf = _S_IREAD | _S_IWRITE;
else if( shflag == _SH_DENYRD )
shf = _S_IWRITE;
else if( shflag == _SH_DENYRW )
shf = 0;
else if( shflag == _SH_DENYWR )
shf = _S_IREAD;
else
shf = _S_IREAD | _S_IWRITE;
fd = _open(file, oflags, shf);
if (fd < 0)
return NULL;
// ms crtdll ensures that writes will end up at the end of file in append mode
// we just move the file pointer to the end of file initially
if (*mode == 'a')
lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
f->_base = f->_ptr = NULL;
return f;
}
FILE* _wfsopen(const wchar_t *file, const wchar_t *mode, int shflag)
{
FILE *f;
int fd, rw, oflags = 0;
wchar_t tbchar;
int shf;
if (file == 0)
return 0;
if (mode == 0)
return 0;
f = __alloc_file();
if (f == NULL)
return NULL;
rw = (mode[1] == L'+') || (mode[1] && (mode[2] == L'+'));
switch (*mode)
{
case L'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case L'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case L'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return (NULL);
}
if (mode[1] == L'+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == L't')
oflags |= O_TEXT;
else if (tbchar == L'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
if ( shflag == _SH_DENYNO )
shf = _S_IREAD | _S_IWRITE;
else if( shflag == _SH_DENYRD )
shf = _S_IWRITE;
else if( shflag == _SH_DENYRW )
shf = 0;
else if( shflag == _SH_DENYWR )
shf = _S_IREAD;
else
shf = _S_IREAD | _S_IWRITE;
fd = _wopen(file, oflags, shf);
if (fd < 0)
return NULL;
// ms crtdll ensures that writes will end up at the end of file in append mode
// we just move the file pointer to the end of file initially
if (*mode == L'a')
lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (*mode == L'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
f->_base = f->_ptr = NULL;
return f;
}

View file

@ -0,0 +1,46 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
//#include <crtdll/unistd.h>
#include <msvcrt/fcntl.h>
#include <msvcrt/io.h>
#include <msvcrt/errno.h>
#include <msvcrt/internal/file.h>
long ftell(FILE *f)
{
long tres;
int adjust=0;
if (!f)
{
__set_errno(EBADF);
return -1;
}
if (f->_cnt < 0)
f->_cnt = 0;
else if (f->_flag&_IOREAD)
{
adjust = - f->_cnt;
}
else if (f->_flag&(_IOWRT))
{
if (f->_base && (f->_flag&_IONBF)==0)
adjust = f->_ptr - f->_base;
}
else
return -1;
tres = lseek(fileno(f), 0L, SEEK_CUR);
if (tres<0)
return tres;
tres += adjust;
//f->_cnt = f->_bufsiz - tres;
//f->_ptr = f->_base + tres;
return tres;
}

View file

@ -0,0 +1,10 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/internal/file.h>
#undef getchar
int
getchar(void)
{
return getc(stdin);
}

View file

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

View file

@ -0,0 +1,30 @@
/* 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 <msvcrt/stdio.h>
/* Read a word (int) from STREAM. */
int _getw(FILE *stream)
{
int w;
/* Is there a better way? */
if (fread( &w, sizeof(w), 1, stream) != 1)
return(EOF);
return(w);
}

View file

@ -0,0 +1,20 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/string.h>
#include <msvcrt/errno.h>
#ifdef perror
#undef perror
void perror(const char *s);
#endif
void perror(const char *s)
{
fprintf(stderr, "%s: %s\n", s, _strerror(NULL));
}
void _wperror(const wchar_t *s)
{
fwprintf(stderr, L"%s: %S\n", s, _strerror(NULL));
}

View file

@ -0,0 +1,102 @@
#include <windows.h>
#include <msvcrt/io.h>
#include <msvcrt/errno.h>
#include <msvcrt/stdio.h>
#include <msvcrt/stdlib.h>
#include <msvcrt/string.h>
#include <msvcrt/internal/file.h>
FILE *_popen (const char *cm, const char *md) /* program name, pipe mode */
{
FILE *pf;
HANDLE hReadPipe, hWritePipe;
STARTUPINFOA StartupInfo;
PROCESS_INFORMATION ProcessInformation;
// fixme CreatePipe
// if ( !CreatePipe(&hReadPipe,&hWritePipe,NULL,1024))
// return NULL;
StartupInfo.cb = sizeof(STARTUPINFOA);
if ( md == "r" ) {
StartupInfo.hStdOutput = hWritePipe;
}
else if ( md == "w" ) {
StartupInfo.hStdInput = hReadPipe;
}
if (CreateProcessA("cmd.exe",(char *)cm,NULL,NULL,TRUE,
CREATE_NEW_CONSOLE,NULL,NULL,
&StartupInfo,
&ProcessInformation) == FALSE)
return NULL;
if ( *md == 'r' )
{
pf = _fdopen(__fileno_alloc(hReadPipe, _fmode) , "r");
}
else
{
pf = _fdopen( __fileno_alloc(hWritePipe, _fmode) , "w");
}
pf->_name_to_remove = ProcessInformation.hProcess;
return pf;
}
int _pclose (FILE *pp)
{
fclose(pp);
printf("Terminate Process\n");
// if (!TerminateProcess(pp->_name_to_remove,0))
// return -1;
return 0;
}
FILE *_wpopen (const wchar_t *cm, const wchar_t *md) /* program name, pipe mode */
{
FILE *pf;
HANDLE hReadPipe, hWritePipe;
STARTUPINFOW StartupInfo;
PROCESS_INFORMATION ProcessInformation;
// fixme CreatePipe
// if ( !CreatePipe(&hReadPipe,&hWritePipe,NULL,1024))
// return NULL;
StartupInfo.cb = sizeof(STARTUPINFOW);
if (*md == L'r')
{
StartupInfo.hStdOutput = hWritePipe;
}
else if (*md == L'w')
{
StartupInfo.hStdInput = hReadPipe;
}
if (CreateProcessW(L"cmd.exe",(wchar_t *)cm,NULL,NULL,TRUE,
CREATE_NEW_CONSOLE,NULL,NULL,
&StartupInfo,
&ProcessInformation) == FALSE)
return NULL;
if (*md == L'r')
{
pf = _wfdopen(__fileno_alloc(hReadPipe, _fmode) , L"r");
}
else
{
pf = _wfdopen( __fileno_alloc(hWritePipe, _fmode) , L"w");
}
pf->_name_to_remove = ProcessInformation.hProcess;
return pf;
}

View file

@ -0,0 +1,30 @@
/* 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 <msvcrt/stdio.h>
/* Write the word (int) W to STREAM. */
int _putw(int w,FILE *stream)
{
/* Is there a better way? */
if (fwrite( &w, sizeof(w), 1, stream) < 1)
return(EOF);
return(0);
}

View file

@ -0,0 +1,27 @@
#include <windows.h>
#include <msvcrt/stdio.h>
#include <msvcrt/io.h>
int rename(const char *old_, const char *new_)
{
if (old_ == NULL || new_ == NULL)
return -1;
if (!MoveFileA(old_,new_))
return -1;
return 0;
}
int _wrename(const wchar_t *old_, const wchar_t *new_)
{
if (old_ == NULL || new_ == NULL)
return -1;
if (!MoveFileW(old_,new_))
return -1;
return 0;
}

View file

@ -0,0 +1,15 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/io.h>
#include <msvcrt/internal/file.h>
void rewind(FILE *f)
{
fflush(f);
lseek(fileno(f), 0L, SEEK_SET);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~(_IOERR|_IOEOF|_IOAHEAD);
}

View file

@ -0,0 +1,72 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crtdll/stdio/rmtmp.c
* PURPOSE: remove temporary files in current directory
* PROGRAMMER: Boudewijn ( ariadne@xs4all.nl)
* UPDATE HISTORY:
* Created 19/01/99
* NOTE Not tested.
*/
#include <msvcrt/stdio.h>
#include <msvcrt/string.h>
#include <msvcrt/internal/file.h>
#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
// should be replace by a closure of the tmp files
extern __file_rec *__file_rec_list;
int _rmtmp( void )
{
/*
loop files and check for name_to_remove
*/
__file_rec *fr = __file_rec_list;
__file_rec **last_fr = &__file_rec_list;
int total_closed = 0;
int i = 0;
char temp_name[260];
/* Try to find an empty slot */
while (fr)
{
last_fr = &(fr->next);
/* If one of the existing slots is available, return it */
for (i=0; i<fr->count; i++) {
if (fr->files[i]->_name_to_remove != NULL) {
if ( _access(fr->files[i]->_name_to_remove,W_OK) ) {
strcpy(temp_name,fr->files[i]->_name_to_remove);
fclose(fr->files[i]);
remove(temp_name);
total_closed++;
}
}
}
/* If this one is full, go to the next */
if (fr->count == __FILE_REC_MAX)
fr = fr->next;
else
/* it isn't full, we can add to it */
break;
}
return total_closed;
}

View file

@ -0,0 +1,12 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/stdlib.h>
#include <msvcrt/internal/file.h>
void setbuf(FILE *f, char *buf)
{
if (buf)
setvbuf(f, buf, _IOFBF, BUFSIZ);
else
setvbuf(f, 0, _IONBF, BUFSIZ);
}

View file

@ -7,12 +7,33 @@ char *_tempnam(const char *dir,const char *prefix )
{ {
char *TempFileName = malloc(MAX_PATH); char *TempFileName = malloc(MAX_PATH);
char *d; char *d;
if (dir == NULL) if (dir == NULL)
d = getenv("TMP"); d = getenv("TMP");
else else
d = (char *)dir; d = (char *)dir;
if ( GetTempFileNameA(d, prefix, 0, TempFileName ) == 0 ) { if (GetTempFileNameA(d, prefix, 0, TempFileName) == 0)
{
free(TempFileName);
return NULL;
}
return TempFileName;
}
wchar_t *_wtempnam(const wchar_t *dir,const wchar_t *prefix)
{
wchar_t *TempFileName = malloc(MAX_PATH);
wchar_t *d;
if (dir == NULL)
d = _wgetenv(L"TMP");
else
d = (wchar_t *)dir;
if (GetTempFileNameW(d, prefix, 0, TempFileName) == 0)
{
free(TempFileName); free(TempFileName);
return NULL; return NULL;
} }

View file

@ -0,0 +1,67 @@
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h>
#include <msvcrt/string.h>
#include <msvcrt/stdlib.h>
#include <msvcrt/errno.h>
#include <msvcrt/fcntl.h>
//#include <msvcrt/unistd.h>
#include <msvcrt/io.h>
#include <msvcrt/share.h>
#include <msvcrt/internal/file.h>
FILE * __alloc_file(void);
FILE *
tmpfile(void)
{
int temp_fd;
FILE *f;
char *temp_name = tmpnam(0);
char *n_t_r = (char *)malloc(L_tmpnam);
if (!n_t_r)
return 0;
/* We could have a race condition, whereby another program
(in another virtual machine, or if the temporary file is
in a directory which is shared via a network) opens the
file returned by `tmpnam' between the call above and the
moment when we actually open the file below. This loop
retries the call to `tmpnam' until we actually succeed
to create the file which didn't exist before. */
do {
// errno = 0;
temp_fd = _open(temp_name, 0, SH_DENYRW);
// if ( errno == ENOENT )
// break;
} while (temp_fd == -1 && (temp_name = tmpnam(0)) != 0);
if (temp_name == 0)
return 0;
/* This should have been fdopen(temp_fd, "wb+"), but `fdopen'
is non-ANSI. So we need to dump some of its guts here. Sigh... */
f = __alloc_file();
if (f)
{
f->_file = temp_fd;
f->_cnt = 0;
f->_bufsiz = 0;
f->_flag = _IORMONCL | _IOREAD | _IOWRT;
f->_name_to_remove = n_t_r;
strcpy(f->_name_to_remove, temp_name);
f->_base = f->_ptr = NULL;
}
else
{
close(temp_fd);
remove(temp_name);
free(n_t_r);
}
return f;
}

View file

@ -0,0 +1,28 @@
#include <windows.h>
#include <msvcrt/stdio.h>
#include <msvcrt/string.h>
char *tmpnam(char *s)
{
char PathName[MAX_PATH];
static char static_buf[MAX_PATH];
GetTempPathA(MAX_PATH, PathName);
GetTempFileNameA(PathName, "ARI", 007, static_buf);
strcpy(s, static_buf);
return s;
}
wchar_t *_wtmpnam(wchar_t *s)
{
wchar_t PathName[MAX_PATH];
static wchar_t static_buf[MAX_PATH];
GetTempPathW(MAX_PATH, PathName);
GetTempFileNameW(PathName, L"ARI", 007, static_buf);
wcscpy(s, static_buf);
return s;
}