added some files and impl diff between fileno and handles

svn path=/trunk/; revision=250
This commit is contained in:
Boudewijn Dekker 1999-02-20 18:36:47 +00:00
parent 25f46657b5
commit 17a714dfcd
18 changed files with 104 additions and 80 deletions

View file

@ -1,16 +1,5 @@
#include <io.h>
#include <windows.h>
#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 <io.h>
int _access( const char *_path, int _amode )
{
@ -19,13 +8,13 @@ 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;

View file

@ -0,0 +1,19 @@
#include <windows.h>
#include <io.h>
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;
}

View file

@ -0,0 +1,12 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
int
chsize(int _fd, long size)
{
if (lseek(_fd, size, 0) == -1)
return -1;
if (_write(_fd, 0, 0) < 0)
return -1;
return 0;
}

View file

@ -1,16 +1,10 @@
#include <io.h>
#include <windows.h>
//#include <libc/file.h>
int close(int _fd)
{
return _close(_fd);
}
#include <io.h>
#include <libc/file.h>
int _close(int _fd)
{
CloseHandle(filehnd(_fd));
CloseHandle(_get_osfhandle(_fd));
return __fileno_close(_fd);
}

View file

@ -0,0 +1,7 @@
#include <windows.h>
#include <io.h>
unsigned int _commit(int _fd)
{
return FlushFileBuffers(_get_osfhandle(_fd)) ? 0 : GetLastError();
}

View file

@ -1,8 +1,8 @@
#include <io.h>
#include <fcntl.h>
#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);
}

View file

@ -1,13 +1,9 @@
#include <windows.h>
#include <io.h>
#undef dup
int dup( int handle )
{
return _dup(handle);
}
int _dup( int handle )
int _dup( int _fd )
{
return _open_osfhandle(filehnd(handle), 0666);
return _open_osfhandle(_get_osfhandle(_fd), 0666);
}

View file

@ -1,14 +1,9 @@
#include <windows.h>
#include <io.h>
#include <libc/file.h>
#undef dup2
int dup2( int handle1, int handle2 )
int _dup2( int _fd1, int _fd2 )
{
return _dup2(handle1,handle2);
}
int _dup2( int handle1, int handle2 )
{
return __fileno_dup2( handle1, handle2 );
return __fileno_dup2( _fd1, _fd2 );
}

View file

@ -0,0 +1,7 @@
#include <windows.h>
#include <io.h>
int _eof( int _fd )
{
return 0;
}

View file

@ -0,0 +1,8 @@
#include <windows.h>
#include <io.h>
long
_filelength(int _fd)
{
return GetFileSize(_get_osfhandle(_fd),NULL);
}

View file

@ -5,4 +5,4 @@
#undef _fmode
int _fmode = O_TEXT;
unsigned int fmode_dll = &_fmode;
unsigned int _fmode_dll = &_fmode;

View file

@ -1,8 +1,10 @@
#include <io.h>
#undef isatty
int isatty( int handle )
int _isatty( int handle )
{
return (handle & 3);
if ( handle < 5 )
return 1;
return 0;
}

View file

@ -1,16 +1,9 @@
#include <windows.h>
#include <io.h>
//#include <libc/file.h>
#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);
}

View file

@ -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)
{
@ -246,6 +240,8 @@ int __fileno_close(int _fd)
fileno_modes[_fd].fd = -1;
fileno_modes[_fd].hFile = (HANDLE)-1;
return 0;
}
int _open_osfhandle (void *osfhandle, int flags )

View file

@ -0,0 +1,7 @@
#include <windows.h>
#include <io.h>
int _pipe(int _fildes[2], unsigned int size, int mode )
{
return -1;
}

View file

@ -10,15 +10,11 @@
#include <io.h>
#include <windows.h>
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;
}

View file

@ -0,0 +1,8 @@
#include <io.h>
int _sopen(char *path,int access,int shflag,int mode)
{
return _open((path), (access)|(shflag), (mode));
}

View file

@ -10,16 +10,11 @@
#include <io.h>
#include <windows.h>
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;