mirror of
https://github.com/reactos/reactos.git
synced 2025-07-27 04:23:57 +00:00
Sync with trunk r63430.
svn path=/branches/shell-experiments/; revision=63433
This commit is contained in:
commit
d5e23caf7a
136 changed files with 6159 additions and 3600 deletions
|
@ -553,6 +553,29 @@ int CDECL _isatty(int fd)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/* INTERNAL: Allocate temporary buffer for stdout and stderr */
|
||||
static BOOL add_std_buffer(FILE *file)
|
||||
{
|
||||
static char buffers[2][BUFSIZ];
|
||||
|
||||
if((file->_file!=STDOUT_FILENO && file->_file!=STDERR_FILENO)
|
||||
|| !_isatty(file->_file) || file->_bufsiz)
|
||||
return FALSE;
|
||||
|
||||
file->_ptr = file->_base = buffers[file->_file == STDOUT_FILENO ? 0 : 1];
|
||||
file->_bufsiz = file->_cnt = BUFSIZ;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* INTERNAL: Removes temporary buffer from stdout or stderr */
|
||||
/* Only call this function when add_std_buffer returned TRUE */
|
||||
static void remove_std_buffer(FILE *file)
|
||||
{
|
||||
flush_buffer(file);
|
||||
file->_ptr = file->_base = NULL;
|
||||
file->_bufsiz = file->_cnt = 0;
|
||||
}
|
||||
|
||||
/* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */
|
||||
static int int_to_base32(int num, char *str)
|
||||
{
|
||||
|
@ -3416,34 +3439,9 @@ LONG CDECL ftell(FILE* file)
|
|||
*/
|
||||
int CDECL fgetpos(FILE* file, fpos_t *pos)
|
||||
{
|
||||
int off=0;
|
||||
|
||||
_lock_file(file);
|
||||
*pos = _lseeki64(file->_file,0,SEEK_CUR);
|
||||
if(*pos == -1) {
|
||||
_unlock_file(file);
|
||||
*pos = _ftelli64(file);
|
||||
if(*pos == -1)
|
||||
return -1;
|
||||
}
|
||||
if(file->_bufsiz) {
|
||||
if( file->_flag & _IOWRT ) {
|
||||
off = file->_ptr - file->_base;
|
||||
} else {
|
||||
off = -file->_cnt;
|
||||
if (get_ioinfo(file->_file)->wxflag & WX_TEXT) {
|
||||
/* Black magic correction for CR removal */
|
||||
int i;
|
||||
for (i=0; i<file->_cnt; i++) {
|
||||
if (file->_ptr[i] == '\n')
|
||||
off--;
|
||||
}
|
||||
/* Black magic when reading CR at buffer boundary*/
|
||||
if(get_ioinfo(file->_file)->wxflag & WX_READCR)
|
||||
off--;
|
||||
}
|
||||
}
|
||||
}
|
||||
*pos += off;
|
||||
_unlock_file(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3452,23 +3450,13 @@ int CDECL fgetpos(FILE* file, fpos_t *pos)
|
|||
*/
|
||||
int CDECL fputs(const char *s, FILE* file)
|
||||
{
|
||||
size_t i, len = strlen(s);
|
||||
size_t len = strlen(s);
|
||||
int ret;
|
||||
|
||||
_lock_file(file);
|
||||
if (!(get_ioinfo(file->_file)->wxflag & WX_TEXT)) {
|
||||
ret = fwrite(s,sizeof(*s),len,file) == len ? 0 : EOF;
|
||||
_unlock_file(file);
|
||||
return ret;
|
||||
}
|
||||
for (i=0; i<len; i++)
|
||||
if (fputc(s[i], file) == EOF) {
|
||||
_unlock_file(file);
|
||||
return EOF;
|
||||
}
|
||||
|
||||
ret = fwrite(s, sizeof(*s), len, file) == len ? 0 : EOF;
|
||||
_unlock_file(file);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
|
@ -3477,6 +3465,7 @@ int CDECL fputs(const char *s, FILE* file)
|
|||
int CDECL fputws(const wchar_t *s, FILE* file)
|
||||
{
|
||||
size_t i, len = strlenW(s);
|
||||
BOOL tmp_buf;
|
||||
int ret;
|
||||
|
||||
_lock_file(file);
|
||||
|
@ -3485,14 +3474,17 @@ int CDECL fputws(const wchar_t *s, FILE* file)
|
|||
_unlock_file(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
tmp_buf = add_std_buffer(file);
|
||||
for (i=0; i<len; i++) {
|
||||
if (((s[i] == '\n') && (fputc('\r', file) == EOF))
|
||||
|| fputwc(s[i], file) == WEOF) {
|
||||
if(fputwc(s[i], file) == WEOF) {
|
||||
if(tmp_buf) remove_std_buffer(file);
|
||||
_unlock_file(file);
|
||||
return WEOF;
|
||||
}
|
||||
}
|
||||
|
||||
if(tmp_buf) remove_std_buffer(file);
|
||||
_unlock_file(file);
|
||||
return 0;
|
||||
}
|
||||
|
@ -3726,6 +3718,7 @@ char * CDECL tmpnam(char *s)
|
|||
{
|
||||
size = int_to_base32(tmpnam_unique++, tmpstr);
|
||||
memcpy(p, tmpstr, size);
|
||||
p[size] = '\0';
|
||||
if (GetFileAttributesA(s) == INVALID_FILE_ATTRIBUTES &&
|
||||
GetLastError() == ERROR_FILE_NOT_FOUND)
|
||||
break;
|
||||
|
@ -3757,6 +3750,7 @@ wchar_t * CDECL _wtmpnam(wchar_t *s)
|
|||
{
|
||||
size = int_to_base32_w(tmpnam_unique++, tmpstr);
|
||||
memcpy(p, tmpstr, size*sizeof(wchar_t));
|
||||
p[size] = '\0';
|
||||
if (GetFileAttributesW(s) == INVALID_FILE_ATTRIBUTES &&
|
||||
GetLastError() == ERROR_FILE_NOT_FOUND)
|
||||
break;
|
||||
|
@ -3830,15 +3824,39 @@ int CDECL ungetc(int c, FILE * file)
|
|||
wint_t CDECL ungetwc(wint_t wc, FILE * file)
|
||||
{
|
||||
wchar_t mwc = wc;
|
||||
char * pp = (char *)&mwc;
|
||||
int i;
|
||||
|
||||
if (wc == WEOF)
|
||||
return WEOF;
|
||||
|
||||
_lock_file(file);
|
||||
for(i=sizeof(wchar_t)-1;i>=0;i--) {
|
||||
if(pp[i] != ungetc(pp[i],file)) {
|
||||
|
||||
if((get_ioinfo(file->_file)->exflag & (EF_UTF8 | EF_UTF16))
|
||||
|| !(get_ioinfo(file->_file)->wxflag & WX_TEXT)) {
|
||||
unsigned char * pp = (unsigned char *)&mwc;
|
||||
int i;
|
||||
|
||||
for(i=sizeof(wchar_t)-1;i>=0;i--) {
|
||||
if(pp[i] != ungetc(pp[i],file)) {
|
||||
_unlock_file(file);
|
||||
return WEOF;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
char mbs[MB_LEN_MAX];
|
||||
int len;
|
||||
|
||||
len = wctomb(mbs, mwc);
|
||||
if(len == -1) {
|
||||
_unlock_file(file);
|
||||
return WEOF;
|
||||
}
|
||||
|
||||
for(len--; len>=0; len--) {
|
||||
if(mbs[len] != ungetc(mbs[len], file)) {
|
||||
_unlock_file(file);
|
||||
return WEOF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_unlock_file(file);
|
||||
|
|
|
@ -10,36 +10,39 @@
|
|||
|
||||
#include <precomp.h>
|
||||
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
/*********************************************************************
|
||||
* _mbtowc_l(MSVCRT.@)
|
||||
*/
|
||||
|
||||
int mbtowc (wchar_t *charptr, const char *address, size_t number)
|
||||
int CDECL _mbtowc_l(wchar_t *dst, const char* str, size_t n, _locale_t locale)
|
||||
{
|
||||
int bytes;
|
||||
MSVCRT_pthreadlocinfo locinfo;
|
||||
wchar_t tmpdst = '\0';
|
||||
|
||||
if (address == 0)
|
||||
return 0;
|
||||
if(!locale)
|
||||
locinfo = get_locinfo();
|
||||
else
|
||||
locinfo = (MSVCRT_pthreadlocinfo)(locale->locinfo);
|
||||
|
||||
if ((bytes = mblen (address, number)) < 0)
|
||||
return bytes;
|
||||
|
||||
if (charptr) {
|
||||
switch (bytes) {
|
||||
case 0:
|
||||
if (number > 0)
|
||||
*charptr = (wchar_t) '\0';
|
||||
break;
|
||||
case 1:
|
||||
*charptr = (wchar_t) ((unsigned char) address[0]);
|
||||
break;
|
||||
case 2:
|
||||
*charptr = (wchar_t) (((unsigned char) address[0] << 8)
|
||||
| (unsigned char) address[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
if(n <= 0 || !str)
|
||||
return 0;
|
||||
if(!locinfo->lc_codepage)
|
||||
tmpdst = (unsigned char)*str;
|
||||
else if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, n, &tmpdst, 1))
|
||||
return -1;
|
||||
if(dst)
|
||||
*dst = tmpdst;
|
||||
/* return the number of bytes from src that have been used */
|
||||
if(!*str)
|
||||
return 0;
|
||||
if(n >= 2 && _isleadbyte_l((unsigned char)*str, locale) && str[1])
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* mbtowc(MSVCRT.@)
|
||||
*/
|
||||
int CDECL mbtowc(wchar_t *dst, const char* str, size_t n)
|
||||
{
|
||||
return _mbtowc_l(dst, str, n, NULL);
|
||||
}
|
||||
|
|
|
@ -614,6 +614,15 @@ int __cdecl _isctype (int c, int ctypeFlags)
|
|||
{
|
||||
return _isctype_l(c, ctypeFlags, NULL);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _isleadbyte_l (MSVCRT.@)
|
||||
*/
|
||||
int __cdecl _isleadbyte_l(int c, _locale_t locale)
|
||||
{
|
||||
return _isctype_l( c, _LEADBYTE, locale );
|
||||
}
|
||||
|
||||
#endif /* _LIBCNT_ */
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue