Last active
June 27, 2018 10:56
-
-
Save orgads/92a3a42a961e93dbae9664db5808566f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <windows.h> | |
static HANDLE do_open(const char *filename, int access) | |
{ | |
return CreateFileA(filename, access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, | |
FILE_ATTRIBUTE_NORMAL, NULL); | |
} | |
static void write_file(const char *filename) | |
{ | |
FILE *f = fopen(filename, "w"); | |
fputs(filename, f); | |
fclose(f); | |
} | |
int main() | |
{ | |
write_file("locked-read"); | |
HANDLE f1 = do_open("locked-read", GENERIC_READ); | |
printf("unlink: %d\n", unlink("locked-read")); | |
HANDLE f2 = do_open("locked-read", GENERIC_WRITE); | |
if (f2 == INVALID_HANDLE_VALUE) | |
printf("create failed\n"); | |
else | |
CloseHandle(f2); | |
CloseHandle(f1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment