- Implemented 73 CRT functions

- Reimplemented file I/O using Win32 calls
- Set errno/doserrno in most calls
This commit is contained in:
Jon Griffiths 2000-11-08 22:42:53 +00:00 committed by Alexandre Julliard
parent b56a8df9e7
commit d3576a9f85
14 changed files with 3828 additions and 1563 deletions

View File

@ -8,7 +8,14 @@ IMPORTS = kernel32 ntdll
C_SRCS = \
crtdll_main.c \
dir.c \
exit.c \
file.c \
mbstring.c \
memory.c \
spawn.c \
string.c \
time.c \
wcstring.c
@MAKE_DLL_RULES@

View File

@ -1,7 +1,17 @@
#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
@ -24,19 +34,324 @@
#define CRTDLL_LEADBYTE 0x8000
#define CRTDLL_ALPHA (0x0100|CRTDLL_UPPER|CRTDLL_LOWER)
/* function prototypes used in crtdll.c */
extern int LastErrorToErrno(DWORD);
/* 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
void __cdecl *CRTDLL_malloc( DWORD size );
void __cdecl CRTDLL_free( void *ptr );
/* _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
/* _access() bit flags FIXME: incomplete */
#define W_OK 2
/* windows.h RAND_MAX is smaller than normal RAND_MAX */
#define CRTDLL_RAND_MAX 0x7fff
/* CRTDLL Globals */
extern INT CRTDLL_doserrno;
extern INT CRTDLL_errno;
/* Binary compatable structures, types and defines used
* by CRTDLL. These should move to external header files,
* and in some cases need be renamed (CRTDLL_FILE!) to defs
* as used by lcc/bcc/watcom/vc++ etc, in order to get source
* compatability 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 EOF -1
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 fpos_t;
struct complex
{
double real;
double imaginary;
};
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)(LPVOID *,LPVOID *);
/* CRTDLL functions */
/* CRTDLL_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 );
/* CRTDLL_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);
/* CRTDLL_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 );
CRTDLL_FILE* __cdecl CRTDLL_fopen( LPCSTR path, LPCSTR mode );
CRTDLL_FILE* __cdecl CRTDLL_freopen( LPCSTR path,LPCSTR mode,CRTDLL_FILE* f );
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, LPSTR format, ... );
INT __cdecl CRTDLL__filbuf( CRTDLL_FILE* file );
INT __cdecl CRTDLL__fileno( CRTDLL_FILE* file );
INT __cdecl CRTDLL__flsbuf( INT c, CRTDLL_FILE* file );
INT __cdecl CRTDLL__fputchar( INT c );
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, 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__read( INT fd, LPVOID buf, UINT count );
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 );
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__unlink( LPCSTR pathname );
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__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 );
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__isatty(INT fd);
VOID __cdecl CRTDLL__beep( UINT freq, UINT duration );
INT __cdecl CRTDLL_rand( VOID );
UINT __cdecl CRTDLL__rotl( UINT x,INT shift );
DWORD __cdecl CRTDLL__lrotl( DWORD x,INT shift );
DWORD __cdecl CRTDLL__lrotr( DWORD x,INT shift );
DWORD __cdecl CRTDLL__rotr( UINT x,INT shift );
INT __cdecl CRTDLL__mbsicmp( unsigned char *x,unsigned char *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 );
BOOL __cdecl CRTDLL__isctype( CHAR x,CHAR type );
LPSTR __cdecl CRTDLL__fullpath( LPSTR buf, LPCSTR name, INT size );
VOID __cdecl CRTDLL__splitpath( LPCSTR path, LPSTR drive, LPSTR directory,
LPSTR filename, LPSTR extension );
LPINT __cdecl CRTDLL__errno( VOID );
LPINT __cdecl CRTDLL___doserrno( VOID );
LPCSTR**__cdecl CRTDLL__sys_errlist( VOID );
VOID __cdecl CRTDLL_perror( LPCSTR err );
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 );
LPSTR __cdecl CRTDLL__mbsrchr( LPSTR s,CHAR x );
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( LONG c );
INT __cdecl CRTDLL___iscsymf( LONG 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, UINT );
UINT __cdecl CRTDLL__controlfp( UINT, UINT );
double __cdecl CRTDLL__copysign(double x, double sign);
INT __cdecl CRTDLL__finite( 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 );
/* CRTDLL_mem.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 );
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 );
/* CRTDLL_spawn.c */
HANDLE __cdecl CRTDLL__spawnve( INT flags, LPSTR name, LPSTR *argv, LPSTR *envv);
INT __cdecl CRTDLL_system( LPSTR x );
/* CRTDLL_str.c */
LPSTR __cdecl CRTDLL__strdec( LPSTR str1, LPSTR str2 );
LPSTR __cdecl CRTDLL__strdup( LPCSTR ptr );
LPSTR __cdecl CRTDLL__strinc( LPSTR 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 );
/* CRTDLL_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 );
/* wcstring.c */
INT __cdecl CRTDLL_iswalnum( WCHAR wc );
INT __cdecl CRTDLL_iswalpha( WCHAR wc );
INT __cdecl CRTDLL_iswcntrl( WCHAR wc );
@ -48,35 +363,10 @@ INT __cdecl CRTDLL_iswpunct( WCHAR wc );
INT __cdecl CRTDLL_iswspace( WCHAR wc );
INT __cdecl CRTDLL_iswupper( WCHAR wc );
INT __cdecl CRTDLL_iswxdigit( WCHAR wc );
INT __cdecl CRTDLL_iswctype( WCHAR wc, WCHAR wct );
INT __cdecl CRTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n );
INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n );
DWORD __cdecl CRTDLL_wcscoll( LPCWSTR str1, LPCWSTR str2 );
LPWSTR __cdecl CRTDLL_wcspbrk( LPCWSTR str, LPCWSTR accept );
INT __cdecl CRTDLL_wctomb( LPSTR dst, WCHAR ch );
#ifdef notyet
#define _mbsinc CRTDLL__mbsinc
#define _mbslen CRTDLL__mbslen
#define _wcsdup CRTDLL__wcsdup
#define _wcsicoll CRTDLL__wcsicoll
#define _wcsnset CRTDLL__wcsnset
#define _wcsrev CRTDLL__wcsrev
#define _wcsset CRTDLL__wcsset
#define iswalnum CRTDLL_iswalnum
#define iswalpha CRTDLL_iswalpha
#define iswcntrl CRTDLL_iswcntrl
#define iswdigit CRTDLL_iswdigit
#define iswgraph CRTDLL_iswgraph
#define iswlower CRTDLL_iswlower
#define iswprint CRTDLL_iswprint
#define iswpunct CRTDLL_iswpunct
#define iswspace CRTDLL_iswspace
#define iswupper CRTDLL_iswupper
#define iswxdigit CRTDLL_iswxdigit
#define mbtowc CRTDLL_mbtowc
#define wcscoll CRTDLL_wcscoll
#define wctomb CRTDLL_wctomb
#endif
/* INTERNAL: Shared internal functions */
void __CRTDLL__set_errno(ULONG err);
LPSTR __CRTDLL__strndup(LPSTR buf, INT size);
VOID __CRTDLL__init_io(VOID);
#endif /* __WINE_CRTDLL_H */

View File

@ -33,47 +33,47 @@ debug_channels (crtdll)
@ extern __argc_dll CRTDLL_argc_dll
@ extern __argv_dll CRTDLL_argv_dll
@ cdecl __dllonexit() CRTDLL___dllonexit
@ stub __doserrno
@ cdecl __doserrno() CRTDLL___doserrno
@ stub __fpecode
@ stub __isascii
@ stub __iscsym
@ stub __iscsymf
@ cdecl __isascii(long) CRTDLL___isascii
@ cdecl __iscsym(long) CRTDLL___iscsym
@ cdecl __iscsymf(long) CRTDLL___iscsymf
@ stub __mb_cur_max_dll
@ stub __pxcptinfoptrs
@ cdecl __threadhandle() GetCurrentThread
@ cdecl __threadid() GetCurrentThreadId
@ stub __toascii
@ cdecl __toascii(long) CRTDLL___toascii
@ cdecl _abnormal_termination() CRTDLL__abnormal_termination
@ cdecl _access(str long) CRTDLL__access
@ extern _acmdln_dll CRTDLL_acmdln_dll
@ stub _aexit_rtn_dll
@ stub _amsg_exit
@ stub _assert
@ cdecl _amsg_exit(long) CRTDLL__amsg_exit
@ cdecl _assert(ptr ptr long) CRTDLL__assert
@ extern _basemajor_dll CRTDLL_basemajor_dll
@ extern _baseminor_dll CRTDLL_baseminor_dll
@ extern _baseversion_dll CRTDLL_baseversion_dll
@ stub _beep
@ cdecl _beep(long long) CRTDLL__beep
@ stub _beginthread
@ stub _c_exit
@ stub _cabs
@ cdecl _cexit(long) CRTDLL__cexit
@ cdecl _c_exit() CRTDLL__c_exit
@ cdecl _cabs(long) CRTDLL__cabs
@ cdecl _cexit() CRTDLL__cexit
@ stub _cgets
@ cdecl _chdir(str) CRTDLL__chdir
@ cdecl _chdrive(long) CRTDLL__chdrive
@ stub _chgsign
@ cdecl _chgsign(double) CRTDLL__chgsign
@ stub _chmod
@ stub _chsize
@ stub _clearfp
@ cdecl _close(long) CRTDLL__close
@ stub _commit
@ cdecl _commit(long) CRTDLL__commit
@ extern _commode_dll CRTDLL_commode_dll
@ stub _control87
@ stub _controlfp
@ stub _copysign
@ cdecl _control87(long long) CRTDLL__control87
@ cdecl _controlfp(long long) CRTDLL__controlfp
@ cdecl _copysign(double double) CRTDLL__copysign
@ stub _cprintf
@ stub _cpumode_dll
@ stub _cputs
@ stub _creat
@ cdecl _creat(str long) CTRDLL__creat
@ stub _cscanf
@ stub _ctype
@ stub _cwait
@ -83,7 +83,7 @@ debug_channels (crtdll)
@ stub _ecvt
@ stub _endthread
@ extern _environ_dll CRTDLL_environ_dll
@ stub _eof
@ cdecl _eof(long) CRTDLL__eof
@ cdecl _errno() CRTDLL__errno
@ cdecl _except_handler2(ptr ptr ptr ptr) CRTDLL__except_handler2
@ stub _execl
@ -94,45 +94,45 @@ debug_channels (crtdll)
@ stub _execve
@ stub _execvp
@ stub _execvpe
@ stub _exit
@ stub _expand
@ stub _fcloseall
@ cdecl _exit(long) CRTDLL__exit
@ cdecl _expand(ptr long) CRTDLL__expand
@ cdecl _fcloseall() CRTDLL__fcloseall
@ stub _fcvt
@ cdecl _fdopen(long ptr) CRTDLL__fdopen
@ stub _fgetchar
@ cdecl _fgetchar() CRTDLL__fgetchar
@ stub _fgetwchar
@ stub _filbuf
@ cdecl _filbuf(ptr) CRTDLL__filbuf
@ stub _fileinfo_dll
@ stub _filelength
@ stub _fileno
@ stub _findclose
@ cdecl _fileno(ptr) CRTDLL__fileno
@ cdecl _findclose(long) CRTDLL__findclose
@ cdecl _findfirst(str ptr) CRTDLL__findfirst
@ cdecl _findnext(long ptr) CRTDLL__findnext
@ stub _finite
@ stub _flsbuf
@ stub _flushall
@ cdecl _finite(double) CRTDLL__finite
@ cdecl _flsbuf(long ptr) CRTDLL__flsbuf
@ cdecl _flushall() CRTDLL__flushall
@ extern _fmode_dll CRTDLL_fmode_dll
@ stub _fpclass
@ stub _fpieee_flt
@ cdecl _fpreset() CRTDLL__fpreset
@ stub _fputchar
@ cdecl _fputchar(long) CRTDLL__fputchar
@ stub _fputwchar
@ cdecl _fsopen(str str long) CRTDLL__fsopen
@ cdecl _fstat(long ptr) CRTDLL__fstat
@ stub _ftime
@ cdecl _ftime(ptr) CRTDLL__ftime
@ forward _ftol ntdll._ftol
@ cdecl _fullpath(ptr str long) CRTDLL__fullpath
@ stub _futime
@ stub _gcvt
@ stub _get_osfhandle
@ cdecl _get_osfhandle(long) CRTDLL__get_osfhandle
@ stub _getch
@ stub _getche
@ cdecl _getcwd(ptr long) CRTDLL__getcwd
@ cdecl _getdcwd(long ptr long) CRTDLL__getdcwd
@ stub _getdiskfree
@ stub _getdllprocaddr
@ cdecl _getdiskfree(long ptr) CRTDLL__getdiskfree
@ forward _getdllprocaddr kernel32.GetProcAddress
@ cdecl _getdrive() CRTDLL__getdrive
@ stub _getdrives
@ forward _getdrives kernel32.GetLogicalDrives
@ stub _getpid
@ stub _getsystime
@ stub _getw
@ -143,7 +143,7 @@ debug_channels (crtdll)
@ stub _heapwalk
@ cdecl _hypot(double double) hypot
@ cdecl _initterm(ptr ptr) CRTDLL__initterm
@ extern _iob CRTDLL_iob
@ extern _iob __CRTDLL_iob
@ cdecl _isatty(long) CRTDLL__isatty
@ cdecl _isctype(long long) CRTDLL__isctype
@ stub _ismbbalnum
@ -171,29 +171,29 @@ debug_channels (crtdll)
@ stub _ismbcupper
@ stub _ismbslead
@ stub _ismbstrail
@ stub _isnan
@ cdecl _isnan(double) CRTDLL__isnan
@ forward _itoa ntdll._itoa
@ stub _itow
@ cdecl _j0(double) j0
@ cdecl _j1(double) j1
@ cdecl _jn(long double) jn
@ cdecl _itow(long str long) CRTDLL__itow
@ cdecl _j0(double) CRTDLL__j0
@ cdecl _j1(double) CRTDLL__j1
@ cdecl _jn(long double) CRTDLL__jn
@ stub _kbhit
@ stub _lfind
@ stub _loaddll
@ cdecl _loaddll(str) CRTDLL__loaddll
@ cdecl _local_unwind2(ptr long) CRTDLL__local_unwind2
@ stub _locking
@ stub _logb
@ cdecl _lrotl (long long) CRTDLL__lrotl
@ stub _lrotr
@ stub _lsearch
@ cdecl _lrotr (long long) CRTDLL__lrotr
@ cdecl _lsearch(ptr ptr long long ptr) CRTDLL__lsearch
@ cdecl _lseek(long long long) CRTDLL__lseek
@ forward _ltoa ntdll._ltoa
@ stub _ltow
@ cdecl _ltow(long str long) CRTDLL__ltow
@ cdecl _makepath (ptr str str str str) CRTDLL__makepath
@ stub _matherr
@ stub _mbbtombc
@ stub _mbbtype
@ stub _mbccpy
@ cdecl _mbccpy (str str) CRTDLL__mbccpy
@ stub _mbcjistojms
@ stub _mbcjmstojis
@ stub _mbclen
@ -239,13 +239,13 @@ debug_channels (crtdll)
@ stub _mbstok
@ stub _mbstrlen
@ stub _mbsupr
@ stub _memccpy
@ cdecl _memccpy(ptr ptr long long) memccpy
@ forward _memicmp ntdll._memicmp
@ cdecl _mkdir(str) CRTDLL__mkdir
@ stub _mktemp
@ stub _msize
@ cdecl _msize(ptr) CRTDLL__msize
@ stub _nextafter
@ stub _onexit
@ cdecl _onexit(ptr) CRTDLL__onexit
@ cdecl _open(str long) CRTDLL__open
@ cdecl _open_osfhandle(long long) CRTDLL__open_osfhandle
@ extern _osmajor_dll CRTDLL_osmajor_dll
@ -264,10 +264,10 @@ debug_channels (crtdll)
@ stub _putw
@ stub _pwctype_dll
@ cdecl _read(long ptr long) CRTDLL__read
@ stub _rmdir
@ cdecl _rmdir(str) CRTDLL__rmdir
@ stub _rmtmp
@ cdecl _rotl (long long) CRTDLL__rotl
@ stub _rotr
@ cdecl _rotr (long long) CRTDLL__rotr
@ stub _scalb
@ stub _searchenv
@ stub _seterrormode
@ -283,7 +283,7 @@ debug_channels (crtdll)
@ stub _spawnlp
@ stub _spawnlpe
@ stub _spawnv
@ stub _spawnve
@ cdecl _spawnve(long str ptr ptr) CRTDLL__spawnve
@ stub _spawnvp
@ stub _spawnvpe
@ cdecl _splitpath (str ptr ptr ptr ptr) CRTDLL__splitpath
@ -291,39 +291,39 @@ debug_channels (crtdll)
@ stub _statusfp
@ cdecl _strcmpi(str str) strcasecmp
@ cdecl _strdate(str) CRTDLL__strdate
@ stub _strdec
@ cdecl _strdec(str str) CRTDLL__strdec
@ cdecl _strdup(str) CRTDLL__strdup
@ stub _strerror
@ cdecl _strerror(long) CRTDLL__strerror
@ cdecl _stricmp(str str) strcasecmp
@ stub _stricoll
@ stub _strinc
@ cdecl _strinc(str) CRTDLL__strinc
@ forward _strlwr ntdll._strlwr
@ stub _strncnt
@ cdecl _strncnt(str long) CRTDLL__strncnt
@ stub _strnextc
@ cdecl _strnicmp(str str long) strncasecmp
@ stub _strninc
@ stub _strnset
@ stub _strrev
@ stub _strset
@ stub _strspnp
@ cdecl _strninc(str long) CRTDLL__strninc
@ cdecl _strnset(str long long) CRTDLL__strnset
@ cdecl _strrev(str) CRTDLL__strrev
@ cdecl _strset(str long) CRTDLL__strset
@ cdecl _strspnp(str str) CRTDLL__strspnp
@ cdecl _strtime(str) CRTDLL__strtime
@ forward _strupr ntdll._strupr
@ stub _swab
@ stub _sys_errlist
@ stub _sys_nerr_dll
@ stub _tell
@ cdecl _swab(str str long) CRTDLL__swab
@ extern _sys_errlist sys_errlist
@ extern _sys_nerr_dll CRTDLL__sys_nerr
@ cdecl _tell(long) CRTDLL__tell
@ cdecl _tempnam(str ptr) CRTDLL__tempnam
@ stub _timezone_dll
@ stub _tolower
@ stub _toupper
@ cdecl _tolower(long) CRTDLL__toupper
@ cdecl _toupper(long) CRTDLL__tolower
@ stub _tzname
@ stub _tzset
@ forward _ultoa ntdll._ultoa
@ stub _ultow
@ stub _umask
@ cdecl _ultow(long str long) CRTDLL__ultow
@ cdecl _umask(long) CRTDLL__umask
@ stub _ungetch
@ cdecl _unlink(str) CRTDLL__unlink
@ stub _unloaddll
@ cdecl _unloaddll(long) CRTDLL__unloaddll
@ stub _utime
@ cdecl _vsnprintf(ptr long ptr ptr) vsnprintf
@ stub _vsnwprintf
@ -345,7 +345,7 @@ debug_channels (crtdll)
@ cdecl _y0(double) y0
@ cdecl _y1(double) y1
@ cdecl _yn(long double) yn
@ stub abort
@ cdecl abort() CRTDLL_abort
@ cdecl abs(long) abs
@ cdecl acos(double) acos
@ cdecl asctime(ptr) asctime
@ -359,7 +359,7 @@ debug_channels (crtdll)
@ cdecl bsearch(ptr ptr long long ptr) bsearch
@ cdecl calloc(long long) CRTDLL_calloc
@ cdecl ceil(double) ceil
@ stub clearerr
@ cdecl clearerr(ptr) CRTDLL_clearerr
@ cdecl clock() CRTDLL_clock
@ cdecl cos(double) cos
@ cdecl cosh(double) cosh
@ -371,10 +371,10 @@ debug_channels (crtdll)
@ cdecl fabs(double) fabs
@ cdecl fclose(ptr) CRTDLL_fclose
@ cdecl feof(ptr) CRTDLL_feof
@ stub ferror
@ cdecl ferror(ptr) CRTDLL_ferror
@ cdecl fflush(ptr) CRTDLL_fflush
@ cdecl fgetc(ptr) CRTDLL_fgetc
@ stub fgetpos
@ cdecl fgetpos(ptr ptr) CRTDLL_fgetpos
@ cdecl fgets(ptr long ptr) CRTDLL_fgets
@ stub fgetwc
@ cdecl floor(double) floor
@ -396,11 +396,11 @@ debug_channels (crtdll)
@ cdecl fwrite(ptr long long ptr) CRTDLL_fwrite
@ stub fwscanf
@ cdecl getc(ptr) CRTDLL_getc
@ stub getchar
@ cdecl getchar() CRTDLL_getchar
@ cdecl getenv (str) CRTDLL_getenv
@ cdecl gets(ptr) CRTDLL_gets
@ cdecl gmtime(ptr) gmtime
@ stub is_wctype
@ forward is_wctype ntdll.iswctype
@ cdecl isalnum(long) isalnum
@ cdecl isalpha(long) isalpha
@ cdecl iscntrl(long) iscntrl
@ -414,7 +414,7 @@ debug_channels (crtdll)
@ cdecl isupper(long) isupper
@ cdecl iswalnum(long) CRTDLL_iswalnum
@ forward iswalpha ntdll.iswalpha
@ stub iswascii
@ cdecl iswascii(long) CRTDLL_iswascii
@ cdecl iswcntrl(long) CRTDLL_iswcntrl
@ forward iswctype ntdll.iswctype
@ cdecl iswdigit(long) CRTDLL_iswdigit
@ -445,7 +445,7 @@ debug_channels (crtdll)
@ cdecl memset(ptr long long) memset
@ cdecl mktime(ptr) mktime
@ cdecl modf(double ptr) modf
@ stub perror
@ cdecl perror(str) CRTDLL_perror
@ cdecl pow(double double) pow
@ varargs printf() printf
@ cdecl putc(long ptr) CRTDLL_putc
@ -457,7 +457,7 @@ debug_channels (crtdll)
@ cdecl realloc(ptr long) CRTDLL_realloc
@ cdecl remove(str) CRTDLL_remove
@ cdecl rename(str str) CRTDLL_rename
@ stub rewind
@ cdecl rewind(ptr) CRTDLL_rewind
@ stub scanf
@ cdecl setbuf(ptr ptr) CRTDLL_setbuf
@ cdecl setlocale(long ptr) CRTDLL_setlocale
@ -475,7 +475,7 @@ debug_channels (crtdll)
@ cdecl strcoll(str str) strcoll
@ cdecl strcpy(ptr str) strcpy
@ cdecl strcspn(str str) strcspn
@ cdecl strerror(long) strerror
@ cdecl strerror(long) CRTDLL_strerror
@ cdecl strftime(ptr long str ptr) strftime
@ cdecl strlen(str) strlen
@ cdecl strncat(str str long) strncat

