Turn crtdll into forwards to msvcrt.

This commit is contained in:
Jon Griffiths 2001-01-12 20:42:06 +00:00 committed by Alexandre Julliard
parent 5f308d3cb0
commit 0b47b289a8
16 changed files with 555 additions and 7709 deletions

View File

@ -412,7 +412,7 @@ advapi32/libadvapi32.@LIBEXT@: libkernel32.@LIBEXT@ libntdll.@LIBEXT@
avifil32/libavifil32.@LIBEXT@: libmsvfw32.@LIBEXT@ libkernel32.@LIBEXT@ libntdll.@LIBEXT@
comctl32/libcomctl32.@LIBEXT@: libmsvfw32.@LIBEXT@ libwinmm.@LIBEXT@ libuser32.@LIBEXT@ libgdi32.@LIBEXT@ libadvapi32.@LIBEXT@ libkernel32.@LIBEXT@ libntdll.@LIBEXT@
commdlg/libcomdlg32.@LIBEXT@: libshell32.@LIBEXT@ libshlwapi.@LIBEXT@ libcomctl32.@LIBEXT@ libwinspool.drv.@LIBEXT@ libuser32.@LIBEXT@ libgdi32.@LIBEXT@ libkernel32.@LIBEXT@ libntdll.@LIBEXT@
crtdll/libcrtdll.@LIBEXT@: libkernel32.@LIBEXT@ libntdll.@LIBEXT@
crtdll/libcrtdll.@LIBEXT@: libmsvcrt.@LIBEXT@ libkernel32.@LIBEXT@ libntdll.@LIBEXT@
dciman32/libdciman32.@LIBEXT@: libkernel32.@LIBEXT@ libntdll.@LIBEXT@
ddraw/libddraw.@LIBEXT@: libuser32.@LIBEXT@ libx11drv.@LIBEXT@ libgdi32.@LIBEXT@ libkernel32.@LIBEXT@
dinput/libdinput.@LIBEXT@: libuser32.@LIBEXT@ libkernel32.@LIBEXT@ libntdll.@LIBEXT@

View File

@ -9,18 +9,7 @@ LDDLLFLAGS = @LDDLLFLAGS@
SYMBOLFILE = $(MODULE).tmp.o
C_SRCS = \
console.c \
crtdll_main.c \
dir.c \
exit.c \
file.c \
locale.c \
mbstring.c \
memory.c \
spawn.c \
string.c \
time.c \
wcstring.c
crtdll_main.c
@MAKE_DLL_RULES@

View File

