mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
Added debug messages.
Added LN to CR/LN translation for text files. svn path=/trunk/; revision=2799
This commit is contained in:
parent
5cd1300eac
commit
e129158330
1 changed files with 71 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
* FILE: lib/crtdll/io/write.c
|
* FILE: lib/msvcrt/io/write.c
|
||||||
* PURPOSE: Writes to a file
|
* PURPOSE: Writes to a file
|
||||||
* PROGRAMER: Boudewijn Dekker
|
* PROGRAMER: Boudewijn Dekker
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
|
@ -9,15 +9,80 @@
|
||||||
*/
|
*/
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <msvcrt/io.h>
|
#include <msvcrt/io.h>
|
||||||
|
#include <msvcrt/internal/file.h>
|
||||||
|
|
||||||
|
#define NDEBUG
|
||||||
|
#include <msvcrt/msvcrtdbg.h>
|
||||||
|
|
||||||
|
#define BUFSIZE 4096
|
||||||
|
|
||||||
size_t _write(int _fd, const void *_buf, size_t _nbyte)
|
size_t _write(int _fd, const void *_buf, size_t _nbyte)
|
||||||
{
|
{
|
||||||
DWORD _wbyte;
|
char *tmp, *in, *out;
|
||||||
|
int count, result;
|
||||||
if (!WriteFile(_get_osfhandle(_fd),_buf,_nbyte,&_wbyte,NULL))
|
DWORD wbyte;
|
||||||
|
|
||||||
|
DPRINT("_write(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
|
||||||
|
if (__fileno_getmode(_fd) & O_TEXT)
|
||||||
{
|
{
|
||||||
return -1;
|
result = _nbyte;
|
||||||
|
tmp = (char*) malloc(BUFSIZE);
|
||||||
|
if (tmp == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
count = BUFSIZE;
|
||||||
|
out = tmp;
|
||||||
|
in = (char*) _buf;
|
||||||
|
while (_nbyte--)
|
||||||
|
{
|
||||||
|
if (*in == 0x0a)
|
||||||
|
{
|
||||||
|
*out++ = 0x0d;
|
||||||
|
count--;
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL))
|
||||||
|
{
|
||||||
|
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(_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL))
|
||||||
|
{
|
||||||
|
result = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (wbyte < BUFSIZE - count)
|
||||||
|
{
|
||||||
|
result = in - (char*)_buf;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
count = BUFSIZE;
|
||||||
|
out = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(tmp);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!WriteFile(_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return wbyte;
|
||||||
}
|
}
|
||||||
return (size_t)_wbyte;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue