File: getc_putc_helper.cpp

package info (click to toggle)
bonnie%2B%2B 2.00a%2Bnmu3
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 384 kB
  • sloc: cpp: 4,413; perl: 164; sh: 117; makefile: 76
file content (64 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download | duplicates (7)
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
56
57
58
59
60
61
62
63
64
#include "bonnie.h"

#include <unistd.h>
#include <stdlib.h>
#include <cstring>
#include "duration.h"
#include <vector>
#include "getc_putc.h"

int main(int argc, char *argv[])
{
  if(argc != 2)
  {
    fprintf(stderr, "Error - don't run this yourself, run getc_putc!\n");
    return 1;
  }

  int size = atoi(argv[1]);
  bool quiet = false;

  if(argv[1][strlen(argv[1]) - 1] == 'q')
    quiet = true;

  volatile char c;
  int i;
  Duration dur;
  double res[2];

  FILE *fp = fdopen(FILE_FD, "w+");
  if(!fp)
  {
    fprintf(stderr, "Can't reopen for putc.\n");
    return 1;
  }
  if(fseek(fp, 0, SEEK_SET) != 0)
  {
    fprintf(stderr, "Can't seek.\n");
    return 1;
  }
  fflush(NULL);
  TEST_FUNC_WRITE("putc(c, fp) no thread", if(putc(c, fp) == EOF), res[0]);
  if(fseek(fp, 0, SEEK_SET) != 0)
  {
    fprintf(stderr, "Can't seek.\n");
    return 1;
  }
  fflush(NULL);
  TEST_FUNC_READ("getc() no thread", if( (c = getc(fp)) == EOF), res[1]);
  if(fseek(fp, 0, SEEK_SET) != 0)
  {
    fprintf(stderr, "Can't seek.\n");
    return 1;
  }
  fflush(NULL);

  if(write(1, res, sizeof(res)) != sizeof(res))
  {
    fprintf(stderr, "Can't write results to parent process.\n");
    return 1;
  }

  return 0;
}