about summary refs log tree commit diff homepage
path: root/test/Runtime/POSIX/Stdin.c
blob: e7e3f2ff19d90ec45c69e13e2f983d1434c29c97 (plain) (blame)
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
// RUN: %llvmgcc %s -emit-llvm -O0 -c -o %t.bc
// RUN: %klee --libc=klee --posix-runtime --exit-on-error %t.bc --sym-files 0 4 > %t.log
// RUN: grep "mode:file" %t.log
// RUN: grep "mode:dir" %t.log
// RUN: grep "mode:chr" %t.log
// RUN: grep "mode:blk" %t.log
// RUN: grep "mode:fifo" %t.log
// RUN: grep "mode:lnk" %t.log
// RUN: grep "read:sym:yes" %t.log
// RUN: grep "read:sym:no" %t.log

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <assert.h>

int main(int argc, char **argv) {
  struct stat stats;
  assert(fstat(0, &stats) == 0);

  if (S_ISREG(stats.st_mode)) {
    printf("mode:file\n");
  } else if (S_ISDIR(stats.st_mode)) {
    printf("mode:dir\n");
  } else if (S_ISCHR(stats.st_mode)) {
    printf("mode:chr\n");
  } else if (S_ISBLK(stats.st_mode)) {
    printf("mode:blk\n");
  } else if (S_ISFIFO(stats.st_mode)) {
    printf("mode:fifo\n");
  } else if (S_ISLNK(stats.st_mode)) {
    printf("mode:lnk\n");
  } else if (S_ISSOCK(stats.st_mode)) {
    printf("mode:sock\n");
  } else {
    printf("unknown mode\n");
  }

  assert(stats.st_size==4);

  if (S_ISREG(stats.st_mode)) {
    char buf[10];
    int n = read(0, buf, 5);
    assert(n == 4);
    
    if (strcmp(buf, "HI!")) {
      printf("read:sym:yes\n");
    } else {
      printf("read:sym:no\n");
    }
  }

  fflush(stdout);

  return 0;
}