@ -1,363 +0,0 @@
/*
* CRTDLL console functions
*
* Copyright 2000 Jon Griffiths
*
* NOTES
* Only a one byte ungetch buffer is implemented, as per MS docs.
* Output is not redirectable using these functions, as per MS docs.
*
* FIXME:
* There are several problems with the console input mechanism as
* currently implemented in Wine. When these are ironed out the
* getch() function will work correctly (gets() is currently fine).
* The problem is that opening CONIN$ does not work, and
* reading from STD_INPUT_HANDLE is line buffered.
*/
#include "crtdll.h"
#include "wincon.h"
#include <stdio.h>
DEFAULT_DEBUG_CHANNEL(crtdll);
static HANDLE __CRTDLL_console_in = INVALID_HANDLE_VALUE;
static HANDLE __CRTDLL_console_out = INVALID_HANDLE_VALUE;
static int __CRTDLL_console_buffer = CRTDLL_EOF;
/* INTERNAL: Initialise console handles */
VOID __CRTDLL_init_console(VOID)
{
TRACE(":Opening console handles\n");
__CRTDLL_console_in = GetStdHandle(STD_INPUT_HANDLE);
/* FIXME: Should be initialised with:
* CreateFileA("CONIN$", GENERIC_READ, FILE_SHARE_READ,
* NULL, OPEN_EXISTING, 0, (HANDLE)NULL);
*/
__CRTDLL_console_out = CreateFileA("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, (HANDLE)NULL);
if ((__CRTDLL_console_in == INVALID_HANDLE_VALUE) ||
(__CRTDLL_console_out == INVALID_HANDLE_VALUE))
WARN(":Console handle Initialisation FAILED!\n");
}
/* INTERNAL: Free console handles */
void __CRTDLL_free_console(void)
{
TRACE(":Closing console handles\n");
CloseHandle(__CRTDLL_console_in);
CloseHandle(__CRTDLL_console_out);
}
/*********************************************************************
* _cgets (CRTDLL.050)
*
* Get a string from CONIN$.
*/
LPSTR __cdecl CRTDLL__cgets(LPSTR str)
{
char *buf = str + 2;
int c;
str[1] = 0; /* Length */
/* FIXME: No editing of string supported */
do
{
if (str[1] >= str[0] || (str[1]++, c = CRTDLL__getche()) == CRTDLL_EOF || c == '\n')
{
*buf = '\0';
return str + 2;
}
*buf++ = c & 0xff;
} while(1);
}
/*********************************************************************
* _cprintf (CRTDLL.064)
*
* Write a formatted string to CONOUT$.
*/
INT __cdecl CRTDLL__cprintf( LPCSTR format, ... )
{
va_list valist;
char buffer[2048];
va_start( valist, format );
if (snprintf( buffer, sizeof(buffer), format, valist ) == -1)
ERR("Format too large for internal buffer!\n");
va_end(valist);
return CRTDLL__cputs( buffer );
}
/*********************************************************************
* _cputs (CRTDLL.065)
*
* Write a string to CONOUT$.
*/
INT __cdecl CRTDLL__cputs(LPCSTR str)
{
DWORD count;
if (WriteConsoleA(__CRTDLL_console_out, str, strlen(str), &count, NULL)
&& count == 1)
return 0;
return CRTDLL_EOF;
}
/*********************************************************************
* _cscanf (CRTDLL.067)
*
* Read formatted input from CONIN$.
*/
INT __cdecl CRTDLL__cscanf( LPCSTR format, ... )
{
/* NOTE: If you extend this function, extend CRTDLL_fscanf in file.c too */
INT rd = 0;
int nch;
va_list ap;
if (!*format) return 0;
WARN("\"%s\": semi-stub\n", format);
nch = CRTDLL__getch();
va_start(ap, format);
while (*format) {
if (*format == ' ') {
/* skip whitespace */
while ((nch!=CRTDLL_EOF) && isspace(nch))
nch = CRTDLL__getch();
}
else if (*format == '%') {
int st = 0;
format++;
switch(*format) {
case 'd': { /* read an integer */
int*val = va_arg(ap, int*);
int cur = 0;
/* skip initial whitespace */
while ((nch!=CRTDLL_EOF) && isspace(nch))
nch = CRTDLL__getch();
/* get sign and first digit */
if (nch == '-') {
nch = CRTDLL__getch();
if (isdigit(nch))
cur = -(nch - '0');
else break;
} else {
if (isdigit(nch))
cur = nch - '0';
else break;
}
nch = CRTDLL__getch();
/* read until no more digits */
while ((nch!=CRTDLL_EOF) && isdigit(nch)) {
cur = cur*10 + (nch - '0');
nch = CRTDLL__getch();
}
st = 1;
*val = cur;
}
break;
case 'f': { /* read a float */
float*val = va_arg(ap, float*);
float cur = 0;
/* skip initial whitespace */
while ((nch!=CRTDLL_EOF) && isspace(nch))
nch = CRTDLL__getch();
/* get sign and first digit */
if (nch == '-') {
nch = CRTDLL__getch();
if (isdigit(nch))
cur = -(nch - '0');
else break;
} else {
if (isdigit(nch))
cur = nch - '0';
else break;
}
/* read until no more digits */
while ((nch!=CRTDLL_EOF) && isdigit(nch)) {
cur = cur*10 + (nch - '0');
nch = CRTDLL__getch();
}
if (nch == '.') {
/* handle decimals */
float dec = 1;
nch = CRTDLL__getch();
while ((nch!=CRTDLL_EOF) && isdigit(nch)) {
dec /= 10;
cur += dec * (nch - '0');
nch = CRTDLL__getch();
}
}
st = 1;
*val = cur;
}
break;
case 's': { /* read a word */
char*str = va_arg(ap, char*);
char*sptr = str;
/* skip initial whitespace */
while ((nch!=CRTDLL_EOF) && isspace(nch))
nch = CRTDLL__getch();
/* read until whitespace */
while ((nch!=CRTDLL_EOF) && !isspace(nch)) {
*sptr++ = nch; st++;
nch = CRTDLL__getch();
}
/* terminate */
*sptr = 0;
TRACE("read word: %s\n", str);
}
break;
default: FIXME("unhandled: %%%c\n", *format);
}
if (st) rd++;
else break;
}
else {
/* check for character match */
if (nch == *format)
nch = CRTDLL__getch();
else break;
}
format++;
}
va_end(ap);
if (nch != CRTDLL_EOF)
CRTDLL__ungetch(nch);
TRACE("returning %d\n", rd);
return rd;
}
/*********************************************************************
* _getch (CRTDLL.118)
*
* Get a character from CONIN$.
*/
INT __cdecl CRTDLL__getch(VOID)
{
if (__CRTDLL_console_buffer != CRTDLL_EOF)
{
INT retVal = __CRTDLL_console_buffer;
__CRTDLL_console_buffer = CRTDLL_EOF;
return retVal;
}
else
{
INPUT_RECORD ir;
DWORD count;
DWORD mode = 0;
GetConsoleMode(__CRTDLL_console_in, &mode);
if(mode) SetConsoleMode(__CRTDLL_console_in, 0);
do {
if (ReadConsoleInputA(__CRTDLL_console_in, &ir, 1, &count))
{
/* Only interested in ASCII chars */
if (ir.EventType == KEY_EVENT &&
ir.Event.KeyEvent.bKeyDown &&
ir.Event.KeyEvent.uChar.AsciiChar)
{
if(mode) SetConsoleMode(__CRTDLL_console_in, mode);
return ir.Event.KeyEvent.uChar.AsciiChar;
}
}
else
break;
} while(1);
if (mode) SetConsoleMode(__CRTDLL_console_in, mode);
}
return CRTDLL_EOF;
}
/*********************************************************************
* _getche (CRTDLL.119)
*
* Get a character from CONIN$ and echo it to CONOUT$.
*/
INT __cdecl CRTDLL__getche(VOID)
{
INT res = CRTDLL__getch();
if (res != CRTDLL_EOF && CRTDLL__putch(res) != CRTDLL_EOF)
return res;
return CRTDLL_EOF;
}
/*********************************************************************
* _kbhit (CRTDLL.169)
*
* Check if a character is waiting in CONIN$.
*/
INT __cdecl CRTDLL__kbhit(VOID)
{
if (__CRTDLL_console_buffer != CRTDLL_EOF)
return 1;
else
{
/* FIXME: There has to be a faster way than this in Win32.. */
INPUT_RECORD *ir;
DWORD count = 0, i;
int retVal = 0;
GetNumberOfConsoleInputEvents(__CRTDLL_console_in, &count);
if (!count)
return 0;
if (!(ir = CRTDLL_malloc(count * sizeof(INPUT_RECORD))))
return 0;
if (PeekConsoleInputA(__CRTDLL_console_in, ir, count, &count))
for(i = 0; i < count - 1; i++)
{
if (ir[i].EventType == KEY_EVENT &&
ir[i].Event.KeyEvent.bKeyDown &&
ir[i].Event.KeyEvent.uChar.AsciiChar)
{
retVal = 1;
break;
}
}
CRTDLL_free(ir);
return retVal;
}
}
/*********************************************************************
* _putch (CRTDLL.250)
*
* Write a character to CONOUT$.
*/
INT __cdecl CRTDLL__putch(INT c)
{
DWORD count;
if (WriteConsoleA(__CRTDLL_console_out, &c, 1, &count, NULL) &&
count == 1)
return c;
return CRTDLL_EOF;
}
/*********************************************************************
* _ungetch (CRTDLL.311)
*
* Un-get a character from CONIN$.
*/
INT __cdecl CRTDLL__ungetch(INT c)
{
if (c == CRTDLL_EOF || __CRTDLL_console_buffer != CRTDLL_EOF)
return CRTDLL_EOF;
return __CRTDLL_console_buffer = c;
}

View File

@ -1,551 +0,0 @@
#ifndef __WINE_CRTDLL_H
#define __WINE_CRTDLL_H
#include "config.h"
#include "windef.h"
#include "wine/windef16.h"
#include "debugtools.h"
#include "winbase.h"
#include "winerror.h"
#include "winnls.h"
#include <time.h>
#include <stdarg.h>
#include <setjmp.h>
#define CRTDLL_LC_ALL 0
#define CRTDLL_LC_COLLATE 1
#define CRTDLL_LC_CTYPE 2
#define CRTDLL_LC_MONETARY 3
#define CRTDLL_LC_NUMERIC 4
#define CRTDLL_LC_TIME 5
#define CRTDLL_LC_MIN CRTDLL_LC_ALL
#define CRTDLL_LC_MAX CRTDLL_LC_TIME
/* ctype defines */
#define CRTDLL_UPPER C1_UPPER
#define CRTDLL_LOWER C1_LOWER
#define CRTDLL_DIGIT C1_DIGIT
#define CRTDLL_SPACE C1_SPACE
#define CRTDLL_PUNCT C1_PUNCT
#define CRTDLL_CONTROL C1_CNTRL
#define CRTDLL_BLANK C1_BLANK
#define CRTDLL_HEX C1_XDIGIT
#define CRTDLL_LEADBYTE 0x8000
#define CRTDLL_ALPHA (C1_ALPHA|CRTDLL_UPPER|CRTDLL_LOWER)
/* stat() mode bits */
#define _S_IFMT 0170000
#define _S_IFREG 0100000
#define _S_IFDIR 0040000
#define _S_IFCHR 0020000
#define _S_IFIFO 0010000
#define _S_IREAD 0000400
#define _S_IWRITE 0000200
#define _S_IEXEC 0000100
/* _open modes */
#define _O_RDONLY 0x0000
#define _O_WRONLY 0x0001
#define _O_RDWR 0x0002
#define _O_APPEND 0x0008
#define _O_CREAT 0x0100
#define _O_TRUNC 0x0200
#define _O_EXCL 0x0400
#define _O_TEXT 0x4000
#define _O_BINARY 0x8000
#define _O_TEMPORARY 0x0040 /* Will be closed and deleted on exit */
/* _access() bit flags FIXME: incomplete */
#define W_OK 2
/* windows.h RAND_MAX is smaller than normal RAND_MAX */
#define CRTDLL_RAND_MAX 0x7fff
/* heap function constants */
#define _HEAPEMPTY -1
#define _HEAPOK -2
#define _HEAPBADBEGIN -3
#define _HEAPBADNODE -4
#define _HEAPEND -5
#define _HEAPBADPTR -6
#define _FREEENTRY 0
#define _USEDENTRY 1
/* fpclass constants */
#define _FPCLASS_SNAN 1
#define _FPCLASS_QNAN 2
#define _FPCLASS_NINF 4
#define _FPCLASS_NN 8
#define _FPCLASS_ND 16
#define _FPCLASS_NZ 32
#define _FPCLASS_PZ 64
#define _FPCLASS_PD 128
#define _FPCLASS_PN 256
#define _FPCLASS_PINF 512
/* _statusfp bit flags */
#define _SW_INEXACT 0x1
#define _SW_UNDERFLOW 0x2
#define _SW_OVERFLOW 0x4
#define _SW_ZERODIVIDE 0x8
#define _SW_INVALID 0x10
#define _SW_DENORMAL 0x80000
/* _controlfp masks and bitflags - x86 only so far*/
#ifdef __i386__
#define _MCW_EM 0x8001f
#define _EM_INEXACT 0x1
#define _EM_UNDERFLOW 0x2
#define _EM_OVERFLOW 0x4
#define _EM_ZERODIVIDE 0x8
#define _EM_INVALID 0x10
#define _MCW_RC 0x300
#define _RC_NEAR 0x0
#define _RC_DOWN 0x100
#define _RC_UP 0x200
#define _RC_CHOP 0x300
#define _MCW_PC 0x30000
#define _PC_64 0x0
#define _PC_53 0x10000
#define _PC_24 0x20000
#define _MCW_IC 0x40000
#define _IC_AFFINE 0x40000
#define _IC_PROJECTIVE 0x0
#define _EM_DENORMAL 0x80000
#endif
/* CRTDLL Globals */
extern INT CRTDLL_doserrno;
extern INT CRTDLL_errno;
/* Binary compatible structures, types and defines used
* by CRTDLL. These should move to external header files,
* and in some cases need to be renamed (CRTDLL_FILE!) to defs
* as used by lcc/bcc/watcom/vc++ etc, in order to get source
* compatibility for winelib.
*/
typedef struct _crtfile
{
CHAR* _ptr;
INT _cnt;
CHAR* _base;
INT _flag;
INT _file; /* fd */
int _charbuf;
int _bufsiz;
char *_tmpfname;
} CRTDLL_FILE;
/* file._flag flags */
#define _IOREAD 0x0001
#define _IOWRT 0x0002
#define _IOEOF 0x0010
#define _IOERR 0x0020
#define _IORW 0x0080
#define _IOAPPEND 0x0200
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define CRTDLL_EOF -1
#define CRTDLL_WEOF (WCHAR)(0xFFFF)
extern CRTDLL_FILE __CRTDLL_iob[3];
#define CRTDLL_stdin (&__CRTDLL_iob[0])
#define CRTDLL_stdout (&__CRTDLL_iob[1])
#define CRTDLL_stderr (&__CRTDLL_iob[2])
typedef struct _find_t
{
unsigned attrib;
time_t time_create; /* -1 when N/A */
time_t time_access; /* -1 when N/A */
time_t time_write;
unsigned long size; /* FIXME: 64 bit ??*/
char name[MAX_PATH];
} find_t;
typedef struct _diskfree_t {
unsigned num_clusters;
unsigned available;
unsigned cluster_sectors;
unsigned sector_bytes;
} diskfree_t;
struct _stat
{
UINT16 st_dev;
UINT16 st_ino;
UINT16 st_mode;
INT16 st_nlink;
INT16 st_uid;
INT16 st_gid;
UINT st_rdev;
INT st_size;
INT st_atime;
INT st_mtime;
INT st_ctime;
};
struct _timeb
{
time_t time;
UINT16 millitm;
INT16 timezone;
INT16 dstflag;
};
typedef long CRTDLL_fpos_t;
struct complex
{
double real;
double imaginary;
};
typedef struct _heapinfo
{
int * _pentry;
size_t _size;
int _useflag;
} _HEAPINFO;
struct _utimbuf
{
time_t actime;
time_t modtime;
};
/* _matherr exception type */
struct _exception
{
int type;
char *name;
double arg1;
double arg2;
double retval;
};
typedef VOID (*sig_handler_type)(VOID);
typedef VOID (*new_handler_type)(VOID);
typedef VOID (*_INITTERMFUN)();
typedef VOID (*atexit_function)(VOID);
typedef INT (__cdecl *comp_func)(LPCVOID, LPCVOID );
/* CRTDLL functions */
/* dir.c */
INT __cdecl CRTDLL__chdir( LPCSTR newdir );
BOOL __cdecl CRTDLL__chdrive( INT newdrive );
INT __cdecl CRTDLL__findclose( DWORD hand );
DWORD __cdecl CRTDLL__findfirst( LPCSTR fspec, find_t* ft );
INT __cdecl CRTDLL__findnext( DWORD hand, find_t * ft );
CHAR* __cdecl CRTDLL__getcwd( LPSTR buf, INT size );
CHAR* __cdecl CRTDLL__getdcwd( INT drive,LPSTR buf, INT size );
UINT __cdecl CRTDLL__getdiskfree( UINT disk, diskfree_t* d );
INT __cdecl CRTDLL__getdrive( VOID );
INT __cdecl CRTDLL__mkdir( LPCSTR newdir );
INT __cdecl CRTDLL__rmdir( LPSTR dir );
/* exit.c */
INT __cdecl CRTDLL__abnormal_termination( VOID );
VOID __cdecl CRTDLL__amsg_exit( INT err );
VOID __cdecl CRTDLL__assert( LPVOID str, LPVOID file, UINT line );
VOID __cdecl CRTDLL__c_exit( VOID );
VOID __cdecl CRTDLL__cexit( VOID );
void __cdecl CRTDLL_exit( DWORD ret );
VOID __cdecl CRTDLL__exit( LONG ret );
VOID __cdecl CRTDLL_abort( VOID );
INT __cdecl CRTDLL_atexit( atexit_function x );
atexit_function __cdecl CRTDLL__onexit( atexit_function func);
/* file.c */
CRTDLL_FILE* __cdecl CRTDLL__iob( VOID );
CRTDLL_FILE* __cdecl CRTDLL__fsopen( LPCSTR path, LPCSTR mode, INT share );
CRTDLL_FILE* __cdecl CRTDLL__fdopen( INT fd, LPCSTR mode );
LPSTR __cdecl CRTDLL__mktemp( LPSTR pattern );
CRTDLL_FILE* __cdecl CRTDLL_fopen( LPCSTR path, LPCSTR mode );
CRTDLL_FILE* __cdecl CRTDLL_freopen( LPCSTR path,LPCSTR mode,CRTDLL_FILE* f );
CRTDLL_FILE* __cdecl CRTDLL_tmpfile( void );
WCHAR __cdecl CRTDLL__fgetwchar( VOID );
INT __cdecl CRTDLL__fgetchar( VOID );
DWORD __cdecl CRTDLL_fread( LPVOID ptr,INT size,INT nmemb,CRTDLL_FILE* file );
INT __cdecl CRTDLL_fscanf( CRTDLL_FILE* stream, LPCSTR format, ... );
INT __cdecl CRTDLL__filbuf( CRTDLL_FILE* file );
LONG __cdecl CRTDLL__filelength( INT fd );
INT __cdecl CRTDLL__fileno( CRTDLL_FILE* file );
INT __cdecl CRTDLL__flsbuf( INT c, CRTDLL_FILE* file );
INT __cdecl CRTDLL__fputchar( INT c );
WCHAR __cdecl CRTDLL__fputwchar( WCHAR wc );
INT __cdecl CRTDLL__flushall( VOID );
INT __cdecl CRTDLL__fcloseall( VOID );
LONG __cdecl CRTDLL__lseek( INT fd, LONG offset, INT whence );
LONG __cdecl CRTDLL_fseek( CRTDLL_FILE* file, LONG offset, INT whence );
VOID __cdecl CRTDLL_rewind( CRTDLL_FILE* file );
INT __cdecl CRTDLL_fsetpos( CRTDLL_FILE* file, CRTDLL_fpos_t *pos );
LONG __cdecl CRTDLL_ftell( CRTDLL_FILE* file );
UINT __cdecl CRTDLL_fwrite( LPCVOID ptr,INT size,INT nmemb,CRTDLL_FILE*file);
INT __cdecl CRTDLL_setbuf( CRTDLL_FILE* file, LPSTR buf );
INT __cdecl CRTDLL__open_osfhandle( HANDLE osfhandle, INT flags );
INT __cdecl CRTDLL_vfprintf( CRTDLL_FILE* file, LPCSTR format,va_list args);
INT __cdecl CRTDLL_fprintf( CRTDLL_FILE* file, LPCSTR format, ... );
INT __cdecl CRTDLL__putw( INT val, CRTDLL_FILE* file );
INT __cdecl CRTDLL__read( INT fd, LPVOID buf, UINT count );
INT __cdecl CRTDLL__rmtmp( void );
UINT __cdecl CRTDLL__write( INT fd,LPCVOID buf,UINT count );
INT __cdecl CRTDLL__access( LPCSTR filename, INT mode );
INT __cdecl CRTDLL_fflush( CRTDLL_FILE* file );
INT __cdecl CRTDLL_fputc( INT c, CRTDLL_FILE* file );
VOID __cdecl CRTDLL_putchar( INT x );
INT __cdecl CRTDLL_fputs( LPCSTR s, CRTDLL_FILE* file );
INT __cdecl CRTDLL_puts( LPCSTR s );
INT __cdecl CRTDLL_putc( INT c, CRTDLL_FILE* file );
INT __cdecl CRTDLL_fgetc( CRTDLL_FILE* file );
INT __cdecl CRTDLL_getchar( VOID );
INT __cdecl CRTDLL_getc( CRTDLL_FILE* file );
WCHAR __cdecl CRTDLL_fgetwc( CRTDLL_FILE* file );
WCHAR __cdecl CRTDLL_fputwc( WCHAR wc, CRTDLL_FILE* file );
CHAR* __cdecl CRTDLL_fgets( LPSTR s, INT size, CRTDLL_FILE* file );
LPSTR __cdecl CRTDLL_gets( LPSTR buf );
INT __cdecl CRTDLL_fclose( CRTDLL_FILE* file );
INT __cdecl CTRDLL__creat( LPCSTR path, INT flags );
INT __cdecl CRTDLL__eof( INT fd );
LONG __cdecl CRTDLL__tell( INT fd );
INT __cdecl CRTDLL__umask( INT umask );
INT __cdecl CRTDLL__utime( LPCSTR path, struct _utimbuf *t );
INT __cdecl CRTDLL__unlink( LPCSTR pathname );
INT __cdecl CRTDLL_scanf( LPCSTR format, ... );
INT __cdecl CRTDLL_rename( LPCSTR oldpath,LPCSTR newpath );
int __cdecl CRTDLL__stat( LPCSTR filename, struct _stat * buf );
INT __cdecl CRTDLL__open( LPCSTR path,INT flags );
INT __cdecl CRTDLL__chmod( LPCSTR path, INT flags );
INT __cdecl CRTDLL__close( INT fd );
INT __cdecl CRTDLL_feof( CRTDLL_FILE* file );
INT __cdecl CRTDLL__setmode( INT fh,INT mode );
INT __cdecl CRTDLL_remove( LPCSTR path );
INT __cdecl CRTDLL__commit( INT fd );
INT __cdecl CRTDLL__fstat( int file, struct _stat* buf );
INT __cdecl CRTDLL__futime( INT fd, struct _utimbuf *t );
HANDLE __cdecl CRTDLL__get_osfhandle( INT fd );
/* CRTDLL_main.c */
DWORD __cdecl CRTDLL__initterm( _INITTERMFUN *start,_INITTERMFUN *end );
VOID __cdecl CRTDLL__global_unwind2( PEXCEPTION_FRAME frame );
VOID __cdecl CRTDLL__local_unwind2( PEXCEPTION_FRAME endframe, DWORD nr );
INT __cdecl CRTDLL__setjmp( LPDWORD *jmpbuf );
VOID __cdecl CRTDLL_srand( DWORD seed );
INT __cdecl CRTDLL__getw( CRTDLL_FILE* file );
INT __cdecl CRTDLL__isatty( INT fd );
VOID __cdecl CRTDLL__beep( UINT freq, UINT duration );
INT __cdecl CRTDLL_rand( VOID );
UINT __cdecl CRTDLL__rotl( UINT x,INT shift );
double __cdecl CRTDLL__logb( double x );
DWORD __cdecl CRTDLL__lrotl( DWORD x,INT shift );
DWORD __cdecl CRTDLL__lrotr( DWORD x,INT shift );
DWORD __cdecl CRTDLL__rotr( UINT x,INT shift );
double __cdecl CRTDLL__scalb( double x, LONG y );
INT __cdecl CRTDLL_vswprintf( LPWSTR buffer, LPCWSTR spec, va_list args );
VOID __cdecl CRTDLL_longjmp( jmp_buf env, int val );
LPSTR __cdecl CRTDLL_setlocale( INT category,LPCSTR locale );
INT __cdecl CRTDLL__isctype( INT c, UINT type );
LPSTR __cdecl CRTDLL__fullpath( LPSTR buf, LPCSTR name, INT size );
VOID __cdecl CRTDLL__splitpath( LPCSTR inpath, LPSTR drv, LPSTR dir,
LPSTR fname, LPSTR ext );
INT __cdecl CRTDLL__matherr( struct _exception *e );
VOID __cdecl CRTDLL__makepath( LPSTR path, LPCSTR drive,
LPCSTR directory, LPCSTR filename,
LPCSTR extension );
LPINT __cdecl CRTDLL__errno( VOID );
LPINT __cdecl CRTDLL___doserrno( VOID );
LPCSTR**__cdecl CRTDLL__sys_errlist( VOID );
VOID __cdecl CRTDLL_perror( LPCSTR err );
UINT __cdecl CRTDLL__statusfp( VOID );
LPSTR __cdecl CRTDLL__strerror( LPCSTR err );
LPSTR __cdecl CRTDLL_strerror( INT err );
LPSTR __cdecl CRTDLL__tempnam( LPCSTR dir, LPCSTR prefix );
LPSTR __cdecl CRTDLL_tmpnam( LPSTR s );
LPVOID __cdecl CRTDLL_signal( INT sig, sig_handler_type ptr );
VOID __cdecl CRTDLL__sleep( ULONG timeout );
LPSTR __cdecl CRTDLL_getenv( LPCSTR name );
INT __cdecl CRTDLL_isalnum( INT c );
INT __cdecl CRTDLL_isalpha( INT c );
INT __cdecl CRTDLL_iscntrl( INT c );
INT __cdecl CRTDLL_isdigit( INT c );
INT __cdecl CRTDLL_isgraph( INT c );
INT __cdecl CRTDLL_islower( INT c);
INT __cdecl CRTDLL_isprint( INT c);
INT __cdecl CRTDLL_ispunct( INT c);
INT __cdecl CRTDLL_isspace( INT c);
INT __cdecl CRTDLL_isupper( INT c);
INT __cdecl CRTDLL_isxdigit( INT c );
INT __cdecl CRTDLL_isleadbyte( UCHAR c );
double __cdecl CRTDLL_ldexp( double x, LONG y );
VOID __cdecl CRTDLL___dllonexit ( VOID );
VOID __cdecl CRTDLL__mbccpy( LPSTR dest, LPSTR src );
INT __cdecl CRTDLL___isascii( INT c );
INT __cdecl CRTDLL___toascii( INT c );
INT __cdecl CRTDLL_iswascii( LONG c );
INT __cdecl CRTDLL___iscsym( UCHAR c );
INT __cdecl CRTDLL___iscsymf( UCHAR c );
INT __cdecl CRTDLL__loaddll( LPSTR dllname );
INT __cdecl CRTDLL__unloaddll( HANDLE dll );
WCHAR* __cdecl CRTDLL__itow( INT value,WCHAR* out,INT base );
WCHAR* __cdecl CRTDLL__ltow( LONG value,WCHAR* out,INT base );
WCHAR* __cdecl CRTDLL__ultow( ULONG value,WCHAR* out,INT base );
CHAR __cdecl CRTDLL__toupper( CHAR c );
CHAR __cdecl CRTDLL__tolower( CHAR c );
double __cdecl CRTDLL__cabs( struct complex c );
double __cdecl CRTDLL__chgsign( double d );
UINT __cdecl CRTDLL__control87( UINT newVal, UINT mask);
UINT __cdecl CRTDLL__controlfp( UINT newVal, UINT mask);
double __cdecl CRTDLL__copysign( double x, double sign );
INT __cdecl CRTDLL__finite( double d );
UINT __cdecl CRTDLL__clearfp( VOID );
INT __cdecl CRTDLL__fpclass( double d );
VOID __cdecl CRTDLL__fpreset( void );
INT __cdecl CRTDLL__isnan( double d );
LPVOID __cdecl CRTDLL__lsearch( LPVOID match, LPVOID start, LPUINT array_size,
UINT elem_size, comp_func cf );
VOID __cdecl CRTDLL__purecall( VOID );
double __cdecl CRTDLL__y0( double x );
double __cdecl CRTDLL__y1( double x );
double __cdecl CRTDLL__yn( INT x, double y );
double __cdecl CRTDLL__nextafter( double x, double y );
VOID __cdecl CRTDLL__searchenv(LPCSTR file, LPCSTR env, LPSTR buff);
/* memory.c */
LPVOID __cdecl CRTDLL_new( DWORD size );
VOID __cdecl CRTDLL_delete( LPVOID ptr );
new_handler_type __cdecl CRTDLL_set_new_handler( new_handler_type func );
INT __cdecl CRTDLL__heapchk( VOID );
INT __cdecl CRTDLL__heapmin( VOID );
INT __cdecl CRTDLL__heapset( UINT value );
INT __cdecl CRTDLL__heapwalk( struct _heapinfo *next );
LPVOID __cdecl CRTDLL__expand( LPVOID ptr, INT size );
LONG __cdecl CRTDLL__msize( LPVOID mem );
LPVOID __cdecl CRTDLL_calloc( DWORD size, DWORD count );
VOID __cdecl CRTDLL_free( LPVOID ptr );
LPVOID __cdecl CRTDLL_malloc( DWORD size );
LPVOID __cdecl CRTDLL_realloc( VOID *ptr, DWORD size );
/* spawn.c */
HANDLE __cdecl CRTDLL__spawnv( INT flags, LPCSTR name, LPCSTR *argv);
HANDLE __cdecl CRTDLL__spawnve( INT flags, LPCSTR name, LPCSTR *argv, LPCSTR *envv);
HANDLE __cdecl CRTDLL__spawnvp( INT flags, LPCSTR name, LPCSTR *argv);
HANDLE __cdecl CRTDLL__spawnvpe( INT flags, LPCSTR name, LPCSTR *argv, LPCSTR *envv);
INT __cdecl CRTDLL_system( LPCSTR cmd );
INT __cdecl CRTDLL__cwait( LPINT status, INT pid, INT action );
/* str.c */
LPSTR __cdecl CRTDLL__strdec( LPSTR str1, LPSTR str2 );
LPSTR __cdecl CRTDLL__strdup( LPCSTR ptr );
LPSTR __cdecl CRTDLL__strinc( LPSTR str );
UINT __cdecl CRTDLL__strnextc( LPCSTR str );
LPSTR __cdecl CRTDLL__strninc( LPSTR str, INT n );
LPSTR __cdecl CRTDLL__strnset( LPSTR str, INT c, INT len );
LPSTR __cdecl CRTDLL__strrev ( LPSTR str );
LPSTR __cdecl CRTDLL__strset ( LPSTR str, INT set );
LONG __cdecl CRTDLL__strncnt( LPSTR str, LONG max );
LPSTR __cdecl CRTDLL__strspnp( LPSTR str1, LPSTR str2 );
VOID __cdecl CRTDLL__swab( LPSTR src, LPSTR dst, INT len );
/* time.c */
LPSTR __cdecl CRTDLL__strdate ( LPSTR date );
LPSTR __cdecl CRTDLL__strtime ( LPSTR date );
clock_t __cdecl CRTDLL_clock ( void );
double __cdecl CRTDLL_difftime ( time_t time1, time_t time2 );
time_t __cdecl CRTDLL_time ( time_t *timeptr );
/* mbstring.c */
LPSTR __cdecl CRTDLL__mbsinc( LPCSTR str );
INT __cdecl CRTDLL__mbslen( LPCSTR str );
INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n );
LPWSTR __cdecl CRTDLL__wcsdup( LPCWSTR str );
INT __cdecl CRTDLL__wcsicoll( LPCWSTR str1, LPCWSTR str2 );
LPWSTR __cdecl CRTDLL__wcsnset( LPWSTR str, WCHAR c, INT n );
LPWSTR __cdecl CRTDLL__wcsrev( LPWSTR str );
LPWSTR __cdecl CRTDLL__wcsset( LPWSTR str, WCHAR c );
DWORD __cdecl CRTDLL_wcscoll( LPCWSTR str1, LPCWSTR str2 );
LPWSTR __cdecl CRTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept );
INT __cdecl CRTDLL_wctomb( LPSTR dst, WCHAR ch );
LPSTR __cdecl CRTDLL__mbsdec( LPCSTR start, LPCSTR cur );
LPSTR __cdecl CRTDLL__mbsninc( LPCSTR str, INT num );
INT __cdecl CRTDLL__mbscmp( LPCSTR str, LPCSTR cmp );
INT __cdecl CRTDLL__mbsicmp( LPCSTR str, LPCSTR cmp );
INT __cdecl CRTDLL__mbsncmp( LPCSTR str, LPCSTR cmp, UINT len );
INT __cdecl CRTDLL__mbsnicmp( LPCSTR str, LPCSTR cmp, UINT len );
LPSTR __cdecl CRTDLL__mbsrchr( LPCSTR s,CHAR x );
USHORT __cdecl CRTDLL__mbbtombc( USHORT c );
INT __cdecl CRTDLL__mbclen( LPCSTR str );
INT __cdecl CRTDLL__ismbbkana( UINT c );
INT __cdecl CRTDLL__ismbckata( UINT c );
INT __cdecl CRTDLL__ismbchira( UINT c );
INT __cdecl CRTDLL__ismbblead( UINT c );
INT __cdecl CRTDLL__ismbslead( LPCSTR start, LPCSTR str);
INT __cdecl CRTDLL__ismbbtrail( UINT c );
INT __cdecl CRTDLL__ismbstrail( LPCSTR start, LPCSTR str );
LPSTR __cdecl CRTDLL__mbsset( LPSTR str, UINT c );
LPSTR __cdecl CRTDLL__mbsnset( LPSTR str, UINT c, UINT len );
INT __cdecl CRTDLL__mbstrlen( LPCSTR str );
UINT __cdecl CRTDLL__mbsnextc( LPCSTR str );
LPSTR __cdecl CRTDLL__mbsncpy( LPSTR dst, LPCSTR src, UINT len );
LPSTR __cdecl CRTDLL__mbschr( LPCSTR str, UINT c );
UINT __cdecl CRTDLL__mbsnccnt( LPCSTR str, UINT len );
LPSTR __cdecl CRTDLL__mbsncat( LPSTR dst, LPCSTR src, UINT len );
/* wcstring.c */
INT __cdecl CRTDLL_iswalnum( WCHAR wc );
INT __cdecl CRTDLL_iswalpha( WCHAR wc );
INT __cdecl CRTDLL_iswcntrl( WCHAR wc );
INT __cdecl CRTDLL_iswdigit( WCHAR wc );
INT __cdecl CRTDLL_iswgraph( WCHAR wc );
INT __cdecl CRTDLL_iswlower( WCHAR wc );
INT __cdecl CRTDLL_iswprint( WCHAR wc );
INT __cdecl CRTDLL_iswpunct( WCHAR wc );
INT __cdecl CRTDLL_iswspace( WCHAR wc );
INT __cdecl CRTDLL_iswupper( WCHAR wc );
INT __cdecl CRTDLL_iswxdigit( WCHAR wc );
/* console.c */
LPSTR __cdecl CRTDLL__cgets( LPSTR str );
INT __cdecl CRTDLL__cfprintf( LPCSTR format, ... );
INT __cdecl CRTDLL__cputs( LPCSTR str );
INT __cdecl CRTDLL__cscanf( LPCSTR format, ... );
INT __cdecl CRTDLL__getch( VOID );
INT __cdecl CRTDLL__getche( VOID );
INT __cdecl CRTDLL__kbhit( VOID );
INT __cdecl CRTDLL__putch( INT c );
INT __cdecl CRTDLL__ungetch( INT c );
/* INTERNAL: Shared internal functions */
void __CRTDLL__set_errno(ULONG err);
LPSTR __CRTDLL__strndup(LPSTR buf, INT size);
VOID __CRTDLL__init_io(VOID);
VOID __CRTDLL_init_console(VOID);
VOID __CRTDLL_free_console(VOID);
extern WORD CRTDLL_ctype [257];
extern UCHAR CRTDLL_mbctype[257];
extern WORD __CRTDLL_current_ctype[257];
extern WORD* CRTDLL_pctype_dll;
extern INT CRTDLL__mb_cur_max_dll;
extern LCID __CRTDLL_current_lc_all_lcid;
extern UINT __CRTDLL_current_lc_all_cp;
#endif /* __WINE_CRTDLL_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,347 +0,0 @@
/*
* CRTDLL drive/directory functions
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
*
* Implementation Notes:
* MT Safe.
*/
#include "crtdll.h"
#include <errno.h>
#include "ntddk.h"
#include <time.h>
DEFAULT_DEBUG_CHANNEL(crtdll);
/* INTERNAL: Translate find_t to PWIN32_FIND_DATAA */
static void __CRTDLL__fttofd(LPWIN32_FIND_DATAA fd, find_t* ft)
{
DWORD dw;
/* Tested with crtdll.dll Version 2.50.4170 (NT) from win98 SE:
* attrib 0x80 (FILE_ATTRIBUTE_NORMAL)is returned as 0.
*/
if (fd->dwFileAttributes == FILE_ATTRIBUTE_NORMAL)
ft->attrib = 0;
else
ft->attrib = fd->dwFileAttributes;
RtlTimeToSecondsSince1970( &fd->ftCreationTime, &dw );
ft->time_create = dw;
RtlTimeToSecondsSince1970( &fd->ftLastAccessTime, &dw );
ft->time_access = dw;
RtlTimeToSecondsSince1970( &fd->ftLastWriteTime, &dw );
ft->time_write = dw;
ft->size = fd->nFileSizeLow;
strcpy(ft->name, fd->cFileName);
}
/*********************************************************************
* _chdir (CRTDLL.51)
*
* Change the current directory.
*
* PARAMS
* newdir [in] Directory to change to
*
* RETURNS
* Sucess: 0
*
* Failure: -1
*/
INT __cdecl CRTDLL__chdir(LPCSTR newdir)
{
if (!SetCurrentDirectoryA(newdir))
{
__CRTDLL__set_errno(newdir?GetLastError():0);
return -1;
}
return 0;
}
/*********************************************************************
* _chdrive (CRTDLL.52)
*
* Change the current drive.
*
* PARAMS
* newdrive [in] new drive to change to, A: =1, B: =2, etc
*
* RETURNS
* Sucess: 0
*
* Failure: 1
*/
BOOL __cdecl CRTDLL__chdrive(INT newdrive)
{
char buffer[3] = "A:";
buffer[0] += newdrive - 1;
if (!SetCurrentDirectoryA( buffer ))
{
__CRTDLL__set_errno(GetLastError());
if (newdrive <= 0)
CRTDLL_errno = EACCES;
return -1;
}
return 0;
}
/*********************************************************************
* _findclose (CRTDLL.098)
*
* Free the resources from a search handle created from _findfirst.
*
* PARAMS
* hand [in]: Search handle to close
*
* RETURNS
* Success: 0
*
* Failure: -1
*/
INT __cdecl CRTDLL__findclose(DWORD hand)
{
TRACE(":handle %ld\n",hand);
if (!FindClose((HANDLE)hand))
{
__CRTDLL__set_errno(GetLastError());
return -1;
}
return 0;
}
/*********************************************************************
* _findfirst (CRTDLL.099)
*
* Create and return a search handle for iterating through a file and
* directory list.
*
* PARAMS
* fspec [in] File specification string for search, e.g "C:\*.BAT"
*
* ft [out] A pointer to a find_t structure to populate.
*
* RETURNS
* Success: A handle for the search, suitable for passing to _findnext
* or _findclose. Populates the members of ft with the details
* of the first matching file.
*
* Failure: -1.
*/
DWORD __cdecl CRTDLL__findfirst(LPCSTR fspec, find_t* ft)
{
WIN32_FIND_DATAA find_data;
HANDLE hfind;
hfind = FindFirstFileA(fspec, &find_data);
if (hfind == INVALID_HANDLE_VALUE)
{
__CRTDLL__set_errno(GetLastError());
return -1;
}
__CRTDLL__fttofd(&find_data,ft);
TRACE(":got handle %d\n",hfind);
return hfind;
}
/*********************************************************************
* _findnext (CRTDLL.100)
*
* Return the next matching file/directory from a search hadle.
*
* PARAMS
* hand [in] Search handle from a pervious call to _findfirst
*
* ft [out] A pointer to a find_t structure to populate.
*
* RETURNS
* Success: 0. Populates the members of ft with the details
* of the first matching file
*
* Failure: -1
*/
INT __cdecl CRTDLL__findnext(DWORD hand, find_t * ft)
{
WIN32_FIND_DATAA find_data;
if (!FindNextFileA(hand, &find_data))
{
CRTDLL_errno = ENOENT;
return -1;
}
__CRTDLL__fttofd(&find_data,ft);
return 0;
}
/*********************************************************************
* _getcwd (CRTDLL.120)
*
* Get the current directory.
*
* PARAMS
* buf [out] A buffer to place the current directory name in
*
* size [in] The size of buf.
*
* RETURNS
* Success: buf, or if buf is NULL, an allocated buffer
*
* Failure: NULL
*/
CHAR* __cdecl CRTDLL__getcwd(LPSTR buf, INT size)
{
char dir[_MAX_PATH];
int dir_len = GetCurrentDirectoryA(MAX_PATH,dir);
if (dir_len < 1)
return NULL; /* FIXME: Real return value untested */
TRACE(":returning '%s'\n", dir);
if (!buf)
{
if (size < 0)
return CRTDLL__strdup(dir);
return __CRTDLL__strndup(dir,size);
}
if (dir_len >= size)
{
CRTDLL_errno = ERANGE;
return NULL; /* buf too small */
}
strcpy(buf,dir);
return buf;
}
/*********************************************************************
* _getdcwd (CRTDLL.121)
*
* Get the current directory on a drive. A: =1, B: =2, etc.
* Passing drive 0 means the current drive.
*/
CHAR* __cdecl CRTDLL__getdcwd(INT drive, LPSTR buf, INT size)
{
static CHAR* dummy;
TRACE(":drive %d(%c), size %d\n",drive, drive + 'A' - 1, size);
if (!drive || drive == CRTDLL__getdrive())
return CRTDLL__getcwd(buf,size); /* current */
else
{
char dir[_MAX_PATH];
char drivespec[4] = {'A', ':', '\\', 0};
int dir_len;
drivespec[0] += drive - 1;
if (GetDriveTypeA(drivespec) < DRIVE_REMOVABLE)
{
CRTDLL_errno = EACCES;
return NULL;
}
dir_len = GetFullPathNameA(drivespec,_MAX_PATH,dir,&dummy);
if (dir_len >= size || dir_len < 1)
{
CRTDLL_errno = ERANGE;
return NULL; /* buf too small */
}
TRACE(":returning '%s'\n", dir);
if (!buf)
return CRTDLL__strdup(dir); /* allocate */
strcpy(buf,dir);
}
return buf;
}
/*********************************************************************
* _getdiskfree (CRTDLL.122)
*
* Get free disk space on given drive or the current drive.
*
*/
UINT __cdecl CRTDLL__getdiskfree(UINT disk, diskfree_t* d)
{
char drivespec[4] = {'@', ':', '\\', 0};
DWORD ret[4];
UINT err;
if (disk > 26)
return ERROR_INVALID_PARAMETER; /* CRTDLL doesn't set errno here */
drivespec[0] += disk; /* make a drive letter */
if (GetDiskFreeSpaceA(disk==0?NULL:drivespec,ret,ret+1,ret+2,ret+3))
{
d->cluster_sectors = (unsigned)ret[0];
d->sector_bytes = (unsigned)ret[1];
d->available = (unsigned)ret[2];
d->num_clusters = (unsigned)ret[3];
return 0;
}
err = GetLastError();
__CRTDLL__set_errno(err);
return err;
}
/*********************************************************************
* _getdrive (CRTDLL.124)
*
* Return current drive, A: =1, B: =2, etc
*/
INT __cdecl CRTDLL__getdrive(VOID)
{
char buffer[MAX_PATH];
if (!GetCurrentDirectoryA( sizeof(buffer), buffer )) return 0;
if (buffer[1] != ':') return 0;
return toupper(buffer[0]) - 'A' + 1;
}
/*********************************************************************
* _mkdir (CRTDLL.234)
*
* Create a directory.
*/
INT __cdecl CRTDLL__mkdir(LPCSTR newdir)
{
if (CreateDirectoryA(newdir,NULL))
return 0;
__CRTDLL__set_errno(GetLastError());
return -1;
}
/*********************************************************************
* _rmdir (CRTDLL.255)
*
* Delete a directory
*
*/
INT __cdecl CRTDLL__rmdir(LPSTR dir)
{
if (RemoveDirectoryA(dir))
return 0;
__CRTDLL__set_errno(GetLastError());
return -1;
}

