Create a branch for Aleksandar Andrejevic for his work on NTVDM. See http://jira.reactos.org/browse/CORE-7250 for more details.

svn path=/branches/ntvdm/; revision=59241
This commit is contained in:
Hermès Bélusca-Maïto 2013-06-16 22:01:41 +00:00
parent 3e3200acef
commit 4f0b8d3db0
20620 changed files with 0 additions and 1232833 deletions

View file

@ -0,0 +1,83 @@
/*
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
* PROJECT: ReactOS crt library
* FILE: lib/sdk/crt/stdio/_flsbuf.c
* PURPOSE: Implementation of _flsbuf / _flswbuf
* PROGRAMMER: Timo Kreuzer
*/
#include <precomp.h>
void __cdecl alloc_buffer(FILE *stream);
int __cdecl
_flsbuf(int ch, FILE *stream)
{
int count, written;
/* Check if the stream supports flushing */
if ((stream->_flag & _IOSTRG) || !(stream->_flag & (_IORW|_IOWRT)))
{
stream->_flag |= _IOERR;
return EOF;
}
/* Always reset _cnt */
stream->_cnt = 0;
/* Check if this was a read buffer */
if (stream->_flag & _IOREAD)
{
/* Must be at the end of the file */
if (!(stream->_flag & _IOEOF))
{
stream->_flag |= _IOERR;
return EOF;
}
/* Reset buffer */
stream->_ptr = stream->_base;
}
/* Fixup flags */
stream->_flag &= ~(_IOREAD|_IOEOF);
stream->_flag |= _IOWRT;
/* Check if should get a buffer */
if (!(stream->_flag & _IONBF) && stream != stdout && stream != stderr)
{
/* If we have no buffer, try to allocate one */
if (!stream->_base) alloc_buffer(stream);
}
/* Check if we can use a buffer now */
if (stream->_base && !(stream->_flag & _IONBF))
{
/* We can, check if there is something to write */
count = (int)(stream->_ptr - stream->_base);
if (count > 0)
written = _write(stream->_file, stream->_base, count);
else
written = 0;
/* Reset buffer and put the char into it */
stream->_ptr = stream->_base + sizeof(TCHAR);
stream->_cnt = stream->_bufsiz - sizeof(TCHAR);
*(TCHAR*)stream->_base = ch;
}
else
{
/* There is no buffer, write the char directly */
count = sizeof(TCHAR);
written = _write(stream->_file, &ch, sizeof(TCHAR));
}
/* Check for failure */
if (written != count)
{
stream->_flag |= _IOERR;
return EOF;
}
return ch & (sizeof(TCHAR) > sizeof(char) ? 0xffff : 0xff);
}

View file

@ -0,0 +1,11 @@
/*
* COPYRIGHT: GNU GPL, see COPYING in the top level directory
* PROJECT: ReactOS crt library
* FILE: lib/sdk/crt/stdio/_flswbuf
* PURPOSE: Implementation of _flswbuf
* PROGRAMMER: Timo Kreuzer
*/
#define _UNICODE
#define _flsbuf _flswbuf
#include "_flsbuf.c"

View file

@ -0,0 +1,38 @@
#include <precomp.h>
#include <tchar.h>
#ifdef _UNICODE
#define _TS S
#define sT "S"
#define access_dirT access_dirW
#else
#define _TS s
#define sT "s"
#define access_dirT access_dirA
#endif
#define MK_STR(s) #s
/*
* INTERNAL
*/
int access_dirT(const _TCHAR *_path)
{
DWORD Attributes = GetFileAttributes(_path);
TRACE(MK_STR(is_dirT)"('%"sT"')\n", _path);
if (Attributes == (DWORD)-1) {
_dosmaperr(GetLastError());
return -1;
}
if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
{
_set_errno(EACCES);
return -1;
}
return 0;
}

3369
lib/sdk/crt/stdio/file.c Normal file

File diff suppressed because it is too large Load diff

19
lib/sdk/crt/stdio/find.c Normal file
View file