File diff suppressed because it is too large Load Diff

336
dlls/crtdll/dir.c Normal file
View File

@ -0,0 +1,336 @@
/*
* 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 "drive.h"
#include <time.h>
#include "file.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
/* INTERNAL: Translate find_t to PWIN32_FIND_DATAA */
static void __CRTDLL__fttofd(LPWIN32_FIND_DATAA fd, find_t* ft);
static void __CRTDLL__fttofd(LPWIN32_FIND_DATAA fd, find_t* ft)
{
static DWORD dummy;
/* 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;
ft->time_create = DOSFS_FileTimeToUnixTime(&fd->ftCreationTime,&dummy);
ft->time_access = DOSFS_FileTimeToUnixTime(&fd->ftLastAccessTime,&dummy);
ft->time_write = DOSFS_FileTimeToUnixTime(&fd->ftLastWriteTime,&dummy);
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)
{
if (!DRIVE_SetCurrentDrive(newdrive-1))
{
__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))
{
SetLastError(ERROR_INVALID_DRIVE);
__CRTDLL__set_errno(GetLastError());
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 */
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;
if (!drive || --drive == DRIVE_GetCurrentDrive())
return CRTDLL__getcwd(buf,size); /* current */
else
{
char dir[_MAX_PATH];
char drivespec[4] = {'A', ':', '\\', 0};
int dir_len;
drivespec[0] += drive;
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 */
}
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)
{
return DRIVE_GetCurrentDrive() + 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;
}

186
dlls/crtdll/exit.c Normal file
View File

@ -0,0 +1,186 @@
/*
* 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>
#include "process.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)
{
CRTDLL_fprintf(CRTDLL_stderr,"\nrun-time error:\nError Code %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)
{
FIXME("not calling CRTDLL cleanup\n");
/* dont exit, return to caller */
}
/*********************************************************************
* _cexit (CRTDLL.049)
*/
VOID __cdecl CRTDLL__cexit(VOID)
{
FIXME("not calling CRTDLL cleanup\n");
/* dont exit, 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;
}

1524
dlls/crtdll/file.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,12 +4,31 @@
* Copyright 1999 Alexandre Julliard
*/
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "crtdll.h"
DEFAULT_DEBUG_CHANNEL(crtdll);
/*********************************************************************
* _mbsicmp (CRTDLL.204)
*/
int __cdecl CRTDLL__mbsicmp(unsigned char *x,unsigned char *y)
{
do {
if (!*x)
return !!*y;
if (!*y)
return !!*x;
/* FIXME: MBCS handling... */
if (*x!=*y)
return 1;
x++;
y++;
} while (1);
}
/*********************************************************************
* CRTDLL__mbsinc (CRTDLL.205)
*/
@ -31,6 +50,17 @@ INT __cdecl CRTDLL__mbslen( LPCSTR str )
}
/*********************************************************************
* _mbsrchr (CRTDLL.223)
*/
LPSTR __cdecl CRTDLL__mbsrchr(LPSTR s,CHAR x)
{
/* FIXME: handle multibyte strings */
return strrchr(s,x);
}
/*********************************************************************
* CRTDLL_mbtowc (CRTDLL.430)
*/
@ -44,3 +74,16 @@ INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
if (n >= 2 && IsDBCSLeadByte(*str) && str[1]) return 2;
return 1;
}
/*********************************************************************
* _mbccpy (CRTDLL.??)
*
* Copy one multibyte character to another
*/
VOID __cdecl CRTDLL__mbccpy(LPSTR dest, LPSTR src)
{
FIXME("MBCS copy treated as ASCII\n");
*dest = *src;
}