View File

@ -1,186 +0,0 @@
/*
* CRTDLL exit/abort/atexit functions
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
* exit functions differ in whether they perform cleanup
* and whether they return to the caller (really!).
* return do
* Name to caller? cleanup?
* _c_exit Y N
* _cexit Y Y
* _exit N N
* exit N Y
*
* Implementation Notes:
* Not MT Safe - Adding/Executing exit() functions should be locked
* for MT safety.
*
* FIXME:
* Need a better way of printing errors for GUI programs(MsgBox?).
* Is there really a difference between onexit/atexit?
*/
#include "crtdll.h"
#include <errno.h>
DEFAULT_DEBUG_CHANNEL(crtdll);
/* INTERNAL: Table of registered atexit() functions */
/* FIXME: This should be dynamically allocated */
#define CRTDLL_ATEXIT_TABLE_SIZE 16
static atexit_function atexit_table[CRTDLL_ATEXIT_TABLE_SIZE];
static int atexit_registered = 0; /* Points to free slot */
/* INTERNAL: call atexit functions */
void __CRTDLL__call_atexit(VOID);
void __CRTDLL__call_atexit(VOID)
{
/* Last registered gets executed first */
while (atexit_registered > 0)
{
atexit_registered--;
TRACE(":call function (%p)\n",atexit_table[atexit_registered]);
(*atexit_table[atexit_registered])();
}
}
/*********************************************************************
* __dllonexit (CRTDLL.25)
*/
VOID __cdecl CRTDLL___dllonexit ()
{
FIXME("stub\n");
}
/*********************************************************************
* _abnormal_termination (CRTDLL.36)
*
* Check if execution is processing during an exception.
*/
INT __cdecl CRTDLL__abnormal_termination(VOID)
{
TRACE("(void)\n");
return 0; /* FIME: Can we determine if we are in an exception? */
}
/*********************************************************************
* _amsg_exit (CRTDLL.040)
*
* Print an error message and terminate execution. Returns 255 to the
* host OS.
*/
VOID __cdecl CRTDLL__amsg_exit(INT err)
{
/* FIXME: Should be a popup for msvcrt gui executables, and should have
* text for the error number.
*/
CRTDLL_fprintf(CRTDLL_stderr,"\nruntime error R60%d\n",err);
CRTDLL__exit(255);
}
/*********************************************************************
* _assert (CRTDLL.041)
*
* Print an assertion message and call abort(). Really only present
* for win binaries. Winelib programs would typically use libc's
* version.
*/
VOID __cdecl CRTDLL__assert(LPVOID str, LPVOID file, UINT line)
{
CRTDLL_fprintf(CRTDLL_stderr,"Assertion failed: %s, file %s, line %d\n\n",
(char*)str,(char*)file, line);
CRTDLL_abort();
}
/*********************************************************************
* _c_exit (CRTDLL.047)
*/
VOID __cdecl CRTDLL__c_exit(VOID)
{
/* All cleanup is done on DLL detach; Return to caller */
}
/*********************************************************************
* _cexit (CRTDLL.049)
*/
VOID __cdecl CRTDLL__cexit(VOID)
{
/* All cleanup is done on DLL detach; Return to caller */
}
/*********************************************************************
* _exit (CRTDLL.087)
*/
VOID __cdecl CRTDLL__exit(LONG ret)
{
TRACE(":exit code %ld\n",ret);
CRTDLL__c_exit();
ExitProcess(ret);
}
/*********************************************************************
* _onexit (CRTDLL.236)
*
* Register a function to be called when the process terminates.
*/
atexit_function __cdecl CRTDLL__onexit( atexit_function func)
{
TRACE("registering function (%p)\n",func);
if (func && atexit_registered <= CRTDLL_ATEXIT_TABLE_SIZE - 1)
{
atexit_table[atexit_registered] = (atexit_function)func;
atexit_registered++;
return func; /* successful */
}
ERR(":Too many onexit() functions, or NULL function - not registered!\n");
return NULL;
}
/*********************************************************************
* exit (CRTDLL.359)
*/
void __cdecl CRTDLL_exit(DWORD ret)
{
TRACE(":exit code %ld\n",ret);
__CRTDLL__call_atexit();
CRTDLL__cexit();
ExitProcess(ret);
}
/*********************************************************************
* abort (CRTDLL.335)
*
* Terminate the progam with an abnormal termination message. Returns
* 3 to the host OS.
*/
VOID __cdecl CRTDLL_abort()
{
CRTDLL_fprintf(CRTDLL_stderr,"\nabnormal program termination\n");
CRTDLL__exit(3);
}
/*********************************************************************
* atexit (CRTDLL.345)
*
* Register a function to be called when the process terminates.
*/
INT __cdecl CRTDLL_atexit( atexit_function func)
{
return CRTDLL__onexit(func) == func ? 0 : -1;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,448 +0,0 @@
/*
* CRT Locale functions
*
* Copyright 2000 Jon Griffiths
*
* NOTES:
* Currently only LC_CTYPE behaviour is actually implemented.
* Passing a code page only is not yet supported.
*
* The code maps a (potentially incomplete) locale description to
* an LCID. The algorithm enumerates supported locales and
* compares the locale strings to the locale information given.
* Fully qualified locales should be completely compatable.
* Some countries (e.g. US) have synonyms that can be used in
* setlocale() calls - these are mapped to ISO codes before
* searching begins, but I may have missed some out of the list.
*
* It should be noted that the algorithm may locate a valid
* locale from a 2 letter ISO code, while the real DLL won't
* (it requires 3 letter codes or synonyms at a minimum).
* e.g. setlocale(LC_ALL,"de") will return "German_Germany.1252"
* with this implementation, while this fails in win32.
*
* It should also be noted that this implementation follows
* the MSVCRT behaviour, and not the CRTDLL behaviour.
* This is because MSVCRT provides a superset of the CRTDLL
* allowed locales, so this code can be used for both. Also
* The CRTDLL implementation can be considered broken.
*
* The code currently works for isleadbyte() but will fail
* (produce potentially incorrect values) for other locales
* with isalpha() etc. This is because the current Wine
* implementation of GetStringTypeA() is not locale aware.
* Fixing this requires a table of which characters in the
* code page are upper/lower/digit etc. If you locate such
* a table for a supported Wine locale, mail it to me and
* I will add the needed support (jon_p_griffiths@yahoo.com).
*/
#include "crtdll.h"
#include "winnt.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
DEFAULT_DEBUG_CHANNEL(crtdll);
#define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
#define MAX_LOCALE_LENGTH 256
/* FIXME: Need to hold locale for each LC_* type and aggregate
* string to produce lc_all.
*/
char __CRTDLL_current_lc_all[MAX_LOCALE_LENGTH];
LCID __CRTDLL_current_lc_all_lcid;
UINT __CRTDLL_current_lc_all_cp;
/* Friendly country strings & iso codes for synonym support.
* Based on MS documentation for setlocale().
*/
static const char* _country_synonyms[] =
{
"Hong Kong","HK",
"Hong-Kong","HK",
"New Zealand","NZ",
"New-Zealand","NZ",
"PR China","CN",
"PR-China","CN",
"United Kingdom","GB",
"United-Kingdom","GB",
"Britain","GB",
"England","GB",
"Great Britain","GB",
"United States","US",
"United-States","US",
"America","US"
};
/* INTERNAL: Map a synonym to an ISO code */
static void remap_synonym(char *name)
{
size_t i;
for (i = 0; i < sizeof(_country_synonyms)/sizeof(char*); i += 2 )
{
if (!strcasecmp(_country_synonyms[i],name))
{
TRACE(":Mapping synonym %s to %s\n",name,_country_synonyms[i+1]);
name[0] = _country_synonyms[i+1][0];
name[1] = _country_synonyms[i+1][1];
name[2] = '\0';
return;
}
}
}
/* Note: Flags are weighted in order of matching importance */
#define FOUND_LANGUAGE 0x4
#define FOUND_COUNTRY 0x2
#define FOUND_CODEPAGE 0x1
typedef struct {
char search_language[MAX_ELEM_LEN];
char search_country[MAX_ELEM_LEN];
char search_codepage[MAX_ELEM_LEN];
char found_language[MAX_ELEM_LEN];
char found_country[MAX_ELEM_LEN];
char found_codepage[MAX_ELEM_LEN];
unsigned int match_flags;
LANGID found_lang_id;
} locale_search_t;
#define CONTINUE_LOOKING TRUE
#define STOP_LOOKING FALSE
/* INTERNAL: Get and compare locale info with a given string */
static int compare_info(LCID lcid, DWORD flags, char* buff, const char* cmp)
{
buff[0] = 0;
GetLocaleInfoA(lcid, flags|LOCALE_NOUSEROVERRIDE,buff, MAX_ELEM_LEN);
if (!buff[0] || !cmp[0])
return 0;
/* Partial matches are allowed, e.g. "Germ" matches "Germany" */
return !strncasecmp(cmp, buff, strlen(cmp));
}
/* INTERNAL: Callback for enumerated languages */
static BOOL CALLBACK
find_best_locale_proc(HMODULE hModule, LPCSTR type,
LPCSTR name, WORD LangID, LONG lParam)
{
locale_search_t *res = (locale_search_t *)lParam;
const LCID lcid = MAKELCID(LangID, SORT_DEFAULT);
char buff[MAX_ELEM_LEN];
unsigned int flags = 0;
if(PRIMARYLANGID(LangID) == LANG_NEUTRAL)
return CONTINUE_LOOKING;
/* Check Language */
if (compare_info(lcid,LOCALE_SISO639LANGNAME,buff,res->search_language) ||
compare_info(lcid,LOCALE_SABBREVLANGNAME,buff,res->search_language) ||
compare_info(lcid,LOCALE_SENGLANGUAGE,buff,res->search_language))
{
TRACE(":Found language: %s->%s\n", res->search_language, buff);
flags |= FOUND_LANGUAGE;
memcpy(res->found_language,res->search_language,MAX_ELEM_LEN);
}
else if (res->match_flags & FOUND_LANGUAGE)
{
return CONTINUE_LOOKING;
}
/* Check Country */
if (compare_info(lcid,LOCALE_SISO3166CTRYNAME,buff,res->search_country) ||
compare_info(lcid,LOCALE_SABBREVCTRYNAME,buff,res->search_country) ||
compare_info(lcid,LOCALE_SENGCOUNTRY,buff,res->search_country))
{
TRACE("Found country:%s->%s\n", res->search_country, buff);
flags |= FOUND_COUNTRY;
memcpy(res->found_country,res->search_country,MAX_ELEM_LEN);
}
else if (res->match_flags & FOUND_COUNTRY)
{
return CONTINUE_LOOKING;
}
/* Check codepage */
if (compare_info(lcid,LOCALE_IDEFAULTCODEPAGE,buff,res->search_codepage) ||
(compare_info(lcid,LOCALE_IDEFAULTANSICODEPAGE,buff,res->search_codepage)))
{
TRACE("Found codepage:%s->%s\n", res->search_codepage, buff);
flags |= FOUND_CODEPAGE;
memcpy(res->found_codepage,res->search_codepage,MAX_ELEM_LEN);
}
else if (res->match_flags & FOUND_CODEPAGE)
{
return CONTINUE_LOOKING;
}
if (flags > res->match_flags)
{
/* Found a better match than previously */
res->match_flags = flags;
res->found_lang_id = LangID;
}
if (flags & (FOUND_LANGUAGE & FOUND_COUNTRY & FOUND_CODEPAGE))
{
TRACE(":found exact locale match\n");
return STOP_LOOKING;
}
return CONTINUE_LOOKING;
}
/* Internal: Find the LCID for a locale specification */
static LCID __CRTDLL_locale_to_LCID(locale_search_t* locale)
{
LCID lcid;
EnumResourceLanguagesA(GetModuleHandleA("KERNEL32"), RT_STRINGA,
(LPCSTR)LOCALE_ILANGUAGE,find_best_locale_proc,
(LONG)locale);
if (!locale->match_flags)
return 0;
/* If we were given something that didn't match, fail */
if (locale->search_country[0] && !(locale->match_flags & FOUND_COUNTRY))
return 0;
lcid = MAKELCID(locale->found_lang_id, SORT_DEFAULT);
/* Populate partial locale, translating LCID to locale string elements */
if (!locale->found_codepage[0])
{
/* Even if a codepage is not enumerated for a locale
* it can be set if valid */
if (locale->search_codepage[0])
{
if (IsValidCodePage(atoi(locale->search_codepage)))
memcpy(locale->found_codepage,locale->search_codepage,MAX_ELEM_LEN);
else
{
/* Special codepage values: OEM & ANSI */
if (strcasecmp(locale->search_codepage,"OCP"))
{
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
locale->found_codepage, MAX_ELEM_LEN);
}
if (strcasecmp(locale->search_codepage,"ACP"))
{
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
locale->found_codepage, MAX_ELEM_LEN);
}
else
return 0;
if (!atoi(locale->found_codepage))
return 0;
}
}
else
{
/* Prefer ANSI codepages if present */
GetLocaleInfoA(lcid, LOCALE_IDEFAULTANSICODEPAGE,
locale->found_codepage, MAX_ELEM_LEN);
if (!locale->found_codepage[0] || !atoi(locale->found_codepage))
GetLocaleInfoA(lcid, LOCALE_IDEFAULTCODEPAGE,
locale->found_codepage, MAX_ELEM_LEN);
}
}
GetLocaleInfoA(lcid, LOCALE_SENGLANGUAGE|LOCALE_NOUSEROVERRIDE,
locale->found_language, MAX_ELEM_LEN);
GetLocaleInfoA(lcid, LOCALE_SENGCOUNTRY|LOCALE_NOUSEROVERRIDE,
locale->found_country, MAX_ELEM_LEN);
return lcid;
}
/* INTERNAL: Set ctype behaviour for a codepage */
static void __CRTDLL_set_ctype(UINT codepage, LCID lcid)
{
CPINFO cp;
memset(&cp, 0, sizeof(CPINFO));
if (GetCPInfo(codepage, &cp))
{
int i;
char str[3];
unsigned char *traverse = (unsigned char *)cp.LeadByte;
memset(__CRTDLL_current_ctype, 0, sizeof(CRTDLL_ctype));
__CRTDLL_current_lc_all_cp = codepage;
/* Switch ctype macros to MBCS if needed */
CRTDLL__mb_cur_max_dll = cp.MaxCharSize;
/* Set remaining ctype flags: FIXME: faster way to do this? */
str[1] = str[2] = 0;
for (i = 0; i < 256; i++)
{
if (!(CRTDLL_pctype_dll[i] & CRTDLL_LEADBYTE))
{
str[0] = i;
GetStringTypeA(lcid, CT_CTYPE1, str, 1, CRTDLL_pctype_dll + i);
}
}
/* Set leadbyte flags */
while (traverse[0] || traverse[1])
{
for( i = traverse[0]; i <= traverse[1]; i++ )
__CRTDLL_current_ctype[i+1] |= CRTDLL_LEADBYTE;
traverse += 2;
};
}
}
/*********************************************************************
* setlocale (CRTDLL.453)
*/
LPSTR __cdecl CRTDLL_setlocale(INT category, LPCSTR locale)
{
LCID lcid = 0;
locale_search_t lc;
int haveLang, haveCountry, haveCP;
char* next;
int lc_all = 0;
if (category < CRTDLL_LC_MIN || category > CRTDLL_LC_MAX)
return NULL;
if (locale == NULL)
{
/* Report the current Locale */
return __CRTDLL_current_lc_all;
}
if (locale[0] == 'L' && locale[1] == 'C' && locale[2] == '_')
{
FIXME(":restore previous locale not implemented!\n");
/* FIXME: Easiest way to do this is parse the string and
* call this function recursively with its elements,
* Where they differ for each lc_ type.
*/
return __CRTDLL_current_lc_all;
}
/* Default Locale: Special case handling */
if (!strlen(locale) || ((toupper(locale[0]) == 'C') && !locale[1]))
{
__CRTDLL_current_lc_all[0] = 'C';
__CRTDLL_current_lc_all[1] = '\0';
__CRTDLL_current_lc_all_cp = GetACP();
switch (category) {
case CRTDLL_LC_ALL:
lc_all = 1; /* Fall through all cases ... */
case CRTDLL_LC_COLLATE:
if (!lc_all) break;
case CRTDLL_LC_CTYPE:
/* Restore C locale ctype info */
CRTDLL__mb_cur_max_dll = 1;
memcpy(__CRTDLL_current_ctype, CRTDLL_ctype, sizeof(CRTDLL_ctype));
memset(CRTDLL_mbctype, 0, sizeof(CRTDLL_mbctype));
if (!lc_all) break;
case CRTDLL_LC_MONETARY:
if (!lc_all) break;
case CRTDLL_LC_NUMERIC:
if (!lc_all) break;
case CRTDLL_LC_TIME:
}
return __CRTDLL_current_lc_all;
}
/* Get locale elements */
haveLang = haveCountry = haveCP = 0;
memset(&lc,0,sizeof(lc));
next = strchr(locale,'_');
if (next && next != locale)
{
haveLang = 1;
strncpy(lc.search_language,locale,next-locale);
locale += next-locale+1;
}
next = strchr(locale,'.');
if (next)
{
haveCP = 1;
if (next == locale)
{
locale++;
strncpy(lc.search_codepage, locale, MAX_ELEM_LEN);
}
else
{
if (haveLang)
{
haveCountry = 1;
strncpy(lc.search_country,locale,next-locale);
locale += next-locale+1;
}
else
{
haveLang = 1;
strncpy(lc.search_language,locale,next-locale);
locale += next-locale+1;
}
strncpy(lc.search_codepage, locale, MAX_ELEM_LEN);
}
}
else
{
if (haveLang)
{
haveCountry = 1;
strncpy(lc.search_country, locale, MAX_ELEM_LEN);
}
else
{
haveLang = 1;
strncpy(lc.search_language, locale, MAX_ELEM_LEN);
}
}
if (haveCountry)
remap_synonym(lc.search_country);
if (haveCP && !haveCountry && !haveLang)
{
FIXME(":Codepage only locale not implemented");
/* FIXME: Use default lang/country and skip locale_to_LCID()
* call below...
*/
return NULL;
}
lcid = __CRTDLL_locale_to_LCID(&lc);
TRACE(":found LCID %ld\n",lcid);
if (lcid == 0)
return NULL;
__CRTDLL_current_lc_all_lcid = lcid;
snprintf(__CRTDLL_current_lc_all,MAX_LOCALE_LENGTH,"%s_%s.%s",
lc.found_language,lc.found_country,lc.found_codepage);
switch (category) {
case CRTDLL_LC_ALL:
lc_all = 1; /* Fall through all cases ... */
case CRTDLL_LC_COLLATE:
if (!lc_all) break;
case CRTDLL_LC_CTYPE:
__CRTDLL_set_ctype(atoi(lc.found_codepage),lcid);
if (!lc_all) break;
break;
case CRTDLL_LC_MONETARY:
if (!lc_all) break;
case CRTDLL_LC_NUMERIC:
if (!lc_all) break;
case CRTDLL_LC_TIME:
}
return __CRTDLL_current_lc_all;
}

