- Completely rewrite most of stdio functions by merging Wine's msvcrt code adapted for ReactOS.

- Leave and refactor existing underlying linux-code based sprintf implementation into lnx_ prefixed functions.
- Misc source code and headers cleanup.
- Fixes bugs 2910, 2803.
See issue #2803 for more details.

svn path=/trunk/; revision=33927
This commit is contained in:
Aleksey Bragin 2008-06-11 08:54:46 +00:00
parent 553e9f4821
commit 7b57917c46
137 changed files with 1918 additions and 6187 deletions

View file

@ -309,8 +309,8 @@ _setjmp
_setmode
_setsystime
_sleep
_snprintf=crt__snprintf
_snwprintf=crt__snwprintf
_snprintf
_snwprintf
_sopen
_spawnl
_spawnle
@ -499,7 +499,7 @@ setvbuf
signal
sin=NTDLL.sin
sinh
sprintf=crt_sprintf
sprintf
sqrt=NTDLL.sqrt
srand
sscanf
@ -525,7 +525,7 @@ strtol=NTDLL.strtol
strtoul
strtoull
strxfrm
swprintf=crt_swprintf
swprintf
swscanf
system
tan=NTDLL.tan

View file

@ -2,7 +2,7 @@
*
* dllmain.c
*
* ReactOS MSVCRT.DLL Compatibility Library
* ReactOS CRTDLL.DLL Compatibility Library
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
@ -14,10 +14,6 @@
* DISCLAMED. This includes but is not limited to warrenties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* $Revision: 1.24 $
* $Author: mf $
* $Date: 2005-01-06 14:58:04 +0100 (Thu, 06 Jan 2005) $
*
*/
#include <precomp.h>
@ -32,8 +28,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(crtdll);
/* EXTERNAL PROTOTYPES ********************************************************/
//void __fileno_init(void);
extern BOOL __fileno_init(void);
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
extern void FreeEnvironment(char **environment);
@ -136,8 +130,6 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
hHeap = HeapCreate(0, 100000, 0);
if (hHeap == NULL)
return FALSE;
if (!__fileno_init())
return FALSE;
/* create tls stuff */
if (!CreateThreadData())
@ -159,6 +151,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
/* FIXME: Initialization of the WINE code */
msvcrt_init_mt_locks();
msvcrt_init_io();
setlocale(0, "C");
//_setmbcp(_MB_CP_LOCALE);
@ -174,8 +167,9 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
case DLL_PROCESS_DETACH://0
//TRACE("Detach %d\n", nAttachCount);
/* FIXME: more cleanup... */
_fcloseall();
/* Deinit of the WINE code */
msvcrt_free_io();
msvcrt_free_mt_locks();
_atexit_cleanup();
/* destroy tls stuff */

View file

@ -30,8 +30,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
/* EXTERNAL PROTOTYPES ********************************************************/
//void __fileno_init(void);
extern BOOL __fileno_init(void);
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
extern void FreeEnvironment(char **environment);
@ -76,8 +74,6 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
hHeap = HeapCreate(0, 100000, 0);
if (hHeap == NULL)
return FALSE;
if (!__fileno_init())
return FALSE;
/* create tls stuff */
if (!CreateThreadData())
@ -99,6 +95,7 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
/* Initialization of the WINE code */
msvcrt_init_mt_locks();
msvcrt_init_io();
setlocale(0, "C");
//_setmbcp(_MB_CP_LOCALE);
@ -116,9 +113,13 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
//DPRINT1("Detach %d\n", nAttachCount);
//DPRINT("Detach\n");
/* FIXME: more cleanup... */
_fcloseall();
/* Deinit of the WINE code */
msvcrt_free_io();
msvcrt_free_mt_locks();
_atexit_cleanup();
/* destroy tls stuff */
DestroyThreadData();

View file

@ -497,9 +497,9 @@ EXPORTS
_setmode @490
_setsystime @491
_sleep @492
_snprintf=crt__snprintf @493
_snprintf @493
; _snscanf @494
_snwprintf=crt__snwprintf @495
_snwprintf @495
; _snwscanf @496
_sopen @497
_spawnl @498
@ -761,7 +761,7 @@ EXPORTS
putc @754
putchar @755
puts @756
putwc @757
putwc=fputwc @757
putwchar=_fputwchar @758
qsort=ntdll.qsort @759
raise @760
@ -777,7 +777,7 @@ EXPORTS
signal @770
sin=ntdll.sin @771
sinh @772
sprintf=crt_sprintf @773
sprintf @773
sqrt=ntdll.sqrt @774
srand @775
sscanf @776
@ -802,7 +802,7 @@ EXPORTS
strtol=ntdll.strtol @795
strtoul=ntdll.strtoul @796
strxfrm @797
swprintf=crt_swprintf @798
swprintf @798
swscanf @799
system @800
tan=ntdll.tan @801

View file

@ -30,9 +30,16 @@
/* Flags for the iobuf structure */
#define _IOREAD 1 /* currently reading */
#define _IOWRT 2 /* currently writing */
#define _IORW 0x0080 /* opened as "r+w" */
#define _IOREAD 0x0001 /* currently reading */
#define _IOWRT 0x0002 /* currently writing */
#define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
#define _IOEOF 0x0010 /* EOF reached on read */
#define _IOERR 0x0020 /* I/O error from system */
#define _IOSTRG 0x0040 /* Strange or no file descriptor */
#define _IORW 0x0080 /* opened as "r+w" */
#ifdef _POSIX_SOURCE
# define _IOAPPEND 0x0200
#endif
/*
@ -87,13 +94,6 @@
#define _IOLBF 0x0040 /* line buffered */
#define _IONBF 0x0004 /* not buffered */
#define _IOMYBUF 0x0008 /* stdio malloc()'d buffer */
#define _IOEOF 0x0010 /* EOF reached on read */
#define _IOERR 0x0020 /* I/O error from system */
#define _IOSTRG 0x0040 /* Strange or no file descriptor */
#ifdef _POSIX_SOURCE
# define _IOAPPEND 0x0200
#endif
/*
* The buffer size as used by setbuf such that it is equivalent to
* (void) setvbuf(fileSetBuffer, caBuffer, _IOFBF, BUFSIZ).
@ -456,7 +456,7 @@ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*);
_CRTIMP wint_t __cdecl __MINGW_NOTHROW putwc (wint_t, FILE*);
_CRTIMP int __cdecl __MINGW_NOTHROW _putws (const wchar_t*);
_CRTIMP wint_t __cdecl __MINGW_NOTHROW putwchar (wint_t);
_CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfdopen(int, wchar_t *);
_CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfdopen(int, const wchar_t *);
_CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfopen (const wchar_t*, const wchar_t*);
_CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfreopen (const wchar_t*, const wchar_t*, FILE*);
_CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfsopen (const wchar_t*, const wchar_t*, int);

View file

@ -1,13 +1,10 @@
This file contains information about the status the MSVCRT runtime in ReactOS.
Big chunks of this CRT library are taken from Wine's msvcrt implementation,
you can find a list of synced files in README.WINE file.
Please note that all of the MSVCRT.DLL runtime sources are license GPL unless
otherwise noted. The sources from WINE are dual licensed GPL/LGPL.
If you update a function in the ~/wine directory please send a patch to wine-patches@winehq.com
TODO List:
Implement the remaining functions that are commented out in the .def file
Update source code headers for the license information.
Complete the W32API conversion for all source files.
Write a decent regression test suite.
Convert all C++ style comments to C style comments.
????
Notes:
1. When syncing, omit MSVCRT_ prefix where possible, Wine has to keep this
because they are linking with *both* original crt, and ms crt implementation.
ReactOS has the only CRT, so no need to make distinct functions.
2. ReactOS compiles two versions of the CRT library, one for usermode
(called just "crt"), and one version for kernelmode usage (called "libcntpr").
In order to separate the code, you can use #ifdef _LIBCNT_ for libcntpr code.

View file

@ -1,23 +1,35 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* COPYRIGHT: LGPL - See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/conio/cputs.c
* PURPOSE: Writes a character to stdout
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
* PROGRAMER: Aleksey Bragin
*/
#include <precomp.h>
extern FDINFO *fdesc;
/*
* @implemented
*/
int _cputs(const char *_str)
{
#if 0
DWORD count;
int retval = EOF;
LOCK_CONSOLE;
if (WriteConsoleA(console_out, str, strlen(str), &count, NULL)
&& count == 1)
retval = 0;
UNLOCK_CONSOLE;
return retval;
#else
int len = strlen(_str);
DWORD written = 0;
if (!WriteFile( fdinfo(stdout->_file)->hFile ,_str,len,&written,NULL))
if (!WriteFile( fdesc[stdout->_file].hFile ,_str,len,&written,NULL))
return -1;
return 0;
#endif
}

View file

@ -76,46 +76,6 @@
</directory>
</if>
</directory>
<directory name="io">
<file>access.c</file>
<file>chmod.c</file>
<file>chsize.c</file>
<file>close.c</file>
<file>commit.c</file>
<file>creat.c</file>
<file>dup.c</file>
<file>dup2.c</file>
<file>eof.c</file>
<file>filelen.c</file>
<file>fileleni.c</file>
<file>find.c</file>
<file>fmode.c</file>
<file>isatty.c</file>
<file>locking.c</file>
<file>lseek.c</file>
<file>lseeki64.c</file>
<file>mktemp.c</file>
<file>open.c</file>
<file>pipe.c</file>
<file>read.c</file>
<file>setmode.c</file>
<file>sopen.c</file>
<file>stubs.c</file>
<file>tell.c</file>
<file>telli64.c</file>
<file>umask.c</file>
<file>unlink.c</file>
<file>utime.c</file>
<file>waccess.c</file>
<file>wchmod.c</file>
<file>wcreat.c</file>
<file>wfind.c</file>
<file>wmktemp.c</file>
<file>wopen.c</file>
<file>write.c</file>
<file>wunlink.c</file>
<file>wutime.c</file>
</directory>
<directory name="locale">
<file>locale.c</file>
</directory>
@ -272,79 +232,20 @@
<file>xcptinfo.c</file>
</directory>
<directory name="stdio">
<file>allocfil.c</file>
<file>clearerr.c</file>
<file>fclose.c</file>
<file>fdopen.c</file>
<file>feof.c</file>
<file>ferror.c</file>
<file>fflush.c</file>
<file>fgetc.c</file>
<file>fgetchar.c</file>
<file>fgetpos.c</file>
<file>fgets.c</file>
<file>fgetws.c</file>
<file>filbuf.c</file>
<file>access.c</file>
<file>file.c</file>
<file>fileno.c</file>
<file>flsbuf.c</file>
<file>fopen.c</file>
<file>fprintf.c</file>
<file>fputc.c</file>
<file>fputchar.c</file>
<file>fputs.c</file>
<file>fputws.c</file>
<file>fread.c</file>
<file>freopen.c</file>
<file>fseek.c</file>
<file>fsetpos.c</file>
<file>fsopen.c</file>
<file>ftell.c</file>
<file>fwalk.c</file>
<file>fwprintf.c</file>
<file>fwrite.c</file>
<file>getc.c</file>
<file>getchar.c</file>
<file>gets.c</file>
<file>getw.c</file>
<file>find.c</file>
<file>fmode.c</file>
<file>lnx_sprintf.c</file>
<file>lnx_vfprintf.c</file>
<file>lnx_vfwprint.c</file>
<file>lnx_vsprintf.c</file>
<file>lnx_vswprintf.c</file>
<file>perror.c</file>
<file>popen.c</file>
<file>printf.c</file>
<file>putc.c</file>
<file>putchar.c</file>
<file>puts.c</file>
<file>putw.c</file>
<file>putwchar.c</file>
<file>remove.c</file>
<file>rename.c</file>
<file>rewind.c</file>
<file>rmtmp.c</file>
<file>setbuf.c</file>
<file>setvbuf.c</file>
<file>sprintf.c</file>
<file>swprintf.c</file>
<file>stdhnd.c</file>
<file>tempnam.c</file>
<file>tmpfile.c</file>
<file>tmpnam.c</file>
<file>ungetc.c</file>
<file>ungetwc.c</file>
<file>vfprintf.c</file>
<file>vfwprint.c</file>
<file>vprintf.c</file>
<file>vsprintf.c</file>
<file>vswprintf.c</file>
<file>vwprintf.c</file>
<file>wfdopen.c</file>
<file>wfopen.c</file>
<file>wfreopen.c</file>
<file>wfsopen.c</file>
<file>waccess.c</file>
<file>wfind.c</file>
<file>wpopen.c</file>
<file>wprintf.c</file>
<file>wremove.c</file>
<file>wrename.c</file>
<file>wtempnam.c</file>
<file>wtmpnam.c</file>
</directory>
<directory name="stdlib">
<file>_exit.c</file>
@ -440,17 +341,12 @@
<file>strtoull.c</file>
<file>strupr.c</file>
<file>strxfrm.c</file>
<file>wcstod.c</file>
<file>wcstombs.c</file>
<file>wctomb.c</file>
<file>wsplitp.c</file>
<file>wcs.c</file>
</directory>
<directory name="sys_stat">
<file>fstat.c</file>
<file>fstati64.c</file>
<file>futime.c</file>
<file>stat.c</file>
<file>wstat.c</file>
<file>systime.c</file>
</directory>
<directory name="time">
@ -470,13 +366,9 @@
<directory name="wstring">
<file>wcscoll.c</file>
<file>wcscspn.c</file>
<file>wcsdup.c</file>
<file>wcsicmp.c</file>
<file>wcslwr.c</file>
<file>wcsnicmp.c</file>
<file>wcspbrk.c</file>
<file>wcsrev.c</file>
<file>wcsset.c</file>
<file>wcsspn.c</file>
<file>wcsstr.c</file>
<file>wcstok.c</file>

View file

@ -37,22 +37,17 @@
#define WRITE_STREAM(f) ((((f)->_flag & _IOWRT) == _IOWRT))
#define READ_STREAM(f) ((((f)->_flag & _IOREAD) == _IOREAD))
char __validfp(FILE*);
int __set_errno(int err);
int __set_doserrno(int error);
void* filehnd(int fn);
char __is_text_file(FILE*);
int alloc_fd(void* hFile, char mode);
int _doprnt(const char* fmt, va_list args, FILE *);
int _doscan(FILE* iop, const char* fmt, va_list argp);
int __fileno_dup2(int handle1, int handle2);
char __fileno_getmode(int _fd);
int __fileno_setmode(int _fd, int _newmode);
void free_fd(int _fd);
void sigabort_handler(int sig);
char split_oflags(int oflags);
unsigned create_io_inherit_block(STARTUPINFOA* si);
void UnixTimeToFileTime(time_t unix_time, FILETIME* filetime, DWORD remainder);
time_t FileTimeToUnixTime(const FILETIME* filetime, DWORD *remainder);
@ -106,14 +101,12 @@ typedef struct _FDINFO
/* get fdinfo ptr. from an fd */
#define fdinfo(i) (fdinfo_bucket(i) + fdinfo_bucket_entry_idx(i))
extern FDINFO* __pioinfo[];
//extern FDINFO* __pioinfo[];
void _dosmaperr(unsigned long oserrcode);
FILE* __alloc_file(void);
@ -128,8 +121,6 @@ int access_dirW(const wchar_t *_path);
void _fwalk(void (*func)(FILE*)); // not exported
#undef MB_CUR_MAX

View file

@ -0,0 +1,22 @@
#ifndef _CRT_PRINTF_H
#define _CRT_PRINTF_H
/* Implementation of a printf appropriated from Linux kernel */
int lnx_sprintf(char *str, const char *fmt, ...);
int lnx__vsprintf(char *str, const char *fmt, va_list ap);
int lnx__vswprintf(wchar_t *str, const wchar_t *fmt, va_list ap);
int lnx__vsnprintf(char *str, size_t maxlen, const char *fmt, va_list ap);
int lnx__vsnwprintf(wchar_t *str, size_t maxlen, const char *fmt, va_list ap);
int lnx_vfprintf(FILE* f, const char* fmt, va_list ap);
int lnx_vfwprintf(FILE *f, const wchar_t *fmt, va_list ap);
#ifdef _UNICODE
#define lnx_vftprintf lnx_vfwprintf
#define lnx__vstprintf lnx__vswprintf
#else
#define lnx_vftprintf lnx_vfprintf
#define lnx__vstprintf lnx__vsprintf
#endif
#endif /* _CRT_PRINTF_H */

View file

@ -129,6 +129,8 @@ extern void msvcrt_free_args(void);
extern void msvcrt_init_signals(void);
extern void msvcrt_free_signals(void);
extern unsigned create_io_inherit_block(WORD*, BYTE**);
#define MSVCRT__OUT_TO_DEFAULT 0
#define MSVCRT__REPORT_ERRMODE 3

View file

@ -1,60 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
#include <sys/stat.h>
#include <tchar.h>
#define mode_t int
#define MK_STR(s) #s
#ifdef _UNICODE
#define sT "S"
#else
#define sT "s"
#endif
/*
* @implemented
*/
int _tchmod(const _TCHAR* filename, mode_t mode)
{
DWORD FileAttributes = 0;
BOOLEAN Set = FALSE;
TRACE(MK_STR(_tchmod)"('%"sT"', %x)\n", filename, mode);
FileAttributes = GetFileAttributes(filename);
if ( FileAttributes == INVALID_FILE_ATTRIBUTES ) {
_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 && SetFileAttributes(filename, FileAttributes) == FALSE) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}

View file

@ -1,18 +0,0 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
int _chsize(int _fd, long size)
{
TRACE("_chsize(fd %d, size %d)\n", _fd, size);
long location = _lseek(_fd, 0, SEEK_CUR);
if (location == -1) return -1;
if (_lseek(_fd, size, 0) == -1)
return -1;
if (!SetEndOfFile((HANDLE)_get_osfhandle(_fd)))
return -1;
_lseek(_fd, location, SEEK_SET);
return 0;
}

View file

@ -1,21 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
int _close(int _fd)
{
TRACE("_close(%i)", _fd);
if (_fd == -1)
return(-1);
if (!CloseHandle((HANDLE)_get_osfhandle(_fd)))
{
WARN(":failed-last error (%d)\n",GetLastError());
_dosmaperr(GetLastError());
return -1;
}
free_fd(_fd);
return(0);
}

View file

@ -1,14 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
int _commit(int _fd)
{
if (! FlushFileBuffers((HANDLE)_get_osfhandle(_fd)) ) {
__set_errno(EBADF);
return -1;
}
return 0;
}

View file

@ -1,22 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
/*
* @implemented
*/
int _creat(const char* filename, int mode)
{
TRACE("_creat('%s', mode %x)\n", filename, mode);
return _open(filename,_O_CREAT|_O_TRUNC,mode);
}

View file

@ -1,38 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
int _dup(int handle)
{
HANDLE hFile;
HANDLE hProcess = GetCurrentProcess();
BOOL result;
int fd;
int mode;
hFile = (HANDLE)_get_osfhandle(handle);
if (hFile == INVALID_HANDLE_VALUE) {
__set_errno(EBADF);
return -1;
}
mode = __fileno_getmode(handle);
result = DuplicateHandle(hProcess,
hFile,
hProcess,
&hFile,
0,
mode & FNOINHERIT ? FALSE : TRUE,
DUPLICATE_SAME_ACCESS);
if (result == FALSE) {
_dosmaperr(GetLastError());
return -1;
}
fd = alloc_fd(hFile, mode);
if (fd < 0)
{
CloseHandle(hFile);
}
return fd;
}

View file

@ -1,9 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
int _dup2(int handle1, int handle2)
{
return __fileno_dup2(handle1, handle2);
}

View file

@ -1,27 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
/*
* @implemented
*/
int _eof(int _fd)
{
__int64 cur_pos = _lseeki64(_fd, 0, SEEK_CUR);
__int64 end_pos = _lseeki64(_fd, 0, SEEK_END);
if ( cur_pos == -1 || end_pos == -1)
return -1;
if (cur_pos == end_pos)
return 1;
return 0;
}

View file

@ -1,17 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
long _filelength(int _fd)
{
DWORD len = GetFileSize((HANDLE)_get_osfhandle(_fd), NULL);
if (len == INVALID_FILE_SIZE) {
DWORD oserror = GetLastError();
if (oserror != 0) {
_dosmaperr(oserror);
return -1L;
}
}
return (long)len;
}

View file

@ -1,19 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
__int64 _filelengthi64(int _fd)
{
DWORD lo_length, hi_length;
lo_length = GetFileSize((HANDLE)_get_osfhandle(_fd), &hi_length);
if (lo_length == INVALID_FILE_SIZE) {
DWORD oserror = GetLastError();
if (oserror != 0) {
_dosmaperr(oserror);
return (__int64)-1;
}
}
return((((__int64)hi_length) << 32) + lo_length);
}

View file

@ -1,13 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
int _isatty(int fd)
{
HANDLE hFile = fdinfo(fd)->hFile;
if (hFile == INVALID_HANDLE_VALUE)
return 0;
return GetFileType(hFile) == FILE_TYPE_CHAR ? 1 : 0;
}

View file

