Path: blob/master/tools/testing/selftests/efivarfs/create-read.c
26288 views
// SPDX-License-Identifier: GPL-2.01#include <stdio.h>2#include <stdint.h>3#include <stdlib.h>4#include <unistd.h>5#include <sys/types.h>6#include <sys/stat.h>7#include <fcntl.h>8#include <errno.h>9#include <string.h>1011int main(int argc, char **argv)12{13const char *path;14char buf[4];15int fd, rc;1617if (argc < 2) {18fprintf(stderr, "usage: %s <path>\n", argv[0]);19return EXIT_FAILURE;20}2122path = argv[1];2324/* create a test variable */25fd = open(path, O_RDWR | O_CREAT, 0600);26if (fd < 0) {27perror("open(O_WRONLY)");28return EXIT_FAILURE;29}3031rc = read(fd, buf, sizeof(buf));32if (rc != 0) {33fprintf(stderr, "Reading a new var should return EOF\n");34close(fd);35return EXIT_FAILURE;36}3738close(fd);39return EXIT_SUCCESS;40}414243