View File

@ -1,558 +0,0 @@
/*
* CRTDLL multi-byte string functions
*
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
* NOTES
* See msdn.microsoft.com
* /library/devprods/vs6/visualc/vccore/_crt__ismbb_routines.htm
* For details and CP 932 information.
*
* This code assumes that MB_LEN_MAX is 2 and that [0,0] is an
* invalid MB char. If that changes, this will need to too.
*
* CRTDLL reports valid CP 932 multibyte chars when the current
* code page is not 932. MSVCRT fixes this bug - we implement
* MSVCRT's behaviour, since its correct. However, MSVCRT fails
* to set the code page correctly when the locale is changed, so
* it must be explicitly set to get matching results.
*
* FIXME
* Not currently binary compatable with win32. CRTDLL_mbctype must be
* populated correctly and the ismb* functions should reference it.
*/
#include "crtdll.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
UCHAR CRTDLL_mbctype[257];
/*********************************************************************
* _mbscmp (CRTDLL.??)
*
* Compare two multibyte strings.
*/
INT __cdecl CRTDLL__mbscmp( LPCSTR str, LPCSTR cmp )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
UINT strc, cmpc;
do {
if (!*str)
return *cmp ? -1 : 0;
if (!*cmp)
return 1;
strc = CRTDLL__mbsnextc(str);
cmpc = CRTDLL__mbsnextc(cmp);
if (strc != cmpc)
return strc < cmpc ? -1 : 1;
str += (strc > 255) ? 2 : 1;
cmp += (strc > 255) ? 2 : 1; /* equal, use same increment */
} while (1);
}
return strcmp(str, cmp); /* ASCII CP */
}
/*********************************************************************
* _mbsicmp (CRTDLL.??)
*
* Compare two multibyte strings case insensitively.
*/
INT __cdecl CRTDLL__mbsicmp( LPCSTR str, LPCSTR cmp )
{
/* FIXME: No tolower() for mb strings yet */
if (CRTDLL__mb_cur_max_dll > 1)
return CRTDLL__mbscmp( str, cmp );
return strcasecmp( str, cmp ); /* ASCII CP */
}
/*********************************************************************
* _mbsncmp (CRTDLL.??)
*
* Compare two multibyte strings to 'len' characters.
*/
INT __cdecl CRTDLL__mbsncmp( LPCSTR str, LPCSTR cmp, UINT len )
{
if (!len)
return 0;
if (CRTDLL__mb_cur_max_dll > 1)
{
UINT strc, cmpc;
while (len--)
{
if (!*str)
return *cmp ? -1 : 0;
if (!*cmp)
return 1;
strc = CRTDLL__mbsnextc(str);
cmpc = CRTDLL__mbsnextc(cmp);
if (strc != cmpc)
return strc < cmpc ? -1 : 1;
str += (strc > 255) ? 2 : 1;
cmp += (strc > 255) ? 2 : 1; /* Equal, use same increment */
}
return 0; /* Matched len chars */
}
return strncmp(str, cmp, len); /* ASCII CP */
}
/*********************************************************************
* _mbsnicmp (CRTDLL.??)
*
* Compare two multibyte strings case insensitively to 'len' characters.
*/
INT __cdecl CRTDLL__mbsnicmp( LPCSTR str, LPCSTR cmp, UINT len )
{
/* FIXME: No tolower() for mb strings yet */
if (CRTDLL__mb_cur_max_dll > 1)
return CRTDLL__mbsncmp( str, cmp, len );
return strncasecmp( str, cmp, len ); /* ASCII CP */
}
/*********************************************************************
* _mbsinc (CRTDLL.205)
*
* Return the next character of a string.
*/
LPSTR __cdecl CRTDLL__mbsinc( LPCSTR str )
{
if (CRTDLL__mb_cur_max_dll > 1 &&
CRTDLL_isleadbyte(*str))
return (LPSTR)str + 2; /* MB char */
return (LPSTR)str + 1; /* ASCII CP or SB char */
}
/*********************************************************************
* _mbsninc (CRTDLL.??)
*
* Return the 'num'th character of a string.
*/
LPSTR CRTDLL__mbsninc( LPCSTR str, INT num )
{
if (!str || num < 1)
return NULL;
if (CRTDLL__mb_cur_max_dll > 1)
{
while(num--)
str = CRTDLL__mbsinc( str );
return (LPSTR)str;
}
return (LPSTR)str + num; /* ASCII CP */
}
/*********************************************************************
* _mbslen (CRTDLL.206)
*
* Get the length of a string.
*/
INT __cdecl CRTDLL__mbslen( LPCSTR str )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
INT len = 0;
while (*str)
{
str += CRTDLL_isleadbyte( *str ) ? 2 : 1;
len++;
}
return len;
}
return strlen( str ); /* ASCII CP */
}
/*********************************************************************
* _mbsrchr (CRTDLL.223)
*/
LPSTR __cdecl CRTDLL__mbsrchr(LPCSTR s,CHAR x)
{
/* FIXME: handle multibyte strings */
return strrchr(s,x);
}
/*********************************************************************
* mbtowc (CRTDLL.430)
*/
INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
{
if (n <= 0) return 0;
if (!str) return 0;
if (!MultiByteToWideChar( CP_ACP, 0, str, n, dst, 1 )) return 0;
/* return the number of bytes from src that have been used */
if (!*str) return 0;
if (n >= 2 && CRTDLL_isleadbyte(*str) && str[1]) return 2;
return 1;
}
/*********************************************************************
* _mbccpy (CRTDLL.??)
*
* Copy one multibyte character to another
*/
VOID __cdecl CRTDLL__mbccpy(LPSTR dest, LPSTR src)
{
*dest++ = *src;
if (CRTDLL__mb_cur_max_dll > 1 && CRTDLL_isleadbyte(*src))
*dest = *++src; /* MB char */
}
/*********************************************************************
* _mbsdec (CRTDLL.??)
*
* Return the character before 'cur'.
*/
LPSTR __cdecl CRTDLL__mbsdec( LPCSTR start, LPCSTR cur )
{
if (CRTDLL__mb_cur_max_dll > 1)
return (LPSTR)(CRTDLL__ismbstrail(start,cur-1) ? cur - 2 : cur -1);
return (LPSTR)cur - 1; /* ASCII CP or SB char */
}
/*********************************************************************
* _mbbtombc (CRTDLL.??)
*
* Convert a single byte character to a multi byte character.
*/
USHORT __cdecl CRTDLL__mbbtombc( USHORT c )
{
if (CRTDLL__mb_cur_max_dll > 1 &&
((c >= 0x20 && c <=0x7e) || (c >= 0xa1 && c <= 0xdf)))
{
/* FIXME: I can't get this function to return anything
* different to what I pass it...
*/
}
return c; /* ASCII CP or no MB char */
}
/*********************************************************************
* _mbclen (CRTDLL.??)
*
* Get the length of a multibyte character.
*/
INT __cdecl CRTDLL__mbclen( LPCSTR str )
{
return CRTDLL_isleadbyte( *str ) ? 2 : 1;
}
/*********************************************************************
* _ismbbkana (CRTDLL.??)
*
* Is the given single byte character Katakana?
*/
INT __cdecl CRTDLL__ismbbkana( UINT c )
{
/* FIXME: use lc_ctype when supported, not lc_all */
if (__CRTDLL_current_lc_all_cp == 932)
{
/* Japanese/Katakana, CP 932 */
return (c >= 0xa1 && c <= 0xdf);
}
return 0;
}
/*********************************************************************
* _ismbchira (CRTDLL.??)
*
* Is the given character Hiragana?
*/
INT __cdecl CRTDLL__ismbchira( UINT c )
{
/* FIXME: use lc_ctype when supported, not lc_all */
if (__CRTDLL_current_lc_all_cp == 932)
{
/* Japanese/Hiragana, CP 932 */
return (c >= 0x829f && c <= 0x82f1);
}
return 0;
}
/*********************************************************************
* _ismbckata (CRTDLL.??)
*
* Is the given double byte character Katakana?
*/
INT __cdecl CRTDLL__ismbckata( UINT c )
{
/* FIXME: use lc_ctype when supported, not lc_all */
if (__CRTDLL_current_lc_all_cp == 932)
{
if ( c < 256)
return CRTDLL__ismbbkana( c );
/* Japanese/Katakana, CP 932 */
return (c >= 0x8340 && c <= 0x8396 && c != 0x837f);
}
return 0;
}
/*********************************************************************
* _ismbblead (CRTDLL.??)
*
* Is the given single byte character a lead byte?
*/
INT __cdecl CRTDLL__ismbblead( UINT c )
{
/* FIXME: should reference CRTDLL_mbctype */
return CRTDLL__mb_cur_max_dll > 1 && CRTDLL_isleadbyte( c );
}
/*********************************************************************
* _ismbbtrail (CRTDLL.??)
*
* Is the given single byte character a trail byte?
*/
INT __cdecl CRTDLL__ismbbtrail( UINT c )
{
/* FIXME: should reference CRTDLL_mbctype */
return !CRTDLL__ismbblead( c );
}
/*********************************************************************
* _ismbslead (CRTDLL.??)
*
* Is the character pointed to 'str' a lead byte?
*/
INT __cdecl CRTDLL__ismbslead( LPCSTR start, LPCSTR str )
{
/* Lead bytes can also be trail bytes if caller messed up
* iterating through the string...
*/
if (CRTDLL__mb_cur_max_dll > 1)
{
while (start < str)
start += CRTDLL_isleadbyte ( *str ) ? 2 : 1;
if (start == str)
return CRTDLL_isleadbyte( *str );
}
return 0; /* Must have been a trail, we skipped it */
}
/*********************************************************************
* _ismbstrail (CRTDLL.??)
*
* Is the character pointed to 'str' a trail byte?
*/
INT __cdecl CRTDLL__ismbstrail( LPCSTR start, LPCSTR str )
{
/* Must not be a lead, and must be preceeded by one */
return !CRTDLL__ismbslead( start, str ) && CRTDLL_isleadbyte(str[-1]);
}
/*********************************************************************
* _mbsset (CRTDLL.??)
*
* Fill a multibyte string with a value.
*/
LPSTR __cdecl CRTDLL__mbsset( LPSTR str, UINT c )
{
LPSTR ret = str;
if (CRTDLL__mb_cur_max_dll == 1 || c < 256)
return CRTDLL__strset( str, c ); /* ASCII CP or SB char */
c &= 0xffff; /* Strip high bits */
while (str[0] && str[1])
{
*str++ = c >> 8;
*str++ = c & 0xff;
}
if (str[0])
str[0] = '\0'; /* FIXME: OK to shorten? */
return ret;
}
/*********************************************************************
* _mbsnset (CRTDLL.??)
*
* Fill a multibyte string with a value up to 'len' characters.
*/
LPSTR __cdecl CRTDLL__mbsnset( LPSTR str, UINT c, UINT len )
{
LPSTR ret = str;
if (!len)
return ret;
if (CRTDLL__mb_cur_max_dll == 1 || c < 256)
return CRTDLL__strnset( str, c, len ); /* ASCII CP or SB char */
c &= 0xffff; /* Strip high bits */
while (str[0] && str[1] && len--)
{
*str++ = c >> 8;
*str++ = c & 0xff;
}
if (len && str[0])
str[0] = '\0'; /* FIXME: OK to shorten? */
return ret;
}
/*********************************************************************
* _mbstrlen (CRTDLL.??)
*
* Get the length of a multibyte string.
*/
INT __cdecl CRTDLL__mbstrlen( LPCSTR str )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
INT len = 0;
while (*str)
{
str += CRTDLL_isleadbyte ( *str ) ? 2 : 1;
len++;
}
return len;
}
return strlen( str ); /* ASCII CP */
}
/*********************************************************************
* _mbsnextc (CRTDLL.??)
*
* Get the next character from a multibyte string.
*/
UINT __cdecl CRTDLL__mbsnextc( LPCSTR str )
{
if (CRTDLL__mb_cur_max_dll > 1 && CRTDLL_isleadbyte( *str ))
return *str << 8 | str[1];
return *str; /* ASCII CP or SB char */
}
/*********************************************************************
* _mbsncpy (CRTDLL.??)
*
* Copy one multibyte string to another up to 'len' characters.
*/
LPSTR __cdecl CRTDLL__mbsncpy( LPSTR dst, LPCSTR src, UINT len )
{
if (!len)
return dst;
if (CRTDLL__mb_cur_max_dll > 1)
{
LPSTR ret = dst;
while (src[0] && src[1] && len--)
{
*dst++ = *src++;
*dst++ = *src++;
}
if (len--)
{
*dst++ = *src++; /* Last char or '\0' */
while(len--)
*dst++ = '\0';
}
return ret;
}
return strncpy( dst, src, len ); /* ASCII CP */
}
/*********************************************************************
* _mbschr (CRTDLL.??)
*
* Find a multibyte character in a multibyte string.
*/
LPSTR __cdecl CRTDLL__mbschr( LPCSTR str, UINT c )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
UINT next;
while((next = CRTDLL__mbsnextc( str )))
{
if (next == c)
return (LPSTR)str;
str += next > 255 ? 2 : 1;
}
return c ? NULL : (LPSTR)str;
}
return strchr( str, c ); /* ASCII CP */
}
/*********************************************************************
* _mbsnccnt (CRTDLL.??)
*
* Return the number of mutibyte characters in 'len' bytes of a string.
*/
UINT __cdecl CRTDLL__mbsnccnt( LPCSTR str, UINT len )
{
int ret = 0;
if (CRTDLL__mb_cur_max_dll > 1)
{
while(*str && len-- > 0)
{
if (CRTDLL_isleadbyte ( *str ))
{
str++;
len--;
}
ret++;
str++;
}
return ret;
}
return min( strlen( str ), len ); /* ASCII CP */
}
/*********************************************************************
* _mbsncat (CRTDLL.??)
*
* Add 'len' characters from one multibyte string to another.
*/
LPSTR __cdecl CRTDLL__mbsncat( LPSTR dst, LPCSTR src, UINT len )
{
if (CRTDLL__mb_cur_max_dll > 1)
{
LPSTR res = dst;
dst += CRTDLL__mbslen( dst );
while (*src && len--)
{
*dst = *src;
if (CRTDLL_isleadbyte( *src ))
*++dst = *++src;
dst++;
src++;
}
*dst++ = '\0';
return res;
}
return strncat( dst, src, len ); /* ASCII CP */
}

