Path: blob/main/lib/libc/tests/db/dbm_open_test.c
103367 views
/*-1* Copyright (c) 2025 Klara, Inc.2*3* SPDX-License-Identifier: BSD-2-Clause4*/56#include <fcntl.h>7#include <ndbm.h>8#include <stdio.h>910#include <atf-c.h>1112static const char *path = "tmp";13static const char *dbname = "tmp.db";1415ATF_TC(dbm_open_missing_test);16ATF_TC_HEAD(dbm_open_missing_test, tc)17{18atf_tc_set_md_var(tc, "descr",19"Test dbm_open when creating a new database");20}2122ATF_TC_BODY(dbm_open_missing_test, tc)23{2425/*26* POSIX.1 specifies that a missing database file should27* always get created if O_CREAT is present, except when28* O_EXCL is specified as well.29*/30ATF_CHECK(dbm_open(path, O_RDONLY, 0755) == NULL);31ATF_REQUIRE(!atf_utils_file_exists(dbname));32ATF_CHECK(dbm_open(path, O_RDONLY | O_CREAT, 0755) != NULL);33ATF_REQUIRE(atf_utils_file_exists(dbname));34ATF_CHECK(dbm_open(path, O_RDONLY | O_CREAT | O_EXCL, 0755) == NULL);35}3637ATF_TC_WITHOUT_HEAD(dbm_open_wronly_test);38ATF_TC_BODY(dbm_open_wronly_test, tc)39{40ATF_CHECK(dbm_open(path, O_WRONLY, 0755) == NULL);41ATF_REQUIRE(!atf_utils_file_exists(dbname));42ATF_CHECK(dbm_open(path, O_WRONLY | O_CREAT, 0755) != NULL);43ATF_REQUIRE(atf_utils_file_exists(dbname));44}4546ATF_TP_ADD_TCS(tp)47{48ATF_TP_ADD_TC(tp, dbm_open_missing_test);49ATF_TP_ADD_TC(tp, dbm_open_wronly_test);50return (atf_no_error());51}525354