diff --git a/reactos/lib/crtdll/io/access.c b/reactos/lib/crtdll/io/access.c index bcc65527abf..d7108c1d08f 100644 --- a/reactos/lib/crtdll/io/access.c +++ b/reactos/lib/crtdll/io/access.c @@ -1,16 +1,5 @@ -#include #include - -#define F_OK 0x01 -#define R_OK 0x02 -#define W_OK 0x04 -#define X_OK 0x08 -#define D_OK 0x10 - -int access(const char *_path, int _amode) -{ - return _access(_path,_amode); -} +#include int _access( const char *_path, int _amode ) { @@ -19,15 +8,15 @@ int _access( const char *_path, int _amode ) if ( Attributes == -1 ) return -1; - if ( _amode & W_OK == W_OK ) { + if ( (_amode & W_OK) == W_OK ) { if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY ) return -1; } - if ( _amode & D_OK == D_OK ) { - if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) - return 0; + if ( (_amode & D_OK) != D_OK ) { + if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY ) + return -1; } return 0; -} \ No newline at end of file +} diff --git a/reactos/lib/crtdll/io/chmod.c b/reactos/lib/crtdll/io/chmod.c new file mode 100644 index 00000000000..67f3fd1f571 --- /dev/null +++ b/reactos/lib/crtdll/io/chmod.c @@ -0,0 +1,19 @@ +#include +#include + +int +_chmod(const char *filename, int func) +{ + DWROD FileAttributes = 0; + if ( func == _S_IREAD ) + FileAttributes &= FILE_ATTRIBUTE_READONLY; + if ( ((func & _S_IREAD) == _S_IREAD) && ((func & _S_IWRITE) == _S_IWRITE) ) + FileAttributes &= FILE_ATTRIBUTE_NORMAL; + + + + if ( SetFileAttributes(filename,func) == FALSE ) + return -1; + + return 1; +} diff --git a/reactos/lib/crtdll/io/chsize.c b/reactos/lib/crtdll/io/chsize.c new file mode 100644 index 00000000000..37f4242eca0 --- /dev/null +++ b/reactos/lib/crtdll/io/chsize.c @@ -0,0 +1,12 @@ +/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ +#include + +int +chsize(int _fd, long size) +{ + if (lseek(_fd, size, 0) == -1) + return -1; + if (_write(_fd, 0, 0) < 0) + return -1; + return 0; +} diff --git a/reactos/lib/crtdll/io/close.c b/reactos/lib/crtdll/io/close.c index d51a7f0a923..2431a04cd05 100644 --- a/reactos/lib/crtdll/io/close.c +++ b/reactos/lib/crtdll/io/close.c @@ -1,16 +1,10 @@ -#include #include -//#include - - -int close(int _fd) -{ - return _close(_fd); -} +#include +#include int _close(int _fd) { - CloseHandle(filehnd(_fd)); + CloseHandle(_get_osfhandle(_fd)); return __fileno_close(_fd); } diff --git a/reactos/lib/crtdll/io/commit.c b/reactos/lib/crtdll/io/commit.c new file mode 100644 index 00000000000..3320b75d2c1 --- /dev/null +++ b/reactos/lib/crtdll/io/commit.c @@ -0,0 +1,7 @@ +#include +#include + +unsigned int _commit(int _fd) +{ + return FlushFileBuffers(_get_osfhandle(_fd)) ? 0 : GetLastError(); +} diff --git a/reactos/lib/crtdll/io/create.c b/reactos/lib/crtdll/io/create.c index bd382e9218b..402c51e4916 100644 --- a/reactos/lib/crtdll/io/create.c +++ b/reactos/lib/crtdll/io/create.c @@ -1,8 +1,8 @@ #include #include -#undef creat -int creat(const char *filename, int mode) + +int _creat(const char *filename, int mode) { - return open(filename,_O_CREAT|_O_TRUNC,mode); + return _open(filename,_O_CREAT|_O_TRUNC,mode); } diff --git a/reactos/lib/crtdll/io/dup.c b/reactos/lib/crtdll/io/dup.c index b0168a8e927..12a09226825 100644 --- a/reactos/lib/crtdll/io/dup.c +++ b/reactos/lib/crtdll/io/dup.c @@ -1,13 +1,9 @@ #include #include -#undef dup -int dup( int handle ) -{ - return _dup(handle); -} -int _dup( int handle ) + +int _dup( int _fd ) { - return _open_osfhandle(filehnd(handle), 0666); -} \ No newline at end of file + return _open_osfhandle(_get_osfhandle(_fd), 0666); +} diff --git a/reactos/lib/crtdll/io/dup2.c b/reactos/lib/crtdll/io/dup2.c index 504338848b7..e59fa232163 100644 --- a/reactos/lib/crtdll/io/dup2.c +++ b/reactos/lib/crtdll/io/dup2.c @@ -1,14 +1,9 @@ #include #include +#include -#undef dup2 -int dup2( int handle1, int handle2 ) + +int _dup2( int _fd1, int _fd2 ) { - return _dup2(handle1,handle2); + return __fileno_dup2( _fd1, _fd2 ); } - - -int _dup2( int handle1, int handle2 ) -{ - return __fileno_dup2( handle1, handle2 ); -} \ No newline at end of file diff --git a/reactos/lib/crtdll/io/eof.c b/reactos/lib/crtdll/io/eof.c new file mode 100644 index 00000000000..622ec48c553 --- /dev/null +++ b/reactos/lib/crtdll/io/eof.c @@ -0,0 +1,7 @@ +#include +#include + +int _eof( int _fd ) +{ + return 0; +} diff --git a/reactos/lib/crtdll/io/filelen.c b/reactos/lib/crtdll/io/filelen.c new file mode 100644 index 00000000000..67073134655 --- /dev/null +++ b/reactos/lib/crtdll/io/filelen.c @@ -0,0 +1,8 @@ +#include +#include + +long +_filelength(int _fd) +{ + return GetFileSize(_get_osfhandle(_fd),NULL); +} diff --git a/reactos/lib/crtdll/io/fmode.c b/reactos/lib/crtdll/io/fmode.c index 1175dde3f6e..e541dbecf40 100644 --- a/reactos/lib/crtdll/io/fmode.c +++ b/reactos/lib/crtdll/io/fmode.c @@ -5,4 +5,4 @@ #undef _fmode int _fmode = O_TEXT; -unsigned int fmode_dll = &_fmode; +unsigned int _fmode_dll = &_fmode; diff --git a/reactos/lib/crtdll/io/isatty.c b/reactos/lib/crtdll/io/isatty.c index 4bb04934d25..b1437809963 100644 --- a/reactos/lib/crtdll/io/isatty.c +++ b/reactos/lib/crtdll/io/isatty.c @@ -1,8 +1,10 @@ #include -#undef isatty -int isatty( int handle ) + +int _isatty( int handle ) { - return (handle & 3); -} \ No newline at end of file + if ( handle < 5 ) + return 1; + return 0; +} diff --git a/reactos/lib/crtdll/io/lseek.c b/reactos/lib/crtdll/io/lseek.c index cba29e64f4d..f078cf8bd30 100644 --- a/reactos/lib/crtdll/io/lseek.c +++ b/reactos/lib/crtdll/io/lseek.c @@ -1,16 +1,9 @@ #include #include -//#include -#undef lseek -long lseek(int _fildes, long _offset, int _whence) +off_t _lseek(int _fd, off_t _offset, int _whence) { - return _lseek(_fildes,_offset,_whence); -} - -long _lseek(int _fildes, long _offset, int _whence) -{ - //return _llseek(filehnd(_fildes),_offset,_whence); + return _llseek((HFILE)_get_osfhandle(_fd),_offset,_whence); } diff --git a/reactos/lib/crtdll/io/open.c b/reactos/lib/crtdll/io/open.c index 9c2c4b2dc68..5aba4441b5b 100644 --- a/reactos/lib/crtdll/io/open.c +++ b/reactos/lib/crtdll/io/open.c @@ -39,12 +39,6 @@ char __is_text_file(FILE *p) { int __fileno_alloc(HANDLE hFile, int mode); -// fixme -#undef open -int open(const char *_path, int _oflag,...) -{ - return _open(_path,_oflag); -} int _open(const char *_path, int _oflag,...) { @@ -168,7 +162,7 @@ __fileno_alloc(HANDLE hFile, int mode) return i; } -void *filehnd(int fileno) +void *_get_osfhandle(int fileno) { @@ -245,6 +239,8 @@ int __fileno_close(int _fd) fileno_modes[_fd].fd = -1; fileno_modes[_fd].hFile = (HANDLE)-1; + + return 0; } diff --git a/reactos/lib/crtdll/io/pipe.c b/reactos/lib/crtdll/io/pipe.c new file mode 100644 index 00000000000..4561a24e083 --- /dev/null +++ b/reactos/lib/crtdll/io/pipe.c @@ -0,0 +1,7 @@ +#include +#include + +int _pipe(int _fildes[2], unsigned int size, int mode ) +{ + return -1; +} diff --git a/reactos/lib/crtdll/io/read.c b/reactos/lib/crtdll/io/read.c index a0bfbae5611..332ae71cb13 100644 --- a/reactos/lib/crtdll/io/read.c +++ b/reactos/lib/crtdll/io/read.c @@ -10,17 +10,13 @@ #include #include -size_t read(int _fd, void *_buf, size_t _nbyte) -{ - return _read(_fd,_buf,_nbyte); -} + size_t _read(int _fd, void *_buf, size_t _nbyte) { size_t _rbyte; - if ( !ReadFile(filehnd(_fd),_buf,_nbyte,&_rbyte,NULL) ) { - printf("%d\n",GetLastError()); + if ( !ReadFile(_get_osfhandle(_fd),_buf,_nbyte,&_rbyte,NULL) ) { return -1; } return _rbyte; -} \ No newline at end of file +} diff --git a/reactos/lib/crtdll/io/sopen.c b/reactos/lib/crtdll/io/sopen.c new file mode 100644 index 00000000000..680227e30a2 --- /dev/null +++ b/reactos/lib/crtdll/io/sopen.c @@ -0,0 +1,8 @@ +#include + + +int _sopen(char *path,int access,int shflag,int mode) +{ + + return _open((path), (access)|(shflag), (mode)); +} diff --git a/reactos/lib/crtdll/io/write.c b/reactos/lib/crtdll/io/write.c index 5572b60f620..15c9285255d 100644 --- a/reactos/lib/crtdll/io/write.c +++ b/reactos/lib/crtdll/io/write.c @@ -10,16 +10,11 @@ #include #include -int write(int _fd, const void *_buf,int _nbyte) -{ - return _write(_fd,_buf,_nbyte); -} size_t _write(int _fd, const void *_buf, size_t _nbyte) { size_t _wbyte; - if ( !WriteFile(filehnd(_fd),_buf,_nbyte,&_wbyte,NULL) ) { - printf("%d\n",GetLastError()); + if ( !WriteFile(_get_osfhandle(_fd),_buf,_nbyte,&_wbyte,NULL) ) { return -1; } return _wbyte;