View File

@ -1,228 +0,0 @@
/*
* CRTDLL memory functions
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
* Implementation Notes:
* MT Safe.
* heapwalk from win does not work. This is most likely due to internal
* differences between wine and win (see memory/heap.c comments). This
* version works fine, however.
*/
#include "crtdll.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
static new_handler_type new_handler;
/*********************************************************************
* new (CRTDLL.001)
*
* Allocate memory.
*/
LPVOID __cdecl CRTDLL_new(DWORD size)
{
VOID* result;
if(!(result = HeapAlloc(GetProcessHeap(),0,size)) && new_handler)
(*new_handler)();
return result;
}
/*********************************************************************
* delete (CRTDLL.002)
*
* Free memory created with new.
*/
VOID __cdecl CRTDLL_delete(LPVOID ptr)
{
HeapFree(GetProcessHeap(),0,ptr);
}
/*********************************************************************
* set_new_handler(CRTDLL.003)
*/
new_handler_type __cdecl CRTDLL_set_new_handler(new_handler_type func)
{
new_handler_type old_handler = new_handler;
new_handler = func;
return old_handler;
}
/*********************************************************************
* _expand (CRTDLL.088)
*
* Increase the size of a block of memory allocated with malloc()
* or realloc().
*/
LPVOID __cdecl CRTDLL__expand(LPVOID ptr, INT size)
{
return HeapReAlloc( GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, ptr, size );
}
/*********************************************************************
* _heapchk (CRTDLL.130)
*
* Check the consistency of the process heap.
*/
INT __cdecl CRTDLL__heapchk(VOID)
{
if (!HeapValidate( GetProcessHeap(), 0, NULL))
{
__CRTDLL__set_errno(GetLastError());
return _HEAPBADNODE;
}
return _HEAPOK;
}
/*********************************************************************
* _heapmin (CRTDLL.131)
*
* Minimise the size of the heap.
*/
INT __cdecl CRTDLL__heapmin(VOID)
{
if (!HeapCompact( GetProcessHeap(), 0 ))
{
if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
__CRTDLL__set_errno(GetLastError());
return -1;
}
return 0;
}
/*********************************************************************
* _heapset (CRTDLL.132)
*
* Fill free memory in the heap with a given value.
*/
INT __cdecl CRTDLL__heapset(UINT value)
{
INT retVal;
struct _heapinfo heap;
memset( &heap, 0, sizeof(heap) );
while ((retVal = CRTDLL__heapwalk(&heap)) == _HEAPOK)
{
if (heap._useflag == _FREEENTRY)
memset(heap._pentry, value, heap._size);
}
return retVal == _HEAPEND? _HEAPOK : retVal;
}
/*********************************************************************
* _heapwalk (CRTDLL.133)
*
* Walk the heap block by block.
*/
INT __cdecl CRTDLL__heapwalk(struct _heapinfo *next)
{
PROCESS_HEAP_ENTRY phe;
phe.lpData = next->_pentry;
phe.cbData = next->_size;
phe.wFlags = next->_useflag == _USEDENTRY ? PROCESS_HEAP_ENTRY_BUSY : 0;
if (phe.lpData && phe.wFlags & PROCESS_HEAP_ENTRY_BUSY &&
!HeapValidate( GetProcessHeap(), 0, phe.lpData ))
{
__CRTDLL__set_errno(GetLastError());
return _HEAPBADNODE;
}
do
{
if (!HeapWalk( GetProcessHeap(), &phe ))
{
if (GetLastError() == ERROR_NO_MORE_ITEMS)
return _HEAPEND;
__CRTDLL__set_errno(GetLastError());
if (!phe.lpData)
return _HEAPBADBEGIN;
return _HEAPBADNODE;
}
} while (phe.wFlags & (PROCESS_HEAP_REGION|PROCESS_HEAP_UNCOMMITTED_RANGE));
next->_pentry = phe.lpData;
next->_size = phe.cbData;
next->_useflag = phe.wFlags & PROCESS_HEAP_ENTRY_BUSY ? _USEDENTRY : _FREEENTRY;
return _HEAPOK;
}
/*********************************************************************
* _msize (CRTDLL.234)
*
* Return the actual used size of an allocated block of memory.
*
*/
LONG __cdecl CRTDLL__msize(LPVOID mem)
{
LONG size = HeapSize(GetProcessHeap(),0,mem);
if (size == -1)
{
WARN(":Probably called with non wine-allocated memory, ret = -1\n");
/* At least the win98/nt crtdlls also return -1 in this case */
}
return size;
}
/*********************************************************************
* calloc (CRTDLL.350)
*
* Allocate memory from the heap and initialise it to zero.
*/
LPVOID __cdecl CRTDLL_calloc(DWORD size, DWORD count)
{
return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
}
/*********************************************************************
* free (CRTDLL.375)
*
* Free a block of memory allocated with malloc()
*/
VOID __cdecl CRTDLL_free(LPVOID ptr)
{
HeapFree(GetProcessHeap(),0,ptr);
}
/*********************************************************************
* malloc (CRTDLL.424)
*
* Alocate memory from the heap.
*/
LPVOID __cdecl CRTDLL_malloc(DWORD size)
{
LPVOID ret = HeapAlloc(GetProcessHeap(),0,size);
if (!ret)
__CRTDLL__set_errno(GetLastError());
return ret;
}
/*********************************************************************
* realloc (CRTDLL.444)
*
* Resize a block of memory allocated with malloc() or realloc().
*/
LPVOID __cdecl CRTDLL_realloc( VOID *ptr, DWORD size )
{
return HeapReAlloc( GetProcessHeap(), 0, ptr, size );
}

