summaryrefslogtreecommitdiffstats
path: root/Tests/CTestTestResourceLock/lockFile.c
blob: f8edc3f5451a79ace8634989eaec2a7270330946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>

/* Disable deprecation warning for fopen */
#define _CRT_SECURE_NO_WARNINGS

/*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;
  if(argc >= 2)
    {
    fname = argv[1];
    }
  else
    {
    fname = "lockedFile.txt";
    }
  file = fopen(fname, "w");

  for(i = 0; i < 10000; i++)
    {
    fprintf(file, "%s", "x");
    fflush(file);
    }
  fclose(file);
  return remove(fname);
}