0001
0002 #include <stdio.h>
0003 #include <stdint.h>
0004 #include <stdlib.h>
0005 #include <unistd.h>
0006 #include <sys/types.h>
0007 #include <sys/stat.h>
0008 #include <fcntl.h>
0009 #include <errno.h>
0010 #include <string.h>
0011
0012 int main(int argc, char **argv)
0013 {
0014 const char *path;
0015 char buf[4];
0016 int fd, rc;
0017
0018 if (argc < 2) {
0019 fprintf(stderr, "usage: %s <path>\n", argv[0]);
0020 return EXIT_FAILURE;
0021 }
0022
0023 path = argv[1];
0024
0025
0026 fd = open(path, O_RDWR | O_CREAT, 0600);
0027 if (fd < 0) {
0028 perror("open(O_WRONLY)");
0029 return EXIT_FAILURE;
0030 }
0031
0032 rc = read(fd, buf, sizeof(buf));
0033 if (rc != 0) {
0034 fprintf(stderr, "Reading a new var should return EOF\n");
0035 return EXIT_FAILURE;
0036 }
0037
0038 return EXIT_SUCCESS;
0039 }