View File

@ -1,249 +0,0 @@
/*
* CRTDLL spawn functions
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
* These functions differ in whether they pass arguments as an array
* (v in the name) or as varags (l in the name), whether they
* seach the path (p in the name) and/or whether they take an
* environment (e in the name) or pass the parents environment.
* Args as Search Take
* Name varargs? path? environment?
* spawnl N N N
* spawnle N N Y
* spawnlp N Y N
* spawnlpe N Y Y
* spawnv Y N N
* spawnve Y N Y
* spawnvp Y Y N
* spawnvpe Y Y Y
*
* Implementation Notes:
* MT Safe - But only because of missing functionality.
*
* After translating input arguments into the required format for
* CreateProcess(), the internal function __CRTDLL__spawn() is
* called to perform the actual spawning.
*
* FIXME:
* -File handles need some special handling. Sometimes children get
* open file handles, sometimes not. The docs are confusing.
* -No check for maximum path/argument/environment size is done.
* Unresolved issues Uwe Bonnes 970904:
* -system-call calls another wine process, but without debugging arguments
* and uses the first wine executable in the path
*/
#include "crtdll.h"
#include <errno.h>
#include <stdlib.h>
DEFAULT_DEBUG_CHANNEL(crtdll);
/* Process creation flags */
#define _P_WAIT 0
#define _P_NOWAIT 1
#define _P_OVERLAY 2
#define _P_NOWAITO 3
#define _P_DETACH 4
extern void __CRTDLL__set_errno(ULONG err);
extern LPVOID __cdecl CRTDLL_calloc(DWORD size, DWORD count);
extern VOID __cdecl CRTDLL_free(void *ptr);
extern VOID __cdecl CRTDLL__exit(LONG ret);
extern INT CRTDLL_doserrno;
/* INTERNAL: Spawn a child process */
static int __CRTDLL__spawn(INT flags, LPCSTR exe, LPSTR args, LPSTR env)
{
STARTUPINFOA si;
PROCESS_INFORMATION pi;
if ((unsigned)flags > _P_DETACH)
{
CRTDLL_errno = EINVAL;
return -1;
}
FIXME(":must dup/kill streams for child process\n");
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
if (!CreateProcessA(exe, args, NULL, NULL, TRUE,
flags == _P_DETACH ? DETACHED_PROCESS : 0,
env, NULL, &si, &pi))
{
__CRTDLL__set_errno(GetLastError());
return -1;
}
switch(flags)
{
case _P_WAIT:
WaitForSingleObject(pi.hProcess,-1); /* wait forvever */
GetExitCodeProcess(pi.hProcess,&pi.dwProcessId);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return pi.dwProcessId;
case _P_DETACH:
CloseHandle(pi.hProcess);
pi.hProcess = 0;
/* fall through */
case _P_NOWAIT:
case _P_NOWAITO:
CloseHandle(pi.hThread);
return pi.hProcess;
case _P_OVERLAY:
CRTDLL__exit(0);
}
return -1; /* cant reach here */
}
/* INTERNAL: Convert argv list to a single 'delim'-seperated string */
static LPSTR __CRTDLL__argvtos(LPCSTR *arg, CHAR delim)
{
LPCSTR *search = arg;
LONG size = 0;
LPSTR ret;
if (!arg && !delim)
return NULL;
/* get length */
while(*search)
{
size += strlen(*search) + 1;
search++;
}
if (!(ret = (LPSTR)CRTDLL_calloc(size + 1, 1)))
return NULL;
/* fill string */
search = arg;
size = 0;
while(*search)
{
int strsize = strlen(*search);
memcpy(ret+size,*search,strsize);
ret[size+strsize] = delim;
size += strsize + 1;
search++;
}
return ret;
}
/*********************************************************************
* _cwait (CRTDLL.069)
*
* Wait for a spawned process to finish.
*/
INT __cdecl CRTDLL__cwait(LPINT status, INT pid, INT action)
{
HANDLE hPid = (HANDLE)pid;
action = action; /* Remove warning */
if (!WaitForSingleObject(hPid, -1)) /* wait forvever */
{
if (status)
{
DWORD stat;
GetExitCodeProcess(hPid, &stat);
*status = (INT)stat;
}
return pid;
}
CRTDLL_doserrno = GetLastError();
if (CRTDLL_doserrno == ERROR_INVALID_HANDLE)
CRTDLL_errno = ECHILD;
else
__CRTDLL__set_errno(CRTDLL_doserrno);
return status ? *status = -1 : -1;
}
/*********************************************************************
* _spawnv (CRTDLL.273)
*
* Spawn a process.
*/
HANDLE __cdecl CRTDLL__spawnv(INT flags, LPCSTR name, LPCSTR *argv)
{
return CRTDLL__spawnve(flags, name, argv, NULL);
}
/*********************************************************************
* _spawnve (CRTDLL.274)
*
* Spawn a process.
*/
HANDLE __cdecl CRTDLL__spawnve(INT flags, LPCSTR name, LPCSTR *argv, LPCSTR *envv)
{
LPSTR args = __CRTDLL__argvtos(argv,' ');
LPSTR envs = __CRTDLL__argvtos(envv,0);
LPCSTR fullname = name;
HANDLE ret = -1;
FIXME(":not translating name %s to locate program\n",fullname);
TRACE(":call (%s), params (%s), env (%s)\n",name,args,envs?"Custom":"Null");
if (args)
{
ret = __CRTDLL__spawn(flags, fullname, args, envs);
CRTDLL_free(args);
}
if (envs)
CRTDLL_free(envs);
return ret;
}
/*********************************************************************
* _spawnvp (CRTDLL.275)
*
* Spawn a process.
*/
HANDLE __cdecl CRTDLL__spawnvp(INT flags, LPCSTR name, LPCSTR *argv)
{
return CRTDLL__spawnvpe(flags, name, argv, NULL);
}
/*********************************************************************
* _spawnvpe (CRTDLL.276)
*
* Spawn a process.
*/
HANDLE __cdecl CRTDLL__spawnvpe(INT flags, LPCSTR name, LPCSTR *argv, LPCSTR *envv)
{
char fullname[MAX_PATH];
CRTDLL__searchenv(name, "PATH", fullname);
return CRTDLL__spawnve(flags, fullname[0] ? fullname : name, argv, envv);
}
/*********************************************************************
* system (CRTDLL.485)
*
* Spawn an O/S process.
*/
INT __cdecl CRTDLL_system(LPCSTR cmd)
{
/* FIXME: should probably launch cmd interpreter in COMSPEC */
return __CRTDLL__spawn(_P_WAIT, cmd, NULL, NULL);
}