@ -1,17 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
int _locking(int _fd, int mode, long nbytes)
{
long offset = _lseek(_fd, 0L, 1);
if (offset == -1L)
return -1;
if (!LockFile((HANDLE)_get_osfhandle(_fd),offset,0,nbytes,0)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}

View file

@ -1,17 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
long _lseek(int _fildes, long _offset, int _whence)
{
DWORD newpos = SetFilePointer((HANDLE)fdinfo(_fildes)->hFile, _offset, NULL, _whence);
if (newpos == INVALID_SET_FILE_POINTER) {
DWORD oserror = GetLastError();
if (oserror != 0) {
_dosmaperr(oserror);
return -1L;
}
}
return newpos;
}

View file

@ -1,39 +0,0 @@
#include <precomp.h>
//#define SETFILEPOINTEREX_AVAILABLE
/*
* @implemented
*/
__int64 _lseeki64(int _fildes, __int64 _offset, int _whence)
{
#ifdef SETFILEPOINTEREX_AVAILABLE
LARGE_INTEGER new_pos;
LARGE_INTEGER offset;
offset.QuadPart = _offset;
// if (invalid_filehnd(_fildes)) {
// __set_errno ( EBADF );
// return -1L;
// }
if (SetFilePointerEx((HANDLE)fdinfo(_fildes)->hFile, offset, &new_pos, _whence)) {
} else {
_dosmaperr(error);
return -1L;
}
return new_pos.QuadPart;
#else
//ULONG lo_pos;
//DWORD hi_pos = 0; // must equal 0 or -1 if supplied, -1 for negative 32 seek value
//lo_pos = SetFilePointer((HANDLE)filehnd(_fildes), _offset, &hi_pos, _whence);
//return((((__int64)hi_pos) << 32) + lo_pos);
LARGE_INTEGER offset;
offset.QuadPart = _offset;
offset.u.LowPart = SetFilePointer((HANDLE)fdinfo(_fildes)->hFile,
offset.u.LowPart, &offset.u.HighPart, _whence);
return ((((__int64)offset.u.HighPart) << 32) + offset.u.LowPart);
#endif /*SETFILEPOINTEREX_AVAILABLE*/
}

View file

@ -1,72 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/mktemp.c
* PURPOSE: Makes a temp file based on a template
* PROGRAMER: DJ Delorie
Ariadne
* UPDATE HISTORY:
* 28/12/98: Appropriated for the Reactos Kernel
*/
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
char* _mktemp(char* _template)
{
static int count = 0;
char *cp, *dp;
int i, len, xcount, loopcnt;
TRACE("_mktemp('%s')\n", _template);
len = strlen (_template);
cp = _template + len;
xcount = 0;
while (xcount < 6 && cp > _template && cp[-1] == 'X')
xcount++, cp--;
if (xcount) {
dp = cp;
while (dp > _template && dp[-1] != '/' && dp[-1] != '\\' && dp[-1] != ':')
dp--;
/* Keep the first characters of the template, but turn the rest into
Xs. */
while (cp > dp + 8 - xcount) {
*--cp = 'X';
xcount = (xcount >= 6) ? 6 : 1 + xcount;
}
/* If dots occur too early -- squash them. */
while (dp < cp) {
if (*dp == '.') *dp = 'a';
dp++;
}
/* Try to add ".tmp" to the filename. Truncate unused Xs. */
if (cp + xcount + 3 < _template + len)
strcpy (cp + xcount, ".tmp");
else
cp[xcount] = 0;
/* This loop can run up to 2<<(5*6) times, or about 10^9 times. */
for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) {
int c = count++;
for (i = 0; i < xcount; i++, c >>= 5)
cp[i] = "abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f];
if (_access(_template,0) == -1)
return _template;
}
}
/* Failure: truncate the template and return NULL. */
*_template = 0;
return 0;
}

View file

@ -1,597 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/open.c
* PURPOSE: Opens a file and translates handles to fileno
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 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
// possibly store extra information at the handle
#include <precomp.h>
#if !defined(NDEBUG) && defined(DBG)
#include <stdarg.h>
#endif
#include <sys/stat.h>
#include <string.h>
#include <share.h>
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)
/////////////////////////////////////////
static int g_fdstart = 3; /* first unallocated fd */
static int g_fdend = 3; /* highest allocated fd */
/*
* INTERNAL
*/
/*
static __inline FD_INFO* fdinfo(int fd)
{
FD_INFO* bucket = __pioinfo[fd >> FDINFO_ENTRIES_PER_BUCKET_SHIFT];
if (!bucket){
bucket = alloc_init_bucket(fd);
}
return bucket + (fd & (FDINFO_ENTRIES_PER_BUCKET - 1));
}
*/
/*
* INTERNAL
*/
__inline BOOL is_valid_fd(int fd)
{
BOOL b = (fd >= 0 && fd < g_fdend && (fdinfo(fd)->fdflags & FOPEN));
if (!b){
if (fd >= 0 && fd < g_fdend)
{
ERR("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);
}
else
{
ERR("not valid fd %i, g_fdend %i\n",fd,g_fdend);
}
}
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))
ERR(":unsupported oflags 0x%04x\n",oflags);
return fdflags;
}
/*
* INTERNAL
*/
char __is_text_file(FILE* p)
{
if ( p == NULL || fdinfo_bucket((p)->_file) == NULL )
return FALSE;
return (!((p)->_flag&_IOSTRG) && (fdinfo((p)->_file)->fdflags & FTEXT));
}
/*********************************************************************
* _open (MSVCRT.@)
*/
int CDECL _open( const char *path, int flags, ... )
{
va_list ap;
if (flags & O_CREAT)
{
int pmode;
va_start(ap, flags);
pmode = va_arg(ap, int);
va_end(ap);
return _sopen( path, flags, SH_DENYNO, pmode );
}
else
return _sopen( path, flags, SH_DENYNO);
}
/*
* INTERNAL
*/
static void init_bucket(FDINFO* entry)
{
int i;
for(i=0;
i < FDINFO_ENTRIES_PER_BUCKET;
i++, entry++)
{
entry->hFile = INVALID_HANDLE_VALUE;
entry->fdflags = 0;
entry->pipechar = LF;
entry->lockinitflag = 0;
}
}
/*
* INTERNAL
*/
static BOOL alloc_init_bucket(int fd)
{
fdinfo_bucket(fd) = malloc(FDINFO_ENTRIES_PER_BUCKET * sizeof(FDINFO));
if (!fdinfo_bucket(fd)) return FALSE;
init_bucket(fdinfo_bucket(fd));
return TRUE;
}
/*
* 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)
{
if (fd >= FDINFO_ENTRIES)
{
ERR("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);
}
TRACE("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);
return -1;
}
return fdinfo(fd)->fdflags;
}
/*
* INTERNAL
*/
void free_fd(int fd)
{
LOCK_FILES();
fdinfo(fd)->hFile = INVALID_HANDLE_VALUE;
fdinfo(fd)->fdflags = 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
*/
int _open_osfhandle(long osfhandle, int oflags)
{
/*
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
*/
long _get_osfhandle(int fd)
{
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)
{
HANDLE hProcess;
BOOL result;
if (handle1 >= FDINFO_ENTRIES || handle1 < 0 || handle2 >= FDINFO_ENTRIES || handle2 < 0) {
__set_errno(EBADF);
return -1;
}
// if (_pioinfo[handle1]->fd == -1) {
if (fdinfo(handle1)->hFile == INVALID_HANDLE_VALUE) {
__set_errno(EBADF);
return -1;
}
if (handle1 == handle2)
return handle1;
// if (_pioinfo[handle2]->fd != -1) {
if (fdinfo(handle2)->hFile != INVALID_HANDLE_VALUE) {
_close(handle2);
}
hProcess = GetCurrentProcess();
result = DuplicateHandle(hProcess,
fdinfo(handle1)->hFile,
hProcess,
&fdinfo(handle2)->hFile,
0,
fdinfo(handle1)->fdflags & FNOINHERIT ? FALSE : TRUE,
DUPLICATE_SAME_ACCESS);
if (result) {
// _pioinfo[handle2]->fd = handle2;
fdinfo(handle2)->fdflags = fdinfo(handle1)->fdflags;
switch (handle2) {
case 0:
SetStdHandle(STD_INPUT_HANDLE, fdinfo(handle2)->hFile);
break;
case 1:
SetStdHandle(STD_OUTPUT_HANDLE, fdinfo(handle2)->hFile);
break;
case 2:
SetStdHandle(STD_ERROR_HANDLE, fdinfo(handle2)->hFile);
break;
}
return handle1;
} else {
__set_errno(EMFILE); // Is this the correct error no.?
return -1;
}
}
void* malloc(size_t sizeObject);
/*
* INTERNAL
*/
BOOL __fileno_init(void)
{
STARTUPINFOA si;
int i;
init_bucket(first_bucket);
GetStartupInfoA(&si);
if (si.cbReserved2 != 0 && si.lpReserved2 != NULL)
{
char* fdflags_ptr;
HANDLE* handle_ptr;
g_fdend = *(unsigned*)si.lpReserved2;
fdflags_ptr= (char*)(si.lpReserved2 + sizeof(unsigned));
handle_ptr = (HANDLE*)(fdflags_ptr + g_fdend * sizeof(char));
g_fdend = min(g_fdend, FDINFO_ENTRIES);
for (i = 0; i < g_fdend; i++)
{
if (!fdinfo_bucket(i))
{
if (!alloc_init_bucket(i)){
/* FIXME: free other buckets? */
return FALSE;
}
}
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;
}
InitializeCriticalSection(&g_file_cs);
if (fdinfo(0)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(0)->fdflags & FOPEN)) {
fdinfo(0)->hFile = GetStdHandle(STD_INPUT_HANDLE);
if (fdinfo(0)->hFile == NULL)
fdinfo(0)->hFile = INVALID_HANDLE_VALUE;
fdinfo(0)->fdflags = FOPEN|FTEXT;
}
if (fdinfo(1)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(1)->fdflags & FOPEN)) {
fdinfo(1)->hFile = GetStdHandle(STD_OUTPUT_HANDLE);
if (fdinfo(1)->hFile == NULL)
fdinfo(1)->hFile = INVALID_HANDLE_VALUE;
fdinfo(1)->fdflags = FOPEN|FTEXT;
}
if (fdinfo(2)->hFile == INVALID_HANDLE_VALUE || !(fdinfo(2)->fdflags & FOPEN)) {
fdinfo(2)->hFile = GetStdHandle(STD_ERROR_HANDLE);
if (fdinfo(2)->hFile == NULL)
fdinfo(2)->hFile = INVALID_HANDLE_VALUE;
fdinfo(2)->fdflags = FOPEN|FTEXT;
}
for (i = 0; i < 3; i++)
{
/* FILE structs for stdin/out/err are static and never deleted */
// MSVCRT_fstreams[i] = &MSVCRT__iob[i];
}
// MSVCRT_stream_idx = 3;
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 );
}

View file

@ -1,49 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/pipe.c
* PURPOSE: Creates a pipe
* PROGRAMER: DJ Delorie
* UPDATE HISTORY:
* 28/12/98: Appropriated for Reactos
*/
#include <precomp.h>
/*
* @implemented
*/
int _pipe(int _fildes[2], unsigned int size, int mode )
{
HANDLE hReadPipe, hWritePipe;
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
TRACE("_pipe((%i,%i), %ui, %i)", _fildes[0], _fildes[1], size, mode);
if (mode & O_NOINHERIT)
sa.bInheritHandle = FALSE;
if (!CreatePipe(&hReadPipe,&hWritePipe,&sa,size)) {
_dosmaperr(GetLastError());
return( -1);
}
if ((_fildes[0] = alloc_fd(hReadPipe, split_oflags(mode))) < 0)
{
CloseHandle(hReadPipe);
CloseHandle(hWritePipe);
__set_errno(EMFILE);
return(-1);
}
if ((_fildes[1] = alloc_fd(hWritePipe, split_oflags(mode))) < 0)
{
free_fd(_fildes[0]);
CloseHandle(hReadPipe);
CloseHandle(hWritePipe);
__set_errno(EMFILE);
return(-1);
}
return(0);
}

View file

