-critical.c: catch (more) invalid use
-impl. sscanf (stolen from wine)
crt:
-use native mingw headers and not private copies of them
-converted some routines to using tchar == impl. many missing unicode routines
-impl. sscanf and friends correctly (stolen from wine)
tchar.h:
-added lotsa missin stuff

svn path=/trunk/; revision=13608
This commit is contained in:
Gunnar Dalsnes 2005-02-16 22:29:48 +00:00
parent 0645d3e055
commit 55fb40a502
388 changed files with 3422 additions and 4595 deletions

View file

@ -6,8 +6,8 @@
* PROGRAMMER: Eric Kohl (Imported from DJGPP) * PROGRAMMER: Eric Kohl (Imported from DJGPP)
*/ */
#include <msvcrt/conio.h> #include <conio.h>
#include <msvcrt/stdlib.h> #include <stdlib.h>
/* /*
* @implemented * @implemented

View file

@ -6,8 +6,9 @@
* PROGRAMMER: Eric Kohl (Imported from DJGPP) * PROGRAMMER: Eric Kohl (Imported from DJGPP)
*/ */
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/conio.h> #include <stdarg.h>
#include <conio.h>
/* /*
* @unimplemented * @unimplemented

View file

@ -9,10 +9,10 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/conio.h> #include <conio.h>
#include <msvcrt/string.h> #include <string.h>
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
@ -22,7 +22,7 @@ int _cputs(const char *_str)
{ {
int len = strlen(_str); int len = strlen(_str);
DWORD written = 0; DWORD written = 0;
if (!WriteFile(filehnd(stdout->_file),_str,len,&written,NULL)) if (!WriteFile( fdinfo(stdout->_file)->hFile ,_str,len,&written,NULL))
return -1; return -1;
return 0; return 0;
} }

View file

@ -1,29 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: msvcrt/conio/cscanf.c
* PURPOSE: C Runtime
* PROGRAMMER: Eric Kohl (Imported from DJGPP)
*/
#include <msvcrt/conio.h>
#include <msvcrt/stdarg.h>
#include <msvcrt/stdio.h>
#include <msvcrt/internal/stdio.h>
/*
* @unimplemented
*/
int _cscanf(char *fmt, ...)
{
int cnt;
va_list ap;
//fixme cscanf should scan the console's keyboard
va_start(ap, fmt);
cnt = __vscanf(fmt, ap);
va_end(ap);
return cnt;
}

View file

@ -9,10 +9,10 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/conio.h> #include <conio.h>
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/console.h> #include <internal/console.h>
/* /*
@ -26,7 +26,7 @@ int _getch(void)
c = ungot_char; c = ungot_char;
char_avail = 0; char_avail = 0;
} else { } else {
ReadConsoleA(_get_osfhandle(stdin->_file), ReadConsoleA((HANDLE)_get_osfhandle(stdin->_file),
&c, &c,
1, 1,
&NumberOfCharsRead, &NumberOfCharsRead,

View file

@ -10,11 +10,11 @@
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/conio.h> #include <conio.h>
#include <msvcrt/internal/console.h> #include <internal/console.h>
int getche(void) int _getche(void)
{ {
if (char_avail) if (char_avail)
/* /*
@ -26,6 +26,6 @@ int getche(void)
* hasn't been got by a conio function. * hasn't been got by a conio function.
* We don't echo again. * We don't echo again.
*/ */
return(getch()); return(_getch());
return (_putch(getch())); return (_putch(_getch()));
} }

View file

@ -9,8 +9,8 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/conio.h> #include <conio.h>
#include <msvcrt/internal/console.h> #include <internal/console.h>
/* /*

View file

@ -9,7 +9,7 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/conio.h> #include <conio.h>
/* /*
* @implemented * @implemented

View file

@ -10,8 +10,8 @@
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/conio.h> #include <conio.h>
#include <msvcrt/internal/console.h> #include <internal/console.h>
#define EOF -1 #define EOF -1

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
unsigned short _ctype[] = { unsigned short _ctype[] = {
0, /* <EOF>, 0xFFFF */ 0, /* <EOF>, 0xFFFF */

View file

@ -7,7 +7,7 @@
* UPDATE HISTORY: * UPDATE HISTORY:
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isalnum #undef isalnum

View file

@ -8,7 +8,7 @@
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isalpha #undef isalpha

View file

@ -8,7 +8,7 @@
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
/* /*
* @implemented * @implemented

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef iscntrl #undef iscntrl
/* /*

View file

@ -7,7 +7,7 @@
* UPDATE HISTORY: * UPDATE HISTORY:
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
/* /*

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
extern unsigned short _ctype[]; extern unsigned short _ctype[];
@ -34,7 +34,7 @@ unsigned short **__p__pwctype(void)
/* /*
* @implemented * @implemented
*/ */
int _isctype(unsigned int c, int ctypeFlags) int _isctype(int c, int ctypeFlags)
{ {
return (_pctype[(unsigned char)(c & 0xFF)] & ctypeFlags); return (_pctype[(unsigned char)(c & 0xFF)] & ctypeFlags);
} }

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isdigit #undef isdigit

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isgraph #undef isgraph
/* /*

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef islower #undef islower

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isprint #undef isprint
/* /*

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef ispunct #undef ispunct
/* /*

View file

@ -8,7 +8,7 @@
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isspace #undef isspace

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isupper #undef isupper
/* /*

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef isxdigit #undef isxdigit
/* /*

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
/* /*
* @implemented * @implemented

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef tolower #undef tolower
/* /*

View file

@ -6,7 +6,7 @@
* PROGRAMMER: Copyright (C) 1995 DJ Delorie * PROGRAMMER: Copyright (C) 1995 DJ Delorie
*/ */
#include <msvcrt/ctype.h> #include <ctype.h>
#undef toupper #undef toupper
/* /*

View file

@ -1,7 +1,7 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/ctype.h> #include <ctype.h>
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
* @implemented * @implemented

View file

@ -1,9 +1,9 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/ctype.h> #include <ctype.h>
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/stdlib.h> #include <stdlib.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
int cur_drive = 0; int cur_drive = 0;

View file

@ -1,8 +1,8 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/stdlib.h> #include <stdlib.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
* @implemented * @implemented

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/ctype.h> #include <ctype.h>
#include <msvcrt/direct.h> #include <direct.h>
/* /*

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/ctype.h> #include <ctype.h>
#include <msvcrt/direct.h> #include <direct.h>
extern int cur_drive; extern int cur_drive;

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,8 +1,7 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/ctype.h> #include <ctype.h>
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
#include <msvcrt/internal/file.h>
/* /*
* @implemented * @implemented

View file

@ -1,8 +1,8 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/stdlib.h> #include <stdlib.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/direct.h> #include <direct.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,5 +1,5 @@
#include <msvcrt/float.h> #include <float.h>
#include <msvcrt/internal/ieee.h> #include <internal/ieee.h>
/* /*

View file

@ -1,4 +1,4 @@
#include <msvcrt/float.h> #include <float.h>
/* /*
* @implemented * @implemented

View file

@ -1,6 +1,6 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/float.h> #include <float.h>
#define X87_CW_IM (1<<0) /* Invalid operation mask */ #define X87_CW_IM (1<<0) /* Invalid operation mask */
#define X87_CW_DM (1<<1) /* Denormal operand mask */ #define X87_CW_DM (1<<1) /* Denormal operand mask */

View file

@ -1,5 +1,5 @@
#include <msvcrt/float.h> #include <float.h>
#include <msvcrt/internal/ieee.h> #include <internal/ieee.h>
/* /*
* @implemented * @implemented

View file

@ -1,6 +1,6 @@
#include <msvcrt/float.h> #include <float.h>
#include <msvcrt/math.h> #include <math.h>
#include <msvcrt/internal/ieee.h> #include <internal/ieee.h>
#define _FPCLASS_SNAN 0x0001 /* signaling NaN */ #define _FPCLASS_SNAN 0x0001 /* signaling NaN */

View file

