File: file1.c

package info (click to toggle)
dmtcp 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,496 kB
  • sloc: cpp: 33,592; ansic: 28,099; sh: 6,735; makefile: 1,950; perl: 1,690; python: 1,241; asm: 138; java: 13
file content (55 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#define __USE_GNU
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

int main()
{
    long int count = 0;
    int fd;
    FILE *fp;
    char filename[100];  /* "/tmp/ff_jdl_XXXXXX" for current TMPDIR */
    FILE *fp2;

    char *dir = getenv("DMTCP_TMPDIR");
    if (!dir) dir = getenv("TMPDIR");
    if (!dir) dir = "/tmp";
    if (sizeof(filename) < strlen(dir) + sizeof("/ff_jdl_XXXXXX")) {
      printf("Directory string too large.\n");
      return 1;
    }
    strcpy(filename, dir);
    strcat(filename, "/ff_jdl_XXXXXX");

    fp2 = fopen("/proc/self/exe", "r");
    if (fp2 == NULL)
      abort();

    close(mkstemp(filename));
    fd = open(filename, O_WRONLY|O_CREAT, S_IWUSR|S_IWUSR);
    if (fd == -1)
      abort();
    // Problematic only when in "w" mode or "a". All + modes and "r" are fine.
    fp = fdopen(fd, "w");
    //fp = fopen("/tmp/ff_jdl", "w");

    fprintf(stdout, "Opened ff_jdl\n");
    fprintf(stdout, "Deleting ff_jdl\n");
    unlink(filename);

    while (1) {
      if (count % (int)1e6 == 0) {
        printf("%ld ", count);
        fflush(stdout);
      }
      fprintf(fp, "%ld", count++);
    }

    fprintf(stdout, "I have returned\n");
    sleep(2);
    return 0;
}