1 /*
2 american fuzzy lop++ - a trivial program to test the build
3 --------------------------------------------------------
4 Originally written by Michal Zalewski
5 Copyright 2014 Google Inc. All rights reserved.
6 Copyright 2019-2020 AFLplusplus Project. All rights reserved.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at:
10 http://www.apache.org/licenses/LICENSE-2.0
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <string.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20
21 #ifdef TEST_SHARED_OBJECT
22 #define main main_exported
23 #endif
24
main(int argc,char ** argv)25 int main(int argc, char **argv) {
26
27 int fd = 0;
28 char buff[8];
29 char *buf = buff;
30
31 // we support command line parameter and stdin
32 if (argc == 2) {
33
34 buf = argv[1];
35 printf("Input %s - ", buf);
36
37 } else {
38
39 if (argc >= 3 && strcmp(argv[1], "-f") == 0) {
40
41 if ((fd = open(argv[2], O_RDONLY)) < 0) {
42
43 fprintf(stderr, "Error: unable to open %s\n", argv[2]);
44 exit(-1);
45
46 }
47
48 }
49
50 if (read(fd, buf, sizeof(buf)) < 1) {
51
52 printf("Hum?\n");
53 return 1;
54
55 }
56
57 }
58
59 // we support three input cases (plus a 4th if stdin is used but there is no
60 // input)
61 if (buf[0] == '0')
62 printf("Looks like a zero to me!\n");
63 else if (buf[0] == '1')
64 printf("Pretty sure that is a one!\n");
65 else
66 printf("Neither one or zero? How quaint!\n");
67
68 return 0;
69
70 }
71
72