Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- bool test() {
- unsigned char buf[] = {
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99
- };
- HANDLE h;
- DWORD nbytes;
- LPCTSTR fn_tmp = "aaa";
- LPCTSTR fn = "bbb";
- h = CreateFile(fn_tmp, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS, 0, 0);
- if (h == INVALID_HANDLE_VALUE) return 0;
- if (!WriteFile(h, buf, sizeof buf, &nbytes, 0)) goto error;
- if (!FlushFileBuffers(h)) goto error;
- if (!CloseHandle(h)) goto error;
- if (!MoveFileEx(fn_tmp, fn, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH)) {
- printf("error=%dn", GetLastError());
- return 0;
- }
- return 1;
- error:
- CloseHandle(h);
- return 0;
- }
- int main(int argc, char** argv) {
- unsigned int i;
- for (i = 0;; ++i) {
- printf("*%un", i);
- if (!test()) return 1;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment