1 // SPDX-License-Identifier: GPL-2.0 2 #include <stdio.h> 3 #include <stdint.h> 4 #include <stdlib.h> 5 #include <unistd.h> 6 #include <sys/types.h> 7 #include <sys/stat.h> 8 #include <fcntl.h> 9 #include <errno.h> 10 #include <string.h> 11 12 int main(int argc, char **argv) 13 { 14 const char *path; 15 char buf[4]; 16 int fd, rc; 17 18 if (argc < 2) { 19 fprintf(stderr, "usage: %s <path>\n", argv[0]); 20 return EXIT_FAILURE; 21 } 22 23 path = argv[1]; 24 25 /* create a test variable */ 26 fd = open(path, O_RDWR | O_CREAT, 0600); 27 if (fd < 0) { 28 perror("open(O_WRONLY)"); 29 return EXIT_FAILURE; 30 } 31 32 rc = read(fd, buf, sizeof(buf)); 33 if (rc != 0) { 34 fprintf(stderr, "Reading a new var should return EOF\n"); 35 return EXIT_FAILURE; 36 } 37 38 return EXIT_SUCCESS; 39 } 40