@ -0,0 +1,19 @@
#include <precomp.h>
#include <tchar.h>
#include <io.h>
// Generate _findfirst and _findnext
#include "findgen.c"
/*
* @implemented
*/
int _findclose(intptr_t handle)
{
if (!FindClose((HANDLE)handle)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}

View file

@ -0,0 +1,13 @@
#include <precomp.h>
#include <tchar.h>
#include <io.h>
// Generate _findfirst64 and _findnext64
#undef _findfirst
#define _findfirst _findfirst64
#undef _findnext
#define _findnext _findnext64
#undef _finddata_t
#define _finddata_t __finddata64_t
#include "findgen.c"

View file

@ -0,0 +1,46 @@
/*
* @implemented
*/
intptr_t _tfindfirst(const _TCHAR* _name, struct _tfinddata_t* result)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFindFile;
hFindFile = FindFirstFile(_name, &FindFileData);
if (hFindFile == INVALID_HANDLE_VALUE) {
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = (time_t)FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = (time_t)FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = (time_t)FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = (((__int64)FindFileData.nFileSizeHigh)<<32) + FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName,MAX_PATH);
return (intptr_t)hFindFile;
}
/*
* @implemented
*/
int _tfindnext(intptr_t handle, struct _tfinddata_t* result)
{
WIN32_FIND_DATA FindFileData;
if (!FindNextFile((HANDLE)handle, &FindFileData)) {
_dosmaperr(GetLastError());
return -1;
}
result->attrib = FindFileData.dwFileAttributes;
result->time_create = (time_t)FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL);
result->time_access = (time_t)FileTimeToUnixTime(&FindFileData.ftLastAccessTime,NULL);
result->time_write = (time_t)FileTimeToUnixTime(&FindFileData.ftLastWriteTime,NULL);
result->size = (((__int64)FindFileData.nFileSizeHigh)<<32) + FindFileData.nFileSizeLow;
_tcsncpy(result->name,FindFileData.cFileName, MAX_PATH);
return 0;
}

View file

@ -0,0 +1,13 @@
#include <precomp.h>
#include <tchar.h>
#include <io.h>
// Generate _findfirsti64 and _findnexti64
#undef _findfirst
#define _findfirst _findfirsti64
#undef _findnext
#define _findnext _findnexti64
#undef _finddata_t
#define _finddata_t _finddatai64_t
#include "findgen.c"

12
lib/sdk/crt/stdio/fmode.c Normal file
View file

@ -0,0 +1,12 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
int _fmode = _O_TEXT;
/*
* @implemented
*/
int *__p__fmode(void)
{
return &_fmode;
}

View file

@ -0,0 +1,11 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
void _wperror(const wchar_t *s)
{
fwprintf(stderr, L"%s: %S\n", s, _strerror(NULL));
}

145
lib/sdk/crt/stdio/popen.c Normal file
View file

@ -0,0 +1,145 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS C runtime library
* FILE: lib/sdk/crt/stdio/popen.c
* PURPOSE: Pipe Functions
* PROGRAMERS: Eric Kohl
Hartmut Birr
*/
#include <precomp.h>
#include <tchar.h>
#ifdef _UNICODE
#define sT "S"
#else
#define sT "s"
#endif
#define MK_STR(s) #s
int alloc_fd(HANDLE hand, int flag); //FIXME: Remove
unsigned split_oflags(unsigned oflags); //FIXME: Remove
/*
* @implemented
*/
FILE *_tpopen (const _TCHAR *cm, const _TCHAR *md) /* program name, pipe mode */
{
_TCHAR *szCmdLine=NULL;
_TCHAR *szComSpec=NULL;
_TCHAR *s;
FILE *pf;
HANDLE hReadPipe, hWritePipe;
BOOL result;
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInformation;
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
TRACE(MK_STR(_tpopen)"('%"sT"', '%"sT"')\n", cm, md);
if (cm == NULL)
return( NULL );
szComSpec = _tgetenv(_T("COMSPEC"));
if (szComSpec == NULL)
{
szComSpec = _T("cmd.exe");
}
s = max(_tcsrchr(szComSpec, '\\'), _tcsrchr(szComSpec, '/'));
if (s == NULL)
s = szComSpec;
else
s++;
szCmdLine = malloc((_tcslen(s) + 4 + _tcslen(cm) + 1) * sizeof(_TCHAR));
if (szCmdLine == NULL)
{
return NULL;
}
_tcscpy(szCmdLine, s);
s = _tcsrchr(szCmdLine, '.');
if (s)
*s = 0;
_tcscat(szCmdLine, _T(" /C "));
_tcscat(szCmdLine, cm);
if ( !CreatePipe(&hReadPipe,&hWritePipe,&sa,1024))
{
free (szCmdLine);
return NULL;
}
memset(&StartupInfo, 0, sizeof(STARTUPINFO));
StartupInfo.cb = sizeof(STARTUPINFO);
if (*md == 'r' ) {
StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
StartupInfo.hStdOutput = hWritePipe;
StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
}
else if ( *md == 'w' ) {
StartupInfo.hStdInput = hReadPipe;
StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
}
if (StartupInfo.dwFlags & STARTF_USESTDHANDLES)
StartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
result = CreateProcess(szComSpec,
szCmdLine,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&StartupInfo,
&ProcessInformation);
free (szCmdLine);
if (result == FALSE)
{
CloseHandle(hReadPipe);
CloseHandle(hWritePipe);
return NULL;
}
CloseHandle(ProcessInformation.hThread);
CloseHandle(ProcessInformation.hProcess);
if ( *md == 'r' )
{
pf = _tfdopen(alloc_fd(hReadPipe, split_oflags(_fmode)) , _T("r"));
CloseHandle(hWritePipe);
}
else
{
pf = _tfdopen( alloc_fd(hWritePipe, split_oflags(_fmode)) , _T("w"));
CloseHandle(hReadPipe);
}
return( pf );
}
#ifndef _UNICODE
/*
* @implemented
*/
int _pclose (FILE *pp)
{
TRACE("_pclose(%x)",pp);
fclose(pp);
//if (!TerminateProcess(pp->_tmpfname ,0))
// return( -1 );
return( 0 );
}
#endif

