2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/msvcrt/io/write.c
5 * PURPOSE: Writes to a file
6 * PROGRAMER: Boudewijn Dekker
11 #include <msvcrt/io.h>
12 #include <msvcrt/stdlib.h>
13 #include <msvcrt/internal/file.h>
16 #include <msvcrt/msvcrtdbg.h>
20 void ReportLastError(void)
22 DWORD error = GetLastError();
23 if (error != ERROR_SUCCESS) {
25 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
26 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL)) {
27 printf("ReportLastError() %d - %s\n", error, msg);
29 printf("ReportLastError() %d - unknown error\n", error);
38 size_t _write(int _fd, const void* _buf, size_t _nbyte)
45 DPRINT("_write(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
46 if (__fileno_getmode(_fd) & O_TEXT) {
48 tmp = (char*) malloc(BUFSIZE);
60 if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) {
65 if (wbyte < BUFSIZE) {
66 result = in - (char*)_buf;
75 if (count == 0 || _nbyte == 0) {
76 int tmp_len_debug = strlen(tmp);
77 if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) {
83 if (wbyte < (BUFSIZE - count)) {
84 result = in - (char*)_buf;
94 if(!WriteFile(_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) {