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);
35 size_t _write(int _fd, const void* _buf, size_t _nbyte)
42 DPRINT("_write(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
43 if (__fileno_getmode(_fd) & O_TEXT) {
45 tmp = (char*) malloc(BUFSIZE);
57 if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE, &wbyte, NULL)) {
62 if (wbyte < BUFSIZE) {
63 result = in - (char*)_buf;
72 if (count == 0 || _nbyte == 0) {
73 int tmp_len_debug = strlen(tmp);
74 if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) {
80 if (wbyte < (BUFSIZE - count)) {
81 result = in - (char*)_buf;
91 if(!WriteFile(_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) {