64
lib/sdk/crt/stdio/stat.c Normal file
View file

@ -0,0 +1,64 @@
#include <precomp.h>
#include <tchar.h>
#define stat64_to_stat(buf64, buf) \
do { \
buf->st_dev = (buf64)->st_dev; \
buf->st_ino = (buf64)->st_ino; \
buf->st_mode = (buf64)->st_mode; \
buf->st_nlink = (buf64)->st_nlink; \
buf->st_uid = (buf64)->st_uid; \
buf->st_gid = (buf64)->st_gid; \
buf->st_rdev = (buf64)->st_rdev; \
buf->st_size = (_off_t)(buf64)->st_size; \
buf->st_atime = (time_t)(buf64)->st_atime; \
buf->st_mtime = (time_t)(buf64)->st_mtime; \
buf->st_ctime = (time_t)(buf64)->st_ctime; \
} while (0)
int CDECL _tstat(const _TCHAR* path, struct _stat * buf)
{
int ret;
struct __stat64 buf64;
ret = _tstat64(path, &buf64);
if (!ret)
stat64_to_stat(&buf64, buf);
return ret;
}
int CDECL _tstati64(const _TCHAR* path, struct _stati64 * buf)
{
int ret;
struct __stat64 buf64;
ret = _tstat64(path, &buf64);
if (!ret)
stat64_to_stat(&buf64, buf);
return ret;
}
#ifndef _UNICODE
int CDECL _fstat(int fd, struct _stat* buf)
{ int ret;
struct __stat64 buf64;
ret = _fstat64(fd, &buf64);
if (!ret)
stat64_to_stat(&buf64, buf);
return ret;
}
int CDECL _fstati64(int fd, struct _stati64* buf)
{
int ret;
struct __stat64 buf64;
ret = _fstat64(fd, &buf64);
if (!ret)
stat64_to_stat(&buf64, buf);
return ret;
}
#endif

146
lib/sdk/crt/stdio/stat64.c Normal file
View file

