diff --git a/reactos/include/msvcrt/msvcrtdbg.h b/reactos/include/msvcrt/msvcrtdbg.h new file mode 100644 index 00000000000..3916f9ad63d --- /dev/null +++ b/reactos/include/msvcrt/msvcrtdbg.h @@ -0,0 +1,43 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: include/msvcrt/msvcrtdbg.h + * PURPOSE: Useful debugging macros + * PROGRAMMER: + * UPDATE HISTORY: + * + */ + +/* + * NOTE: Define NDEBUG before including this header to disable debugging + * macros + */ + +#ifndef __MSVCRT_DEBUG +#define __MSVCRT_DEBUG + +#include + +#if 0 +#ifdef NDEBUG +#undef NDEBUG +#endif +#endif + +#ifdef DBG +#define DPRINT1(args...) do { DbgPrint("(MSVCRT:%s:%d) ",__FILE__,__LINE__); DbgPrint(args); } while(0); +#define CHECKPOINT1 do { DbgPrint("MSVCRT:%s:%d\n",__FILE__,__LINE__); } while(0); +#else +#define DPRINT1(args...) +#define CHECKPOINT1 +#endif + +#if !defined(NDEBUG) && defined(DBG) +#define DPRINT(args...) do { DbgPrint("(MSVCRT:%s:%d) ",__FILE__,__LINE__); DbgPrint(args); } while(0); +#define CHECKPOINT do { DbgPrint("MSVCRT:%s:%d\n",__FILE__,__LINE__); } while(0); +#else +#define DPRINT(args...) +#define CHECKPOINT +#endif /* NDEBUG */ + +#endif /* __MSVCRT_DEBUG */ diff --git a/reactos/lib/msvcrt/io/access.c b/reactos/lib/msvcrt/io/access.c index 36f0e18fcbe..493c4a748eb 100644 --- a/reactos/lib/msvcrt/io/access.c +++ b/reactos/lib/msvcrt/io/access.c @@ -1,5 +1,8 @@ #include #include +#include +#define NDEBUG +#include #ifndef F_OK #define F_OK 0x01 @@ -20,17 +23,24 @@ int _access( const char *_path, int _amode ) { DWORD Attributes = GetFileAttributesA(_path); + DPRINT("_access('%s', %x)\n", _path, _amode); - if ( Attributes == -1 ) + if ( Attributes == -1 ) { + __set_errno(ENOENT); return -1; + } if ( (_amode & W_OK) == W_OK ) { - if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY ) + if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY ) { + __set_errno(EACCES); return -1; + } } if ( (_amode & D_OK) == D_OK ) { - if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) + if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) { + __set_errno(EACCES); return -1; + } } return 0; @@ -40,16 +50,22 @@ int _waccess( const wchar_t *_path, int _amode ) { DWORD Attributes = GetFileAttributesW(_path); - if ( Attributes == -1 ) + if ( Attributes == -1 ) { + __set_errno(ENOENT); return -1; + } if ( (_amode & W_OK) == W_OK ) { - if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY ) + if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY ) { + __set_errno(EACCES); return -1; + } } if ( (_amode & D_OK) == D_OK ) { - if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) + if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) { + __set_errno(EACCES); return -1; + } } return 0; diff --git a/reactos/lib/msvcrt/io/chmod.c b/reactos/lib/msvcrt/io/chmod.c index 8932834d496..f5d61aa97f0 100644 --- a/reactos/lib/msvcrt/io/chmod.c +++ b/reactos/lib/msvcrt/io/chmod.c @@ -1,12 +1,15 @@ #include #include -#define mode_t int +#define NDEBUG +#include +#define mode_t int int _chmod(const char *filename, mode_t mode) { DWORD FileAttributes = 0; + DPRINT("_chmod('%s', %x)\n", filename, mode); FileAttributes = GetFileAttributesA(filename); if ( FileAttributes == -1 ) @@ -31,6 +34,7 @@ int _chmod(const char *filename, mode_t mode) int _wchmod(const wchar_t *filename, mode_t mode) { DWORD FileAttributes = 0; + DPRINT("_wchmod('%S', %x)\n", filename, mode); FileAttributes = GetFileAttributesW(filename); if ( FileAttributes == -1 ) diff --git a/reactos/lib/msvcrt/io/chsize.c b/reactos/lib/msvcrt/io/chsize.c index a0ca25ef237..865bec2e461 100644 --- a/reactos/lib/msvcrt/io/chsize.c +++ b/reactos/lib/msvcrt/io/chsize.c @@ -1,8 +1,12 @@ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ #include +#define NDEBUG +#include + int _chsize(int _fd, long size) { + DPRINT("_chsize(fd %d, size %d)\n", _fd, size); if (lseek(_fd, size, 0) == -1) return -1; if (_write(_fd, 0, 0) < 0) diff --git a/reactos/lib/msvcrt/io/close.c b/reactos/lib/msvcrt/io/close.c index db9bd4e9240..65d6230ce39 100644 --- a/reactos/lib/msvcrt/io/close.c +++ b/reactos/lib/msvcrt/io/close.c @@ -2,8 +2,12 @@ #include #include +#define NDEBUG +#include + int _close(int _fd) { + DPRINT("_close(fd %d)\n", _fd); if (_fd == -1) return -1; if (CloseHandle(_get_osfhandle(_fd)) == FALSE) diff --git a/reactos/lib/msvcrt/io/create.c b/reactos/lib/msvcrt/io/create.c index f8ee1a0fb4c..3f11706db79 100644 --- a/reactos/lib/msvcrt/io/create.c +++ b/reactos/lib/msvcrt/io/create.c @@ -1,12 +1,17 @@ #include #include +#define NDEBUG +#include + int _creat(const char *filename, int mode) { + DPRINT("_creat('%s', mode %x)\n", filename, mode); return _open(filename,_O_CREAT|_O_TRUNC,mode); } int _wcreat(const wchar_t *filename, int mode) { + DPRINT("_wcreat('%S', mode %x)\n", filename, mode); return _wopen(filename,_O_CREAT|_O_TRUNC,mode); } diff --git a/reactos/lib/msvcrt/io/isatty.c b/reactos/lib/msvcrt/io/isatty.c index 0291bfbdee2..3ed7a80d1e6 100644 --- a/reactos/lib/msvcrt/io/isatty.c +++ b/reactos/lib/msvcrt/io/isatty.c @@ -1,11 +1,13 @@ #include #include +#define NDEBUG +#include int _isatty( int fd ) { struct stat buf; - + DPRINT("_isatty(fd %d)\n", fd); if (_fstat (fd, &buf) < 0) return 0; if (S_ISCHR (buf.st_mode)) diff --git a/reactos/lib/msvcrt/io/mktemp.c b/reactos/lib/msvcrt/io/mktemp.c index 4f531706de8..6f31b4a0007 100644 --- a/reactos/lib/msvcrt/io/mktemp.c +++ b/reactos/lib/msvcrt/io/mktemp.c @@ -17,6 +17,9 @@ #include #include +#define NDEBUG +#include + char* _mktemp (char *_template) { @@ -24,6 +27,7 @@ char* _mktemp (char *_template) char *cp, *dp; int i, len, xcount, loopcnt; + DPRINT("_mktemp('%s')\n", _template); len = strlen (_template); cp = _template + len; @@ -76,6 +80,7 @@ wchar_t* _wmktemp (wchar_t *_template) wchar_t *cp, *dp; int i, len, xcount, loopcnt; + DPRINT("_wmktemp('%S')\n", _template); len = wcslen (_template); cp = _template + len; diff --git a/reactos/lib/msvcrt/io/unlink.c b/reactos/lib/msvcrt/io/unlink.c index 542e766ee32..9165aac0440 100644 --- a/reactos/lib/msvcrt/io/unlink.c +++ b/reactos/lib/msvcrt/io/unlink.c @@ -10,16 +10,23 @@ #include #include +#define NDEBUG +#include + int _unlink(const char *filename) { + int result = 0; + DPRINT("_unlink('%s')\n", filename); if (!DeleteFileA(filename)) - return -1; - return 0; + result = -1; + DPRINT("%d\n", result); + return result; } int _wunlink(const wchar_t *filename) { + DPRINT("_wunlink('%S')\n", filename); if (!DeleteFileW(filename)) return -1; return 0; diff --git a/reactos/lib/msvcrt/stdio/remove.c b/reactos/lib/msvcrt/stdio/remove.c index 52b04f8e142..5f309af75f5 100644 --- a/reactos/lib/msvcrt/stdio/remove.c +++ b/reactos/lib/msvcrt/stdio/remove.c @@ -2,15 +2,22 @@ #include #include +#define NDEBUG +#include + int remove(const char *fn) { + int result = 0; + DPRINT("remove('%s')\n", fn); if (!DeleteFileA(fn)) - return -1; - return 0; + result = -1; + DPRINT("%d\n", result); + return result; } int _wremove(const wchar_t *fn) { + DPRINT("_wremove('%S')\n", fn); if (!DeleteFileW(fn)) return -1; return 0; diff --git a/reactos/lib/msvcrt/stdlib/senv.c b/reactos/lib/msvcrt/stdlib/senv.c index 6311b8183b8..32c1afea984 100644 --- a/reactos/lib/msvcrt/stdlib/senv.c +++ b/reactos/lib/msvcrt/stdlib/senv.c @@ -2,6 +2,9 @@ #include #include +#define NDEBUG +#include + void _searchenv(const char *file,const char *var,char *path ) { char *env = getenv(var); @@ -9,6 +12,7 @@ void _searchenv(const char *file,const char *var,char *path ) char *y; char *FilePart; + DPRINT("_searchenv()\n"); x = strchr(env,'='); if ( x != NULL ) { *x = 0; @@ -33,6 +37,7 @@ void _wsearchenv(const wchar_t *file,const wchar_t *var,wchar_t *path) wchar_t *y; wchar_t *FilePart; + DPRINT("_searchenw()\n"); x = wcschr(env,L'='); if ( x != NULL ) { *x = 0;