2010-03-03 18:32:03 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* Disable deprecation warning for fopen */
|
2016-05-16 17:34:04 +03:00
|
|
|
#pragma warning(disable : 4996)
|
2010-03-03 18:32:03 +03:00
|
|
|
|
|
|
|
/*if run serially, works fine.
|
|
|
|
If run in parallel, someone will attempt to delete
|
|
|
|
a locked file, which will fail */
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
FILE* file;
|
|
|
|
int i;
|
|
|
|
const char* fname;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argc >= 2) {
|
2010-03-03 18:32:03 +03:00
|
|
|
fname = argv[1];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2010-03-03 18:32:03 +03:00
|
|
|
fname = "lockedFile.txt";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-03-03 18:32:03 +03:00
|
|
|
file = fopen(fname, "w");
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (i = 0; i < 10000; i++) {
|
2010-03-03 18:32:03 +03:00
|
|
|
fprintf(file, "%s", "x");
|
|
|
|
fflush(file);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-03-03 18:32:03 +03:00
|
|
|
fclose(file);
|
|
|
|
return remove(fname);
|
|
|
|
}
|