@ -0,0 +1,146 @@
#include <precomp.h>
#include <tchar.h>
#include <direct.h>
HANDLE fdtoh(int fd);
#define ALL_S_IREAD (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
#define ALL_S_IWRITE (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
#define ALL_S_IEXEC (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))
#ifdef UNICODE
#define TCHAR4 ULONGLONG
#else
#define TCHAR4 ULONG
#endif
#define TCSIZE sizeof(_TCHAR)
#define TOULL(x) ((TCHAR4)(x))
#define EXE ((TOULL('e')<<(2*TCSIZE)) | (TOULL('x')<<TCSIZE) | (TOULL('e')))
#define BAT ((TOULL('b')<<(2*TCSIZE)) | (TOULL('a')<<TCSIZE) | (TOULL('t')))
#define CMD ((TOULL('c')<<(2*TCSIZE)) | (TOULL('m')<<TCSIZE) | (TOULL('d')))
#define COM ((TOULL('c')<<(2*TCSIZE)) | (TOULL('o')<<TCSIZE) | (TOULL('m')))
int CDECL _tstat64(const _TCHAR *path, struct __stat64 *buf)
{
DWORD dw;
WIN32_FILE_ATTRIBUTE_DATA hfi;
unsigned short mode = ALL_S_IREAD;
size_t plen;
TRACE(":file (%s) buf(%p)\n",path,buf);
if (!GetFileAttributesEx(path, GetFileExInfoStandard, &hfi))
{
TRACE("failed (%d)\n",GetLastError());
_dosmaperr(ERROR_FILE_NOT_FOUND);
return -1;
}
memset(buf,0,sizeof(struct __stat64));
/* FIXME: rdev isn't drive num, despite what the docs say-what is it?
Bon 011120: This FIXME seems incorrect
Also a letter as first char isn't enough to be classified
as a drive letter
*/
if (isalpha((unsigned char)*path)&& (*(path+1)==':'))
buf->st_dev = buf->st_rdev = _totupper(*path) - 'A'; /* drive num */
else
buf->st_dev = buf->st_rdev = _getdrive() - 1;
plen = _tcslen(path);
/* Dir, or regular file? */
if ((hfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
(path[plen-1] == '\\'))
mode |= (_S_IFDIR | ALL_S_IEXEC);
else
{
mode |= _S_IFREG;
/* executable? */
if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */
{
TCHAR4 ext = _totlower(path[plen-1]) | (_totlower(path[plen-2]) << TCSIZE) |
(_totlower(path[plen-3]) << (2*TCSIZE));
if (ext == EXE || ext == BAT || ext == CMD || ext == COM)
mode |= ALL_S_IEXEC;
}
}
if (!(hfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
mode |= ALL_S_IWRITE;
buf->st_mode = mode;
buf->st_nlink = 1;
buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow;
RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastAccessTime, &dw);
buf->st_atime = dw;
RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastWriteTime, &dw);
buf->st_mtime = buf->st_ctime = dw;
TRACE("%d %d 0x%08lx%08lx %ld %ld %ld\n", buf->st_mode,buf->st_nlink,
(long)(buf->st_size >> 32),(long)buf->st_size,
(long)buf->st_atime,(long)buf->st_mtime,(long)buf->st_ctime);
return 0;
}
#ifndef _UNICODE
int CDECL _fstat64(int fd, struct __stat64* buf)
{
DWORD dw;
DWORD type;
BY_HANDLE_FILE_INFORMATION hfi;
HANDLE hand = fdtoh(fd);
TRACE(":fd (%d) stat (%p)\n",fd,buf);
if (hand == INVALID_HANDLE_VALUE)
return -1;
if (!buf)
{
WARN(":failed-NULL buf\n");
_dosmaperr(ERROR_INVALID_PARAMETER);
return -1;
}
memset(&hfi, 0, sizeof(hfi));
memset(buf, 0, sizeof(struct __stat64));
type = GetFileType(hand);
if (type == FILE_TYPE_PIPE)
{
buf->st_dev = buf->st_rdev = fd;
buf->st_mode = _S_IFIFO;
buf->st_nlink = 1;
}
else if (type == FILE_TYPE_CHAR)
{
buf->st_dev = buf->st_rdev = fd;
buf->st_mode = _S_IFCHR;
buf->st_nlink = 1;
}
else /* FILE_TYPE_DISK etc. */
{
if (!GetFileInformationByHandle(hand, &hfi))
{
WARN(":failed-last error (%d)\n",GetLastError());
_dosmaperr(ERROR_INVALID_PARAMETER);
return -1;
}
buf->st_mode = _S_IFREG | ALL_S_IREAD;
if (!(hfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
buf->st_mode |= ALL_S_IWRITE;
buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow;
RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastAccessTime, &dw);
buf->st_atime = dw;
RtlTimeToSecondsSince1970((LARGE_INTEGER *)&hfi.ftLastWriteTime, &dw);
buf->st_mtime = buf->st_ctime = dw;
buf->st_nlink = (short)hfi.nNumberOfLinks;
}
TRACE(":dwFileAttributes = 0x%x, mode set to 0x%x\n",hfi.dwFileAttributes,
buf->st_mode);
return 0;
}
#endif

View file

@ -0,0 +1,4 @@
#define UNICODE
#define _UNICODE
#include "access.c"

View file

@ -0,0 +1,9 @@
#define UNICODE
#define _UNICODE
#include <precomp.h>
#include <tchar.h>
#include <io.h>
// Generate _findfirst and _findnext
#include "findgen.c"

View file

@ -0,0 +1,16 @@
#define UNICODE
#define _UNICODE
#include <precomp.h>
#include <tchar.h>
#include <io.h>
// Generate _findfirst64 and _findnext64
#undef _wfindfirst
#define _wfindfirst _wfindfirst64
#undef _wfindnext
#define _wfindnext _wfindnext64
#undef _wfinddata_t
#define _wfinddata_t _wfinddata64_t
#include "findgen.c"

View file

@ -0,0 +1,16 @@
#define UNICODE
#define _UNICODE
#include <precomp.h>
#include <tchar.h>
#include <io.h>
// Generate _findfirsti64 and _findnexti64
#undef _wfindfirst
#define _wfindfirst _wfindfirsti64
#undef _wfindnext
#define _wfindnext _wfindnexti64
#undef _wfinddata_t
#define _wfinddata_t _wfinddatai64_t
#include "findgen.c"

View file

@ -0,0 +1,5 @@
#define _UNICODE
#define UNICODE
#include "popen.c"

View file

@ -0,0 +1,4 @@
#define UNICODE
#define _UNICODE
#include "stat.c"

View file

@ -0,0 +1,4 @@
#define UNICODE
#define _UNICODE
#include "stat64.c"