131
dlls/crtdll/memory.c Normal file
View File

@ -0,0 +1,131 @@
/*
* 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.
*/
#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 );
}
/*********************************************************************
* _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 );
}

225
dlls/crtdll/spawn.c Normal file
View File

@ -0,0 +1,225 @@
/*
* 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.
* -Wine has a "process.h" which is not the same as any crt version.
* 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 "process.h"
#include "options.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, LPSTR exe, LPSTR args, LPSTR env);
static int __CRTDLL__spawn(INT flags, LPSTR 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(LPSTR *arg, CHAR delim);
static LPSTR __CRTDLL__argvtos(LPSTR *arg, CHAR delim)
{
LPSTR *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;
}
/*********************************************************************
* _spawnve (CRTDLL.274)
*
* Spawn a process.
*
*/
HANDLE __cdecl CRTDLL__spawnve(INT flags, LPSTR name, LPSTR *argv, LPSTR *envv)
{
LPSTR args = __CRTDLL__argvtos(argv,' ');
LPSTR envs = __CRTDLL__argvtos(envv,0);
LPSTR fullname = name;
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)
{
HANDLE ret = __CRTDLL__spawn(flags, fullname, args, envs);
CRTDLL_free(args);
CRTDLL_free(envs);
return ret;
}
if (envs)
CRTDLL_free(envs);
WARN(":No argv[0] passed - process will not be executed");
return -1;
}
/*********************************************************************
* system (CRTDLL.485)
*/
INT __cdecl CRTDLL_system(LPSTR x)
{
#define SYSBUF_LENGTH 1500
char buffer[SYSBUF_LENGTH];
unsigned char *y = x;
unsigned char *bp;
int i;
strcpy(buffer, argv0);
bp = buffer + strlen(buffer);
*bp++ = ' ';
*bp++ = '"';
*bp++ = 0;
i = strlen(buffer) + strlen(x) +2;
/* Calculate needed buffer size to prevent overflow. */
while (*y) {
if (*y =='\\') i++;
y++;
}
/* If buffer too short, exit. */
if (i > SYSBUF_LENGTH) {
TRACE("_system buffer to small\n");
return 127;
}
y =x;
while (*y) {
*bp = *y;
bp++; y++;
if (*(y-1) =='\\') *bp++ = '\\';
}
/* Remove spaces from end of string. */
while (*(y-1) == ' ') {
bp--;y--;
}
*bp++ = '"';
*bp = 0;
TRACE("_system got '%s', executing '%s'\n",x,buffer);
return system(buffer);
}

192
dlls/crtdll/string.c Normal file
View File

@ -0,0 +1,192 @@
/*
* 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! */
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;
}
/*********************************************************************
* _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++;
}
}
}

120
dlls/crtdll/time.c Normal file
View File

@ -0,0 +1,120 @@
/*
* 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 "process.h"
#include "options.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

@ -4,18 +4,13 @@
* Copyright 1999 Alexandre Julliard
*/
#include "config.h"
#include "crtdll.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "wine/unicode.h"
#include "crtdll.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(crtdll);

View File

@ -11,6 +11,7 @@ HANDLE
HFILE
INT
LONG
ULONG
UINT
WCHAR
clock_t
@ -32,6 +33,7 @@ LPCVOID
LPDWORD
LPDWORD *
LPINT
LPUINT
LPSTR *
LPSTR **
LPVOID
@ -44,10 +46,13 @@ WCHAR *
_INITTERMFUN *
char *
jmp_buf
struct find_t *
struct stat *
find_t *
struct _stat *
struct win_stat *
struct _timeb *
time_t *
fpos_t *
diskfree_t *
unsigned char *
va_list
void *
@ -71,3 +76,7 @@ LPWSTR
new_handler_type
sig_handler_type
comp_func
struct complex
atexit_function