fixed bug in scanf

svn path=/trunk/; revision=441
This commit is contained in:
Boudewijn Dekker 1999-05-09 14:01:59 +00:00
parent 0107a0743b
commit b9354028e0
17 changed files with 155 additions and 70 deletions

View file

@ -1,4 +1,4 @@
#include <windows32/defines.h>
#include "../../include/defines.h"
#include "../../include/reactos/resource.h"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

View file

@ -3,7 +3,6 @@
#include <crtdll/errno.h>
#include <crtdll/internal/file.h>
//fixme change this constant to _OCOMMIT
int _commode_dll = _IOCOMMIT;
int _commit(int _fd)

View file

@ -119,7 +119,7 @@ OLD_OBJECTS = $(MISC_OBJECTS) stdlib/malloc.o stdlib/abort.o \
stdlib/errno.o stdio/printf.o stdio/vprintf.o\
$(QUAD_OBJECTS)
RESOURCE_OBJECT = crtdll.coff
#RESOURCE_OBJECT = crtdll.coff
OBJECTS = $(MISC_OBJECTS) $(STDLIB_OBJECTS) $(IO_OBJECTS) \
$(FLOAT_OBJECTS) $(ASSERT_OBJECTS) $(PROCESS_OBJECTS) \

View file

@ -1,3 +1,13 @@
#include <mbctype.h>
/*
* japanese code system utilities < jutil.h >
*
*
*
* Copyright (c) 1992-94 Tokyo Denki University, Taiji Yamada
* Copyright (c) 1997 AIHARA Electrical Engineering Co.,Ltd., Taiji Yamada
*/
static unsigned short han_to_zen_ascii_table[0x5f] = {
0x8140, 0x8149, 0x8168, 0x8194, 0x8190, 0x8193, 0x8195, 0x8166,
@ -84,15 +94,6 @@ static unsigned short _mbctombb(unsigned short c)
}
return c;
}
#endif
unsigned int _mbctohira( unsigned int c )
{
return c;
}
unsigned int _mbctokata( unsigned int c )
{
return c;
}

View file