@ -1,97 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/read.c
* PURPOSE: Reads a file
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/1998: Created
* 03/05/2002: made _read() non-greedy - it now returns as soon as
* any amount of data has been read. It's the expected
* behavior for line-buffered streams (KJK::Hyperion)
*/
#include <precomp.h>
/*
* @implemented
*/
int _read(int _fd, void *_buf, unsigned int _nbyte)
{
DWORD _rbyte = 0, nbyte = _nbyte;
char *bufp = (char*)_buf;
HANDLE hfile;
int istext, error;
TRACE("_read(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
/* null read */
if(_nbyte == 0)
return 0;
hfile = (HANDLE)_get_osfhandle(_fd);
istext = __fileno_getmode(_fd) & O_TEXT;
/* read data */
if (!ReadFile(hfile, bufp, nbyte, &_rbyte, NULL))
{
/* failure */
error = GetLastError();
if (error == ERROR_BROKEN_PIPE)
{
return 0;
}
_dosmaperr(error);
return -1;
}
/* text mode */
if (_rbyte && istext)
{
int found_cr = 0;
int cr = 0;
DWORD count = _rbyte;
/* repeat for all bytes in the buffer */
for(; count; bufp++, count--)
{
#if 1
/* carriage return */
if (*bufp == '\r') {
found_cr = 1;
if (cr != 0) {
*(bufp - cr) = *bufp;
}
continue;
}
if (found_cr) {
found_cr = 0;
if (*bufp == '\n') {
cr++;
*(bufp - cr) = *bufp;
} else {
}
} else if (cr != 0) {
*(bufp - cr) = *bufp;
}
#else
/* carriage return */
if (*bufp == '\r') {
cr++;
}
/* shift characters back, to ignore carriage returns */
else if (cr != 0) {
*(bufp - cr) = *bufp;
}
#endif
}
if (found_cr) {
cr++;
}
/* ignore the carriage returns */
_rbyte -= cr;
}
TRACE("%d\n", _rbyte);
return _rbyte;
}

View file

@ -1,54 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/setmode.c
* PURPOSE: Sets the file translation mode
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <precomp.h>
__inline BOOL is_valid_fd(int fd);
/*
* @implemented
*/
int _setmode(int fd, int newmode)
{
int prevmode;
TRACE("_setmode(%d, %d)", fd, newmode);
if (!is_valid_fd(fd))
{
ERR("_setmode: inval fd (%d)\n",fd);
//errno = EBADF;
return(-1);
}
if (newmode & ~(_O_TEXT|_O_BINARY))
{
ERR("_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

@ -1,111 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
/*
* @implemented
*/
/*********************************************************************
* _sopen (MSVCRT.@)
*/
int CDECL _sopen( const char *path, int oflags, int shflags, ... )
{
va_list ap;
int pmode;
DWORD access = 0, creation = 0, attrib;
DWORD sharing;
int wxflag = 0, fd;
HANDLE hand;
SECURITY_ATTRIBUTES sa;
TRACE(":file (%s) oflags: 0x%04x shflags: 0x%04x\n",
path, oflags, shflags);
wxflag = split_oflags(oflags);
switch (oflags & (O_RDONLY | O_WRONLY | O_RDWR))
{
case O_RDONLY: access |= GENERIC_READ; break;
case O_WRONLY: access |= GENERIC_WRITE; break;
case O_RDWR: access |= GENERIC_WRITE | GENERIC_READ; break;
}
if (oflags & O_CREAT)
{
va_start(ap, shflags);
pmode = va_arg(ap, int);
va_end(ap);
if(pmode & ~(S_IREAD | S_IWRITE))
FIXME(": pmode 0x%04x ignored\n", pmode);
else
WARN(": pmode 0x%04x ignored\n", pmode);
if (oflags & O_EXCL)
creation = CREATE_NEW;
else if (oflags & O_TRUNC)
creation = CREATE_ALWAYS;
else
creation = OPEN_ALWAYS;
}
else /* no O_CREAT */
{
if (oflags & O_TRUNC)
creation = TRUNCATE_EXISTING;
else
creation = OPEN_EXISTING;
}
switch( shflags )
{
case SH_DENYRW:
sharing = 0L;
break;
case SH_DENYWR:
sharing = FILE_SHARE_READ;
break;
case SH_DENYRD:
sharing = FILE_SHARE_WRITE;
break;
case SH_DENYNO:
sharing = FILE_SHARE_READ | FILE_SHARE_WRITE;
break;
default:
ERR( "Unhandled shflags 0x%x\n", shflags );
return -1;
}
attrib = FILE_ATTRIBUTE_NORMAL;
if (oflags & O_TEMPORARY)
{
attrib |= FILE_FLAG_DELETE_ON_CLOSE;
access |= DELETE;
sharing |= FILE_SHARE_DELETE;
}
sa.nLength = sizeof( SECURITY_ATTRIBUTES );
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = (oflags & O_NOINHERIT) ? FALSE : TRUE;
hand = CreateFileA(path, access, sharing, &sa, creation, attrib, 0);
if (hand == INVALID_HANDLE_VALUE) {
WARN(":failed-last error (%d)\n",GetLastError());
_dosmaperr(GetLastError());
return -1;
}
fd = alloc_fd(hand, wxflag);
TRACE(":fd (%d) handle (%p)\n",fd, hand);
return fd;
}

View file

@ -1 +0,0 @@
void *__badioinfo;

View file

@ -1,10 +0,0 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
off_t _tell(int _file)
{
return _lseek(_file, 0, SEEK_CUR);
}

View file

@ -1,19 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
/*
* @implemented
*/
__int64 _telli64(int _file)
{
return _lseeki64(_file, 0, SEEK_CUR);
}

View file

@ -1,14 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <sys/stat.h>
unsigned _unMode_dll = 022;
/*
* @implemented
*/
unsigned _umask (unsigned unMode)
{
unsigned old_mask = _unMode_dll;
_unMode_dll = unMode;
return old_mask;
}

View file

@ -1,24 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/unlink.c
* PURPOSE: Deletes a file
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <precomp.h>
/*
* @implemented
*/
int _unlink(const char* filename)
{
TRACE("_unlink('%s')\n", filename);
if (!DeleteFileA(filename)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}

View file

@ -1,31 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
#include <sys/utime.h>
/*
* @implemented
*/
int _utime(const char* filename, struct _utimbuf* buf)
{
int fn;
int ret;
fn = _open(filename, _O_RDWR);
if (fn == -1) {
__set_errno(EBADF);
return -1;
}
ret = _futime(fn, buf);
if (_close(fn) < 0)
return -1;
return ret;
}

View file

@ -1,22 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
/*
* @implemented
*/
int _wcreat(const wchar_t* filename, int mode)
{
TRACE("_wcreat('%S', mode %x)\n", filename, mode);
return _wopen(filename,_O_CREAT|_O_TRUNC,mode);
}

View file

@ -1,73 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/mktemp.c
* PURPOSE: Makes a temp file based on a template
* PROGRAMER: DJ Delorie
Ariadne
* UPDATE HISTORY:
* 28/12/98: Appropriated for the Reactos Kernel
*/
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
wchar_t* _wmktemp (wchar_t *_template)
{
static int count = 0;
wchar_t *cp, *dp;
int i, len, xcount, loopcnt;
TRACE("_wmktemp('%S')\n", _template);
len = wcslen (_template);
cp = _template + len;
xcount = 0;
while (xcount < 6 && cp > _template && cp[-1] == L'X')
xcount++, cp--;
if (xcount) {
dp = cp;
while (dp > _template && dp[-1] != L'/' && dp[-1] != L'\\' && dp[-1] != L':')
dp--;
/* Keep the first characters of the template, but turn the rest into
Xs. */
while (cp > dp + 8 - xcount) {
*--cp = L'X';
xcount = (xcount >= 6) ? 6 : 1 + xcount;
}
/* If dots occur too early -- squash them. */
while (dp < cp) {
if (*dp == L'.') *dp = L'a';
dp++;
}
/* Try to add ".tmp" to the filename. Truncate unused Xs. */
if (cp + xcount + 3 < _template + len)
wcscpy (cp + xcount, L".tmp");
else
cp[xcount] = 0;
/* This loop can run up to 2<<(5*6) times, or about 10^9 times. */
for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) {
int c = count++;
for (i = 0; i < xcount; i++, c >>= 5)
cp[i] = L"abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f];
if (_waccess(_template,0) == -1)
return _template;
}
}
/* Failure: truncate the template and return NULL. */
*_template = 0;
return 0;
}

View file

@ -1,71 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/open.c
* PURPOSE: Opens a file and translates handles to fileno
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
// rember to interlock the allocation of fileno when making this thread safe
// possibly store extra information at the handle
#include <precomp.h>
#if !defined(NDEBUG) && defined(DBG)
#include <stdarg.h>
#endif
#include <sys/stat.h>
#include <share.h>
/*********************************************************************
* _wopen (MSVCRT.@)
*/
int CDECL _wopen(const wchar_t *path,int flags,...)
{
const unsigned int len = strlenW(path);
char *patha = calloc(len + 1,1);
va_list ap;
int pmode;
va_start(ap, flags);
pmode = va_arg(ap, int);
va_end(ap);
if (patha && WideCharToMultiByte(CP_ACP,0,path,len,patha,len,NULL,NULL))
{
int retval = _open(patha,flags,pmode);
free(patha);
return retval;
}
_dosmaperr(GetLastError());
return -1;
}
/*********************************************************************
* _wsopen (MSVCRT.@)
*/
int CDECL _wsopen( const wchar_t* path, int oflags, int shflags, ... )
{
const unsigned int len = strlenW(path);
char *patha = calloc(len + 1,1);
va_list ap;
int pmode;
va_start(ap, shflags);
pmode = va_arg(ap, int);
va_end(ap);
if (patha && WideCharToMultiByte(CP_ACP,0,path,len,patha,len,NULL,NULL))
{
int retval = sopen(patha,oflags,shflags,pmode);
free(patha);
return retval;
}
_dosmaperr(GetLastError());
return -1;
}

View file

@ -1,96 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/write.c
* PURPOSE: Writes to a file
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <precomp.h>
#define BUFSIZE 4096
/*
void ReportLastError(void)
{
DWORD error = GetLastError();
if (error != ERROR_SUCCESS) {
PTSTR msg;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL)) {
printf("ReportLastError() %d - %s\n", error, msg);
} else {
printf("ReportLastError() %d - unknown error\n", error);
}
LocalFree(msg);
}
}
*/
/*
* @implemented
*/
int _write(int _fd, const void* _buf, unsigned int _nbyte)
{
char *tmp, *in, *out;
int result;
unsigned int count;
DWORD wbyte;
TRACE("_write(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
if (__fileno_getmode(_fd) & O_TEXT) {
result = _nbyte;
tmp = (char*) malloc(BUFSIZE);
if (tmp == NULL) {
__set_errno(ENOMEM);
return -1;
}
count = BUFSIZE;
out = tmp;
in = (char*) _buf;
while (_nbyte--) {
if (*in == 0x0a) {
*out++ = 0x0d;
count--;
if (count == 0) {
if (!WriteFile((HANDLE)_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) {
//ReportLastError();
_dosmaperr(GetLastError());
result = -1;
break;
}
if (wbyte < BUFSIZE) {
result = in - (char*)_buf;
break;
}
count = BUFSIZE;
out = tmp;
}
}
*out++ = *in++;
count--;
if (count == 0 || _nbyte == 0) {
if (!WriteFile((HANDLE)_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) {
_dosmaperr(GetLastError());
result = -1;
break;
}
if (wbyte < (BUFSIZE - count)) {
result = in - (char*)_buf;
break;
}
count = BUFSIZE;
out = tmp;
}
}
free(tmp);
return result;
} else {
if(!WriteFile((HANDLE)_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) {
_dosmaperr(GetLastError());
return -1;
}
return wbyte;
}
}

View file

@ -1,24 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/io/unlink.c
* PURPOSE: Deletes a file
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <precomp.h>
/*
* @implemented
*/
int _wunlink(const wchar_t* filename)
{
TRACE("_wunlink('%S')\n", filename);
if (!DeleteFileW(filename)) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}

View file

@ -1,32 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
#include <sys/utime.h>
/*
* @implemented
*/
int _wutime(const wchar_t* filename, struct _utimbuf* buf)
{
int fn;
int ret;
fn = _wopen(filename, _O_RDWR);
if (fn == -1) {
__set_errno(EBADF);
return -1;
}
ret = _futime(fn, buf);
if (_close(fn) < 0)
return -1;
return ret;
}

View file

@ -152,6 +152,7 @@
<file>strtol.c</file>
<file>strtoul.c</file>
<file>strtoull.c</file>
<file>wcs.c</file>
<file>wcstol.c</file>
<file>wcstombs_nt.c</file>
<file>wcstoul.c</file>
@ -166,10 +167,7 @@
<file>wcsnicmp.c</file>
<file>wcsupr.c</file>
<file>wcscspn.c</file>
<file>wcspbrk.c</file>
<file>wcsset.c</file>
<file>wcsspn.c</file>
<file>wcsstr.c</file>
<file>wcsrev.c</file>
</directory>
</module>

View file

@ -30,25 +30,3 @@ void stub(void)
FIXME("stub\n");
}
/*********************************************************************
* _getmaxstdio (MSVCRT.@)
*/
int CDECL _getmaxstdio(void)
{
FIXME("stub, always returns 512\n");
return 512;
}
/*********************************************************************
* _setmaxstdio_ (MSVCRT.@)
*/
int CDECL _setmaxstdio(int newmax)
{
int res;
if( newmax > 2048)
res = -1;
else
res = newmax;
FIXME("stub: setting new maximum for number of simultaneously open files not implemented,returning %d\n",res);
return res;
}

View file

@ -20,6 +20,7 @@
#include <limits.h>
#include <sys/stat.h>
#include <sys/locking.h>
#include <share.h>
/* PSDK/NDK Headers */
@ -54,5 +55,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
#include <internal/mtdll.h>
#include <internal/rterror.h>
#include <internal/tls.h>
#include <internal/printf.h>
#endif /* _CRT_PRECOMP_H */

View file

@ -1,6 +1,15 @@
/*
* PROJECT: ReactOS CRT library
* LICENSE: GPL (?) - See COPYING in the top level directory
* FILE: lib/sdk/crt/process/process.c
* PURPOSE: Process management functions
* PROGRAMMERS: ???
*/
#include <precomp.h>
#include <process.h>
#include <tchar.h>
#include <internal/wine/msvcrt.h>
#ifdef _UNICODE
#define sT "S"
@ -205,7 +214,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
return(-1);
}
//memset (&StartupInfo, 0, sizeof(StartupInfo));
memset (&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
#if 0
@ -265,7 +274,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
}
#endif
create_io_inherit_block((STARTUPINFOA*) &StartupInfo);
create_io_inherit_block(&StartupInfo.cbReserved2, &StartupInfo.lpReserved2);
bResult = CreateProcess((_TCHAR *)cmdname,
(_TCHAR *)args,

View file

@ -11,28 +11,6 @@
#define MK_STR(s) #s
/*
* @implemented
*/
int _taccess( const _TCHAR *_path, int _amode )
{
DWORD Attributes = GetFileAttributes(_path);
TRACE(MK_STR(_taccess)"('%"sT"', %x)\n", _path, _amode);
if (!_path || Attributes == INVALID_FILE_ATTRIBUTES) {
_dosmaperr(GetLastError());
return -1;
}
if ((_amode & W_OK) == W_OK) {
if ((Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) {
__set_errno(EACCES);
return -1;
}
}
return 0;
}
/*
* INTERNAL
*/

View file

@ -1,95 +0,0 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
char __validfp (FILE *f)
{
if ( (unsigned int)f < 256)
return FALSE;
if( f == NULL || (int)f== -1 )
return FALSE;
return TRUE;
}
/* A FILE* is considered "free" if its flag is zero. */
FILE *__alloc_file(void)
{
__file_rec *fr = __file_rec_list;
__file_rec **last_fr = &__file_rec_list;
FILE *rv=0;
int i;
/* Try to find an empty slot */
while (fr)
{
last_fr = &(fr->next);
/* If one of the existing slots is available, return it */
for (i=0; i<fr->count; i++)
{
if (fr->files[i]->_flag == 0)
{
return fr->files[i];
}
}
/* If this one is full, go to the next */
if (fr->count == __FILE_REC_MAX)
fr = fr->next;
else
/* it isn't full, we can add to it */
break;
}
if (!fr)
{
/* add another one to the end, make it empty */
fr = *last_fr = (__file_rec *)malloc(sizeof(__file_rec));
if (fr == 0)
return 0;
fr->next = 0;
fr->count = 0;
}
/* fr is a pointer to a rec with empty slots in it */
rv = fr->files[fr->count] = (FILE *)malloc(sizeof(FILE));
if (rv == 0)
return 0;
memset(rv, 0, sizeof(FILE));
fr->count ++;
return rv;
}
/*
* @implemented
*/
int _fcloseall( void )
{
__file_rec *fr = __file_rec_list;
__file_rec **last_fr = &__file_rec_list;
int total_closed = 0;
int i = 0;
/* Try to find an empty slot */
while (fr)
{
last_fr = &(fr->next);
/* If one of the existing slots is available, return it */
for (i=0; i<fr->count; i++)
if (fr->files[i]->_flag != 0) {
fclose(fr->files[i]);
total_closed++;
}
/* If this one is full, go to the next */
if (fr->count == __FILE_REC_MAX)
fr = fr->next;
else
/* it isn't full, we can add to it */
break;
}
return total_closed;
}

View file

@ -1,20 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#ifdef clearerr
#undef clearerr
void clearerr(FILE *stream);
#endif
/*
* @implemented
*/
void
clearerr(FILE *f)
{
if (!__validfp (f)) {
__set_errno (EINVAL);
return;
}
f->_flag &= ~(_IOERR|_IOEOF);
}

View file

@ -1,49 +0,0 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <sys/stat.h>
// changed check for writable stream
/*
* @implemented
*/
int
fclose(FILE *f)
{
int r = 0;
if (f == NULL) {
__set_errno (EINVAL);
return EOF;
}
// flush only if stream was opened for writing
if ( !(f->_flag&_IOSTRG) ) {
if ( OPEN4WRITING(f) )
r = fflush(f);
if (_close(_fileno(f)) < 0)
r = EOF;
if (f->_flag&_IOMYBUF)
free(f->_base);
// Kernel might do this later
if (f->_flag & _IORMONCL && f->_tmpfname)
{
remove(f->_tmpfname);
free(f->_tmpfname);
f->_tmpfname = 0;
}
}
f->_cnt = 0;
f->_base = 0;
f->_ptr = 0;
f->_bufsiz = 0;
f->_flag = 0;
f->_file = -1;
return r;
}

View file

@ -1,55 +0,0 @@
#include <precomp.h>
#include <tchar.h>
/*
* @implemented
*/
FILE* _tfdopen(int handle,
#ifndef _UNICODE
const
#endif
_TCHAR* mode)
{
FILE* file;
int rw;
if (handle == 0)
return stdin;
if (handle == 1)
return stdout;
if (handle == 2)
return stderr;
file = __alloc_file();
if (file == NULL)
return NULL;
file->_file = handle;
rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
if (*mode == 'a')
_lseek(handle, 0, SEEK_END);
file->_cnt = 0;
file->_file = handle;
file->_bufsiz = 0;
// The mode of the stream must be compatible with the mode of the file descriptor.
// this should be checked.
if (rw)
file->_flag = _IOREAD | _IOWRT;
else if (*mode == 'r')
file->_flag = _IOREAD;
else
file->_flag = _IOWRT;
file->_base = file->_ptr = NULL;
return file;
}

View file

@ -1,20 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#ifdef feof
#undef feof
int feof(FILE *stream);
#endif
/*
* @implemented
*/
int feof(FILE *stream)
{
if (stream == NULL) {
__set_errno (EINVAL);
return EOF;
}
return stream->_flag & _IOEOF;
}

View file

@ -1,17 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#ifdef ferror
#undef ferror
int ferror(FILE *stream);
#endif
int *_errno(void);
/*
* @implemented
*/
int ferror(FILE *stream)
{
return stream->_flag & _IOERR;
}

View file

@ -1,112 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/stdio/fflush.c
* PURPOSE: Checks for keyboard hits
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
/* Copyright (C) 1998 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 */
#include <precomp.h>
#include <sys/stat.h>
/*
* @implemented
*/
int fflush(FILE *f)
{
char *base;
int n, rn;
if (f == NULL)
{
int e = *_errno();
__set_errno(0);
_fwalk((void (*)(FILE *))fflush);
if (*_errno())
return EOF;
__set_errno(e);
return 0;
}
// nothing to do if stream can not be written to
if ( !OPEN4WRITING(f) ) {
__set_errno (EINVAL);
return 0;
}
// discard any unget characters
f->_flag &= ~_IOUNGETC;
// check for buffered dirty block
if ( (f->_flag&(_IODIRTY|_IONBF)) ==_IODIRTY && f->_base != NULL)
{
base = f->_base;
// if the buffer is read ahead and dirty we will flush it entirely
// else the buffer is appended to the file to the extend it has valid bytes
if ( (f->_flag & _IOAHEAD) == _IOAHEAD )
rn = n = f->_ptr - base + f->_cnt;
else
rn = n = f->_ptr - base;
f->_ptr = base;
if ((f->_flag & _IOFBF) == _IOFBF) {
if ( (f->_flag & _IOAHEAD) == _IOAHEAD )
_lseek(_fileno(f),-rn, SEEK_CUR);
}
f->_flag &= ~_IOAHEAD;
f->_cnt = (f->_flag&(_IO_LBF|_IONBF)) ? 0 : f->_bufsiz;
// how can write return less than rn without being on error ???
// possibly commit the flushed data
// better open the file in write through mode
while (rn > 0) {
n = _write(_fileno(f), base, rn);
if (n <= 0) {
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
};
f->_flag &= ~_IODIRTY;
// commit flushed data
// _commit(_fileno(f));
}
if (OPEN4READING(f) && OPEN4WRITING(f) )
{
f->_cnt = 0;
f->_ptr = f->_base;
}
return 0;
}
/*
* @implemented
*/
int _flushall( void )
{
return fflush(NULL);
}

View file

@ -1,28 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/stdio/fgetc.c
* PURPOSE: Get a character string from stdin
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Appropriated for Reactos
25/02/99: Added fgetwc
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
int fgetc(FILE *f)
{
return getc(f);
}
/*
* @implemented
*/
wint_t fgetwc(FILE *f)
{
return getwc(f);
}

View file

@ -1,37 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* fgetchar.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <precomp.h>
int _fgetchar(void)
{
return getc(stdin);
}
/*
* @implemented
*/
wint_t _fgetwchar(void)
{
return getwc(stdin);
}

View file

@ -1,16 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
int fgetpos(FILE *stream, fpos_t *pos)
{
if (stream && pos)
{
*pos = (fpos_t)ftell(stream);
return 0;
}
//__set_errno ( EFAULT );
return 1;
}

View file

@ -1,44 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* fgets.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* 28/12/1998: Appropriated for Reactos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
char* fgets(char* s, int n, FILE* f)
{
int c = 0;
char* cs;
cs = s;
while (--n>0 && (c = getc(f)) != EOF) {
*cs++ = c;
if (c == '\n')
break;
}
if (c == EOF && cs == s)
return NULL;
*cs++ = '\0';
return s;
}

View file

@ -1,50 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* fgets.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* 28/12/1998: Appropriated for Reactos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#ifndef WEOF
#define WEOF (wchar_t)(0xFFFF)
#endif
wchar_t* fgetws(wchar_t* s, int n, FILE* f)
{
int c=0;
wchar_t *cs;
cs = s;
while (--n>0 && (c = getwc(f)) != WEOF)
{
*cs++ = c;
if (c == L'\n')
break;
}
if (c == WEOF && cs == s)
return NULL;
*cs++ = L'\0';
return s;
}

View file

@ -1,117 +0,0 @@
/* Copyright (C) 1997 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 */
#include <precomp.h>
int _readcnv(int fn, void* buf, size_t siz);
/*
* @implemented
*/
int _filbuf(FILE* f)
{
int size;
char c;
if ( !OPEN4READING(f)) {
__set_errno (EINVAL);
return EOF;
}
if (f->_flag&(_IOSTRG|_IOEOF))
return EOF;
f->_flag &= ~_IOUNGETC;
if (f->_base == NULL && (f->_flag & _IONBF) == 0) {
size = 4096;
if ((f->_base = malloc(size+1)) == NULL) {
// error ENOMEM
f->_flag |= _IONBF;
f->_flag &= ~(_IOFBF|_IO_LBF);
} else {
f->_flag |= _IOMYBUF;
f->_bufsiz = size;
}
}
if (f->_flag&_IONBF)
f->_base = &c;
// flush stdout before reading from stdin
if (f == stdin) {
if (stdout->_flag&_IO_LBF)
fflush(stdout);
if (stderr->_flag&_IO_LBF)
fflush(stderr);
}
// if we have a dirty stream we flush it
if ((f->_flag &_IODIRTY) == _IODIRTY)
fflush(f);
f->_cnt = _read(_fileno(f), f->_base, f->_flag & _IONBF ? 1 : f->_bufsiz );
f->_flag |= _IOAHEAD;
if(__is_text_file(f) && f->_cnt>0)
{
/* truncate text file at Ctrl-Z */
char *cz=memchr(f->_base, 0x1A, f->_cnt);
if(cz)
{
int newcnt = cz - f->_base;
_lseek(_fileno(f), -(f->_cnt - newcnt), SEEK_CUR);
f->_cnt = newcnt;
}
}
f->_ptr = f->_base;
if (f->_flag & _IONBF)
f->_base = NULL; // statically allocated buffer for sprintf
//check for error
if (f->_cnt <= 0) {
if (f->_cnt == 0) {
f->_flag |= _IOEOF;
} else
f->_flag |= _IOERR;
f->_cnt = 0;
// FIXME should set errno
return EOF;
}
f->_cnt--;
return *f->_ptr++ & 0377;
}
wint_t _filwbuf(FILE *fp)
{
return (wint_t )_filbuf(fp);
}
// convert the carriage return line feed pairs
/*
int _readcnv(int fn, void *buf, size_t siz )
{
char *bufp = (char *)buf;
int _bufsiz = siz;
int cr = 0;
int n;
n = _read(fn, buf, siz );
while (_bufsiz > 0) {
if (*bufp == '\r')
cr++;
else if ( cr != 0 )
*bufp = *(bufp + cr);
bufp++;
_bufsiz--;
}
return n + cr;
}
*/

File diff suppressed because it is too large Load diff

View file

@ -1,21 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
#undef _fileno
/*
* @implemented
*/
int _fileno(FILE *f)
{
return f->_file;
}

View file

@ -1,153 +0,0 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <wchar.h>
int cntcr(char* bufp, int bufsiz);
int convert(char* endp, int bufsiz, int n);
int _writecnv(int fn, void* buf, size_t bufsiz);
/*
* @implemented
*/
int _flsbuf(int c, FILE* f)
{
char* base;
int n, rn;
char c1;
int size;
if (!OPEN4WRITING(f)) {
__set_errno(EINVAL);
return EOF;
}
// no file associated with buffer, this is a memory stream
if (_fileno(f) == -1) {
return c;
}
/* if the buffer is not yet allocated, allocate it */
if ((base = f->_base) == NULL && (f->_flag & _IONBF) == 0) {
size = 4096;
if ((f->_base = base = malloc(size)) == NULL) {
f->_flag |= _IONBF;
f->_flag &= ~(_IOFBF|_IO_LBF);
} else {
f->_flag |= _IOMYBUF;
f->_cnt = f->_bufsiz = size;
f->_ptr = base;
rn = 0;
if (f == stdout && _isatty(_fileno(stdout))) {
f->_flag |= _IO_LBF;
}
}
}
if (f->_flag & _IO_LBF) {
/* in line-buffering mode we get here on each character */
*f->_ptr++ = c;
rn = f->_ptr - base;
if (c == '\n' || rn >= f->_bufsiz) {
/* time for real flush */
f->_ptr = base;
f->_cnt = 0;
} else {
/* we got here because _cnt is wrong, so fix it */
/* Negative _cnt causes all output functions to call */
/* _flsbuf for each character, thus realizing line-buffering */
f->_cnt = -rn;
return c;
}
} else if (f->_flag & _IONBF) {
c1 = c;
rn = 1;
base = &c1;
f->_cnt = 0;
} else { /* _IOFBF */
rn = f->_ptr - base;
f->_ptr = base;
if ((f->_flag & _IOAHEAD) == _IOAHEAD)
_lseek(_fileno(f), -(rn+f->_cnt), SEEK_CUR);
f->_cnt = f->_bufsiz;
f->_flag &= ~_IOAHEAD;
}
f->_flag &= ~_IODIRTY;
while (rn > 0) {
n = _write(_fileno(f), base, rn);
if (n <= 0) {
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
}
if ((f->_flag & (_IO_LBF|_IONBF)) == 0) {
f->_cnt--;
*f->_ptr++ = c;
f->_flag |= _IODIRTY;
}
return c;
}
wint_t _flswbuf(wchar_t c, FILE* fp)
{
int result;
result = _flsbuf((int)c, fp);
if (result == EOF)
return WEOF;
return (wint_t)result;
}
int _writecnv(int fn, void* buf, size_t siz)
{
char* bufp = (char*)buf;
int bufsiz = siz;
char* tmp;
int cr1 = 0;
int cr2 = 0;
int n;
cr1 = cntcr(bufp, bufsiz);
tmp = malloc(cr1);
memcpy(tmp, bufp + bufsiz - cr1, cr1);
cr2 = cntcr(tmp, cr1);
convert(bufp, bufsiz - cr2, cr1 - cr2);
n = _write(fn, bufp, bufsiz + cr1);
convert(tmp, cr1, cr2);
n += _write(fn, tmp, cr1 + cr2);
free(tmp);
return n;
}
int convert(char* endp, int bufsiz, int n)
{
endp = endp + bufsiz + n;
while (bufsiz > 0) {
*endp = *(endp - n);
if (*endp == '\n') {
endp--;
n--;
*endp = '\r';
}
endp--;
bufsiz--;
}
return n;
}
int cntcr(char* bufp, int bufsiz)
{
int cr = 0;
while (bufsiz > 0) {
if (*bufp == '\n') {
cr++;
}
bufp++;
bufsiz--;
}
return cr;
}

View file

@ -1,91 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* fopen.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* 28/12/1998: Appropriated for Reactos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <tchar.h>
//might change fopen(file,mode) -> fsopen(file,mode,_SH_DENYNO);
FILE* _tfopen(const _TCHAR *file, const _TCHAR *mode)
{
FILE *f;
int fd, rw, oflags = 0;
if (file == 0)
return 0;
if (mode == 0)
return 0;
f = __alloc_file();
if (f == NULL)
return NULL;
rw = (_tcschr(mode, '+') == NULL) ? 0 : 1;
if (_tcschr(mode, 'a'))
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
if (_tcschr(mode, 'r'))
oflags = rw ? O_RDWR : O_RDONLY;
if (_tcschr(mode, 'w'))
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
if (_tcschr(mode, 't'))
oflags |= O_TEXT;
else if (_tcschr(mode, 'b'))
oflags |= O_BINARY;
else
oflags |= (_fmode& (O_TEXT|O_BINARY));
fd = _topen(file, oflags, 0);
if (fd < 0)
return NULL;
// msvcrt ensures that writes will end up at the end of file in append mode
// we just move the file pointer to the end of file initially
if (_tcschr(mode, 'a'))
_lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (_tcschr(mode, 'r'))
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
if (_tcschr(mode, 't'))
f->_flag |= _IOTEXT;
else if (_tcschr(mode, 'b'))
f->_flag |= _IOBINARY;
else if (_fmode& O_BINARY)
f->_flag |= _IOBINARY;
f->_base = f->_ptr = NULL;
return f;
}

View file

@ -1,34 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <wchar.h>
#include <tchar.h>
/*
* @implemented
*/
int
_ftprintf(register FILE *iop, const _TCHAR *fmt, ...)
{
int len;
_TCHAR localbuf[BUFSIZ];
va_list a=0;
va_start( a, fmt );
if (iop->_flag & _IONBF)
{
iop->_flag &= ~_IONBF;
iop->_ptr = iop->_base = (char *)localbuf;
iop->_bufsiz = BUFSIZ;
len = _vftprintf(iop,fmt,a);
fflush(iop);
iop->_flag |= _IONBF;
iop->_base = NULL;
iop->_bufsiz = 0;
iop->_cnt = 0;
}
else
len = _vftprintf(iop, fmt, a);
return ferror(iop) ? -1 : len;
}

View file

@ -1,24 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <wchar.h>
/*
* @implemented
*/
int
fputc(int c, FILE *fp)
{
return putc(c, fp);
}
/*
* @implemented
*/
wint_t
fputwc(wchar_t c, FILE *fp)
{
return putwc(c,fp);
}

View file

@ -1,38 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* fputchar.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <precomp.h>
int _fputchar(int c)
{
return putc(c, stdout);
}
/*
* @implemented
*/
wint_t _fputwchar(wint_t c)
{
return putwc(c, stdout);
}

View file

@ -1,61 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* fputs.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* 28/12/1998: Appropriated for Reactos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <tchar.h>
int
_fputts(const _TCHAR *s, FILE *f)
{
int r = 0;
int c;
int unbuffered;
_TCHAR localbuf[BUFSIZ];
unbuffered = f->_flag & _IONBF;
if (unbuffered)
{
f->_flag &= ~_IONBF;
f->_ptr = f->_base = (char*)localbuf;
f->_bufsiz = BUFSIZ;
}
while ((c = *s++))
r = _puttc(c, f);
if (unbuffered)
{
fflush(f);
f->_flag |= _IONBF;
f->_base = NULL;
f->_bufsiz = 0;
f->_cnt = 0;
}
return(r);
}

View file

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

View file

@ -1,88 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
{
unsigned char *ptr = (unsigned char *)vptr;
size_t to_read ,n_read;
int c, copy;
to_read = size * count;
if (!OPEN4READING(iop))
{
__set_errno (EINVAL);
return 0;
}
if (!__validfp (iop) )
{
__set_errno (EINVAL);
return 0;
}
if (feof (iop) || ferror (iop))
return 0;
if (vptr == NULL || to_read == 0)
return 0;
if (iop->_base == NULL)
{
int c = _filbuf(iop);
if (c == EOF)
return 0;
*ptr++ = c;
if (--to_read == 0)
return 1;
}
if (iop->_cnt > 0 && to_read > 0)
{
copy = min((size_t)iop->_cnt, to_read);
memcpy(ptr, iop->_ptr, copy);
ptr += copy;
iop->_ptr += copy;
iop->_cnt -= copy;
to_read -= copy;
if (to_read == 0)
return count;
}
if (to_read > 0)
{
if (to_read >= (size_t)iop->_bufsiz)
{
n_read = _read(_fileno(iop), ptr, to_read);
if (n_read < 0)
iop->_flag |= _IOERR;
else if (n_read == 0)
iop->_flag |= _IOEOF;
else
to_read -= n_read;
// the file buffer is empty and there is no read ahead information anymore.
iop->_flag &= ~_IOAHEAD;
}
else
{
c = _filbuf(iop);
if (c != EOF)
{
*ptr++ = c;
to_read--;
copy = min((size_t)iop->_cnt, to_read);
memcpy(ptr, iop->_ptr, copy);
iop->_ptr += copy;
iop->_cnt -= copy;
to_read -= copy;
}
}
}
// return count - (to_read/size)
/* FIXME is this formual right ?, I copy the formula from djgpp
in our to_read or copy ? */
return size != 0 ? count - ((to_read + size - 1) / size) : 0;
}

View file

@ -1,66 +0,0 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <tchar.h>
/*
* @implemented
*/
FILE *_tfreopen(const _TCHAR *file, const _TCHAR *mode, FILE *f)
{
int fd, rw, oflags=0;
_TCHAR tbchar;
if (file == 0 || mode == 0 || f == 0)
return 0;
rw = (mode[1] == '+');
fclose(f);
switch (*mode) {
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return NULL;
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode& (O_TEXT|O_BINARY));
fd = _topen(file, oflags, 0666);
if (fd < 0)
return NULL;
if (*mode == 'a')
_lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
f->_base = f->_ptr = NULL;
return f;
}

View file

@ -1,52 +0,0 @@
/* Copyright (C) 1997 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 */
#include <precomp.h>
/*
* @implemented
*/
int fseek(FILE *f, long offset, int ptrname)
{
long p = -1; /* can't happen? */
if ( f == NULL ) {
__set_errno (EINVAL);
return -1;
}
f->_flag &= ~_IOEOF;
if (!OPEN4WRITING(f))
{
if (f->_base && !(f->_flag & _IONBF))
{
p = ftell(f);
if (ptrname == SEEK_CUR)
{
offset += p;
ptrname = SEEK_SET;
}
/* check if the target position is in the buffer and
optimize seek by moving inside the buffer */
if (ptrname == SEEK_SET && (f->_flag & (_IOUNGETC|_IOREAD|_IOWRT )) == 0
&& p-offset <= f->_ptr-f->_base && offset-p <= f->_cnt)
{
f->_ptr+=offset-p;
f->_cnt+=p-offset;
return 0;
}
}
p = _lseek(_fileno(f), offset, ptrname);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~_IOUNGETC;
}
else
{
p = fflush(f);
return _lseek(_fileno(f), offset, ptrname) == -1 || p == EOF ?
-1 : 0;
}
return p==-1 ? -1 : 0;
}

View file

@ -1,16 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
int fsetpos(FILE *stream,const fpos_t *pos)
{
if (stream && pos)
{
fseek(stream, (long)(*pos), SEEK_SET);
return 0;
}
__set_errno(EFAULT);
return -1;
}

View file

@ -1,99 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/stdio/fsopen.c
* PURPOSE: Checks for keyboard hits
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <sys/stat.h>
#include <share.h>
#include <tchar.h>
/*
* @implemented
*/
FILE* _tfsopen(const _TCHAR *file, const _TCHAR *mode, int shflag)
{
FILE *f;
int fd, rw, oflags = 0;
_TCHAR tbchar;
int shf;
if (file == 0)
return 0;
if (mode == 0)
return 0;
f = __alloc_file();
if (f == NULL)
return NULL;
rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
switch (*mode)
{
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return (NULL);
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode& (O_TEXT|O_BINARY));
if ( shflag == _SH_DENYNO )
shf = _S_IREAD | _S_IWRITE;
else if( shflag == _SH_DENYRD )
shf = _S_IWRITE;
else if( shflag == _SH_DENYRW )
shf = 0;
else if( shflag == _SH_DENYWR )
shf = _S_IREAD;
else
shf = _S_IREAD | _S_IWRITE;
fd = _topen(file, oflags, shf);
if (fd < 0)
return NULL;
// msvcrt ensures that writes will end up at the end of file in append mode
// we just move the file pointer to the end of file initially
if (*mode == 'a')
_lseek(fd, 0, SEEK_END);
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IOREAD | _IOWRT;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
f->_base = f->_ptr = NULL;
return f;
}

View file

@ -1,43 +0,0 @@
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
long ftell(FILE *f)
{
long tres;
int adjust=0;
if (!f)
{
__set_errno(EBADF);
return -1;
}
if (f->_cnt < 0)
f->_cnt = 0;
else if (f->_flag&(_IOWRT))
{
if (f->_base && (f->_flag&_IONBF)==0)
adjust = f->_ptr - f->_base;
}
else if (f->_flag&_IOREAD)
{
adjust = - f->_cnt;
}
else
return -1;
tres = _lseek(_fileno(f), 0L, SEEK_CUR);
if (tres<0)
return tres;
tres += adjust;
//f->_cnt = f->_bufsiz - tres;
//f->_ptr = f->_base + tres;
return tres;
}

View file

@ -1,16 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
// not exported by msvcrt or crtdll
__file_rec *__file_rec_list;
void _fwalk(void (*func)(FILE *))
{
__file_rec *fr;
int i;
for (fr=__file_rec_list; fr; fr=fr->next)
for (i=0; i<fr->count; i++)
if (fr->files[i]->_flag)
func(fr->files[i]);
}

View file

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

View file

@ -1,107 +0,0 @@
#include <precomp.h>
/*
* @implemented
*/
size_t fwrite(const void *vptr, size_t size, size_t count, FILE *iop)
{
size_t to_write, n_written;
unsigned char *ptr = (unsigned char *)vptr;
int copy;
TRACE("fwrite(%x, %d, %d, %x)", vptr, size, count, iop);
to_write = size*count;
if (!OPEN4WRITING(iop))
{
__set_errno (EINVAL);
return(0);
}
if (iop == NULL)
{
__set_errno (EINVAL);
return(0);
}
if (ferror (iop))
return(0);
if (vptr == NULL || to_write == 0)
return(0);
if (iop->_base == NULL && !(iop->_flag&_IONBF))
{
if (EOF == _flsbuf(*ptr++, iop))
return(0);
if (--to_write == 0)
return(1);
}
if (iop->_flag & _IO_LBF)
{
while (to_write > 0)
{
if (EOF == putc(*ptr++, iop))
{
iop->_flag |= _IOERR;
break;
}
to_write--;
}
}
else
{
if (iop->_cnt > 0 && to_write > 0)
{
copy = min((size_t)iop->_cnt, to_write);
memcpy(iop->_ptr, ptr, copy);
ptr += copy;
iop->_ptr += copy;
iop->_cnt -= copy;
to_write -= copy;
iop->_flag |= _IODIRTY;
}
if (to_write > 0)
{
// if the buffer is dirty it will have to be written now
// otherwise the file pointer won't match anymore.
fflush(iop);
if (to_write >= (size_t)iop->_bufsiz)
{
while (to_write > 0)
{
n_written = _write(_fileno(iop), ptr, to_write);
if (n_written <= 0)
{
iop->_flag |= _IOERR;
break;
}
to_write -= n_written;
ptr += n_written;
}
// check to see if this will work with in combination with ungetc
// the file buffer is empty and there is no read ahead information anymore.
iop->_flag &= ~_IOAHEAD;
}
else
{
if (EOF != _flsbuf(*ptr++, iop))
{
if (--to_write > 0)
{
memcpy(iop->_ptr, ptr, to_write);
iop->_ptr += to_write;
iop->_cnt -= to_write;
iop->_flag |= _IODIRTY;
return(count);
}
}
}
}
}
return(count - (to_write/size));
}

View file

@ -1,130 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* getc.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <precomp.h>
//getc can be a macro
#undef getc
#undef getwc
#ifndef MB_CUR_MAX
#define MB_CUR_MAX 10
#endif
int getc(FILE *fp)
{
int c = -1;
// check for invalid stream
if ( !__validfp (fp) ) {
__set_errno(EINVAL);
return EOF;
}
// check for read access on stream
if ( !OPEN4READING(fp) ) {
__set_errno(EINVAL);
return EOF;
}
if(fp->_cnt > 0) {
fp->_cnt--;
c = (int)(*fp->_ptr++ & 0377);
} else {
c = _filbuf(fp);
}
return c;
}
/*
* @implemented
*/
wint_t getwc(FILE *fp)
{
wint_t c = -1;
// check for invalid stream
if (!__validfp(fp)) {
__set_errno(EINVAL);
return WEOF;
}
// check for read access on stream
//#define OPEN4READING(f) ((((f)->_flag & _IOREAD) == _IOREAD ) )
if (!OPEN4READING(fp)) {
__set_errno(EINVAL);
return WEOF;
}
// might check on multi bytes if text mode
if (fp->_flag & _IOBINARY) {
if (fp->_cnt > 1) {
fp->_cnt -= sizeof(wchar_t);
c = *((wchar_t*)fp->_ptr);
fp->_ptr += sizeof(wchar_t);
} else {
c = _filwbuf(fp);
// need to fix by one values of fp->_ptr and fp->_cnt
fp->_ptr++;
fp->_cnt--;
}
} else {
#if 0
BOOL get_bytes = 0;
int mb_cnt = 0;
int found_cr = 0;
//int count;
char mbchar[MB_CUR_MAX];
do {
if (fp->_cnt > 0) {
fp->_cnt--;
mbchar[mb_cnt] = *fp->_ptr++ & 0377;
} else {
mbchar[mb_cnt] = _filbuf(fp);
}
if (isleadbyte(mbchar[mb_cnt])) {
get_bytes = 1;
} else {
get_bytes = 0;
}
if (_ismbblead(mbchar[mb_cnt])) {
}
++mb_cnt;
//}
} while (get_bytes);
// Convert a multibyte character to a corresponding wide character.
mb_cnt = mbtowc(&c, mbchar, mb_cnt);
if (mb_cnt == -1) {
fp->_flag |= _IOERR;
return WEOF;
}
#else
if (fp->_cnt > 0) {
fp->_cnt--;
c = *fp->_ptr++ &0377;
} else {
c = _filbuf(fp);
}
#endif
}
return c;
}

View file

@ -1,44 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* getchar.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* 28/12/1998: Appropriated for Reactos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <precomp.h>
#undef getchar
#undef getwchar
int
getchar(void)
{
return getc(stdin);
}
/*
* @implemented
*/
wint_t
getwchar(void)
{
return getwc(stdin);
}

View file

@ -1,144 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* gets.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
* 28/12/1998: Appropriated for Reactos
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
char* gets(char* s)
{
int c;
char* cs;
cs = s;
while ((c = getc(stdin)) != '\n' && c != EOF)
*cs++ = c;
if (c == EOF && cs == s)
return NULL;
*cs++ = '\0';
return s;
}
#ifndef WEOF
#define WEOF (wchar_t)(0xFFFF)
#endif
/*
* Get a line from the stdin stream.
*
* @implemented
*/
wchar_t* _getws(wchar_t* s)
{
wchar_t c;
wchar_t* cs;
cs = s;
while ((c = getwc(stdin)) != L'\n' && c != WEOF)
*cs++ = c;
if (c == WEOF && cs == s)
return NULL;
*cs++ = L'\0';
return s;
}
#if 0
/* Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <precomp.h>
link_warning (gets, "the `gets' function is dangerous and should not be used.")
/* Read a newline-terminated multibyte string from stdin into S,
removing the trailing newline. Return S or NULL. */
char *
gets (s)
char *s;
{
register char *p = s;
register int c;
FILE *stream = stdin;
int l;
if (!__validfp (stream) || p == NULL)
{
__set_errno (EINVAL);
return NULL;
}
if (feof (stream) || ferror (stream))
return NULL;
while ((c = getc(stdin)) != EOF) {
if (c == '\n')
break;
if ( isascii(c) )
*cs++ = c;
#ifdef _MULTIBYTE
else if ( isleadbyte(c) ) {
l = mblen(c);
while(l > 0 ) {
c = getchar();
if ( isleadbyte(c) || c == EOF )
return NULL; // encoding error
*cs++ = c;
l--;
}
}
#endif
else
return NULL; // suspicious input
}
*p = '\0';
/* Return null if we had an error, or if we got EOF
before writing any characters. */
if (ferror (stream) || (feof (stream) && p == s))
return NULL;
return s;
}
#endif

View file

@ -1,38 +0,0 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <precomp.h>
/*
* Read a word (int) from STREAM.
*
* @implemented
*/
int _getw(FILE *stream)
{
int w;
/* Is there a better way? */
if (fread( &w, sizeof(w), 1, stream) != 1) {
// EOF is a legitimate integer value so users must
// check feof or ferror to verify an EOF return.
return(EOF);
}
return(w);
}

View file

@ -0,0 +1,28 @@
/*
* PROJECT: ReactOS CRT library
* LICENSE: LGPL - See COPYING in the top level directory
* FILE: lib/sdk/crt/stdio/lnx_sprintf.c
* PURPOSE: Base implementation of sprintf
* PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
*/
#include <precomp.h>
#include <wchar.h>
#include <tchar.h>
/*
* @implemented
*/
int
lnx_sprintf(_TCHAR *str, const _TCHAR *fmt, ...)
{
va_list arg;
int done;
va_start (arg, fmt);
done = lnx__vstprintf (str, fmt, arg);
va_end (arg);
return done;
}

View file

@ -7,7 +7,7 @@ int __vfprintf(FILE*, const char*, va_list);
/*
* @implemented
*/
int vfprintf(FILE* f, const char* fmt, va_list ap)
int lnx_vfprintf(FILE* f, const char* fmt, va_list ap)
{
int len;
char localbuf[BUFSIZ];

View file

@ -2,6 +2,7 @@
#include <precomp.h>
int
__vfwprintf(FILE *fp, const wchar_t *fmt0, va_list argp);
@ -10,7 +11,7 @@ __vfwprintf(FILE *fp, const wchar_t *fmt0, va_list argp);
* @implemented
*/
int
vfwprintf(FILE *f, const wchar_t *fmt, va_list ap)
lnx_vfwprintf(FILE *f, const wchar_t *fmt, va_list ap)
{
int len;
wchar_t localbuf[BUFSIZ];

View file

@ -1,13 +1,12 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#include <tchar.h>
/*
* @implemented
*/
int
_vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap)
lnx__vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap)
{
FILE f = {0};
int len;
@ -16,7 +15,7 @@ _vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap)
f._ptr = (char*)str;
f._cnt = INT_MAX;
f._file = -1;
len = _vftprintf(&f,fmt, ap);
len = lnx_vftprintf(&f,fmt, ap);
*(_TCHAR*)f._ptr = 0;
return len;
}
@ -26,7 +25,7 @@ _vstprintf(_TCHAR *str, const _TCHAR *fmt, va_list ap)
* @implemented
*/
int
_vsntprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap)
lnx__vsntprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap)
{
FILE f = {0};
int len;
@ -35,7 +34,7 @@ _vsntprintf(_TCHAR *str, size_t maxlen, const _TCHAR *fmt, va_list ap)
f._ptr = (char*)str;
f._cnt = maxlen * sizeof(_TCHAR);
f._file = -1;
len = _vftprintf(&f,fmt, ap);
len = lnx_vftprintf(&f,fmt, ap);
// what if the buffer is full ??
*(_TCHAR *)f._ptr = 0;
return len;

View file

@ -1,4 +1,4 @@
#define _UNICODE
#define UNICODE
#define _UNICODE
#include "chmod.c"
#include "lnx_vsprintf.c"

View file

@ -18,6 +18,10 @@
#endif
#define MK_STR(s) #s
int alloc_fd(HANDLE hand, int flag); //FIXME: Remove
unsigned split_oflags(unsigned oflags); //FIXME: Remove
/*
* @implemented
*/
@ -128,8 +132,8 @@ int _pclose (FILE *pp)
TRACE("_pclose(%x)",pp);
fclose(pp);
if (!TerminateProcess(pp->_tmpfname ,0))
return( -1 );
//if (!TerminateProcess(pp->_tmpfname ,0))
// return( -1 );
return( 0 );
}

View file

@ -1,36 +0,0 @@
/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <precomp.h>
#include <wchar.h>
#include <tchar.h>
/*
* @implemented
*/
int _tprintf(const _TCHAR* format, ...)
{
va_list arg;
int done;
va_start(arg, format);
done = _vtprintf(format, arg);
va_end(arg);
return done;
}

View file

@ -1,142 +0,0 @@
/* $Id$
*
* ReactOS msvcrt library
*
* putc.c
*
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
*
* Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
// putc can be a macro
#undef putc
#undef putwc
#ifndef MB_CUR_MAX_CONST
#define MB_CUR_MAX_CONST 10
#endif
int putc(int c, FILE* fp)
{
// valid stream macro should check that fp is dword aligned
if (!__validfp(fp)) {
__set_errno(EINVAL);
return EOF;
}
// check for write access on fp
if (!OPEN4WRITING(fp)) {
__set_errno(EINVAL);
return EOF;
}
fp->_flag |= _IODIRTY;
if (fp->_cnt > 0) {
fp->_cnt--;
*(fp)->_ptr++ = (unsigned char)c;
return (int)(unsigned char)c;
} else {
return _flsbuf((unsigned char)c, fp);
}
return EOF;
}
//wint_t putwc(wint_t c, FILE* fp)
/*
* @implemented
*/
wint_t putwc(wint_t c, FILE* fp)
{
// valid stream macro should check that fp is dword aligned
if (!__validfp(fp)) {
__set_errno(EINVAL);
return WEOF;
}
// check for write access on fp
if (!OPEN4WRITING(fp)) {
__set_errno(EINVAL);
return WEOF;
}
// might check on multi bytes if text mode
if (fp->_flag & _IOBINARY) {
//if (1) {
fp->_flag |= _IODIRTY;
if (fp->_cnt > 0) {
fp->_cnt -= sizeof(wchar_t);
//*((wchar_t*)(fp->_ptr))++ = c;
*((wchar_t*)(fp->_ptr)) = c;
fp->_ptr += sizeof(wchar_t);
return (wint_t)c;
} else {
#if 1
wint_t result;
result = _flsbuf(c, fp);
if (result == (wint_t)EOF)
return WEOF;
result = _flsbuf((int)(c >> 8), fp);
if (result == (wint_t)EOF)
return WEOF;
return result;
#else
return _flswbuf(c, fp);
#endif
}
} else {
#if 0
int i;
int mb_cnt;
char mbchar[MB_CUR_MAX_CONST];
// Convert wide character to the corresponding multibyte character.
mb_cnt = wctomb(mbchar, (wchar_t)c);
if (mb_cnt == -1) {
fp->_flag |= _IOERR;
return WEOF;
}
if (mb_cnt > MB_CUR_MAX_CONST) {
// BARF();
}
for (i = 0; i < mb_cnt; i++) {
fp->_flag |= _IODIRTY;
if (fp->_cnt > 0) {
fp->_cnt--;
*(fp)->_ptr++ = (unsigned char)mbchar[i];
} else {
if (_flsbuf((unsigned char)mbchar[i], fp) == EOF) {
return WEOF;
}
}
}
#else
fp->_flag |= _IODIRTY;
if (fp->_cnt > 0) {
fp->_cnt--;
*(fp)->_ptr++ = (unsigned char)c;
} else {
if (_flsbuf(c, fp) == EOF) {
return WEOF;
}
}
#endif
return c;
}
return WEOF;
}

View file

@ -1,30 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/stdio/putchar.c
* PURPOSE: Writes a character to stdout
* PROGRAMER: Ariadne
* UPDATE HISTORY:
* 28/12/98: Created
*/
#include <precomp.h>
#include <tchar.h>
#undef putc
#undef putchar
#undef putwc
#undef putwchar
/*
* @implemented
*/
_TINT _puttchar(_TINT c)
{
_TINT r = _puttc(c, stdout);
if (stdout->_flag & _IO_LBF)
fflush(stdout);
return r;
}

View file

@ -1,32 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
#undef putchar
#undef putwchar
/*
* @implemented
*/
int puts(const char *s)
{
int c;
while ((c = *s++)) {
putchar(c);
}
return putchar('\n');
}
/*
* @implemented
*/
int _putws(const wchar_t *s)
{
wint_t c;
while ((c = *s++)) {
putwchar(c);
}
return putwchar(L'\n');
}

View file

@ -1,32 +0,0 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
* This file is part of the GNU C Library.
*
* The GNU C Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The GNU C Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the GNU C Library; see the file COPYING.LIB. If
* not, write to the Free Software Foundation, Inc., 675 Mass Ave,
* Cambridge, MA 02139, USA. */
#include <precomp.h>
/*
* Write the word (int) W to STREAM.
*
* @implemented
*/
int _putw(int w,FILE *stream)
{
/* Is there a better way? */
if (fwrite( &w, sizeof(w), 1, stream) < 1)
return(EOF);
return(0);
}

View file

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

View file

@ -1,25 +0,0 @@
#include <precomp.h>
#include <tchar.h>
#ifdef _UNICODE
#define sT "S"
#else
#define sT "s"
#endif
#define MK_STR(s) #s
/*
* @implemented
*/
int _tremove(const _TCHAR *fn)
{
int result = 0;
TRACE(MK_STR(_tremove)"('%"sT"')\n", fn);
if (!DeleteFile(fn))
result = -1;
TRACE("%d\n", result);
return result;
}

View file

@ -1,26 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/crt/??????
* PURPOSE: Unknown
* PROGRAMER: Unknown
* UPDATE HISTORY:
* 25/11/05: Created
*/
#include <precomp.h>
#include <tchar.h>
/*
* @implemented
*/
int _trename(const _TCHAR* old_, const _TCHAR* new_)
{
if (old_ == NULL || new_ == NULL)
return -1;
if (!MoveFile(old_, new_))
return -1;
return 0;
}

View file

@ -1,14 +0,0 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <precomp.h>
/*
* @implemented
*/
void rewind(FILE *f)
{
fflush(f);
_lseek(_fileno(f), 0L, SEEK_SET);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~(_IOERR|_IOEOF|_IOAHEAD);
}

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