Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / efivarfs / create-read.c
blob7bc7af4eb2c17f5e301a01e6ec130e40e6b49173
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>
12 int main(int argc, char **argv)
14 const char *path;
15 char buf[4];
16 int fd, rc;
18 if (argc < 2) {
19 fprintf(stderr, "usage: %s <path>\n", argv[0]);
20 return EXIT_FAILURE;
23 path = argv[1];
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;
32 rc = read(fd, buf, sizeof(buf));
33 if (rc != 0) {
34 fprintf(stderr, "Reading a new var should return EOF\n");
35 close(fd);
36 return EXIT_FAILURE;
39 close(fd);
40 return EXIT_SUCCESS;