28 lines
535 B
C
Raw Normal View History

2010-06-23 01:18:35 +03:00
#include <stdio.h>
/* Disable deprecation warning for fopen */
2016-07-09 11:21:54 +02:00
#pragma warning(disable : 4996)
2010-06-23 01:18:35 +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-07-09 11:21:54 +02:00
if (argc >= 2) {
2010-06-23 01:18:35 +03:00
fname = argv[1];
2016-07-09 11:21:54 +02:00
} else {
2010-06-23 01:18:35 +03:00
fname = "lockedFile.txt";
2016-07-09 11:21:54 +02:00
}
2010-06-23 01:18:35 +03:00
file = fopen(fname, "w");
2016-07-09 11:21:54 +02:00
for (i = 0; i < 10000; i++) {
2010-06-23 01:18:35 +03:00
fprintf(file, "%s", "x");
fflush(file);
2016-07-09 11:21:54 +02:00
}
2010-06-23 01:18:35 +03:00
fclose(file);
return remove(fname);
}