View File

@ -1,204 +0,0 @@
/*
* CRTDLL string functions
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
* Implementation Notes:
* MT Safe.
*/
#include "crtdll.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
/* INTERNAL: CRTDLL_malloc() based strndup */
LPSTR __CRTDLL__strndup(LPSTR buf, INT size);
LPSTR __CRTDLL__strndup(LPSTR buf, INT size)
{
char* ret;
int len = strlen(buf);
int max_len;
max_len = size <= len? size : len + 1;
ret = CRTDLL_malloc(max_len);
if (ret)
{
memcpy(ret,buf,max_len);
ret[max_len] = 0;
}
return ret;
}
/*********************************************************************
* _strdec (CRTDLL.282)
*
* Return the byte before str2 while it is >= to str1.
*
* PARAMS
* str1 [in] Terminating string
*
* sre2 [in] string to start searching from
*
* RETURNS
* The byte before str2, or str1, whichever is greater
*
* NOTES
* This function is implemented as tested with windows, which means
* it does not have a terminating condition. It always returns
* the byte before str2. Use with extreme caution!
*/
LPSTR __cdecl CRTDLL__strdec(LPSTR str1, LPSTR str2)
{
/* Hmm. While the docs suggest that the following should work... */
/* return (str2<=str1?0:str2-1); */
/* ...Version 2.50.4170 (NT) from win98 constantly decrements! */
str1 = str1; /* remove warning */
return str2-1;
}
/*********************************************************************
* _strdup (CRTDLL.285)
*
* Duplicate a string.
*/
LPSTR __cdecl CRTDLL__strdup(LPCSTR ptr)
{
LPSTR ret = CRTDLL_malloc(strlen(ptr)+1);
if (ret) strcpy( ret, ptr );
return ret;
}
/*********************************************************************
* _strinc (CRTDLL.287)
*
* Return a pointer to the next character in a string
*/
LPSTR __cdecl CRTDLL__strinc(LPSTR str)
{
return str+1;
}
/*********************************************************************
* _strnextc (CRTDLL.290)
*
* Return an unsigned int from a string.
*/
UINT __cdecl CRTDLL__strnextc(LPCSTR str)
{
return (UINT)*str;
}
/*********************************************************************
* _strninc (CRTDLL.292)
*
* Return a pointer to the 'n'th character in a string
*/
LPSTR __cdecl CRTDLL__strninc(LPSTR str, INT n)
{
return str+n;
}
/*********************************************************************
* _strnset (CRTDLL.293)
*
* Fill a string with a character up to a certain length
*/
LPSTR __cdecl CRTDLL__strnset(LPSTR str, INT c, INT len)
{
if (len > 0 && str)
while (*str && len--)
*str++ = c;
return str;
}
/*********************************************************************
* _strrev (CRTDLL.294)
*
* Reverse a string in place
*/
LPSTR __cdecl CRTDLL__strrev (LPSTR str)
{
LPSTR p1;
LPSTR p2;
if (str && *str)
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
{
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
return str;
}
/*********************************************************************
* _strset (CRTDLL.295)
*
* Fill a string with a value.
*/
LPSTR __cdecl CRTDLL__strset (LPSTR str, INT set)
{
char *ptr = str;
while (*ptr)
*ptr++ = set;
return str;
}
/*********************************************************************
* _strncnt (CRTDLL.289)
*
* Return the length of a string or the maximum given length.
*/
LONG __cdecl CRTDLL__strncnt(LPSTR str, LONG max)
{
LONG len = strlen(str);
return (len > max? max : len);
}
/*********************************************************************
* _strspnp (CRTDLL.296)
*
*/
LPSTR __cdecl CRTDLL__strspnp(LPSTR str1, LPSTR str2)
{
str1 += strspn(str1,str2);
return *str1? str1 : 0;
}
/*********************************************************************
* _swab (CRTDLL.299)
*
* Copy from source to dest alternating bytes (i.e 16 bit big-to-little
* endian or vice versa).
*/
void __cdecl CRTDLL__swab(LPSTR src, LPSTR dst, INT len)
{
if (len > 1)
{
len = (unsigned)len >> 1;
while (len--) {
*dst++ = src[1];
*dst++ = *src++;
src++;
}
}
}

View File

@ -1,118 +0,0 @@
/*
* CRTDLL date/time functions
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*
* Implementation Notes:
* MT Safe.
*/
#include "crtdll.h"
#include <stdlib.h>
#include <sys/times.h>
DEFAULT_DEBUG_CHANNEL(crtdll);
/* INTERNAL: Return formatted current time/date */
static LPSTR __CRTDLL__get_current_time(LPSTR out, const char * format);
static LPSTR __CRTDLL__get_current_time(LPSTR out, const char * format)
{
time_t t;
struct tm *_tm;
if ((time(&t) != ((time_t)-1)) &&
((_tm = localtime(&t)) != 0) &&
(strftime(out,9,format,_tm) == 8))
{
CRTDLL_free(_tm);
return out;
}
return NULL;
}
/*********************************************************************
* _ftime (CRTDLL.112)
*
* Get current time.
*/
VOID __cdecl CRTDLL__ftime (struct _timeb* t)
{
t->time = CRTDLL_time(NULL);
t->millitm = 0; /* FIXME */
t->timezone = 0;
t->dstflag = 0;
}
/**********************************************************************
* _strdate (CRTDLL.283)
*
* Return the current date as MM/DD/YY - (American Format)
*/
LPSTR __cdecl CRTDLL__strdate (LPSTR date)
{
return __CRTDLL__get_current_time(date,"%m/%d/%y");
}
/*********************************************************************
* _strtime (CRTDLL.299)
*
* Return the current time as HH:MM:SS
*/
LPSTR __cdecl CRTDLL__strtime (LPSTR date)
{
return __CRTDLL__get_current_time(date,"%H:%M:%S");
}
/*********************************************************************
* clock (CRTDLL.350)
*/
clock_t __cdecl CRTDLL_clock(void)
{
struct tms alltimes;
clock_t res;
times(&alltimes);
res = alltimes.tms_utime + alltimes.tms_stime+
alltimes.tms_cutime + alltimes.tms_cstime;
/* FIXME: We need some symbolic representation
for (Hostsystem_)CLOCKS_PER_SEC
and (Emulated_system_)CLOCKS_PER_SEC
10 holds only for Windows/Linux_i86)
*/
return 10*res;
}
/*********************************************************************
* difftime (CRTDLL.357)
*/
double __cdecl CRTDLL_difftime (time_t time1, time_t time2)
{
double timediff;
timediff = (double)(time1 - time2);
return timediff;
}
/*********************************************************************
* time (CRTDLL.488)
*/
time_t __cdecl CRTDLL_time(time_t *timeptr)
{
time_t curtime = time(NULL);
if (timeptr)
*timeptr = curtime;
return curtime;
}

View File

@ -1,202 +0,0 @@
/*
* CRTDLL wide-char functions
*
* Copyright 1999 Alexandre Julliard
*/
#include "crtdll.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "winnls.h"
#include "wine/unicode.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
/*********************************************************************
* CRTDLL__wcsdup (CRTDLL.320)
*/
LPWSTR __cdecl CRTDLL__wcsdup( LPCWSTR str )
{
LPWSTR ret = NULL;
if (str)
{
int size = (strlenW(str) + 1) * sizeof(WCHAR);
ret = CRTDLL_malloc( size );
if (ret) memcpy( ret, str, size );
}
return ret;
}
/*********************************************************************
* CRTDLL__wcsicoll (CRTDLL.322)
*/
INT __cdecl CRTDLL__wcsicoll( LPCWSTR str1, LPCWSTR str2 )
{
/* FIXME: handle collates */
return strcmpiW( str1, str2 );
}
/*********************************************************************
* CRTDLL__wcsnset (CRTDLL.325)
*/
LPWSTR __cdecl CRTDLL__wcsnset( LPWSTR str, WCHAR c, INT n )
{
LPWSTR ret = str;
while ((n-- > 0) && *str) *str++ = c;
return ret;
}
/*********************************************************************
* CRTDLL__wcsrev (CRTDLL.326)
*/
LPWSTR __cdecl CRTDLL__wcsrev( LPWSTR str )
{
LPWSTR ret = str;
LPWSTR end = str + strlenW(str) - 1;
while (end > str)
{
WCHAR t = *end;
*end-- = *str;
*str++ = t;
}
return ret;
}
/*********************************************************************
* CRTDLL__wcsset (CRTDLL.327)
*/
LPWSTR __cdecl CRTDLL__wcsset( LPWSTR str, WCHAR c )
{
LPWSTR ret = str;
while (*str) *str++ = c;
return ret;
}
/*********************************************************************
* CRTDLL_wcscoll (CRTDLL.506)
*/
DWORD __cdecl CRTDLL_wcscoll( LPCWSTR str1, LPCWSTR str2 )
{
/* FIXME: handle collates */
return strcmpW( str1, str2 );
}
/*********************************************************************
* CRTDLL_wcspbrk (CRTDLL.514)
*/
LPWSTR __cdecl CRTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept )
{
LPCWSTR p;
while (*str)
{
for (p = accept; *p; p++) if (*p == *str) return (LPWSTR)str;
str++;
}
return NULL;
}
/*********************************************************************
* CRTDLL_wctomb (CRTDLL.524)
*/
INT __cdecl CRTDLL_wctomb( LPSTR dst, WCHAR ch )
{
return WideCharToMultiByte( CP_ACP, 0, &ch, 1, dst, 6, NULL, NULL );
}
/*********************************************************************
* CRTDLL_iswalnum (CRTDLL.405)
*/
INT __cdecl CRTDLL_iswalnum( WCHAR wc )
{
return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
}
/*********************************************************************
* CRTDLL_iswalpha (CRTDLL.406)
*/
INT __cdecl CRTDLL_iswalpha( WCHAR wc )
{
return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
}
/*********************************************************************
* CRTDLL_iswcntrl (CRTDLL.408)
*/
INT __cdecl CRTDLL_iswcntrl( WCHAR wc )
{
return get_char_typeW(wc) & C1_CNTRL;
}
/*********************************************************************
* CRTDLL_iswdigit (CRTDLL.410)
*/
INT __cdecl CRTDLL_iswdigit( WCHAR wc )
{
return get_char_typeW(wc) & C1_DIGIT;
}
/*********************************************************************
* CRTDLL_iswgraph (CRTDLL.411)
*/
INT __cdecl CRTDLL_iswgraph( WCHAR wc )
{
return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
}
/*********************************************************************
* CRTDLL_iswlower (CRTDLL.412)
*/
INT __cdecl CRTDLL_iswlower( WCHAR wc )
{
return get_char_typeW(wc) & C1_LOWER;
}
/*********************************************************************
* CRTDLL_iswprint (CRTDLL.413)
*/
INT __cdecl CRTDLL_iswprint( WCHAR wc )
{
return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
}
/*********************************************************************
* CRTDLL_iswpunct (CRTDLL.414)
*/
INT __cdecl CRTDLL_iswpunct( WCHAR wc )
{
return get_char_typeW(wc) & C1_PUNCT;
}
/*********************************************************************
* CRTDLL_iswspace (CRTDLL.415)
*/
INT __cdecl CRTDLL_iswspace( WCHAR wc )
{
return get_char_typeW(wc) & C1_SPACE;
}
/*********************************************************************
* CRTDLL_iswupper (CRTDLL.416)
*/
INT __cdecl CRTDLL_iswupper( WCHAR wc )
{
return get_char_typeW(wc) & C1_UPPER;
}
/*********************************************************************
* CRTDLL_iswxdigit (CRTDLL.417)
*/
INT __cdecl CRTDLL_iswxdigit( WCHAR wc )
{
return get_char_typeW(wc) & C1_XDIGIT;
}