Improved unicode fileio support.

svn path=/trunk/; revision=3822
This commit is contained in:
Robert Dickenson 2002-12-05 15:31:26 +00:00
parent 2aacb78c3e
commit f1592aa69f
29 changed files with 718 additions and 578 deletions

View file

@ -49,8 +49,9 @@
extern BOOL verbose_flagged; extern BOOL verbose_flagged;
extern BOOL status_flagged; extern BOOL status_flagged;
extern TCHAR test_buffer[TEST_BUFFER_SIZE]; //extern TCHAR test_buffer[TEST_BUFFER_SIZE];
static TCHAR test_buffer[TEST_BUFFER_SIZE];
static TCHAR dos_data[] = _T("line1: this is a bunch of readable text.\r\n")\ static TCHAR dos_data[] = _T("line1: this is a bunch of readable text.\r\n")\
_T("line2: some more printable text and punctuation !@#$%^&*()\r\n")\ _T("line2: some more printable text and punctuation !@#$%^&*()\r\n")\
@ -111,31 +112,33 @@ static BOOL verify_output_file(TCHAR* file_name, TCHAR* file_mode, TCHAR* file_d
_tprintf(_T("ERROR: (%s) Can't open file for reading\n"), file_name); _tprintf(_T("ERROR: (%s) Can't open file for reading\n"), file_name);
_tprintf(_T("ERROR: ferror returned %d\n"), ferror(file)); _tprintf(_T("ERROR: ferror returned %d\n"), ferror(file));
return FALSE; return FALSE;
} else if (verbose_flagged) { } else if (status_flagged) {
_tprintf(_T("STATUS: (%s) opened file for reading\n"), file_name); _tprintf(_T("STATUS: (%s) opened file for reading\n"), file_name);
} }
#ifndef _NO_NEW_DEPENDS_ #ifndef _NO_NEW_DEPENDS_
while (_fgetts(test_buffer, TEST_BUFFER_SIZE, file)) { while (_fgetts(test_buffer, TEST_BUFFER_SIZE, file)) {
int length = _tcslen(test_buffer); int length = _tcslen(test_buffer);
int req_len = _tcschr(file_data+offset, _T('\n')) - (file_data+offset) + 1;
++line_num; ++line_num;
if (verbose_flagged) { if (length > req_len) {
_tprintf(_T("ERROR: read excess bytes from line %d, length %d, but expected %d\n"), line_num, length, req_len);
error_flagged = TRUE;
break;
}
if (status_flagged) {
_tprintf(_T("STATUS: Verifying %d bytes read from line %d\n"), length, line_num); _tprintf(_T("STATUS: Verifying %d bytes read from line %d\n"), length, line_num);
} }
if (_tcsncmp(test_buffer, file_data+offset, length) == 0) { if (_tcsncmp(test_buffer, file_data+offset, length - 1) == 0) {
result = TRUE; result = TRUE;
} else { } else {
if (verbose_flagged) { if (status_flagged) {
int i; int i;
_tprintf(_T("WARNING: (%s) failed to verify file\n"), file_name); _tprintf(_T("WARNING: (%s) failed to verify file\n"), file_name);
//_tprintf(_T("expected: \"%s\"\n"), file_data+offset); for (i = 0; i < length; i++) {
//_tprintf(_T(" found: \"%s\"\n"), test_buffer); if (file_data[offset+i] != test_buffer[i]) {
_tprintf(_T("expected: ")); _tprintf(_T("line %d, offset %d expected: 0x%04x found: 0x%04x\n"), line_num, i, (int)file_data[offset+i], (int)test_buffer[i]);
for (i = 0; i < length, i < 10; i++) { }
_tprintf(_T("0x%02x "), file_data+offset+i);
}
_tprintf(_T("\n found: "));
for (i = 0; i < length, i < 10; i++) {
_tprintf(_T("0x%02x "), test_buffer+i);
} }
_tprintf(_T("\n")); _tprintf(_T("\n"));
} else { } else {
@ -196,7 +199,6 @@ static int check_file_size(TCHAR* file_name, TCHAR* file_mode, int expected)
//_tprintf(_T("STATUS: (%s) checking for %d bytes in %s mode\n"), file_name, expected, _tcschr(file_mode, _T('b')) ? _T("binary") : _T("text")); //_tprintf(_T("STATUS: (%s) checking for %d bytes in %s mode\n"), file_name, expected, _tcschr(file_mode, _T('b')) ? _T("binary") : _T("text"));
_tprintf(_T("STATUS: (%s) checking for %d bytes with mode %s\n"), file_name, expected, file_mode); _tprintf(_T("STATUS: (%s) checking for %d bytes with mode %s\n"), file_name, expected, file_mode);
} }
file = _tfopen(file_name, file_mode); file = _tfopen(file_name, file_mode);
if (file == NULL) { if (file == NULL) {
_tprintf(_T("ERROR: (%s) failed to open file for reading\n"), file_name); _tprintf(_T("ERROR: (%s) failed to open file for reading\n"), file_name);

View file

@ -32,14 +32,10 @@
#define VERSION 1 #define VERSION 1
#define TEST_BUFFER_SIZE 200
#ifdef UNICODE #ifdef UNICODE
#define TARGET "UNICODE" #define TARGET "UNICODE"
w_char_t test_buffer[TEST_BUFFER_SIZE];
#else #else
#define TARGET "MBCS" #define TARGET "MBCS"
char test_buffer[TEST_BUFFER_SIZE*2];
#endif #endif
BOOL verbose_flagged = 0; BOOL verbose_flagged = 0;
@ -145,10 +141,18 @@ int __cdecl main(int argc, char* argv[])
printf("finished\n"); printf("finished\n");
return result; return result;
} }
/*
ANSI:
all tests passing
UNICODE:
writing binary files short one byte. ie. odd number file lengths.
reading text files returns one extra byte.
*/
#ifndef __GNUC__ #ifndef __GNUC__
char* args[] = { "fileio.exe", "0", "ansi", "verbose"}; char* args[] = { "fileio.exe", "0", "unicode", "verbose"};
char* args1[] = { "fileio.exe", "1", "unicode" }; char* args1[] = { "fileio.exe", "1", "unicode" };
char* args2[] = { "fileio.exe", "2", "unicode" }; char* args2[] = { "fileio.exe", "2", "unicode" };

View file

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.28 2002/11/29 15:59:02 robd Exp $ # $Id: Makefile,v 1.29 2002/12/05 15:30:43 robd Exp $
PATH_TO_TOP = ../.. PATH_TO_TOP = ../..
@ -266,7 +266,8 @@ PROCESS_OBJECTS = \
process/process.o \ process/process.o \
process/procid.o \ process/procid.o \
process/thread.o \ process/thread.o \
process/threadid.o process/threadid.o \
process/threadx.o
SEARCH_OBJECTS = \ SEARCH_OBJECTS = \
search/lfind.o \ search/lfind.o \

View file

@ -1,4 +1,4 @@
/* $Id: open.c,v 1.12 2002/11/24 18:42:22 robd Exp $ /* $Id: open.c,v 1.13 2002/12/05 15:30:44 robd Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -29,6 +29,8 @@
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <msvcrt/msvcrtdbg.h>
//#define _OLD_BUILD_
#define STD_AUX_HANDLE 3 #define STD_AUX_HANDLE 3
#define STD_PRINTER_HANDLE 4 #define STD_PRINTER_HANDLE 4
@ -39,11 +41,11 @@ typedef struct _fileno_modes_type
int fd; int fd;
} fileno_modes_type; } fileno_modes_type;
static fileno_modes_type *fileno_modes = NULL; static fileno_modes_type* fileno_modes = NULL;
int maxfno = 0; int maxfno = 0;
char __is_text_file(FILE *p) char __is_text_file(FILE* p)
{ {
if ( p == NULL || fileno_modes == NULL ) if ( p == NULL || fileno_modes == NULL )
return FALSE; return FALSE;
@ -71,12 +73,11 @@ int _open(const char* _path, int _oflag,...)
// DPRINT("_open('%s', %x, (%x))\n", _path, _oflag, pmode); // DPRINT("_open('%s', %x, (%x))\n", _path, _oflag, pmode);
if (( _oflag & S_IREAD ) == S_IREAD) if ((_oflag & S_IREAD ) == S_IREAD)
dwShareMode = FILE_SHARE_READ; dwShareMode = FILE_SHARE_READ;
else if ( ( _oflag & S_IWRITE) == S_IWRITE ) { else if ((_oflag & S_IWRITE) == S_IWRITE) {
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
} }
/* /*
* *
* _O_BINARY Opens file in binary (untranslated) mode. (See fopen for a description of binary mode.) * _O_BINARY Opens file in binary (untranslated) mode. (See fopen for a description of binary mode.)
@ -84,55 +85,57 @@ int _open(const char* _path, int _oflag,...)
* *
* _O_APPEND Moves file pointer to end of file before every write operation. * _O_APPEND Moves file pointer to end of file before every write operation.
*/ */
if (( _oflag & _O_RDWR ) == _O_RDWR ) #ifdef _OLD_BUILD_
dwDesiredAccess |= GENERIC_WRITE|GENERIC_READ ; if ((_oflag & _O_RDWR) == _O_RDWR)
else if (( _oflag & O_RDONLY ) == O_RDONLY ) dwDesiredAccess |= GENERIC_WRITE|GENERIC_READ;
dwDesiredAccess |= GENERIC_READ ; else if ((_oflag & O_RDONLY) == O_RDONLY)
else if (( _oflag & _O_WRONLY ) == _O_WRONLY ) dwDesiredAccess |= GENERIC_READ;
else if ((_oflag & _O_WRONLY) == _O_WRONLY)
dwDesiredAccess |= GENERIC_WRITE ; dwDesiredAccess |= GENERIC_WRITE ;
#else
if (( _oflag & S_IREAD ) == S_IREAD ) if ((_oflag & _O_WRONLY) == _O_WRONLY )
dwDesiredAccess |= GENERIC_WRITE ;
else if ((_oflag & _O_RDWR) == _O_RDWR )
dwDesiredAccess |= GENERIC_WRITE|GENERIC_READ;
else //if ((_oflag & O_RDONLY) == O_RDONLY)
dwDesiredAccess |= GENERIC_READ;
#endif
if (( _oflag & S_IREAD ) == S_IREAD)
dwShareMode |= FILE_SHARE_READ; dwShareMode |= FILE_SHARE_READ;
if (( _oflag & S_IWRITE ) == S_IWRITE ) if (( _oflag & S_IWRITE ) == S_IWRITE)
dwShareMode |= FILE_SHARE_WRITE; dwShareMode |= FILE_SHARE_WRITE;
if (( _oflag & (_O_CREAT | _O_EXCL ) ) == (_O_CREAT | _O_EXCL) ) if (( _oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
dwCreationDistribution |= CREATE_NEW; dwCreationDistribution |= CREATE_NEW;
else if (( _oflag & O_TRUNC ) == O_TRUNC ) { else if ((_oflag & O_TRUNC ) == O_TRUNC) {
if (( _oflag & O_CREAT ) == O_CREAT ) if ((_oflag & O_CREAT ) == O_CREAT)
dwCreationDistribution |= CREATE_ALWAYS; dwCreationDistribution |= CREATE_ALWAYS;
else if (( _oflag & O_RDONLY ) != O_RDONLY ) else if ((_oflag & O_RDONLY ) != O_RDONLY)
dwCreationDistribution |= TRUNCATE_EXISTING; dwCreationDistribution |= TRUNCATE_EXISTING;
} }
else if (( _oflag & _O_APPEND ) == _O_APPEND ) else if ((_oflag & _O_APPEND) == _O_APPEND)
dwCreationDistribution |= OPEN_EXISTING; dwCreationDistribution |= OPEN_EXISTING;
else if (( _oflag & _O_CREAT ) == _O_CREAT ) else if ((_oflag & _O_CREAT) == _O_CREAT)
dwCreationDistribution |= OPEN_ALWAYS; dwCreationDistribution |= OPEN_ALWAYS;
else else
dwCreationDistribution |= OPEN_EXISTING; dwCreationDistribution |= OPEN_EXISTING;
if (( _oflag & _O_RANDOM ) == _O_RANDOM ) if ((_oflag & _O_RANDOM) == _O_RANDOM )
dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
if (( _oflag & _O_SEQUENTIAL ) == _O_SEQUENTIAL ) if ((_oflag & _O_SEQUENTIAL) == _O_SEQUENTIAL)
dwFlagsAndAttributes |= FILE_FLAG_SEQUENTIAL_SCAN; dwFlagsAndAttributes |= FILE_FLAG_SEQUENTIAL_SCAN;
if ((_oflag & _O_TEMPORARY) == _O_TEMPORARY) {
if (( _oflag & _O_TEMPORARY ) == _O_TEMPORARY )
{
dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE;
DPRINT("FILE_FLAG_DELETE_ON_CLOSE\n"); DPRINT("FILE_FLAG_DELETE_ON_CLOSE\n");
} }
if ((_oflag & _O_SHORT_LIVED) == _O_SHORT_LIVED) {
if (( _oflag & _O_SHORT_LIVED ) == _O_SHORT_LIVED )
{
dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE;
DPRINT("FILE_FLAG_DELETE_ON_CLOSE\n"); DPRINT("FILE_FLAG_DELETE_ON_CLOSE\n");
} }
if (_oflag & _O_NOINHERIT) if (_oflag & _O_NOINHERIT)
sa.bInheritHandle = FALSE; sa.bInheritHandle = FALSE;
hFile = CreateFileA(_path, hFile = CreateFileA(_path,
dwDesiredAccess, dwDesiredAccess,
dwShareMode, dwShareMode,
@ -140,39 +143,33 @@ int _open(const char* _path, int _oflag,...)
dwCreationDistribution, dwCreationDistribution,
dwFlagsAndAttributes, dwFlagsAndAttributes,
NULL); NULL);
if (hFile == (HANDLE)-1) if (hFile == (HANDLE)-1) {
{
dwLastError = GetLastError(); dwLastError = GetLastError();
if (dwLastError == ERROR_ALREADY_EXISTS) if (dwLastError == ERROR_ALREADY_EXISTS) {
{ DPRINT("ERROR_ALREADY_EXISTS\n");
DPRINT("ERROR_ALREADY_EXISTS\n"); __set_errno(EEXIST);
__set_errno(EEXIST); } else {
} DPRINT("%x\n", dwLastError);
else
{
DPRINT("%x\n", dwLastError);
__set_errno(ENOFILE); __set_errno(ENOFILE);
} }
return -1; return -1;
} }
DPRINT("OK\n"); DPRINT("OK\n");
if (!(_oflag & (_O_TEXT|_O_BINARY))) if (!(_oflag & (_O_TEXT|_O_BINARY))) {
{
_oflag |= _fmode; _oflag |= _fmode;
} }
return __fileno_alloc(hFile,_oflag); return __fileno_alloc(hFile,_oflag);
} }
int int __fileno_alloc(HANDLE hFile, int mode)
__fileno_alloc(HANDLE hFile, int mode)
{ {
int i; int i;
/* Check for bogus values */ /* Check for bogus values */
if (hFile < 0) if (hFile < 0)
return -1; return -1;
for(i=5;i<maxfno;i++) { for (i = 5; i < maxfno; i++) {
if (fileno_modes[i].fd == -1 ) { if (fileno_modes[i].fd == -1 ) {
fileno_modes[i].fd = i; fileno_modes[i].fd = i;
fileno_modes[i].mode = mode; fileno_modes[i].mode = mode;
@ -183,16 +180,14 @@ __fileno_alloc(HANDLE hFile, int mode)
/* See if we need to expand the tables. Check this BEFORE it might fail, /* See if we need to expand the tables. Check this BEFORE it might fail,
so that when we hit the count'th request, we've already up'd it. */ so that when we hit the count'th request, we've already up'd it. */
if ( i == maxfno) if (i == maxfno) {
{
int oldcount = maxfno; int oldcount = maxfno;
fileno_modes_type *old_fileno_modes = fileno_modes; fileno_modes_type* old_fileno_modes = fileno_modes;
maxfno += 255; maxfno += 255;
fileno_modes = (fileno_modes_type *)malloc(maxfno * sizeof(fileno_modes_type)); fileno_modes = (fileno_modes_type*)malloc(maxfno * sizeof(fileno_modes_type));
if ( old_fileno_modes != NULL ) if (old_fileno_modes != NULL) {
{
memcpy(fileno_modes, old_fileno_modes, oldcount * sizeof(fileno_modes_type)); memcpy(fileno_modes, old_fileno_modes, oldcount * sizeof(fileno_modes_type));
free ( old_fileno_modes ); free(old_fileno_modes);
} }
memset(fileno_modes + oldcount, -1, (maxfno-oldcount)*sizeof(fileno_modes_type)); memset(fileno_modes + oldcount, -1, (maxfno-oldcount)*sizeof(fileno_modes_type));
} }
@ -204,11 +199,10 @@ __fileno_alloc(HANDLE hFile, int mode)
return i; return i;
} }
void *filehnd(int fileno) void* filehnd(int fileno)
{ {
if ( fileno < 0 || fileno>= maxfno || fileno_modes[fileno].fd == -1) if (fileno < 0 || fileno >= maxfno || fileno_modes[fileno].fd == -1) {
{ return (void*)-1;
return (void *)-1;
} }
return fileno_modes[fileno].hFile; return fileno_modes[fileno].hFile;
} }
@ -216,12 +210,10 @@ void *filehnd(int fileno)
int __fileno_setmode(int _fd, int _newmode) int __fileno_setmode(int _fd, int _newmode)
{ {
int m; int m;
if ( _fd < 0 || _fd >= maxfno ) if (_fd < 0 || _fd >= maxfno) {
{
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
m = fileno_modes[_fd].mode; m = fileno_modes[_fd].mode;
fileno_modes[_fd].mode = _newmode; fileno_modes[_fd].mode = _newmode;
return m; return m;
@ -229,8 +221,7 @@ int __fileno_setmode(int _fd, int _newmode)
int __fileno_getmode(int _fd) int __fileno_getmode(int _fd)
{ {
if ( _fd < 0 || _fd >= maxfno ) if (_fd < 0 || _fd >= maxfno) {
{
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
@ -240,81 +231,72 @@ int __fileno_getmode(int _fd)
int __fileno_close(int _fd) int __fileno_close(int _fd)
{ {
if ( _fd < 0 || _fd >= maxfno ) if (_fd < 0 || _fd >= maxfno) {
{
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
fileno_modes[_fd].fd = -1; fileno_modes[_fd].fd = -1;
fileno_modes[_fd].hFile = (HANDLE)-1; fileno_modes[_fd].hFile = (HANDLE)-1;
return 0; return 0;
} }
int _open_osfhandle (void *osfhandle, int flags ) int _open_osfhandle(void* osfhandle, int flags)
{ {
return __fileno_alloc((HANDLE)osfhandle, flags); return __fileno_alloc((HANDLE)osfhandle, flags);
} }
void *_get_osfhandle( int fileno ) void* _get_osfhandle( int fileno )
{ {
return filehnd(fileno); return filehnd(fileno);
} }
int __fileno_dup2( int handle1, int handle2 ) int __fileno_dup2(int handle1, int handle2)
{ {
HANDLE hProcess; HANDLE hProcess;
BOOL result; BOOL result;
if (handle1 >= maxfno || handle1 < 0 || handle2 >= maxfno || handle2 < 0 ) if (handle1 >= maxfno || handle1 < 0 || handle2 >= maxfno || handle2 < 0) {
{
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
if (fileno_modes[handle1].fd == -1) if (fileno_modes[handle1].fd == -1) {
{
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
if (handle1 == handle2) if (handle1 == handle2)
return handle1; return handle1;
if (fileno_modes[handle2].fd != -1) if (fileno_modes[handle2].fd != -1) {
{
_close(handle2); _close(handle2);
} }
hProcess = GetCurrentProcess(); hProcess = GetCurrentProcess();
result = DuplicateHandle(hProcess, result = DuplicateHandle(hProcess,
fileno_modes[handle1].hFile, fileno_modes[handle1].hFile,
hProcess, hProcess,
&fileno_modes[handle2].hFile, &fileno_modes[handle2].hFile,
0, 0,
TRUE, TRUE,
DUPLICATE_SAME_ACCESS); DUPLICATE_SAME_ACCESS);
if (result) if (result) {
{
fileno_modes[handle2].fd = handle2; fileno_modes[handle2].fd = handle2;
fileno_modes[handle2].mode = fileno_modes[handle1].mode; fileno_modes[handle2].mode = fileno_modes[handle1].mode;
switch (handle2) switch (handle2) {
{ case 0:
case 0: SetStdHandle(STD_INPUT_HANDLE, fileno_modes[handle2].hFile);
SetStdHandle(STD_INPUT_HANDLE, fileno_modes[handle2].hFile); break;
break; case 1:
case 1: SetStdHandle(STD_OUTPUT_HANDLE, fileno_modes[handle2].hFile);
SetStdHandle(STD_OUTPUT_HANDLE, fileno_modes[handle2].hFile); break;
break; case 2:
case 2: SetStdHandle(STD_ERROR_HANDLE, fileno_modes[handle2].hFile);
SetStdHandle(STD_ERROR_HANDLE, fileno_modes[handle2].hFile); break;
break; case 3:
case 3: SetStdHandle(STD_AUX_HANDLE, fileno_modes[handle2].hFile);
SetStdHandle(STD_AUX_HANDLE, fileno_modes[handle2].hFile); break;
break; case 4:
case 4: SetStdHandle(STD_AUX_HANDLE, fileno_modes[handle2].hFile);
SetStdHandle(STD_AUX_HANDLE, fileno_modes[handle2].hFile); break;
break;
} }
return handle1; return handle1;
} } else {
else
{
__set_errno(EMFILE); // Is this the correct error no.? __set_errno(EMFILE); // Is this the correct error no.?
return -1; return -1;
} }
@ -326,14 +308,12 @@ void* malloc(size_t sizeObject);
BOOL __fileno_init(void) BOOL __fileno_init(void)
{ {
ULONG count = 0, i; ULONG count = 0, i;
HANDLE *pFile; HANDLE* pFile;
char* pmode; char* pmode;
STARTUPINFO StInfo; STARTUPINFO StInfo;
GetStartupInfoA(&StInfo); GetStartupInfoA(&StInfo);
if (StInfo.lpReserved2 && StInfo.cbReserved2 >= sizeof(ULONG)) {
if (StInfo.lpReserved2 && StInfo.cbReserved2 >= sizeof(ULONG))
{
count = *(ULONG*)StInfo.lpReserved2; count = *(ULONG*)StInfo.lpReserved2;
/* /*
if (sizeof(ULONG) + count * (sizeof(HANDLE) + sizeof(char)) != StInfo.cbReserved2) if (sizeof(ULONG) + count * (sizeof(HANDLE) + sizeof(char)) != StInfo.cbReserved2)
@ -347,10 +327,11 @@ BOOL __fileno_init(void)
maxfno += 255; maxfno += 255;
{ {
#ifdef _OLD_BUILD_
// why was this here ???? - robd. // why was this here ???? - robd.
//int result; int result;
//result = malloc(50); result = malloc(50);
#endif
} }
//fileno_modes = (fileno_modes_type*)malloc(sizeof(fileno_modes_type) * maxfno); //fileno_modes = (fileno_modes_type*)malloc(sizeof(fileno_modes_type) * maxfno);
fileno_modes = malloc(sizeof(fileno_modes_type) * maxfno); fileno_modes = malloc(sizeof(fileno_modes_type) * maxfno);
@ -358,50 +339,40 @@ BOOL __fileno_init(void)
return FALSE; return FALSE;
} }
memset(fileno_modes, -1, sizeof(fileno_modes_type) * maxfno); memset(fileno_modes, -1, sizeof(fileno_modes_type) * maxfno);
if (count) {
if (count)
{
pFile = (HANDLE*)(StInfo.lpReserved2 + sizeof(ULONG) + count * sizeof(char)); pFile = (HANDLE*)(StInfo.lpReserved2 + sizeof(ULONG) + count * sizeof(char));
pmode = (char*)(StInfo.lpReserved2 + sizeof(ULONG)); pmode = (char*)(StInfo.lpReserved2 + sizeof(ULONG));
for (i = 0; i < count; i++) for (i = 0; i < count; i++) {
{ if (*pFile != INVALID_HANDLE_VALUE) {
if (*pFile != INVALID_HANDLE_VALUE)
{
fileno_modes[i].fd = i; fileno_modes[i].fd = i;
fileno_modes[i].mode = ((*pmode << 8) & (_O_TEXT|_O_BINARY)) | (*pmode & _O_ACCMODE); fileno_modes[i].mode = ((*pmode << 8) & (_O_TEXT|_O_BINARY)) | (*pmode & _O_ACCMODE);
fileno_modes[i].hFile = *pFile; fileno_modes[i].hFile = *pFile;
} }
pFile++; pFile++;
pmode++; pmode++;
} }
} }
if (fileno_modes[0].fd == -1) {
if (fileno_modes[0].fd == -1)
{
fileno_modes[0].fd = 0; fileno_modes[0].fd = 0;
fileno_modes[0].hFile = GetStdHandle(STD_INPUT_HANDLE); fileno_modes[0].hFile = GetStdHandle(STD_INPUT_HANDLE);
fileno_modes[0].mode = _O_RDONLY|_O_TEXT; fileno_modes[0].mode = _O_RDONLY|_O_TEXT;
} }
if (fileno_modes[1].fd == -1) if (fileno_modes[1].fd == -1) {
{
fileno_modes[1].fd = 1; fileno_modes[1].fd = 1;
fileno_modes[1].hFile = GetStdHandle(STD_OUTPUT_HANDLE); fileno_modes[1].hFile = GetStdHandle(STD_OUTPUT_HANDLE);
fileno_modes[1].mode = _O_WRONLY|_O_TEXT; fileno_modes[1].mode = _O_WRONLY|_O_TEXT;
} }
if (fileno_modes[2].fd == -1) if (fileno_modes[2].fd == -1) {
{
fileno_modes[2].fd = 2; fileno_modes[2].fd = 2;
fileno_modes[2].hFile = GetStdHandle(STD_ERROR_HANDLE); fileno_modes[2].hFile = GetStdHandle(STD_ERROR_HANDLE);
fileno_modes[2].mode = _O_WRONLY|_O_TEXT; fileno_modes[2].mode = _O_WRONLY|_O_TEXT;
} }
if (fileno_modes[3].fd == -1) if (fileno_modes[3].fd == -1) {
{
fileno_modes[3].fd = 3; fileno_modes[3].fd = 3;
fileno_modes[3].hFile = GetStdHandle(STD_AUX_HANDLE); fileno_modes[3].hFile = GetStdHandle(STD_AUX_HANDLE);
fileno_modes[3].mode = _O_WRONLY|_O_TEXT; fileno_modes[3].mode = _O_WRONLY|_O_TEXT;
} }
if (fileno_modes[4].fd == -1) if (fileno_modes[4].fd == -1) {
{
fileno_modes[4].fd = 4; fileno_modes[4].fd = 4;
fileno_modes[4].hFile = GetStdHandle(STD_PRINTER_HANDLE); fileno_modes[4].hFile = GetStdHandle(STD_PRINTER_HANDLE);
fileno_modes[4].mode = _O_WRONLY|_O_TEXT; fileno_modes[4].mode = _O_WRONLY|_O_TEXT;

View file

@ -1,4 +1,4 @@
/* $Id: wopen.c,v 1.1 2002/11/24 18:42:22 robd Exp $ /* $Id: wopen.c,v 1.2 2002/12/05 15:30:44 robd Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -49,10 +49,10 @@ int _wopen(const wchar_t* _path, int _oflag, ...)
// DPRINT("_wopen('%S', %x, (%x))\n", _path, _oflag, pmode); // DPRINT("_wopen('%S', %x, (%x))\n", _path, _oflag, pmode);
if (( _oflag & S_IREAD ) == S_IREAD) if ((_oflag & S_IREAD) == S_IREAD)
dwShareMode = FILE_SHARE_READ; dwShareMode = FILE_SHARE_READ;
else if ( ( _oflag & S_IWRITE) == S_IWRITE ) { else if ( ( _oflag & S_IWRITE) == S_IWRITE) {
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
} }
/* /*
@ -62,48 +62,61 @@ int _wopen(const wchar_t* _path, int _oflag, ...)
* *
* _O_APPEND Moves file pointer to end of file before every write operation. * _O_APPEND Moves file pointer to end of file before every write operation.
*/ */
if (( _oflag & _O_RDWR ) == _O_RDWR ) #if 0
if ((_oflag & _O_RDWR) == _O_RDWR)
dwDesiredAccess |= GENERIC_WRITE|GENERIC_READ | FILE_READ_DATA | dwDesiredAccess |= GENERIC_WRITE|GENERIC_READ | FILE_READ_DATA |
FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES |
FILE_WRITE_ATTRIBUTES; FILE_WRITE_ATTRIBUTES;
else if (( _oflag & O_RDONLY ) == O_RDONLY ) else if ((_oflag & O_RDONLY) == O_RDONLY)
dwDesiredAccess |= GENERIC_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES | dwDesiredAccess |= GENERIC_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES |
FILE_WRITE_ATTRIBUTES; FILE_WRITE_ATTRIBUTES;
else if (( _oflag & _O_WRONLY ) == _O_WRONLY ) else if ((_oflag & _O_WRONLY) == _O_WRONLY)
dwDesiredAccess |= GENERIC_WRITE | FILE_WRITE_DATA | dwDesiredAccess |= GENERIC_WRITE | FILE_WRITE_DATA |
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES; FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES;
#else
if ((_oflag & _O_WRONLY) == _O_WRONLY)
dwDesiredAccess |= GENERIC_WRITE | FILE_WRITE_DATA |
FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES;
else if ((_oflag & _O_RDWR) == _O_RDWR)
dwDesiredAccess |= GENERIC_WRITE|GENERIC_READ | FILE_READ_DATA |
FILE_WRITE_DATA | FILE_READ_ATTRIBUTES |
FILE_WRITE_ATTRIBUTES;
else //if ((_oflag & O_RDONLY) == O_RDONLY)
dwDesiredAccess |= GENERIC_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES |
FILE_WRITE_ATTRIBUTES;
#endif
if (( _oflag & S_IREAD ) == S_IREAD ) if ((_oflag & S_IREAD) == S_IREAD)
dwShareMode |= FILE_SHARE_READ; dwShareMode |= FILE_SHARE_READ;
if (( _oflag & S_IWRITE ) == S_IWRITE ) if ((_oflag & S_IWRITE) == S_IWRITE)
dwShareMode |= FILE_SHARE_WRITE; dwShareMode |= FILE_SHARE_WRITE;
if (( _oflag & (_O_CREAT | _O_EXCL ) ) == (_O_CREAT | _O_EXCL) ) if ((_oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
dwCreationDistribution |= CREATE_NEW; dwCreationDistribution |= CREATE_NEW;
else if (( _oflag & O_TRUNC ) == O_TRUNC ) { else if ((_oflag & O_TRUNC) == O_TRUNC) {
if (( _oflag & O_CREAT ) == O_CREAT ) if ((_oflag & O_CREAT) == O_CREAT)
dwCreationDistribution |= CREATE_ALWAYS; dwCreationDistribution |= CREATE_ALWAYS;
else if (( _oflag & O_RDONLY ) != O_RDONLY ) else if ((_oflag & O_RDONLY) != O_RDONLY)
dwCreationDistribution |= TRUNCATE_EXISTING; dwCreationDistribution |= TRUNCATE_EXISTING;
} }
else if (( _oflag & _O_APPEND ) == _O_APPEND ) else if ((_oflag & _O_APPEND) == _O_APPEND)
dwCreationDistribution |= OPEN_EXISTING; dwCreationDistribution |= OPEN_EXISTING;
else if (( _oflag & _O_CREAT ) == _O_CREAT ) else if ((_oflag & _O_CREAT) == _O_CREAT)
dwCreationDistribution |= OPEN_ALWAYS; dwCreationDistribution |= OPEN_ALWAYS;
else else
dwCreationDistribution |= OPEN_EXISTING; dwCreationDistribution |= OPEN_EXISTING;
if (( _oflag & _O_RANDOM ) == _O_RANDOM ) if ((_oflag & _O_RANDOM) == _O_RANDOM)
dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
if (( _oflag & _O_SEQUENTIAL ) == _O_SEQUENTIAL ) if ((_oflag & _O_SEQUENTIAL) == _O_SEQUENTIAL)
dwFlagsAndAttributes |= FILE_FLAG_SEQUENTIAL_SCAN; dwFlagsAndAttributes |= FILE_FLAG_SEQUENTIAL_SCAN;
if (( _oflag & _O_TEMPORARY ) == _O_TEMPORARY ) if ((_oflag & _O_TEMPORARY) == _O_TEMPORARY)
dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE;
if (( _oflag & _O_SHORT_LIVED ) == _O_SHORT_LIVED ) if ((_oflag & _O_SHORT_LIVED) == _O_SHORT_LIVED)
dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE;
if (_oflag & _O_NOINHERIT) if (_oflag & _O_NOINHERIT)
@ -121,7 +134,7 @@ int _wopen(const wchar_t* _path, int _oflag, ...)
return __fileno_alloc(hFile,_oflag); return __fileno_alloc(hFile,_oflag);
} }
int _wsopen(wchar_t *path, int access, int shflag, int mode) int _wsopen(wchar_t* path, int access, int shflag, int mode)
{ {
return _wopen((path), (access)|(shflag), (mode)); return _wopen((path), (access)|(shflag), (mode));
} }

View file

@ -15,9 +15,24 @@
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <msvcrt/msvcrtdbg.h>
#define BUFSIZE 4096 #define BUFSIZE 4096
/*
size_t _write(int _fd, const void *_buf, size_t _nbyte) void ReportLastError(void)
{
DWORD error = GetLastError();
if (error != ERROR_SUCCESS) {
PTSTR msg;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL)) {
printf("ReportLastError() %d - %s\n", error, msg);
} else {
printf("ReportLastError() %d - unknown error\n", error);
}
LocalFree(msg);
}
}
*/
size_t _write(int _fd, const void* _buf, size_t _nbyte)
{ {
char *tmp, *in, *out; char *tmp, *in, *out;
int result; int result;
@ -25,86 +40,57 @@ size_t _write(int _fd, const void *_buf, size_t _nbyte)
DWORD wbyte; DWORD wbyte;
DPRINT("_write(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte); DPRINT("_write(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
if (__fileno_getmode(_fd) & O_TEXT) if (__fileno_getmode(_fd) & O_TEXT) {
{
result = _nbyte; result = _nbyte;
tmp = (char*) malloc(BUFSIZE); tmp = (char*) malloc(BUFSIZE);
if (tmp == NULL) if (tmp == NULL) {
{ return -1;
return -1;
} }
count = BUFSIZE; count = BUFSIZE;
out = tmp; out = tmp;
in = (char*) _buf; in = (char*) _buf;
while (_nbyte--) while (_nbyte--) {
{ if (*in == 0x0a) {
if (*in == 0x0a) *out++ = 0x0d;
{ count--;
*out++ = 0x0d; if (count == 0) {
count--; if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) {
if (count == 0) //ReportLastError();
{ result = -1;
if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) break;
{ }
result = -1; if (wbyte < BUFSIZE) {
break; result = in - (char*)_buf;
} break;
if (wbyte < BUFSIZE) }
{ count = BUFSIZE;
result = in - (char*)_buf; out = tmp;
break; }
} }
count = BUFSIZE; *out++ = *in++;
out = tmp; count--;
} if (count == 0 || _nbyte == 0) {
} int tmp_len_debug = strlen(tmp);
*out++ = *in++; if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) {
count--; //ReportLastError();
if (count == 0 || _nbyte == 0) result = -1;
{ tmp_len_debug = 0;
if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) break;
{ }
result = -1; if (wbyte < (BUFSIZE - count)) {
break; result = in - (char*)_buf;
} break;
if (wbyte < (BUFSIZE - count)) }
{ count = BUFSIZE;
result = in - (char*)_buf; out = tmp;
break; }
}
count = BUFSIZE;
out = tmp;
}
} }
free(tmp); free(tmp);
return result; return result;
} } else {
else if(!WriteFile(_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) {
{ //ReportLastError();
if(!WriteFile(_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) return -1;
{
DWORD error = GetLastError();
if (error != ERROR_SUCCESS) {
PTSTR msg;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL))
printf("_write(fd %d, buf %x, nbyte %d) - %s\n", _fd, _buf, _nbyte, msg);
else
printf("_write(fd %d, buf %x, nbyte %d) - unknown error: %d\n", _fd, _buf, _nbyte, msg, error);
LocalFree(msg);
}
/*
DWORD FormatMessage(
DWORD dwFlags, // source and processing options
LPCVOID lpSource, // message source
DWORD dwMessageId, // message identifier
DWORD dwLanguageId, // language identifier
LPTSTR lpBuffer, // message buffer
DWORD nSize, // maximum size of message buffer
va_list *Arguments // array of message inserts
);
*/
return -1;
} }
return wbyte; return wbyte;
} }

View file

@ -1,7 +1,7 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* FILE: lib/crtdll/mbstring/mbbtype.c * FILE: lib/msvcrt/mbstring/mbbtype.c
* PURPOSE: Determines the type of a multibyte character * PURPOSE: Determines the type of a multibyte character
* PROGRAMER: Boudewijn Dekker * PROGRAMER: Boudewijn Dekker
* UPDATE HISTORY: * UPDATE HISTORY:
@ -23,9 +23,7 @@ int _mbbtype(unsigned char c , int type)
return _MBC_ILLEGAL; return _MBC_ILLEGAL;
else else
return 0; return 0;
} else {
}
else {
if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) { if (( c >= 0x20 && c <= 0x7E ) || ( c >= 0xA1 && c <= 0xDF )) {
return _MBC_SINGLE; return _MBC_SINGLE;
} }
@ -36,10 +34,7 @@ int _mbbtype(unsigned char c , int type)
return _MBC_ILLEGAL; return _MBC_ILLEGAL;
else else
return 0; return 0;
} }
return 0; return 0;
} }

View file

@ -1,4 +1,4 @@
/* $Id: crtmain.c,v 1.2 2002/11/25 17:41:39 robd Exp $ /* $Id: crtmain.c,v 1.3 2002/12/05 15:30:44 robd Exp $
* *
* ReactOS MSVCRT.DLL Compatibility Library * ReactOS MSVCRT.DLL Compatibility Library
*/ */
@ -17,8 +17,6 @@ int _fltused;
/* FUNCTIONS **************************************************************/ /* FUNCTIONS **************************************************************/
/*
*/
int int
STDCALL STDCALL
_except_handler3(void) _except_handler3(void)

View file

@ -11,46 +11,36 @@
#include <msvcrt/wchar.h> #include <msvcrt/wchar.h>
#include <msvcrt/errno.h> #include <msvcrt/errno.h>
int _readcnv(int fn, void *buf, size_t siz ); int _readcnv(int fn, void* buf, size_t siz);
int int _filbuf(FILE* f)
_filbuf(FILE *f)
{ {
int size; int size;
char c; char c;
if ( !OPEN4READING(f)) { if ( !OPEN4READING(f)) {
__set_errno (EINVAL); __set_errno (EINVAL);
return EOF; return EOF;
} }
if (f->_flag&(_IOSTRG|_IOEOF)) if (f->_flag&(_IOSTRG|_IOEOF))
return EOF; return EOF;
f->_flag &= ~_IOUNGETC; f->_flag &= ~_IOUNGETC;
if (f->_base==NULL && (f->_flag&_IONBF)==0) { if (f->_base == NULL && (f->_flag & _IONBF) == 0) {
size = 4096; size = 4096;
if ((f->_base = malloc(size+1)) == NULL) if ((f->_base = malloc(size+1)) == NULL) {
{
// error ENOMEM // error ENOMEM
f->_flag |= _IONBF; f->_flag |= _IONBF;
f->_flag &= ~(_IOFBF|_IOLBF); f->_flag &= ~(_IOFBF|_IOLBF);
} } else {
else
{
f->_flag |= _IOMYBUF; f->_flag |= _IOMYBUF;
f->_bufsiz = size; f->_bufsiz = size;
} }
} }
if (f->_flag&_IONBF) if (f->_flag&_IONBF)
f->_base = &c; f->_base = &c;
// flush stdout before reading from stdin
// fush stdout before reading from stdin
if (f == stdin) { if (f == stdin) {
if (stdout->_flag&_IOLBF) if (stdout->_flag&_IOLBF)
fflush(stdout); fflush(stdout);
@ -58,8 +48,8 @@ _filbuf(FILE *f)
fflush(stderr); fflush(stderr);
} }
// if we have a dirty stream we flush it // if we have a dirty stream we flush it
if ( (f->_flag &_IODIRTY) == _IODIRTY ) if ((f->_flag &_IODIRTY) == _IODIRTY)
fflush(f); fflush(f);
@ -99,6 +89,7 @@ _filbuf(FILE *f)
} }
f->_cnt--; f->_cnt--;
return *f->_ptr++ & 0377; return *f->_ptr++ & 0377;
} }

View file

@ -10,147 +10,147 @@
#include <msvcrt/errno.h> #include <msvcrt/errno.h>
int cntcr(char *bufp, int bufsiz); int cntcr(char* bufp, int bufsiz);
int convert(char *endp, int bufsiz,int n); int convert(char* endp, int bufsiz, int n);
int _writecnv(int fn, void *buf, size_t bufsiz); int _writecnv(int fn, void* buf, size_t bufsiz);
int _flsbuf(int c, FILE *f) int _flsbuf(int c, FILE* f)
{ {
char *base; char* base;
int n, rn; int n, rn;
char c1; char c1;
int size; int size;
if (!OPEN4WRITING(f)) { if (!OPEN4WRITING(f)) {
__set_errno(EINVAL); __set_errno(EINVAL);
return EOF; 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) {
size = 4096;
if ((f->_base = base = malloc (size)) == NULL) {
f->_flag |= _IONBF;
f->_flag &= ~(_IOFBF|_IOLBF);
} else {
f->_flag |= _IOMYBUF;
f->_cnt = f->_bufsiz = size;
f->_ptr = base;
rn = 0;
if (f == stdout && isatty (fileno (stdout))) {
f->_flag |= _IOLBF;
}
} }
}
if (f->_flag & _IOLBF) { // no file associated with buffer, this is a memory stream
/* in line-buffering mode we get here on each character */ if (fileno(f) == -1) {
*f->_ptr++ = c; return c;
rn = f->_ptr - base;
if (c == '\n' || rn >= f->_bufsiz) {
/* time for real flush */
f->_ptr = base;
f->_cnt = 0;
} else {
/* we got here because _cnt is wrong, so fix it */
/* Negative _cnt causes all output functions to call */
/* _flsbuf for each character, thus realizing line-buffering */
f->_cnt = -rn;
return c;
} }
} else if (f->_flag & _IONBF) {
c1 = c; /* if the buffer is not yet allocated, allocate it */
rn = 1; if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0) {
base = &c1; size = 4096;
f->_cnt = 0; if ((f->_base = base = malloc(size)) == NULL) {
} else { /* _IOFBF */ f->_flag |= _IONBF;
rn = f->_ptr - base; f->_flag &= ~(_IOFBF|_IOLBF);
f->_ptr = base; } else {
if ( (f->_flag & _IOAHEAD) == _IOAHEAD ) f->_flag |= _IOMYBUF;
_lseek(fileno(f),-(rn+f->_cnt), SEEK_CUR); f->_cnt = f->_bufsiz = size;
f->_cnt = f->_bufsiz; f->_ptr = base;
f->_flag &= ~_IOAHEAD; rn = 0;
} if (f == stdout && isatty(fileno(stdout))) {
f->_flag &= ~_IODIRTY; f->_flag |= _IOLBF;
while (rn > 0) { }
n = _write(fileno(f), base, rn); }
if (n <= 0) {
f->_flag |= _IOERR;
return EOF;
} }
rn -= n;
base += n; if (f->_flag & _IOLBF) {
} /* in line-buffering mode we get here on each character */
if ((f->_flag&(_IOLBF|_IONBF)) == 0) { *f->_ptr++ = c;
f->_cnt--; rn = f->_ptr - base;
*f->_ptr++ = c; if (c == '\n' || rn >= f->_bufsiz) {
} /* time for real flush */
return c; f->_ptr = base;
f->_cnt = 0;
} else {
/* we got here because _cnt is wrong, so fix it */
/* Negative _cnt causes all output functions to call */
/* _flsbuf for each character, thus realizing line-buffering */
f->_cnt = -rn;
return c;
}
} else if (f->_flag & _IONBF) {
c1 = c;
rn = 1;
base = &c1;
f->_cnt = 0;
} else { /* _IOFBF */
rn = f->_ptr - base;
f->_ptr = base;
if ((f->_flag & _IOAHEAD) == _IOAHEAD)
_lseek(fileno(f), -(rn+f->_cnt), SEEK_CUR);
f->_cnt = f->_bufsiz;
f->_flag &= ~_IOAHEAD;
}
f->_flag &= ~_IODIRTY;
while (rn > 0) {
n = _write(fileno(f), base, rn);
if (n <= 0) {
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
}
if ((f->_flag & (_IOLBF|_IONBF)) == 0) {
f->_cnt--;
*f->_ptr++ = c;
}
return c;
} }
wint_t _flswbuf(wchar_t c, FILE *fp) wint_t _flswbuf(wchar_t c, FILE* fp)
{ {
int result; int result;
result = _flsbuf((int)c, fp); result = _flsbuf((int)c, fp);
if (result == EOF) if (result == EOF)
return WEOF; return WEOF;
return (wint_t)result; return (wint_t)result;
} }
int _writecnv(int fn, void *buf, size_t siz) int _writecnv(int fn, void* buf, size_t siz)
{ {
char *bufp = (char*)buf; char* bufp = (char*)buf;
int bufsiz = siz; int bufsiz = siz;
char *tmp; char* tmp;
int cr1 = 0; int cr1 = 0;
int cr2 = 0; int cr2 = 0;
int n; int n;
cr1 = cntcr(bufp,bufsiz); cr1 = cntcr(bufp, bufsiz);
tmp = malloc(cr1); tmp = malloc(cr1);
memcpy(tmp,bufp+bufsiz-cr1,cr1); memcpy(tmp, bufp + bufsiz - cr1, cr1);
cr2 = cntcr(tmp,cr1); cr2 = cntcr(tmp, cr1);
convert(bufp,bufsiz-cr2,cr1-cr2); convert(bufp, bufsiz - cr2, cr1 - cr2);
n = _write(fn, bufp, bufsiz + cr1); n = _write(fn, bufp, bufsiz + cr1);
convert(tmp,cr1,cr2); convert(tmp, cr1, cr2);
n += _write(fn, tmp, cr1 + cr2); n += _write(fn, tmp, cr1 + cr2);
free(tmp); free(tmp);
return n; return n;
} }
int convert(char *endp, int bufsiz,int n) int convert(char* endp, int bufsiz, int n)
{ {
endp = endp + bufsiz + n; endp = endp + bufsiz + n;
while (bufsiz > 0) { while (bufsiz > 0) {
*endp = *(endp - n); *endp = *(endp - n);
if (*endp == '\n') { if (*endp == '\n') {
*endp--; *endp--;
n--; n--;
*endp = '\r'; *endp = '\r';
}
endp--;
bufsiz--;
}
return n;
}
int cntcr(char *bufp, int bufsiz)
{
int cr = 0;
while (bufsiz > 0) {
if (*bufp == '\n') {
cr++;
} }
bufp++; endp--;
bufsiz--; bufsiz--;
} }
return cr; return n;
}
int cntcr(char* bufp, int bufsiz)
{
int cr = 0;
while (bufsiz > 0) {
if (*bufp == '\n') {
cr++;
}
bufp++;
bufsiz--;
}
return cr;
} }

View file

@ -1,4 +1,4 @@
/* $Id: getc.c,v 1.5 2002/11/24 18:42:24 robd Exp $ /* $Id: getc.c,v 1.6 2002/12/05 15:30:44 robd Exp $
* *
* ReactOS msvcrt library * ReactOS msvcrt library
* *
@ -38,19 +38,17 @@
int getc(FILE *fp) int getc(FILE *fp)
{ {
int c = -1; int c = -1;
// check for invalid stream
// check for invalid stream
if ( !__validfp (fp) ) { if ( !__validfp (fp) ) {
__set_errno(EINVAL); __set_errno(EINVAL);
return EOF; return EOF;
} }
// check for read access on stream // check for read access on stream
if ( !OPEN4READING(fp) ) { if ( !OPEN4READING(fp) ) {
__set_errno(EINVAL); __set_errno(EINVAL);
return EOF; return EOF;
} }
if(fp->_cnt > 0) { if(fp->_cnt > 0) {
fp->_cnt--; fp->_cnt--;
c = (int)*fp->_ptr++; c = (int)*fp->_ptr++;
@ -69,25 +67,22 @@ wint_t getwc(FILE *fp)
__set_errno(EINVAL); __set_errno(EINVAL);
return WEOF; return WEOF;
} }
// check for read access on stream // check for read access on stream
//#define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD ) ) //#define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD ) )
if (!OPEN4READING(fp)) { if (!OPEN4READING(fp)) {
__set_errno(EINVAL); __set_errno(EINVAL);
return WEOF; return WEOF;
} }
// might check on multi bytes if text mode // might check on multi bytes if text mode
if (fp->_flag & _IOBINARY) { if (fp->_flag & _IOBINARY) {
if (fp->_cnt > 1) {
if (fp->_cnt > 0) {
fp->_cnt -= sizeof(wchar_t); fp->_cnt -= sizeof(wchar_t);
c = (wint_t)*((wchar_t*)(fp->_ptr))++; c = (wint_t)*((wchar_t*)(fp->_ptr))++;
} else { } else {
c = _filwbuf(fp); c = _filwbuf(fp);
} }
} else { } else {
#if 0
BOOL get_bytes = 0; BOOL get_bytes = 0;
int mb_cnt = 0; int mb_cnt = 0;
int found_cr = 0; int found_cr = 0;
@ -95,41 +90,19 @@ wint_t getwc(FILE *fp)
char mbchar[MB_CUR_MAX]; char mbchar[MB_CUR_MAX];
do { do {
if (fp->_cnt > 0) { if (fp->_cnt > 0) {
fp->_cnt--; fp->_cnt--;
mbchar[mb_cnt] = *fp->_ptr++; mbchar[mb_cnt] = *fp->_ptr++;
} else { } else {
mbchar[mb_cnt] = _filbuf(fp); mbchar[mb_cnt] = _filbuf(fp);
} }
/*
// convert cr/lf pairs into a single lf.
if (mbchar[mb_cnt] == '\r') {
//found_cr = 1;
if (fp->_cnt > 0) {
fp->_cnt--;
mbchar[mb_cnt+1] = *fp->_ptr++;
} else {
mbchar[mb_cnt+1] = _filbuf(fp);
}
if (mbchar[mb_cnt+1] == '\n') {
mbchar[mb_cnt] = '\n';
} else {
++mb_cnt;
}
}
*/
if (isleadbyte(mbchar[mb_cnt])) { if (isleadbyte(mbchar[mb_cnt])) {
get_bytes = 1; get_bytes = 1;
} else { } else {
get_bytes = 0; get_bytes = 0;
} }
if (_ismbblead(mbchar[mb_cnt])) { if (_ismbblead(mbchar[mb_cnt])) {
} }
++mb_cnt; ++mb_cnt;
//} //}
} while (get_bytes); } while (get_bytes);
@ -140,9 +113,15 @@ wint_t getwc(FILE *fp)
fp->_flag |= _IOERR; fp->_flag |= _IOERR;
return WEOF; return WEOF;
} }
#else
if (fp->_cnt > 0) {
fp->_cnt--;
c = *fp->_ptr++;
} else {
c = _filbuf(fp);
}
#endif
} }
return c; return c;
} }
// MultiByteToWideChar
// WideCharToMultiByte

View file

@ -20,35 +20,25 @@
#include <msvcrt/stdio.h> #include <msvcrt/stdio.h>
#include <msvcrt/wchar.h> #include <msvcrt/wchar.h>
/* Write formatted output to stdout from the format string FORMAT. */
/* VARARGS1 */
int
printf (const char *format, ...)
{
va_list arg;
int done;
va_start (arg, format); int printf(const char* format, ...)
done = vprintf (format, arg); {
va_end (arg); va_list arg;
return done; int done;
va_start(arg, format);
done = vprintf(format, arg);
va_end(arg);
return done;
} }
int int wprintf(const wchar_t* format, ...)
wprintf (const wchar_t *format, ...)
{ {
va_list arg; va_list arg;
int done; int done;
va_start (arg, format); va_start(arg, format);
done = vwprintf (format, arg); done = vwprintf(format, arg);
va_end (arg); va_end(arg);
return done; return done;
} }
#ifdef USE_IN_LIBIO
# undef _IO_printf
/* This is for libg++. */
strong_alias (printf, _IO_printf);
#endif

View file

@ -1,4 +1,4 @@
/* $Id: putc.c,v 1.5 2002/11/24 18:42:24 robd Exp $ /* $Id: putc.c,v 1.6 2002/12/05 15:30:44 robd Exp $
* *
* ReactOS msvcrt library * ReactOS msvcrt library
* *
@ -38,7 +38,7 @@
#define MB_CUR_MAX_CONST 10 #define MB_CUR_MAX_CONST 10
#endif #endif
int putc(int c, FILE *fp) int putc(int c, FILE* fp)
{ {
// valid stream macro should check that fp is dword aligned // valid stream macro should check that fp is dword aligned
if (!__validfp(fp)) { if (!__validfp(fp)) {
@ -61,13 +61,9 @@ int putc(int c, FILE *fp)
return EOF; return EOF;
} }
//wint_t putwc(wint_t c, FILE *fp) //wint_t putwc(wint_t c, FILE* fp)
int putwc(wint_t c, FILE *fp) int putwc(wint_t c, FILE* fp)
{ {
int i;
int mb_cnt;
char mbchar[MB_CUR_MAX_CONST];
// valid stream macro should check that fp is dword aligned // valid stream macro should check that fp is dword aligned
if (!__validfp(fp)) { if (!__validfp(fp)) {
__set_errno(EINVAL); __set_errno(EINVAL);
@ -83,17 +79,33 @@ int putwc(wint_t c, FILE *fp)
//if (1) { //if (1) {
fp->_flag |= _IODIRTY; fp->_flag |= _IODIRTY;
if (fp->_cnt > 0 ) { if (fp->_cnt > 0) {
fp->_cnt -= sizeof(wchar_t); fp->_cnt -= sizeof(wchar_t);
//*((wchar_t*)(fp->_ptr))++ = c; //*((wchar_t*)(fp->_ptr))++ = c;
*((wchar_t*)(fp->_ptr)) = c; *((wchar_t*)(fp->_ptr)) = c;
++((wchar_t*)(fp->_ptr)); ++((wchar_t*)(fp->_ptr));
return (wint_t)c; return (wint_t)c;
} else { } else {
#if 1
wint_t result;
result = _flsbuf((int)(c >> 8), fp);
if (result == EOF)
return WEOF;
result = _flsbuf(c, fp);
if (result == EOF)
return WEOF;
return result;
#else
return _flswbuf(c, fp); return _flswbuf(c, fp);
#endif
} }
} else { } else {
#if 0
int i;
int mb_cnt;
char mbchar[MB_CUR_MAX_CONST];
// Convert wide character to the corresponding multibyte character. // Convert wide character to the corresponding multibyte character.
mb_cnt = wctomb(mbchar, (wchar_t)c); mb_cnt = wctomb(mbchar, (wchar_t)c);
if (mb_cnt == -1) { if (mb_cnt == -1) {
@ -105,19 +117,6 @@ int putwc(wint_t c, FILE *fp)
} }
for (i = 0; i < mb_cnt; i++) { for (i = 0; i < mb_cnt; i++) {
fp->_flag |= _IODIRTY; fp->_flag |= _IODIRTY;
#if 0
// convert lf's into a cr/lf pair.
if (mbchar[i] == '\n') {
if (fp->_cnt > 0) {
fp->_cnt--;
*(fp)->_ptr++ = (unsigned char)'\r';
} else {
if (_flsbuf((unsigned char)'\r', fp) == EOF) {
return WEOF;
}
}
}
#endif
if (fp->_cnt > 0) { if (fp->_cnt > 0) {
fp->_cnt--; fp->_cnt--;
*(fp)->_ptr++ = (unsigned char)mbchar[i]; *(fp)->_ptr++ = (unsigned char)mbchar[i];
@ -127,6 +126,17 @@ int putwc(wint_t c, FILE *fp)
} }
} }
} }
#else
fp->_flag |= _IODIRTY;
if (fp->_cnt > 0) {
fp->_cnt--;
*(fp)->_ptr++ = (unsigned char)c;
} else {
if (_flsbuf(c, fp) == EOF) {
return WEOF;
}
}
#endif
return c; return c;
} }
return WEOF; return WEOF;

View file

@ -11,36 +11,34 @@ int _isinf(double x);
int int __vfprintf(FILE*, const char*, va_list);
__vfprintf (FILE *fp, const char *fmt0, va_list args);
int
vfprintf(FILE *f, const char *fmt, va_list ap) int vfprintf(FILE* f, const char* fmt, va_list ap)
{ {
int len; int len;
char localbuf[BUFSIZ]; char localbuf[BUFSIZ];
#if 0 #if 0
__fileno_lock(fileno(f)); __fileno_lock(fileno(f));
#endif #endif
if (f->_flag & _IONBF) if (f->_flag & _IONBF) {
{ f->_flag &= ~_IONBF;
f->_flag &= ~_IONBF; f->_ptr = f->_base = localbuf;
f->_ptr = f->_base = localbuf; f->_bufsiz = BUFSIZ;
f->_bufsiz = BUFSIZ; len = __vfprintf(f, fmt, ap);
len = __vfprintf(f,fmt, ap); (void)fflush(f);
(void)fflush(f); f->_flag |= _IONBF;
f->_flag |= _IONBF; f->_base = NULL;
f->_base = NULL; f->_bufsiz = 0;
f->_bufsiz = 0; f->_cnt = 0;
f->_cnt = 0; } else {
} len = __vfprintf(f,fmt, ap);
else }
len = __vfprintf(f,fmt, ap);
#if 0 #if 0
__fileno_unlock(fileno(f)); __fileno_unlock(fileno(f));
#endif #endif
return (ferror(f) ? EOF : len); return (ferror(f) ? EOF : len);
} }

View file

@ -794,7 +794,7 @@ int __vfscanf (FILE *s, const char *format, va_list argptr)
else else
{ {
if (flags & LONGDBL) { if (flags & LONGDBL) {
*ARG (LONGLONG *) = num.q; *ARG (LONGLONG*) = num.q;
} }
else if (flags & LONG) else if (flags & LONG)
*ARG (long int *) = num.l; *ARG (long int *) = num.l;

View file

@ -21,27 +21,57 @@ Cambridge, MA 02139, USA. */
#include <msvcrt/stdio.h> #include <msvcrt/stdio.h>
#include <msvcrt/wchar.h> #include <msvcrt/wchar.h>
#undef vprintf #undef vprintf
#undef vwprintf #undef vwprintf
/* Write formatted output to stdout according to the //#define _USE_VARARG_
format string FORMAT, using the argument list in ARG. */
int #ifndef _USE_VARARG_
vprintf (format, arg)
const char *format; int vprintf(const char* format, va_list arg)
va_list arg;
{ {
int ret = vfprintf (stdout, format, arg); int ret;
fflush(stdout);
return ret; ret = vfprintf(stdout, format, arg);
fflush(stdout);
return ret;
} }
int int vwprintf(const wchar_t* format, va_list arg)
vwprintf (format, arg)
const wchar_t *format;
va_list arg;
{ {
int ret = vfwprintf (stdout, format, arg); int ret;
fflush(stdout);
return ret; ret = vfwprintf(stdout, format, arg);
fflush(stdout);
return ret;
} }
#else
int vprintf(const char* format, ...)
{
va_list arg;
int ret;
va_start(arg, format);
ret = vfprintf(stdout, format, arg);
va_end(arg);
fflush(stdout);
return ret;
}
int vwprintf(const wchar_t* format, ...)
{
va_list arg;
int ret;
va_start(arg, format);
ret = vfwprintf(stdout, format, arg);
va_end(arg);
fflush(stdout);
return ret;
}
#endif

View file

@ -1,37 +1,118 @@
#include <windows.h>
#include <msvcrt/stdlib.h> #include <msvcrt/stdlib.h>
size_t mbstowcs( wchar_t *wcstr, const char *mbstr, size_t count ) #if 1
size_t mbstowcs(wchar_t* wcstr, const char* mbstr, size_t count)
{ {
size_t Size; size_t size;
return (size_t)Size; int i;
printf("\nmbstowcs(%p, %p, %d) called.\n\n", wcstr, mbstr, count);
if (count <= 0 || !mbstr)
return 0;
if (!*mbstr)
return 0;
if (wcstr == NULL) {
// return required size for the converted string
return strlen(mbstr); // TODO: fixme
}
for (size = 0, i = 0; i < count; size++) {
int result;
////int mbtowc( wchar_t *wchar, const char *mbchar, size_t count )
//// result = mbtowc(wcstr + size, mbstr + i, count - i);
// result = mbtowc(wcstr + size, mbstr + i, 1);
/////////////////////////////////////////
if (mbstr[i] == 0) {
result = 0;
} else {
wcstr[size] = mbstr[i];
result = 1;
}
/////////////////////////////////////////
if (result == -1) {
return -1;
} else if (result == 0) {
wcstr[size] = L'\0';
break;
} else {
i += result;
}
}
return size;
} }
/* #else
NTSTATUS Status; #if 1
ULONG Size;
ULONG Length;
Length = strlen (mbstr); //int mbtowc(wchar_t *dst, const char *str, size_t n)
size_t mbstowcs(wchar_t* wcstr, const char* mbstr, size_t count)
{
size_t len;
if (wcstr == NULL) if (count <= 0 || !mbstr)
{ return 0;
RtlMultiByteToUnicodeSize (&Size, len = MultiByteToWideChar(CP_ACP, 0, mbstr, count, wcstr, (wcstr == NULL) ? 0 : count);
(char *)mbstr,
Length);
return (size_t)Size; if (!len) {
} DWORD err = GetLastError();
switch (err) {
case ERROR_INSUFFICIENT_BUFFER:
break;
case ERROR_INVALID_FLAGS:
break;
case ERROR_INVALID_PARAMETER:
break;
case ERROR_NO_UNICODE_TRANSLATION:
break;
default:
return 1;
}
return -1;
}
/* return the number of bytes from src that have been used */
if (!*mbstr)
return 0;
// if (count >= 2 && isleadbyte(*mbstr) && mbstr[1])
// return 2;
return len;
}
Status = RtlMultiByteToUnicodeN (wcstr, #else
count,
&Size, size_t mbstowcs(wchar_t* wcstr, const char* mbstr, size_t count)
(char *)mbstr, {
Length); size_t size;
if (!NT_SUCCESS(Status)) int i;
return -1;
*/ if (wcstr == NULL) {
// return required size for the converted string
return strlen(mbstr); // TODO: fixme
}
for (size = 0, i = 0; i < count; size++) {
int result;
//int mbtowc( wchar_t *wchar, const char *mbchar, size_t count ) //int mbtowc( wchar_t *wchar, const char *mbchar, size_t count )
//{ // result = mbtowc(wcstr + size, mbstr + i, count - i);
// return 0; result = mbtowc(wcstr + size, mbstr + i, 1);
//} if (result == -1) {
return -1;
} else if (result == 0) {
wcstr[size] = L'\0';
break;
} else {
i += result;
}
}
return (size_t)size;
}
#endif
#endif

View file

@ -1,12 +1,52 @@
#include <windows.h>
#include <msvcrt/stdlib.h> #include <msvcrt/stdlib.h>
#include <msvcrt/ctype.h>
//int mbtowc(wchar_t* wcDest, const char* mbConvert, size_t size) #if 1
int mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
int mbtowc(wchar_t *dst, const char *str, size_t n)
{ {
*wchar = (wchar_t)*mbchar; // printf("\t\t\tmbtowc(%p, %p, %d) called.\n", dst, str, n);
return 1;
// WideCharToMultiByte if (n <= 0 || !str)
// MultiByteToWideChar return 0;
*dst = *str;
if (!*str)
return 0;
return 1;
} }
#else
int mbtowc(wchar_t *dst, const char *str, size_t n)
{
if (n <= 0 || !str)
return 0;
if (!MultiByteToWideChar(CP_ACP, 0, str, n, dst, (dst == NULL) ? 0 : 1)) {
DWORD err = GetLastError();
switch (err) {
case ERROR_INSUFFICIENT_BUFFER:
break;
case ERROR_INVALID_FLAGS:
break;
case ERROR_INVALID_PARAMETER:
break;
case ERROR_NO_UNICODE_TRANSLATION:
break;
default:
return 1;
}
return -1;
}
/* return the number of bytes from src that have been used */
if (!*str)
return 0;
if (n >= 2 && isleadbyte(*str) && str[1])
return 2;
return 1;
}
#endif

View file

@ -29,7 +29,7 @@
static const wchar_t encoding_mask[] = static const wchar_t encoding_mask[] =
{ {
(wchar_t)~0x7ff, (wchar_t)~0xffff, (wchar_t)~0x1fffff, (wchar_t)~0x3ffffff ~0x7ff, ~0xffff, ~0x1fffff, ~0x3ffffff
}; };
static const unsigned char encoding_byte[] = static const unsigned char encoding_byte[] =

View file

@ -16,11 +16,43 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <windows.h>
#include <msvcrt/stdlib.h> #include <msvcrt/stdlib.h>
#include <msvcrt/ctype.h>
#include <msvcrt/wchar.h> #include <msvcrt/wchar.h>
#include <msvcrt/errno.h> #include <msvcrt/errno.h>
#include <msvcrt/internal/file.h> #include <msvcrt/internal/file.h>
int
STDCALL
WideCharToMultiByte(
UINT CodePage,
DWORD dwFlags,
LPCWSTR lpWideCharStr,
int cchWideChar,
LPSTR lpMultiByteStr,
int cchMultiByte,
LPCSTR lpDefaultChar,
LPBOOL lpUsedDefaultChar);
int wctomb(char* dst, wchar_t ch)
{
#if 0
return WideCharToMultiByte(CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL);
#else
if (dst == NULL) {
return 1;
}
*dst = ch;
return 1;
#endif
}
#if 0
#ifndef EILSEQ #ifndef EILSEQ
#define EILSEQ EINVAL #define EILSEQ EINVAL
#endif #endif
@ -110,3 +142,5 @@ size_t __wcrtomb(char *s, wchar_t wc)
} }
return written; return written;
} }
#endif

View file

@ -1,4 +1,4 @@
/* $Id: witow.c,v 1.1 2002/11/24 18:42:25 robd Exp $ /* $Id: witow.c,v 1.2 2002/12/05 15:30:45 robd Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -26,8 +26,7 @@ wchar_t* _i64tow(__int64 value, wchar_t* string, int radix)
int sign; int sign;
wchar_t* sp; wchar_t* sp;
if (radix > 36 || radix <= 1) if (radix > 36 || radix <= 1) {
{
__set_errno(EDOM); __set_errno(EDOM);
return 0; return 0;
} }
@ -37,8 +36,7 @@ wchar_t* _i64tow(__int64 value, wchar_t* string, int radix)
v = -value; v = -value;
else else
v = (unsigned)value; v = (unsigned)value;
while (v || tp == tmp) while (v || tp == tmp) {
{
i = v % radix; i = v % radix;
v = v / radix; v = v / radix;
if (i < 10) if (i < 10)
@ -67,14 +65,12 @@ wchar_t* _ui64tow(unsigned __int64 value, wchar_t* string, int radix)
unsigned long v = value; unsigned long v = value;
wchar_t* sp; wchar_t* sp;
if (radix > 36 || radix <= 1) if (radix > 36 || radix <= 1) {
{
__set_errno(EDOM); __set_errno(EDOM);
return 0; return 0;
} }
while (v || tp == tmp) while (v || tp == tmp) {
{
i = v % radix; i = v % radix;
v = v / radix; v = v / radix;
if (i < 10) if (i < 10)

View file

@ -1,6 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/string.h> #include <msvcrt/string.h>
#pragma function(memcmp)
int memcmp(const void *s1, const void *s2, size_t n) int memcmp(const void *s1, const void *s2, size_t n)
{ {

View file

@ -1,5 +1,6 @@
#include <msvcrt/string.h> #include <msvcrt/string.h>
#pragma function(memcpy)
/* This is the most reliable way to avoid incompatibilities /* This is the most reliable way to avoid incompatibilities
in available built-in functions on various systems. */ in available built-in functions on various systems. */

View file

@ -1,5 +1,6 @@
#include <msvcrt/string.h> #include <msvcrt/string.h>
#pragma function(memset)
void* memset(void* src, int val, size_t count) void* memset(void* src, int val, size_t count)
{ {

View file

@ -1,6 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/string.h> #include <msvcrt/string.h>
#pragma function(strcat)
char* strcat(char* s, const char* append) char* strcat(char* s, const char* append)
{ {

View file

@ -1,6 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/string.h> #include <msvcrt/string.h>
#pragma function(strcmp)
int strcmp(const char* s1, const char* s2) int strcmp(const char* s1, const char* s2)
{ {

View file

@ -1,6 +1,7 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/string.h> #include <msvcrt/string.h>
#pragma function(strlen)
size_t strlen(const char* str) size_t strlen(const char* str)
{ {

View file

@ -245,8 +245,7 @@ settzname(void)
} }
} }
static char * static char* tzdir(void)
tzdir(void)
{ {
static char dir[80]={0}, *cp; static char dir[80]={0}, *cp;
if (dir[0] == 0) if (dir[0] == 0)
@ -266,8 +265,7 @@ tzdir(void)
return dir; return dir;
} }
static int static int tzload(const char* name, struct state* CPP_CONST sp)
tzload(const char *name, struct state * CPP_CONST sp)
{ {
const char * p; const char * p;
int i; int i;
@ -407,8 +405,8 @@ DAYSPERNYEAR, DAYSPERLYEAR
** character. ** character.
*/ */
static const char * static const char*
getzname(const char *strp) getzname(const char* strp)
{ {
char c; char c;
@ -425,8 +423,8 @@ getzname(const char *strp)
** Otherwise, return a pointer to the first character not part of the number. ** Otherwise, return a pointer to the first character not part of the number.
*/ */
static const char * static const char*
getnum(const char *strp, int * CPP_CONST nump, const int min, const int max) getnum(const char* strp, int* CPP_CONST nump, const int min, const int max)
{ {
char c; char c;
int num; int num;

View file

@ -1,9 +1,10 @@
#include <msvcrt/wchar.h> #include <msvcrt/wchar.h>
int wcsncmp(const wchar_t * cs,const wchar_t * ct,size_t count) #if 0
int wcsncmp(const wchar_t* cs, const wchar_t* ct, size_t count)
{ {
while ((*cs) == (*ct) && count > 0) while ((*cs) == (*ct) && count > 0) {
{
if (*cs == 0) if (*cs == 0)
return 0; return 0;
cs++; cs++;
@ -11,6 +12,22 @@ int wcsncmp(const wchar_t * cs,const wchar_t * ct,size_t count)
count--; count--;
} }
return (*cs) - (*ct); return (*cs) - (*ct);
} }
#else
int wcsncmp(const wchar_t* cs, const wchar_t* ct, size_t count)
{
if (count == 0)
return 0;
do {
if (*cs != *ct++)
//return *(unsigned const char *)cs - *(unsigned const char *)--ct;
return (*cs) - (*(--ct));
if (*cs++ == 0)
break;
} while (--count != 0);
return 0;
}
#endif