@ -2,8 +2,8 @@
#undef __USE_W32API #undef __USE_W32API
#endif #endif
#include <msvcrt/float.h> #include <float.h>
#include <msvcrt/internal/tls.h> #include <internal/tls.h>
/* /*
* @implemented * @implemented

View file

@ -1,4 +1,4 @@
#include <msvcrt/float.h> #include <float.h>
/* /*

View file

@ -16,9 +16,9 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave, not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */ Cambridge, MA 02139, USA. */
#include <msvcrt/math.h> #include <math.h>
#include <msvcrt/float.h> #include <float.h>
#include <msvcrt/internal/ieee.h> #include <internal/ieee.h>
/* /*

View file

@ -18,7 +18,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <msvcrt/float.h> #include <float.h>
double _logb (double __x) double _logb (double __x)
{ {

View file

@ -1,4 +1,4 @@
#include <msvcrt/float.h> #include <float.h>
/* /*
@ -9,7 +9,7 @@ double _nextafter( double x, double y )
if ( x == y) if ( x == y)
return x; return x;
if ( isnan(x) || isnan(y) ) if ( _isnan(x) || _isnan(y) )
return x; return x;
return x; return x;

View file

@ -1,5 +1,5 @@
#include <msvcrt/float.h> #include <float.h>
#include <msvcrt/internal/ieee.h> #include <internal/ieee.h>
/* /*
* @implemented * @implemented

View file

@ -1,4 +1,4 @@
#include <msvcrt/float.h> #include <float.h>
/* /*
* @implemented * @implemented

View file

@ -1,17 +1,26 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <tchar.h>
#include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
#ifdef _UNICODE
#define _TS S
#else
#define _TS s
#endif
/* /*
* @implemented * @implemented
*/ */
int _access( const char *_path, int _amode ) int _taccess( const _TCHAR *_path, int _amode )
{ {
DWORD Attributes = GetFileAttributesA(_path); DWORD Attributes = GetFileAttributes(_path);
DPRINT("_access('%s', %x)\n", _path, _amode); DPRINT(MK_STR(_taccess)"('%"_TS"', %x)\n", _path, _amode);
if (Attributes == -1) { if (Attributes == -1) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
@ -23,11 +32,31 @@ int _access( const char *_path, int _amode )
return -1; return -1;
} }
} }
if ((_amode & D_OK) == D_OK) {
if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
__set_errno(EACCES);
return -1;
}
}
return 0; return 0;
} }
/*
* INTERNAL
*/
int access_dirT(const _TCHAR *_path)
{
DWORD Attributes = GetFileAttributes(_path);
DPRINT(MK_STR(is_dirT)"('%"_TS"')\n", _path);
if (Attributes == -1) {
_dosmaperr(GetLastError());
return -1;
}
if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
{
__set_errno(EACCES);
return -1;
}
return 0;
}

View file

@ -1,9 +1,13 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <sys/stat.h>
#include <tchar.h>
#include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
#define mode_t int #define mode_t int
@ -11,14 +15,14 @@
/* /*
* @implemented * @implemented
*/ */
int _chmod(const char* filename, mode_t mode) int _tchmod(const _TCHAR* filename, mode_t mode)
{ {
DWORD FileAttributes = 0; DWORD FileAttributes = 0;
BOOLEAN Set = FALSE; BOOLEAN Set = FALSE;
DPRINT("_chmod('%s', %x)\n", filename, mode); DPRINT(#_tchmod"('%"sT"', %x)\n", filename, mode);
FileAttributes = GetFileAttributesA(filename); FileAttributes = GetFileAttributes(filename);
if ( FileAttributes == -1 ) { if ( FileAttributes == -1 ) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
return -1; return -1;
@ -38,7 +42,7 @@ int _chmod(const char* filename, mode_t mode)
Set = TRUE; Set = TRUE;
} }
} }
if (Set && SetFileAttributesA(filename, FileAttributes) == FALSE) { if (Set && SetFileAttributes(filename, FileAttributes) == FALSE) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
return -1; return -1;
} }

View file

@ -1,8 +1,8 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/io.h> #include <io.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*
* @implemented * @implemented
@ -10,7 +10,7 @@
int _chsize(int _fd, long size) int _chsize(int _fd, long size)
{ {
DPRINT("_chsize(fd %d, size %d)\n", _fd, size); DPRINT("_chsize(fd %d, size %d)\n", _fd, size);
if (lseek(_fd, size, 0) == -1) if (_lseek(_fd, size, 0) == -1)
return -1; return -1;
if (_write(_fd, 0, 0) < 0) if (_write(_fd, 0, 0) < 0)
return -1; return -1;

View file

@ -1,19 +1,22 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*
* @implemented * @implemented
*/ */
int _close(int _fd) int _close(int _fd)
{ {
DPRINT("_close(fd %d)\n", _fd); TRACE("_close(%i)", _fd);
if (_fd == -1)
return -1; if (_fd == -1)
if (CloseHandle(_get_osfhandle(_fd)) == FALSE) return(-1);
return -1; if (CloseHandle((HANDLE)_get_osfhandle(_fd)) == FALSE)
return __fileno_close(_fd); return(-1);
//return
free_fd(_fd);
return(0);
} }

View file

@ -1,7 +1,7 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
@ -9,7 +9,7 @@
*/ */
int _commit(int _fd) int _commit(int _fd)
{ {
if (! FlushFileBuffers(_get_osfhandle(_fd)) ) { if (! FlushFileBuffers((HANDLE)_get_osfhandle(_fd)) ) {
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }

View file

@ -1,8 +1,8 @@
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/fcntl.h> #include <fcntl.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*

View file

@ -1,7 +1,7 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
@ -14,7 +14,7 @@ int _dup(int handle)
BOOL result; BOOL result;
int fd; int fd;
hFile = _get_osfhandle(handle); hFile = (HANDLE)_get_osfhandle(handle);
if (hFile == INVALID_HANDLE_VALUE) { if (hFile == INVALID_HANDLE_VALUE) {
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
@ -31,7 +31,7 @@ int _dup(int handle)
return -1; return -1;
} }
fd = __fileno_alloc(hFile, __fileno_getmode(handle)); fd = alloc_fd(hFile, __fileno_getmode(handle));
if (fd < 0) if (fd < 0)
{ {
CloseHandle(hFile); CloseHandle(hFile);

View file

@ -1,5 +1,5 @@
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
* @implemented * @implemented

View file

@ -1,4 +1,5 @@
#include <msvcrt/io.h> #include <stdio.h>
#include <io.h>
/* /*
* @implemented * @implemented

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
@ -8,7 +8,7 @@
*/ */
long _filelength(int _fd) long _filelength(int _fd)
{ {
DWORD len = GetFileSize(_get_osfhandle(_fd), NULL); DWORD len = GetFileSize((HANDLE)_get_osfhandle(_fd), NULL);
if (len == INVALID_FILE_SIZE) { if (len == INVALID_FILE_SIZE) {
DWORD oserror = GetLastError(); DWORD oserror = GetLastError();
if (oserror != 0) { if (oserror != 0) {

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
@ -10,7 +10,7 @@ __int64 _filelengthi64(int _fd)
{ {
DWORD lo_length, hi_length; DWORD lo_length, hi_length;
lo_length = GetFileSize(_get_osfhandle(_fd), &hi_length); lo_length = GetFileSize((HANDLE)_get_osfhandle(_fd), &hi_length);
if (lo_length == INVALID_FILE_SIZE) { if (lo_length == INVALID_FILE_SIZE) {
DWORD oserror = GetLastError(); DWORD oserror = GetLastError();
if (oserror != 0) { if (oserror != 0) {

View file

@ -1,9 +1,178 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/string.h> #include <string.h>
#include <msvcrt/internal/file.h> #include <tchar.h>
#include <internal/file.h>
/*
* @implemented
*/
#ifdef _UNICODE
long
#else
int
#endif
_tfindfirst(const _TCHAR* _name, struct _tfinddata_t* result)
{
WIN32_FIND_DATA FindFileData;
_TCHAR dir[MAX_PATH];
long hFindFile;
int len = 0;
if (_name == NULL || _name[0] == 0) {
len = GetCurrentDirectory(MAX_PATH-4,dir);
if (dir[len-1] != '\\') {
dir[len] = '\\';
dir[len+1] = 0;
}
_tcscat(dir,_T("*.*"));
} else {
_tcscpy(dir,_name);
}
hFindFile = (long)FindFirstFile(dir, &FindFileData);
if (hFindFile == -1) {
memset(result,0,sizeof(struct _tfinddata_t));
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!_tcschr(dir,'*') && !_tcschr(dir,'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
/*
* @implemented
*/
int _tfindnext(
#ifdef _UNICODE
long handle,
#else
int handle,
#endif
struct _tfinddata_t* result)
{
WIN32_FIND_DATA FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFile((void*)handle, &FindFileData)) {
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName, MAX_PATH);
return 0;
}
/*
* @implemented
*/
long _tfindfirsti64(const _TCHAR *_name, struct _tfinddatai64_t *result)
{
WIN32_FIND_DATA FindFileData;
_TCHAR dir[MAX_PATH];
long hFindFile;
int len = 0;
if ( _name == NULL || _name[0] == 0 )
{
len = GetCurrentDirectory(MAX_PATH-4,dir);
if (dir[len-1] != '\\')
{
dir[len] = '\\';
dir[len+1] = 0;
}
_tcscat(dir, _T("*.*"));
}
else
_tcscpy(dir, _name);
hFindFile = (long)FindFirstFile(dir, &FindFileData);
if (hFindFile == -1)
{
memset(result,0,sizeof(struct _tfinddatai64_t));
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size =
(((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!_tcschr(dir,'*') && !_tcschr(dir,'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
//_CRTIMP long __cdecl _findfirsti64(const char*, struct _finddatai64_t*);
//_CRTIMP int __cdecl _findnexti64(long, struct _finddatai64_t*);
/*
* @implemented
*/
int _tfindnexti64(long handle, struct _tfinddatai64_t *result)
{
WIN32_FIND_DATA FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFile((HANDLE)handle, &FindFileData)) {
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size =
(((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
return 0;
}
#ifndef _UNICODE
/* /*
* @implemented * @implemented
*/ */
@ -15,75 +184,4 @@ int _findclose(int handle)
return FindClose((void*)handle); return FindClose((void*)handle);
} }
/* #endif
* @implemented
*/
int _findfirst(const char* _name, struct _finddata_t* result)
{
WIN32_FIND_DATAA FindFileData;
char dir[MAX_PATH];
long hFindFile;
int len = 0;
if (_name == NULL || _name[0] == 0) {
len = GetCurrentDirectoryA(MAX_PATH-4,dir);
if (dir[len-1] != '\\') {
dir[len] = '\\';
dir[len+1] = 0;
}
strcat(dir,"*.*");
} else {
strcpy(dir,_name);
}
hFindFile = (long)FindFirstFileA(dir, &FindFileData);
if (hFindFile == -1) {
memset(result,0,sizeof(struct _finddata_t));
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!strchr(dir,'*') && !strchr(dir,'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
/*
* @implemented
*/
int _findnext(int handle, struct _finddata_t* result)
{
WIN32_FIND_DATAA FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFileA((void*)handle, &FindFileData)) {
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName, MAX_PATH);
return 0;
}

View file

@ -1,14 +1,14 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/fcntl.h> #include <fcntl.h>
#include <msvcrt/io.h> #include <io.h>
int __fmode = O_TEXT; int _fmode = O_TEXT;
/* /*
* @implemented * @implemented
*/ */
int *__p__fmode(void) int *__p__fmode(void)
{ {
return &__fmode; return &_fmode;
} }

View file

@ -1,15 +1,15 @@
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/sys/stat.h> #include <sys/stat.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*
* @implemented * @implemented
*/ */
int _isatty( int fd ) int _isatty( int fd )
{ {
struct stat buf; struct _stat buf;
DPRINT("_isatty(fd %d)\n", fd); DPRINT("_isatty(fd %d)\n", fd);
if (_fstat (fd, &buf) < 0) if (_fstat (fd, &buf) < 0)
return 0; return 0;

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
@ -11,7 +11,7 @@ int _locking(int _fd, int mode, long nbytes)
long offset = _lseek(_fd, 0L, 1); long offset = _lseek(_fd, 0L, 1);
if (offset == -1L) if (offset == -1L)
return -1; return -1;
if (!LockFile(_get_osfhandle(_fd),offset,0,nbytes,0)) { if (!LockFile((HANDLE)_get_osfhandle(_fd),offset,0,nbytes,0)) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
return -1; return -1;
} }

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*
@ -8,7 +8,7 @@
*/ */
long _lseek(int _fildes, long _offset, int _whence) long _lseek(int _fildes, long _offset, int _whence)
{ {
DWORD newpos = SetFilePointer((HANDLE)filehnd(_fildes), _offset, NULL, _whence); DWORD newpos = SetFilePointer((HANDLE)fdinfo(_fildes)->hFile, _offset, NULL, _whence);
if (newpos == INVALID_SET_FILE_POINTER) { if (newpos == INVALID_SET_FILE_POINTER) {
DWORD oserror = GetLastError(); DWORD oserror = GetLastError();
if (oserror != 0) { if (oserror != 0) {

View file

@ -1,6 +1,6 @@
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
//#define SETFILEPOINTEREX_AVAILABLE //#define SETFILEPOINTEREX_AVAILABLE
@ -19,7 +19,7 @@ __int64 _lseeki64(int _fildes, __int64 _offset, int _whence)
// __set_errno ( EBADF ); // __set_errno ( EBADF );
// return -1L; // return -1L;
// } // }
if (SetFilePointerEx((HANDLE)filehnd(_fildes), offset, &new_pos, _whence)) { if (SetFilePointerEx((HANDLE)fdinfo(_fildes)->hFile, offset, &new_pos, _whence)) {
} else { } else {
_dosmaperr(error); _dosmaperr(error);
return -1L; return -1L;
@ -34,7 +34,7 @@ __int64 _lseeki64(int _fildes, __int64 _offset, int _whence)
LARGE_INTEGER offset; LARGE_INTEGER offset;
offset.QuadPart = _offset; offset.QuadPart = _offset;
offset.u.LowPart = SetFilePointer((HANDLE)filehnd(_fildes), offset.u.LowPart = SetFilePointer((HANDLE)fdinfo(_fildes)->hFile,
offset.u.LowPart, &offset.u.HighPart, _whence); offset.u.LowPart, &offset.u.HighPart, _whence);
return ((((__int64)offset.u.HighPart) << 32) + offset.u.LowPart); return ((((__int64)offset.u.HighPart) << 32) + offset.u.LowPart);

View file

@ -13,12 +13,12 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/string.h> #include <string.h>
#include <msvcrt/io.h> #include <io.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*

View file

@ -8,87 +8,139 @@
* UPDATE HISTORY: * UPDATE HISTORY:
* 28/12/98: Created * 28/12/98: Created
*/ */
/*
* Some stuff taken from active perl: perl\win32.c (ioinfo stuff)
*
* (c) 1995 Microsoft Corporation. All rights reserved.
* Developed by hip communications inc., http://info.hip.com/info/
* Portions (c) 1993 Intergraph Corporation. All rights reserved.
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*/
/*
* Some functions taken from/based on wine\dlls\msvcrt\file.c:
* split_oflags
* _open_osfhandle
* many more...
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
* Copyright 2004 Eric Pouech
* Copyright 2004 Juan Lang
*/
// rember to interlock the allocation of fileno when making this thread safe // rember to interlock the allocation of fileno when making this thread safe
// possibly store extra information at the handle // possibly store extra information at the handle
#include "precomp.h" #include "precomp.h"
#if !defined(NDEBUG) && defined(DBG) #if !defined(NDEBUG) && defined(DBG)
#include <msvcrt/stdarg.h> #include <stdarg.h>
#endif #endif
#include <msvcrt/io.h>
#include <msvcrt/fcntl.h> #include <io.h>
#include <msvcrt/sys/stat.h> #include <fcntl.h>
#include <msvcrt/stdlib.h> #include <sys/stat.h>
#include <msvcrt/string.h> #include <stdlib.h>
#include <msvcrt/share.h> #include <string.h>
#include <msvcrt/errno.h> #include <share.h>
#include <msvcrt/internal/file.h> #include <errno.h>
#include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
//#define _OLD_BUILD_
#define STD_AUX_HANDLE 3
#define STD_PRINTER_HANDLE 4
FDINFO first_bucket[FDINFO_ENTRIES_PER_BUCKET];
FDINFO* __pioinfo[FDINFO_BUCKETS] = {first_bucket};
/* This critical section protects the tables MSVCRT_fdesc and MSVCRT_fstreams,
* and their related indexes, MSVCRT_fdstart, MSVCRT_fdend,
* and MSVCRT_stream_idx, from race conditions.
* It doesn't protect against race conditions manipulating the underlying files
* or flags; doing so would probably be better accomplished with per-file
* protection, rather than locking the whole table for every change.
*/
static CRITICAL_SECTION g_file_cs;
#define LOCK_FILES() do { EnterCriticalSection(&g_file_cs); } while (0)
#define UNLOCK_FILES() do { LeaveCriticalSection(&g_file_cs); } while (0)
///////////////////////////////////////// /////////////////////////////////////////
#if 0 // from perl sources
#ifndef _INTPTR_T_DEFINED static int g_fdstart = 3; /* first unallocated fd */
typedef int intptr_t; static int g_fdend = 3; /* highest allocated fd */
#define _INTPTR_T_DEFINED
#endif
#ifndef _UINTPTR_T_DEFINED
typedef unsigned int uintptr_t;
#define _UINTPTR_T_DEFINED
#endif
/* /*
* Control structure for lowio file handles * INTERNAL
*/ */
typedef struct { /*
intptr_t osfhnd;/* underlying OS file HANDLE */ static inline FD_INFO* fdinfo(int fd)
char osfile; /* attributes of file (e.g., open in text mode?) */
char pipech; /* one char buffer for handles opened on pipes */
int lockinitflag;
//CRITICAL_SECTION lock;
} ioinfo;
/*
* Array of arrays of control structures for lowio files.
*/
//ioinfo* __pioinfo[];
//ioinfo* __pioinfo[] = { NULL };
#endif
/////////////////////////////////////////
typedef struct _fileno_modes_type
{ {
HANDLE hFile; FD_INFO* bucket = __pioinfo[fd >> FDINFO_ENTRIES_PER_BUCKET_SHIFT];
int mode; if (!bucket){
char pipech; /* one char buffer for handles opened on pipes */ bucket = alloc_init_bucket(fd);
int lockinitflag; }
/*CRITICAL_SECTION*/int lock; return bucket + (fd & (FDINFO_ENTRIES_PER_BUCKET - 1));
int fd; }
} fileno_modes_type; */
//static fileno_modes_type* fileno_modes = NULL;
fileno_modes_type* __pioinfo = NULL;
///////////////////////////////////////// /*
int maxfno = 0; * INTERNAL
*/
inline BOOL is_valid_fd(int fd)
{
BOOL b = (fd >= 0 && fd < g_fdend && (fdinfo(fd)->fdflags & FOPEN));
if (!b){
DPRINT1("not valid fd %i, g_fdend %i, fdinfo %x, bucket %x, fdflags %x\n",
fd,g_fdend,fdinfo(fd),fdinfo_bucket(fd),fdinfo(fd)->fdflags);
}
return b;
}
/*
* INTERNAL
*/
char split_oflags(int oflags)
{
char fdflags = 0;
if (oflags & _O_APPEND) fdflags |= FAPPEND;
if (oflags & _O_BINARY) ;
else if (oflags & _O_TEXT) fdflags |= FTEXT;
else if (_fmode& _O_BINARY) ;
else fdflags |= FTEXT; /* default to TEXT*/
if (oflags & _O_NOINHERIT) fdflags |= FNOINHERIT;
if (oflags & ~(_O_BINARY|_O_TEXT|_O_APPEND|_O_TRUNC|
_O_EXCL|_O_CREAT|_O_RDWR|_O_WRONLY|
_O_TEMPORARY|_O_NOINHERIT))
DPRINT1(":unsupported oflags 0x%04x\n",oflags);
return fdflags;
}
/*
* INTERNAL
*/
char __is_text_file(FILE* p) char __is_text_file(FILE* p)
{ {
if ( p == NULL || __pioinfo == NULL ) if ( p == NULL || fdinfo_bucket((p)->_file) == NULL )
return FALSE; return FALSE;
return (!((p)->_flag&_IOSTRG) && (__pioinfo[(p)->_file].mode&O_TEXT)); return (!((p)->_flag&_IOSTRG) && (fdinfo((p)->_file)->fdflags & FTEXT));
} }
/* /*
@ -112,7 +164,9 @@ int _open(const char* _path, int _oflag,...)
pmode = va_arg(arg, int); pmode = va_arg(arg, int);
#endif #endif
// DPRINT("_open('%s', %x, (%x))\n", _path, _oflag, pmode);
TRACE("_open('%s', %x, (%x))\n", _path, _oflag);
if ((_oflag & S_IREAD ) == S_IREAD) if ((_oflag & S_IREAD ) == S_IREAD)
dwShareMode = FILE_SHARE_READ; dwShareMode = FILE_SHARE_READ;
@ -188,155 +242,304 @@ int _open(const char* _path, int _oflag,...)
NULL); NULL);
if (hFile == (HANDLE)-1) { if (hFile == (HANDLE)-1) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
return -1; return( -1);
} }
DPRINT("OK\n"); DPRINT("OK\n");
if (!(_oflag & (_O_TEXT|_O_BINARY))) { if (!(_oflag & (_O_TEXT|_O_BINARY))) {
_oflag |= __fmode; _oflag |= _fmode;
} }
return __fileno_alloc(hFile,_oflag); return(alloc_fd(hFile, split_oflags(_oflag)));
} }
int __fileno_alloc(HANDLE hFile, int mode)
/*
* INTERNAL
*/
static void init_bucket(FDINFO* entry)
{ {
int i; int i;
/* Check for bogus values */
if (hFile < 0) for(i=0;
return -1; i < FDINFO_ENTRIES_PER_BUCKET;
i++, entry++)
for (i = 5; i < maxfno; i++) { {
if (__pioinfo[i].fd == -1 ) { entry->hFile = INVALID_HANDLE_VALUE;
__pioinfo[i].fd = i; entry->fdflags = 0;
__pioinfo[i].mode = mode; entry->pipechar = LF;
__pioinfo[i].hFile = hFile; entry->lockinitflag = 0;
return i; }
}
}
/* See if we need to expand the tables. Check this BEFORE it might fail,
so that when we hit the count'th request, we've already up'd it. */
if (i == maxfno) {
int oldcount = maxfno;
fileno_modes_type* old_fileno_modes = __pioinfo;
maxfno += 255;
__pioinfo = (fileno_modes_type*)malloc(maxfno * sizeof(fileno_modes_type));
if (old_fileno_modes != NULL) {
memcpy(__pioinfo, old_fileno_modes, oldcount * sizeof(fileno_modes_type));
free(old_fileno_modes);
}
memset(__pioinfo + oldcount, -1, (maxfno-oldcount)*sizeof(fileno_modes_type));
}
/* Fill in the value */
__pioinfo[i].fd = i;
__pioinfo[i].mode = mode;
__pioinfo[i].hFile = hFile;
return i;
} }
void* filehnd(int fileno) /*
* INTERNAL
*/
static BOOL alloc_init_bucket(int fd)
{ {
if (fileno < 0 || fileno >= maxfno || __pioinfo[fileno].fd == -1) { fdinfo_bucket(fd) = malloc(FDINFO_ENTRIES_PER_BUCKET * sizeof(FDINFO));
return (void*)-1; if (!fdinfo_bucket(fd)) return FALSE;
}
return __pioinfo[fileno].hFile; init_bucket(fdinfo_bucket(fd));
return TRUE;
} }
int __fileno_setmode(int _fd, int _newmode)
/*
* INTERNAL
* Allocate an fd slot from a Win32 HANDLE, starting from fd
* caller must hold the files lock
*/
static int alloc_fd_from(HANDLE hand, char flag, int fd)
{ {
int m;
if (_fd < 0 || _fd >= maxfno) { if (fd >= FDINFO_ENTRIES)
{
DPRINT1("files exhausted!\n");
return -1;
}
if (!fdinfo_bucket(fd))
{
if (!alloc_init_bucket(fd)){
//errno = ENOMEM
return -1;
}
}
fdinfo(fd)->hFile = hand;
fdinfo(fd)->fdflags = FOPEN | (flag & (FNOINHERIT | FAPPEND | FTEXT));
fdinfo(fd)->pipechar = LF;
fdinfo(fd)->lockinitflag = 0;
//fdinfo(fd)->lock
/* locate next free slot */
if (fd == g_fdstart && fd == g_fdend)
{
g_fdstart = g_fdend + 1;
}
else
{
#if 0 /* alternate (untested) impl. maybe a tiny bit faster? -Gunnar */
int i, bidx;
for (bidx = fdinfo_bucket_idx(g_fdstart); bidx < FDINFO_BUCKETS && __pioinfo[bidx]; bidx++)
{
for (i = fdinfo_bucket_entry_idx(g_fdstart);
g_fdstart < g_fdend && fdinfo(g_fdstart)->fdflags & FOPEN && i < FDINFO_BUCKET_ENTRIES;
i++)
{
g_fdstart++;
}
}
#else
while (g_fdstart < g_fdend &&
fdinfo_bucket(g_fdstart) &&
(fdinfo(g_fdstart)->fdflags & FOPEN))
{
g_fdstart++;
}
#endif
}
/* update last fd in use */
if (fd >= g_fdend)
g_fdend = fd + 1;
/* alloc more fdinfo buckets by demand.
* FIXME: should we dealloc buckets when they become unused also? */
if (!fdinfo_bucket(g_fdstart) && g_fdstart < FDINFO_ENTRIES)
{
alloc_init_bucket(g_fdstart);
}
DPRINT("fdstart is %d, fdend is %d\n", g_fdstart, g_fdend);
switch (fd)
{
case 0: SetStdHandle(STD_INPUT_HANDLE, hand); break;
case 1: SetStdHandle(STD_OUTPUT_HANDLE, hand); break;
case 2: SetStdHandle(STD_ERROR_HANDLE, hand); break;
}
return fd;
}
/*
* INTERNAL: Allocate an fd slot from a Win32 HANDLE
*/
int alloc_fd(HANDLE hand, char flag)
{
int ret;
LOCK_FILES();
// TRACE(":handle (%p) allocating fd (%d)\n",hand,MSVCRT_fdstart);
ret = alloc_fd_from(hand, flag, g_fdstart);
UNLOCK_FILES();
return ret;
}
/*
* INTERNAL
*/
char __fileno_getmode(int fd)
{
if (!is_valid_fd(fd)) {
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
m = __pioinfo[_fd].mode; return fdinfo(fd)->fdflags;
__pioinfo[_fd].mode = _newmode;
return m;
}
int __fileno_getmode(int _fd)
{
if (_fd < 0 || _fd >= maxfno) {
__set_errno(EBADF);
return -1;
}
return __pioinfo[_fd].mode;
} }
int __fileno_close(int _fd) /*
* INTERNAL
*/
void free_fd(int fd)
{ {
if (_fd < 0 || _fd >= maxfno) { LOCK_FILES();
__set_errno(EBADF);
return -1;
} fdinfo(fd)->hFile = INVALID_HANDLE_VALUE;
__pioinfo[_fd].fd = -1; fdinfo(fd)->fdflags = 0;
__pioinfo[_fd].hFile = (HANDLE)-1;
return 0; if (fd < 3) /* don't use 0,1,2 for user files */
{
switch (fd)
{
case 0: SetStdHandle(STD_INPUT_HANDLE, NULL); break;
case 1: SetStdHandle(STD_OUTPUT_HANDLE, NULL); break;
case 2: SetStdHandle(STD_ERROR_HANDLE, NULL); break;
}
}
else
{
if (fd == g_fdend - 1)
g_fdend--;
if (fd < g_fdstart)
g_fdstart = fd;
}
UNLOCK_FILES();
} }
/* /*
* @implemented * @implemented
*/ */
int _open_osfhandle(void* osfhandle, int flags) int _open_osfhandle(long osfhandle, int oflags)
{ {
return __fileno_alloc((HANDLE)osfhandle, flags); /*
PREV:
The _open_osfhandle() function in MSVCRT is expected to take the absence
of either _O_TEXT or _O_BINARY to mean _O_BINARY. Currently it defaults to
_O_TEXT.
An example of this is MFC's CStdioFile::Open in binary mode - it passes flags
of 0 when it wants to write a binary file - under WINE we do text mode conversions!
The attached patch ensures that _O_BINARY is set if neither is set in the passed-in
flags.
* file, so set the write flag. It also only sets _O_TEXT if it wants
* text - it never sets _O_BINARY.
*/
/* FIXME: handle more flags */
/*
flags |= MSVCRT__IOREAD|MSVCRT__IOWRT;
if ( !( flags & _O_TEXT ) ) flags |= _O_BINARY;
fd = msvcrt_alloc_fd((HANDLE)hand,flags);
TRACE(":handle (%ld) fd (%d) flags 0x%08x\n",hand,fd, flags);
*/
/* MSVCRT__O_RDONLY (0) always matches, so set the read flag
* MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the
* file, so set the write flag. It also only sets MSVCRT__O_TEXT if it wants
* text - it never sets MSVCRT__O_BINARY.
*/
/* FIXME: handle more flags */
/*
LAG TEST SOM TESTER UT ALT DETTE flag tingern
*/
if (!(oflags & (_O_BINARY | _O_TEXT)) && (_fmode & _O_BINARY))
oflags |= _O_BINARY;
else
oflags |= _O_TEXT;
return alloc_fd((HANDLE)osfhandle, split_oflags(oflags));
} }
/* /*
* @implemented * @implemented
*/ */
void* _get_osfhandle( int fileno ) long _get_osfhandle(int fd)
{ {
return filehnd(fileno); TRACE("_get_osfhandle(%i)",fd);
if (!is_valid_fd(fd)) {
return( -1 );
}
return( (long)fdinfo(fd)->hFile );
} }
/*
* INTERNAL
*/
int __fileno_dup2(int handle1, int handle2) int __fileno_dup2(int handle1, int handle2)
{ {
HANDLE hProcess; HANDLE hProcess;
BOOL result; BOOL result;
if (handle1 >= maxfno || handle1 < 0 || handle2 >= maxfno || handle2 < 0) {
if (handle1 >= FDINFO_ENTRIES || handle1 < 0 || handle2 >= FDINFO_ENTRIES || handle2 < 0) {
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
if (__pioinfo[handle1].fd == -1) { // if (_pioinfo[handle1]->fd == -1) {
if (fdinfo(handle1)->hFile == INVALID_HANDLE_VALUE) {
__set_errno(EBADF); __set_errno(EBADF);
return -1; return -1;
} }
if (handle1 == handle2) if (handle1 == handle2)
return handle1; return handle1;
if (__pioinfo[handle2].fd != -1) { // if (_pioinfo[handle2]->fd != -1) {
if (fdinfo(handle2)->hFile != INVALID_HANDLE_VALUE) {
_close(handle2); _close(handle2);
} }
hProcess = GetCurrentProcess(); hProcess = GetCurrentProcess();
result = DuplicateHandle(hProcess, result = DuplicateHandle(hProcess,
__pioinfo[handle1].hFile, fdinfo(handle1)->hFile,
hProcess, hProcess,
&__pioinfo[handle2].hFile, &fdinfo(handle2)->hFile,
0, 0,
TRUE, TRUE,
DUPLICATE_SAME_ACCESS); DUPLICATE_SAME_ACCESS);
if (result) { if (result) {
__pioinfo[handle2].fd = handle2; // _pioinfo[handle2]->fd = handle2;
__pioinfo[handle2].mode = __pioinfo[handle1].mode; fdinfo(handle2)->fdflags = fdinfo(handle1)->fdflags;
switch (handle2) { switch (handle2) {
case 0: case 0:
SetStdHandle(STD_INPUT_HANDLE, __pioinfo[handle2].hFile); SetStdHandle(STD_INPUT_HANDLE, fdinfo(handle2)->hFile);
break; break;
case 1: case 1:
SetStdHandle(STD_OUTPUT_HANDLE, __pioinfo[handle2].hFile); SetStdHandle(STD_OUTPUT_HANDLE, fdinfo(handle2)->hFile);
break; break;
case 2: case 2:
SetStdHandle(STD_ERROR_HANDLE, __pioinfo[handle2].hFile); SetStdHandle(STD_ERROR_HANDLE, fdinfo(handle2)->hFile);
break;
case 3:
SetStdHandle(STD_AUX_HANDLE, __pioinfo[handle2].hFile);
break;
case 4:
SetStdHandle(STD_AUX_HANDLE, __pioinfo[handle2].hFile);
break; break;
} }
return handle1; return handle1;
} else { } else {
__set_errno(EMFILE); // Is this the correct error no.? __set_errno(EMFILE); // Is this the correct error no.?
@ -347,77 +550,172 @@ int __fileno_dup2(int handle1, int handle2)
void* malloc(size_t sizeObject); void* malloc(size_t sizeObject);
/*
* INTERNAL
*/
BOOL __fileno_init(void) BOOL __fileno_init(void)
{ {
ULONG count = 0, i; STARTUPINFOA si;
HANDLE* pFile; int i;
char* pmode;
STARTUPINFOA StInfo;
GetStartupInfoA(&StInfo); init_bucket(first_bucket);
if (StInfo.lpReserved2 && StInfo.cbReserved2 >= sizeof(ULONG)) {
count = *(ULONG*)StInfo.lpReserved2;
/*
if (sizeof(ULONG) + count * (sizeof(HANDLE) + sizeof(char)) != StInfo.cbReserved2)
{
count = 0;
}
*/
}
maxfno = 255;
while(count >= maxfno)
maxfno += 255;
GetStartupInfoA(&si);
if (si.cbReserved2 != 0 && si.lpReserved2 != NULL)
{ {
#ifdef _OLD_BUILD_ char* fdflags_ptr;
// why was this here ???? - robd. HANDLE* handle_ptr;
int result;
result = malloc(50); g_fdend = *(unsigned*)si.lpReserved2;
#endif
} fdflags_ptr= (char*)(si.lpReserved2 + sizeof(unsigned));
//__pioinfo = (fileno_modes_type*)malloc(sizeof(fileno_modes_type) * maxfno); handle_ptr = (HANDLE*)(fdflags_ptr + g_fdend * sizeof(char));
__pioinfo = malloc(sizeof(fileno_modes_type) * maxfno);
if (__pioinfo == NULL) { g_fdend = min(g_fdend, FDINFO_ENTRIES);
return FALSE; for (i = 0; i < g_fdend; i++)
} {
memset(__pioinfo, -1, sizeof(fileno_modes_type) * maxfno); if (!fdinfo_bucket(i))
if (count) { {
pFile = (HANDLE*)(StInfo.lpReserved2 + sizeof(ULONG) + count * sizeof(char)); if (!alloc_init_bucket(i)){
pmode = (char*)(StInfo.lpReserved2 + sizeof(ULONG)); /* FIXME: free other buckets? */
for (i = 0; i < count; i++) { return FALSE;
if (*pFile != INVALID_HANDLE_VALUE) { }
__pioinfo[i].fd = i;
__pioinfo[i].mode = ((*pmode << 8) & (_O_TEXT|_O_BINARY)) | (*pmode & _O_ACCMODE);
__pioinfo[i].hFile = *pFile;
}
pFile++;
pmode++;
} }
if ((*fdflags_ptr & FOPEN) && *handle_ptr != INVALID_HANDLE_VALUE)
{
fdinfo(i)->fdflags = *fdflags_ptr;
fdinfo(i)->hFile = *handle_ptr;
}
/*
else
{
fdinfo(i)->fdflags = 0;
fdinfo(i)->hFile = INVALID_HANDLE_VALUE;
}
*/
fdflags_ptr++; handle_ptr++;
}
for (g_fdstart = 3; g_fdstart < g_fdend; g_fdstart++)
if (fdinfo(g_fdstart)->hFile == INVALID_HANDLE_VALUE) break;
} }
if (__pioinfo[0].fd == -1) {
__pioinfo[0].fd = 0; InitializeCriticalSection(&g_file_cs);
__pioinfo[0].hFile = GetStdHandle(STD_INPUT_HANDLE);
__pioinfo[0].mode = _O_RDONLY|_O_TEXT;
if (fdinfo(0)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(0)->fdflags & FOPEN)) {
fdinfo(0)->hFile = GetStdHandle(STD_INPUT_HANDLE);
fdinfo(0)->fdflags = FOPEN|FTEXT;
} }
if (__pioinfo[1].fd == -1) { if (fdinfo(1)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(1)->fdflags & FOPEN)) {
__pioinfo[1].fd = 1; fdinfo(1)->hFile = GetStdHandle(STD_OUTPUT_HANDLE);
__pioinfo[1].hFile = GetStdHandle(STD_OUTPUT_HANDLE); fdinfo(1)->fdflags = FOPEN|FTEXT;
__pioinfo[1].mode = _O_WRONLY|_O_TEXT;
} }
if (__pioinfo[2].fd == -1) { if (fdinfo(2)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(2)->fdflags & FOPEN)) {
__pioinfo[2].fd = 2; fdinfo(2)->hFile = GetStdHandle(STD_ERROR_HANDLE);
__pioinfo[2].hFile = GetStdHandle(STD_ERROR_HANDLE); fdinfo(2)->fdflags = FOPEN|FTEXT;
__pioinfo[2].mode = _O_WRONLY|_O_TEXT;
} }
if (__pioinfo[3].fd == -1) {
__pioinfo[3].fd = 3;
__pioinfo[3].hFile = GetStdHandle(STD_AUX_HANDLE);
__pioinfo[3].mode = _O_WRONLY|_O_TEXT;
} for (i = 0; i < 3; i++)
if (__pioinfo[4].fd == -1) { {
__pioinfo[4].fd = 4; /* FILE structs for stdin/out/err are static and never deleted */
__pioinfo[4].hFile = GetStdHandle(STD_PRINTER_HANDLE); // MSVCRT_fstreams[i] = &MSVCRT__iob[i];
__pioinfo[4].mode = _O_WRONLY|_O_TEXT;
} }
// MSVCRT_stream_idx = 3;
return TRUE; return TRUE;
} }
/* INTERNAL: Create an inheritance data block (for spawned process)
* The inheritance block is made of:
* 00 int nb of file descriptor (NBFD)
* 04 char file flags (wxflag): repeated for each fd
* 4+NBFD HANDLE file handle: repeated for each fd
*/
unsigned create_io_inherit_block(STARTUPINFOA* si)
{
int fd;
char* fdflags_ptr;
HANDLE* handle_ptr;
TRACE("create_io_inherit_block(%x)",si);
si->cbReserved2 = sizeof(unsigned) + (sizeof(char) + sizeof(HANDLE)) * g_fdend;
si->lpReserved2 = calloc(si->cbReserved2, 1);
if (!si->lpReserved2)
{
si->cbReserved2 = 0;
return( FALSE );
}
fdflags_ptr = (char*)si->lpReserved2 + sizeof(unsigned);
handle_ptr = (HANDLE*)(fdflags_ptr + g_fdend * sizeof(char));
*(unsigned*)si->lpReserved2 = g_fdend;
for (fd = 0; fd < g_fdend; fd++)
{
/* to be inherited, we need it to be open, and that DONTINHERIT isn't set */
if ((fdinfo(fd)->fdflags & (FOPEN | FNOINHERIT)) == FOPEN)
{
*fdflags_ptr = fdinfo(fd)->fdflags;
*handle_ptr = fdinfo(fd)->hFile;
}
else
{
*fdflags_ptr = 0;
*handle_ptr = INVALID_HANDLE_VALUE;
}
fdflags_ptr++; handle_ptr++;
}
return( TRUE );
}
/*
* @implemented
*/
int _setmode(int fd, int newmode)
{
int prevmode;
TRACE("_setmode(%d, %d)", fd, newmode);
if (!is_valid_fd(fd))
{
DPRINT1("_setmode: inval fd (%d)\n",fd);
//errno = EBADF;
return(-1);
}
if (newmode & ~(_O_TEXT|_O_BINARY))
{
DPRINT1("_setmode: fd (%d) mode (0x%08x) unknown\n",fd,newmode);
/* FIXME: Should we fail with EINVAL here? */
}
prevmode = fdinfo(fd)->fdflags & FTEXT ? _O_TEXT : _O_BINARY;
if ((newmode & _O_TEXT) == _O_TEXT)
{
fdinfo(fd)->fdflags |= FTEXT;
}
else
{
/* FIXME: If both _O_TEXT and _O_BINARY are set, we get here.
* Should we fail with EINVAL instead? -Gunnar
*/
fdinfo(fd)->fdflags &= ~FTEXT;
}
return(prevmode);
}

View file

@ -10,9 +10,12 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
#define NDEBUG
#include <internal/msvcrtdbg.h>
/* /*
@ -23,29 +26,31 @@ int _pipe(int _fildes[2], unsigned int size, int mode )
HANDLE hReadPipe, hWritePipe; HANDLE hReadPipe, hWritePipe;
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
TRACE("_pipe((%i,%i), %ui, %i)", _fildes[0], _fildes[1], size, mode);
if (mode & O_NOINHERIT) if (mode & O_NOINHERIT)
sa.bInheritHandle = FALSE; sa.bInheritHandle = FALSE;
if (!CreatePipe(&hReadPipe,&hWritePipe,&sa,size)) { if (!CreatePipe(&hReadPipe,&hWritePipe,&sa,size)) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
return -1; return( -1);
} }
if ((_fildes[0] = __fileno_alloc(hReadPipe, mode)) < 0) if ((_fildes[0] = alloc_fd(hReadPipe, split_oflags(mode))) < 0)
{ {
CloseHandle(hReadPipe); CloseHandle(hReadPipe);
CloseHandle(hWritePipe); CloseHandle(hWritePipe);
__set_errno(EMFILE); __set_errno(EMFILE);
return -1; return(-1);
} }
if ((_fildes[1] = __fileno_alloc(hWritePipe, mode)) < 0) if ((_fildes[1] = alloc_fd(hWritePipe, split_oflags(mode))) < 0)
{ {
__fileno_close(_fildes[0]); free_fd(_fildes[0]);
CloseHandle(hReadPipe); CloseHandle(hReadPipe);
CloseHandle(hWritePipe); CloseHandle(hWritePipe);
__set_errno(EMFILE); __set_errno(EMFILE);
return -1; return(-1);
} }
return 0; return(0);
} }

View file

@ -13,16 +13,16 @@
*/ */
#include <windows.h> #include <windows.h>
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*
* @implemented * @implemented
*/ */
size_t _read(int _fd, void *_buf, size_t _nbyte) int _read(int _fd, void *_buf, unsigned int _nbyte)
{ {
DWORD _rbyte = 0, nbyte = _nbyte; DWORD _rbyte = 0, nbyte = _nbyte;
char *bufp = (char*)_buf; char *bufp = (char*)_buf;
@ -35,7 +35,7 @@ size_t _read(int _fd, void *_buf, size_t _nbyte)
if(_nbyte == 0) if(_nbyte == 0)
return 0; return 0;
hfile = _get_osfhandle(_fd); hfile = (HANDLE)_get_osfhandle(_fd);
istext = __fileno_getmode(_fd) & O_TEXT; istext = __fileno_getmode(_fd) & O_TEXT;
/* read data */ /* read data */

View file

@ -9,19 +9,11 @@
* 28/12/98: Created * 28/12/98: Created
*/ */
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/*
* @implemented
*/
int _setmode(int _fd, int _newmode)
{
DPRINT("_setmod(fd %d, newmode %x)\n", _fd, _newmode);
return __fileno_setmode(_fd, _newmode);
}

View file

@ -1,10 +1,11 @@
#include <msvcrt/io.h> #include <io.h>
/* /*
* @implemented * @implemented
*/ */
int _sopen(char *path, int access, int shflag, int mode) int _sopen(const char *path, int access, int shflag, ... /*mode, permissin*/)
{ {
return _open((path), (access)|(shflag), (mode)); //FIXME: vararg
return _open((path), (access)|(shflag));//, (mode));
} }

View file

@ -1,6 +1,7 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/io.h> #include <io.h>
#include <stdio.h>
/* /*

View file

@ -1,5 +1,6 @@
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/io.h> #include <io.h>
#include <stdio.h>
/* /*

View file

@ -1,5 +1,5 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/sys/stat.h> #include <sys/stat.h>
unsigned _unMode_dll = 022; unsigned _unMode_dll = 022;

View file

@ -9,10 +9,11 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*

View file

@ -1,8 +1,8 @@
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/sys/utime.h> #include <sys/utime.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -1,32 +1,4 @@
#include "precomp.h" #define UNICODE
#include <msvcrt/io.h> #define _UNICODE
#include <msvcrt/errno.h>
#define NDEBUG
#include <msvcrt/msvcrtdbg.h>
#include "access.c"
/*
* @implemented
*/
int _waccess(const wchar_t *_path, int _amode)
{
DWORD Attributes = GetFileAttributesW(_path);
if (Attributes == -1) {
_dosmaperr(GetLastError());
return -1;
}
if ((_amode & W_OK) == W_OK) {
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) {
__set_errno(EACCES);
return -1;
}
}
return 0;
}

View file

@ -1,47 +1,4 @@
#include "precomp.h" #define _UNICODE
#include <msvcrt/io.h> #define UNICODE
#define NDEBUG #include "chmod.c"
#include <msvcrt/msvcrtdbg.h>
#define mode_t int
/*
* @implemented
*/
int _wchmod(const wchar_t* filename, mode_t mode)
{
DWORD FileAttributes = 0;
BOOLEAN Set = FALSE;
DPRINT("_wchmod('%S', %x)\n", filename, mode);
FileAttributes = GetFileAttributesW(filename);
if ( FileAttributes == -1 ) {
_dosmaperr(GetLastError());
return -1;
}
if ( mode == 0 )
return -1;
if (mode & _S_IWRITE) {
if (FileAttributes & FILE_ATTRIBUTE_READONLY) {
FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
Set = TRUE;
}
} else {
if (!(FileAttributes & FILE_ATTRIBUTE_READONLY)) {
FileAttributes |= FILE_ATTRIBUTE_READONLY;
Set = TRUE;
}
}
if (Set && SetFileAttributesW(filename, FileAttributes) == FALSE) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}

View file

@ -1,8 +1,8 @@
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/fcntl.h> #include <fcntl.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*

View file

@ -1,226 +1,5 @@
#include "precomp.h"
#include <msvcrt/io.h>
#include <msvcrt/string.h>
#include <msvcrt/internal/file.h>
#define UNICODE
#define _UNICODE
/* #include "find.c"
* @implemented
*/
int _wfindfirst(const wchar_t* _name, struct _wfinddata_t* result)
{
WIN32_FIND_DATAW FindFileData;
wchar_t dir[MAX_PATH];
long hFindFile;
int len = 0;
if ( _name == NULL || _name[0] == 0 ) {
len = GetCurrentDirectoryW(MAX_PATH-4, dir);
if (dir[len-1] != L'\\') {
dir[len] = L'\\';
dir[len+1] = 0;
}
wcscat(dir, L"*.*");
} else {
wcscpy(dir, _name);
}
hFindFile = (long)FindFirstFileW(dir, &FindFileData);
if (hFindFile == -1) {
memset(result,0,sizeof(struct _wfinddata_t));
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
wcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!wcschr(dir, L'*') && !wcschr(dir, L'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
/*
* @implemented
*/
int _findfirsti64(const char *_name, struct _finddatai64_t *result)
{
WIN32_FIND_DATAA FindFileData;
char dir[MAX_PATH];
long hFindFile;
int len = 0;
if ( _name == NULL || _name[0] == 0 )
{
len = GetCurrentDirectoryA(MAX_PATH-4,dir);
if (dir[len-1] != '\\')
{
dir[len] = '\\';
dir[len+1] = 0;
}
strcat(dir, "*.*");
}
else
strcpy(dir, _name);
hFindFile = (long)FindFirstFileA(dir, &FindFileData);
if (hFindFile == -1)
{
memset(result,0,sizeof(struct _finddatai64_t));
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size =
(((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!strchr(dir,'*') && !strchr(dir,'?')) {
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
/*
* @implemented
*/
int _findnexti64(int handle, struct _finddatai64_t *result)
{
WIN32_FIND_DATAA FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFileA((void *)handle, &FindFileData)) {
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size =
(((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
strncpy(result->name,FindFileData.cFileName,MAX_PATH);
return 0;
}
/*
* @implemented
*/
int _wfindfirsti64(const wchar_t *_name, struct _wfinddatai64_t *result)
{
WIN32_FIND_DATAW FindFileData;
wchar_t dir[MAX_PATH];
long hFindFile;
int len = 0;
if (_name == NULL || _name[0] == 0)
{
len = GetCurrentDirectoryW(MAX_PATH-4,dir);
if (dir[len-1] != L'\\')
{
dir[len] = L'\\';
dir[len+1] = 0;
}
wcscat(dir, L"*.*");
}
else
wcscpy(dir, _name);
hFindFile = (long)FindFirstFileW(dir, &FindFileData);
if (hFindFile == -1)
{
memset(result,0,sizeof(struct _wfinddatai64_t));
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size =
(((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
wcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
// if no wildcard the find file handle can be closed right away
// a return value of 0 can flag this.
if (!wcschr(dir,L'*') && !wcschr(dir,L'?'))
{
_findclose(hFindFile);
return 0;
}
return hFindFile;
}
/*
* @implemented
*/
int _wfindnext(int handle, struct _wfinddata_t *result)
{
WIN32_FIND_DATAW FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFileW((void *)handle, &FindFileData))
return -1;
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = FindFileData.nFileSizeLow;
wcsncpy(result->name,FindFileData.cFileName, MAX_PATH);
return 0;
}
/*
* @implemented
*/
int _wfindnexti64(int handle, struct _wfinddatai64_t *result)
{
WIN32_FIND_DATAW FindFileData;
// check no wildcards or invalid handle
if (handle == 0 || handle == -1)
return 0;
if (!FindNextFileW((void *)handle, &FindFileData))
return -1;
result->attrib = FindFileData.dwFileAttributes;
result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size =
(((__int64)FindFileData.nFileSizeLow)<<32) + FindFileData.nFileSizeLow;
wcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
return 0;
}

View file

@ -13,12 +13,12 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/string.h> #include <string.h>
#include <msvcrt/io.h> #include <io.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*

View file

@ -14,19 +14,19 @@
#include "precomp.h" #include "precomp.h"
#if !defined(NDEBUG) && defined(DBG) #if !defined(NDEBUG) && defined(DBG)
#include <msvcrt/stdarg.h> #include <stdarg.h>
#endif #endif
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/fcntl.h> #include <fcntl.h>
#include <msvcrt/sys/stat.h> #include <sys/stat.h>
#include <msvcrt/stdlib.h> #include <stdlib.h>
#include <msvcrt/internal/file.h> #include <string.h>
#include <msvcrt/string.h> #include <share.h>
#include <msvcrt/share.h> #include <errno.h>
#include <msvcrt/errno.h> #include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
/* /*
@ -136,13 +136,14 @@ int _wopen(const wchar_t* _path, int _oflag, ...)
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
return -1; return -1;
} }
return __fileno_alloc(hFile,_oflag); return alloc_fd(hFile,split_oflags(_oflag));
} }
/* /*
* @implemented * @implemented
*/ */
int _wsopen(wchar_t* path, int access, int shflag, int mode) int _wsopen(const wchar_t* path, int access, int shflag,.../* int mode*/)
{ {
return _wopen((path), (access)|(shflag), (mode)); //FIXME: vararg
return _wopen((path), (access)|(shflag));//, (mode));
} }

View file

@ -9,14 +9,14 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/stdlib.h> #include <stdlib.h>
#include <msvcrt/string.h> #include <string.h>
#include <msvcrt/internal/file.h> #include <errno.h>
#include <msvcrt/errno.h> #include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
#define BUFSIZE 4096 #define BUFSIZE 4096
/* /*
@ -38,7 +38,7 @@ void ReportLastError(void)
/* /*
* @implemented * @implemented
*/ */
size_t _write(int _fd, const void* _buf, size_t _nbyte) int _write(int _fd, const void* _buf, unsigned int _nbyte)
{ {
char *tmp, *in, *out; char *tmp, *in, *out;
int result; int result;
@ -61,7 +61,7 @@ size_t _write(int _fd, const void* _buf, size_t _nbyte)
*out++ = 0x0d; *out++ = 0x0d;
count--; count--;
if (count == 0) { if (count == 0) {
if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) { if (!WriteFile((HANDLE)_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) {
//ReportLastError(); //ReportLastError();
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
result = -1; result = -1;
@ -78,7 +78,7 @@ size_t _write(int _fd, const void* _buf, size_t _nbyte)
*out++ = *in++; *out++ = *in++;
count--; count--;
if (count == 0 || _nbyte == 0) { if (count == 0 || _nbyte == 0) {
if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) { if (!WriteFile((HANDLE)_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
result = -1; result = -1;
break; break;
@ -94,7 +94,7 @@ size_t _write(int _fd, const void* _buf, size_t _nbyte)
free(tmp); free(tmp);
return result; return result;
} else { } else {
if(!WriteFile(_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) { if(!WriteFile((HANDLE)_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) {
_dosmaperr(GetLastError()); _dosmaperr(GetLastError());
return -1; return -1;
} }

View file

@ -9,11 +9,11 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/io.h> #include <io.h>
#include <internal/file.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
#include <msvcrt/internal/file.h>
/* /*
* @implemented * @implemented

View file

@ -1,8 +1,8 @@
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/io.h> #include <io.h>
#include <msvcrt/errno.h> #include <errno.h>
#include <msvcrt/sys/utime.h> #include <sys/utime.h>
#include <msvcrt/internal/file.h> #include <internal/file.h>
/* /*

View file

@ -5,15 +5,15 @@
*/ */
#include "precomp.h" #include "precomp.h"
#include <msvcrt/stdio.h> #include <stdio.h>
#include <msvcrt/locale.h> #include <locale.h>
#include <msvcrt/string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <msvcrt/internal/tls.h> #include <internal/tls.h>
#include <msvcrt/stdlib.h> #include <stdlib.h>
#define NDEBUG #define NDEBUG
#include <msvcrt/msvcrtdbg.h> #include <internal/msvcrtdbg.h>
unsigned int __setlc_active; unsigned int __setlc_active;
unsigned int __unguarded_readlc_active; unsigned int __unguarded_readlc_active;

View file

@ -10,11 +10,14 @@ TARGET_NAME = crt
TARGET_PCH = precomp.h TARGET_PCH = precomp.h
TARGET_CFLAGS = -D_MSVCRT_LIB_ -Wall -Werror TARGET_CFLAGS = -D_MSVCRT_LIB_ -D__MSVCRT__ -Wall -Werror -I./include
#-nostdinc
# require os code to explicitly request A/W version of structs/functions # require os code to explicitly request A/W version of structs/functions
TARGET_CFLAGS += \ TARGET_CFLAGS += \
-D_DISABLE_TIDENTS \ -D_DISABLE_TIDENTS \
-D__MINGW_IMPORT=extern \
-D__USE_W32API \ -D__USE_W32API \
-D__REACTOS__ \ -D__REACTOS__ \
-D_WIN32_IE=0x600 \ -D_WIN32_IE=0x600 \
@ -26,7 +29,6 @@ CONIO_OBJECTS = \
conio/cgets.o \ conio/cgets.o \
conio/cprintf.o \ conio/cprintf.o \
conio/cputs.o \ conio/cputs.o \
conio/cscanf.o \
conio/getch.o \ conio/getch.o \
conio/getche.o \ conio/getche.o \
conio/kbhit.o \ conio/kbhit.o \
@ -238,6 +240,7 @@ PROCESS_OBJECTS = \
process/_system.o \ process/_system.o \
process/dll.o \ process/dll.o \
process/process.o \ process/process.o \
process/wprocess.o \
process/procid.o \ process/procid.o \
process/thread.o \ process/thread.o \
process/threadid.o \ process/threadid.o \
@ -275,12 +278,14 @@ STDIO_OBJECTS = \
stdio/fputc.o \ stdio/fputc.o \
stdio/fputchar.o \ stdio/fputchar.o \
stdio/fputs.o \ stdio/fputs.o \
stdio/fputws.o \
stdio/fread.o \ stdio/fread.o \
stdio/freopen.o \ stdio/freopen.o \
stdio/fscanf.o \ stdio/wfreopen.o \
stdio/fseek.o \ stdio/fseek.o \
stdio/fsetpos.o \ stdio/fsetpos.o \
stdio/fsopen.o \ stdio/fsopen.o \
stdio/wfsopen.o \
stdio/ftell.o \ stdio/ftell.o \
stdio/fwalk.o \ stdio/fwalk.o \
stdio/fwrite.o \ stdio/fwrite.o \
@ -290,32 +295,35 @@ STDIO_OBJECTS = \
stdio/getw.o \ stdio/getw.o \
stdio/perror.o \ stdio/perror.o \
stdio/popen.o \ stdio/popen.o \
stdio/wpopen.o \
stdio/printf.o \ stdio/printf.o \
stdio/wprintf.o \
stdio/putc.o \ stdio/putc.o \
stdio/putchar.o \ stdio/putchar.o \
stdio/putwchar.o \
stdio/puts.o \ stdio/puts.o \
stdio/putw.o \ stdio/putw.o \
stdio/remove.o \ stdio/remove.o \
stdio/wremove.o \
stdio/rename.o \ stdio/rename.o \
stdio/rewind.o \ stdio/rewind.o \
stdio/rmtmp.o \ stdio/rmtmp.o \
stdio/scanf.o \
stdio/setbuf.o \ stdio/setbuf.o \
stdio/setvbuf.o \ stdio/setvbuf.o \
stdio/sprintf.o \ stdio/sprintf.o \
stdio/sscanf.o \ stdio/swprintf.o \
stdio/stdhnd.o \ stdio/stdhnd.o \
stdio/tempnam.o \ stdio/tempnam.o \
stdio/tmpfile.o \ stdio/tmpfile.o \
stdio/tmpnam.o \ stdio/tmpnam.o \
stdio/ungetc.o \ stdio/ungetc.o \
stdio/ungetwc.o \
stdio/vfprintf.o \ stdio/vfprintf.o \
stdio/vfscanf.o \
stdio/vfwprint.o \ stdio/vfwprint.o \
stdio/vprintf.o \ stdio/vprintf.o \
stdio/vscanf.o \ stdio/vwprintf.o \
stdio/vsprintf.o \ stdio/vsprintf.o \
stdio/vsscanf.o \ stdio/vswprintf.o \
stdio/wfdopen.o \ stdio/wfdopen.o \
stdio/wrename.o \ stdio/wrename.o \
stdio/wtempnam.o \ stdio/wtempnam.o \
@ -330,6 +338,7 @@ STDLIB_OBJECTS = \
stdlib/atoi.o \ stdlib/atoi.o \
stdlib/atoi64.o \ stdlib/atoi64.o \
stdlib/atol.o \ stdlib/atol.o \
stdlib/wtol.o \
stdlib/bsearch.o \ stdlib/bsearch.o \
stdlib/div.o \ stdlib/div.o \
stdlib/ecvt.o \ stdlib/ecvt.o \
@ -437,7 +446,8 @@ WINE_OBJECTS = \
wine/cpp.o \ wine/cpp.o \
wine/cppexcept.o \ wine/cppexcept.o \
wine/heap.o \ wine/heap.o \
wine/thread.o wine/thread.o \
wine/scanf.o
TARGET_OBJECTS = \ TARGET_OBJECTS = \
$(CONIO_OBJECTS) \ $(CONIO_OBJECTS) \

View file

@ -18,7 +18,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <msvcrt/math.h> #include <math.h>
double acos(double __x) double acos(double __x)

View file

@ -18,7 +18,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <msvcrt/math.h> #include <math.h>
double asin(double __x) double asin(double __x)

View file

@ -18,7 +18,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <msvcrt/math.h> #include <math.h>
double atan (double __x); double atan (double __x);

View file

@ -1,5 +1,5 @@
#include <msvcrt/math.h> #include <math.h>
double atan2 (double __y, double __x); double atan2 (double __y, double __x);

View file

@ -1,4 +1,4 @@
#include <msvcrt/math.h> #include <math.h>
/* /*
* @implemented * @implemented

View file

@ -1,4 +1,4 @@
#include <msvcrt/math.h> #include <math.h>
/* /*
* @implemented * @implemented

View file

@ -1,4 +1,4 @@
#include <msvcrt/math.h> #include <math.h>
double cos (double __x); double cos (double __x);

View file

@ -1,5 +1,5 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <msvcrt/math.h> #include <math.h>
/* /*

View file

@ -18,7 +18,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */ Boston, MA 02111-1307, USA. */
#include <msvcrt/math.h> #include <math.h>
double exp (double __x); double exp (double __x);

Some files were not shown because too many files have changed in this diff Show more