WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / efivarfs / create-read.c
blob9674a19396a325e06336a55942861ab43d086f7e
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 return EXIT_FAILURE;
38 return EXIT_SUCCESS;