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