@ -1,3 +1,5 @@
#include <mbstring.h>
unsigned int _mbctolower(unsigned int c)
{
if (!_ismbblead(c) )

View file

@ -1,3 +1,5 @@
#include <mbstring.h>
unsigned int _mbctoupper(unsigned int c)
{
if (!_ismbblead(c) )

View file

@ -73,6 +73,9 @@ int fflush(FILE *f)
// how can write return less than rn without being on error ???
// possibly commit the flushed data
// better open the file in write through mode
do {
n = _write(fileno(f), base, rn);
if (n <= 0) {

View file

@ -59,7 +59,7 @@ _filbuf(FILE *f)
}
// if we have a dirty stream we flush it
if ( f->_flag &_IODIRTY == _IODIRTY )
if ( (f->_flag &_IODIRTY) == _IODIRTY )
fflush(f);

View file

@ -28,6 +28,12 @@ _flsbuf(int c, FILE *f)
return EOF;
}
// no file associated with buffer
// this is a memory stream
if ( fileno(f) == -1 )
return c;
/* if the buffer is not yet allocated, allocate it */
if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0)
{

View file

@ -9,7 +9,7 @@
int getc(FILE *fp)
{
int c = -1;
// check for invalid stream
if ( !__validfp (fp) ) {
@ -25,12 +25,12 @@ int getc(FILE *fp)
if(fp->_cnt > 0) {
fp->_cnt--;
return (int)*fp->_ptr++;
c = (int)*fp->_ptr++;
}
else {
return _filbuf(fp);
c = _filbuf(fp);
}
return -1;
return c;
}
// not exported

View file

@ -1,15 +1,31 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* 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 <crtdll/stdio.h>
#include <crtdll/internal/file.h>
/* Write the word (int) W to STREAM. */
int
putw(int w, FILE *f)
putw(int w,FILE *stream)
{
char *p;
int i;
p = (char *)&w;
for (i=sizeof(int); --i>=0;)
putc(*p++, f);
return ferror(f);
/* Is there a better way? */
if (fwrite( &w, sizeof(w), 1, stream) < 1)
return(EOF);
return(0);
}

View file

@ -1,6 +1,8 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <crtdll/stdio.h>
// not exported
void setlinebuf(FILE *f)
{
setvbuf(f, 0, _IOLBF, BUFSIZ);

View file

@ -1,4 +1,25 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1991, 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/stdio.h>
#include <crtdll/stdio.h>
#include <limits.h>
#include <crtdll/internal/file.h>
@ -7,15 +28,30 @@
int
sprintf(char *str, const char *fmt, ...)
{
FILE _strbuf;
int len;
va_list a = 0;
va_start( a, fmt );
va_list arg;
int done;
_strbuf._flag = _IOWRT|_IOSTRG;
_strbuf._ptr = str;
_strbuf._cnt = INT_MAX;
len = vfprintf(&_strbuf, fmt, a);
*_strbuf._ptr = 0;
return len;
va_start (arg, fmt);
done = vsprintf (str, fmt, arg);
//va_end (arg);
return done;
}
/* Write formatted output into S, according to the format
string FORMAT, writing no more than MAXLEN characters. */
/* VARARGS3 */
int
snprintf (char *s, size_t maxlen,const char *format, ...)
{
va_list arg;
int done;
va_start (arg, format);
done = vsnprintf (s, maxlen, format, arg);
//va_end (arg);
return done;
}

View file

@ -37,7 +37,6 @@ ungetc(int c, FILE *f)
f->_flag |= _IOUNGETC;
*f->_ptr = c;
}
return c;
}

View file

@ -99,6 +99,28 @@ unsigned long int __strtoul_internal (const char *__nptr, char **__endptr, int
# define flockfile(S) /* nothing */
# define funlockfile(S) /* nothing */
char *wp = NULL; /* Workspace. */
size_t wpmax = 0; /* Maximal size of workspace. */
size_t wpsize = 0; /* Currently used bytes in workspace. */
void ADDW(int Ch) \
{
if (wpsize == wpmax)
{
char *old = wp;
wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax;
wp = (char *) malloc (wpmax);
if (old != NULL) {
memcpy (wp, old, wpsize);
free(old);
}
}
wp[wpsize++] = (Ch);
}
int __vfscanf (FILE *s, const char *format, va_list argptr)
{
va_list arg;
@ -141,23 +163,6 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
int skip_space = 0;
/* Workspace. */
char *tw; /* Temporary pointer. */
char *wp = NULL; /* Workspace. */
size_t wpmax = 0; /* Maximal size of workspace. */
size_t wpsize; /* Currently used bytes in workspace. */
#define ADDW(Ch) \
do \
{ \
if (wpsize == wpmax) \
{ \
char *old = wp; \
wpmax = UCHAR_MAX > 2 * wpmax ? UCHAR_MAX : 2 * wpmax; \
wp = (char *) alloca (wpmax); \
if (old != NULL) \
memcpy (wp, old, wpsize); \
} \
wp[wpsize++] = (Ch); \
} \
while (0)
#ifdef __va_copy
__va_copy (arg, argptr);
@ -165,7 +170,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
arg = (va_list) argptr;
#endif
/* Run through the format string. */
while (*f != '\0')

View file

@ -13,7 +13,24 @@ vsprintf(char *str, const char *fmt, va_list ap)
f._flag = _IOWRT|_IOSTRG;
f._ptr = str;
f._cnt = INT_MAX;
f._file = -1;
len = vfprintf(&f,fmt, ap);
*f._ptr = 0;
return len;
}
int
vsnprintf(char *str, size_t maxlen, const char *fmt, va_list ap)
{
FILE f;
int len;
f._flag = _IOWRT|_IOSTRG;
f._ptr = str;
f._cnt = maxlen;
f._file = -1;
len = vfprintf(&f,fmt, ap);
// what if the buffer is full ??
*f._ptr = 0;
return len;
}

View file

@ -16,19 +16,16 @@ VOID STDCALL GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime );
clock_t clock ( void )
{
FILETIME CreationTime;
FILETIME ExitTime;
FILETIME KernelTime;
FILETIME UserTime;
FILETIME SystemTime;
DWORD Remainder;
FILETIME CreationTime;
FILETIME ExitTime;
FILETIME KernelTime;
FILETIME UserTime;
DWORD Remainder;
if ( !GetProcessTimes(GetCurrentProcess(),&CreationTime,&ExitTime,&KernelTime,&UserTime ) )
return -1;
if ( !GetProcessTimes(GetCurrentProcess(),&CreationTime,&ExitTime,&KernelTime,&UserTime ) )
return -1;
GetSystemTimeAsFileTime(&SystemTime);
return FileTimeToUnixTime( &SystemTime,&Remainder ) - FileTimeToUnixTime( &CreationTime,&Remainder );
}
return FileTimeToUnixTime( &KernelTime,&Remainder ) + FileTimeToUnixTime( &UserTime,&Remainder );
}