From: Colin Finck Date: Sun, 1 Jun 2008 20:34:12 +0000 (+0000) Subject: Use the Windows CreateFile/WriteFile functions instead of open/write. X-Git-Tag: ReactOS-0.3.5~282 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=ce52fa83e3ecb22263802f76fd5e787f0ddf6ed4 Use the Windows CreateFile/WriteFile functions instead of open/write. Fixes compilation with MSVC. (note that you also have to change the calling convention from __stdcall to __cdecl in the auto-created project file for the lib) svn path=/trunk/; revision=33823 --- diff --git a/rostests/apitests/apitest.c b/rostests/apitests/apitest.c index 44720136ce2..bd3abecb1b8 100644 --- a/rostests/apitests/apitest.c +++ b/rostests/apitests/apitest.c @@ -29,25 +29,25 @@ OutputUsage(LPWSTR pszName) } BOOL -WriteFileHeader(UINT hFile, LPWSTR pszModule) +WriteFileHeader(HANDLE hFile, LPDWORD lpdwBytesWritten, LPWSTR pszModule) { char szHeader[100]; - _write(hFile, szFileHeader1, strlen(szFileHeader1)); + WriteFile(hFile, szFileHeader1, strlen(szFileHeader1), lpdwBytesWritten, NULL); sprintf(szHeader, "%ls Test results", pszModule); - _write(hFile, szHeader, strlen(szHeader)); - _write(hFile, szFileHeader2, strlen(szFileHeader2)); + WriteFile(hFile, szHeader, strlen(szHeader), lpdwBytesWritten, NULL); + WriteFile(hFile, szFileHeader2, strlen(szFileHeader2), lpdwBytesWritten, NULL); sprintf(szHeader, "

Test results for %ls

", pszModule); - _write(hFile, szHeader, strlen(szHeader)); + WriteFile(hFile, szHeader, strlen(szHeader), lpdwBytesWritten, NULL); - _write(hFile, szTableHeader, strlen(szTableHeader)); + WriteFile(hFile, szTableHeader, strlen(szTableHeader), lpdwBytesWritten, NULL); return TRUE; } BOOL -WriteRow(UINT hFile, LPWSTR pszFunction, PTESTINFO pti) +WriteRow(HANDLE hFile, LPDWORD lpdwBytesWritten, LPWSTR pszFunction, PTESTINFO pti) { char szLine[500]; @@ -75,7 +75,8 @@ WriteRow(UINT hFile, LPWSTR pszFunction, PTESTINFO pti) sprintf(szLine + strlen(szLine), "%d / %d / %d%d\n", pti->passed+pti->failed, pti->passed, pti->failed, pti->rfailed); - _write(hFile, szLine, strlen(szLine)); + WriteFile(hFile, szLine, strlen(szLine), lpdwBytesWritten, NULL); + return TRUE; } @@ -87,7 +88,8 @@ TestMain(LPWSTR pszName, LPWSTR pszModule) TESTINFO ti; INT opassed, ofailed, orfailed; BOOL bAll, bStatus; - UINT hFile = 0; + HANDLE hFile = NULL; + DWORD dwBytesWritten; ti.bRegress = FALSE; bAll = FALSE; @@ -132,16 +134,20 @@ TestMain(LPWSTR pszName, LPWSTR pszModule) if (bStatus) { + WCHAR szOutputFile[MAX_PATH]; + ti.bRegress = TRUE; - char szOutputFile[MAX_PATH]; - wsprintf(szOutputFile, "%ls.html", pszName); - hFile = _open(szOutputFile, O_CREAT | O_TRUNC | O_RDWR, 00700); - if (hFile == -1) + wcscpy(szOutputFile, pszName); + wcscat(szOutputFile, L".html"); + hFile = CreateFileW(szOutputFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hFile == INVALID_HANDLE_VALUE) { printf("Could not create output file.\n"); return 0; } - WriteFileHeader(hFile, pszModule); + + WriteFileHeader(hFile, &dwBytesWritten, pszModule); } for (i = 0; i < NumTests(); i++) @@ -171,7 +177,7 @@ TestMain(LPWSTR pszName, LPWSTR pszModule) { if (ti.rfailed > 0) ti.nApiStatus = APISTATUS_REGRESSION; - WriteRow(hFile, TestList[i].Test, &ti); + WriteRow(hFile, &dwBytesWritten, TestList[i].Test, &ti); } break; } @@ -187,8 +193,8 @@ TestMain(LPWSTR pszName, LPWSTR pszModule) if (bStatus) { - _write(hFile, szFileFooter, strlen(szFileFooter)); - _close(hFile); + WriteFile(hFile, szFileFooter, strlen(szFileFooter), &dwBytesWritten, NULL); + CloseHandle(hFile); } if (ti.bRegress) diff --git a/rostests/apitests/apitest.h b/rostests/apitests/apitest.h index 2180a020c81..6900789c9a3 100644 --- a/rostests/apitests/apitest.h +++ b/rostests/apitests/apitest.h @@ -4,11 +4,8 @@ #include #include #include -#include #include -#define open _open - #define APISTATUS_NORMAL 0 #define APISTATUS_NOT_FOUND 1 #define APISTATUS_UNIMPLEMENTED 2