1/* 2 * Automated Testing Framework (atf) 3 * 4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#if !defined(ATF_C_FS_H) 31#define ATF_C_FS_H 32 33#include <sys/types.h> 34#include <sys/stat.h> 35 36#include <stdarg.h> 37#include <stdbool.h> 38 39#include <atf-c/error_fwd.h> 40 41#include "dynstr.h" 42 43/* --------------------------------------------------------------------- 44 * The "atf_fs_path" type. 45 * --------------------------------------------------------------------- */ 46 47struct atf_fs_path { 48 atf_dynstr_t m_data; 49}; 50typedef struct atf_fs_path atf_fs_path_t; 51 52/* Constructors/destructors. */ 53atf_error_t atf_fs_path_init_ap(atf_fs_path_t *, const char *, va_list); 54atf_error_t atf_fs_path_init_fmt(atf_fs_path_t *, const char *, ...); 55atf_error_t atf_fs_path_copy(atf_fs_path_t *, const atf_fs_path_t *); 56void atf_fs_path_fini(atf_fs_path_t *); 57 58/* Getters. */ 59atf_error_t atf_fs_path_branch_path(const atf_fs_path_t *, atf_fs_path_t *); 60const char *atf_fs_path_cstring(const atf_fs_path_t *); 61atf_error_t atf_fs_path_leaf_name(const atf_fs_path_t *, atf_dynstr_t *); 62bool atf_fs_path_is_absolute(const atf_fs_path_t *); 63bool atf_fs_path_is_root(const atf_fs_path_t *); 64 65/* Modifiers. */ 66atf_error_t atf_fs_path_append_ap(atf_fs_path_t *, const char *, va_list); 67atf_error_t atf_fs_path_append_fmt(atf_fs_path_t *, const char *, ...); 68atf_error_t atf_fs_path_append_path(atf_fs_path_t *, const atf_fs_path_t *); 69atf_error_t atf_fs_path_to_absolute(const atf_fs_path_t *, atf_fs_path_t *); 70 71/* Operators. */ 72bool atf_equal_fs_path_fs_path(const atf_fs_path_t *, 73 const atf_fs_path_t *); 74 75/* --------------------------------------------------------------------- 76 * The "atf_fs_stat" type. 77 * --------------------------------------------------------------------- */ 78 79struct atf_fs_stat { 80 int m_type; 81 struct stat m_sb; 82}; 83typedef struct atf_fs_stat atf_fs_stat_t; 84 85/* Constants. */ 86extern const int atf_fs_stat_blk_type; 87extern const int atf_fs_stat_chr_type; 88extern const int atf_fs_stat_dir_type; 89extern const int atf_fs_stat_fifo_type; 90extern const int atf_fs_stat_lnk_type; 91extern const int atf_fs_stat_reg_type; 92extern const int atf_fs_stat_sock_type; 93extern const int atf_fs_stat_wht_type; 94 95/* Constructors/destructors. */ 96atf_error_t atf_fs_stat_init(atf_fs_stat_t *, const atf_fs_path_t *); 97void atf_fs_stat_copy(atf_fs_stat_t *, const atf_fs_stat_t *); 98void atf_fs_stat_fini(atf_fs_stat_t *); 99 100/* Getters. */ 101dev_t atf_fs_stat_get_device(const atf_fs_stat_t *); 102ino_t atf_fs_stat_get_inode(const atf_fs_stat_t *); 103mode_t atf_fs_stat_get_mode(const atf_fs_stat_t *); 104off_t atf_fs_stat_get_size(const atf_fs_stat_t *); 105int atf_fs_stat_get_type(const atf_fs_stat_t *); 106bool atf_fs_stat_is_owner_readable(const atf_fs_stat_t *); 107bool atf_fs_stat_is_owner_writable(const atf_fs_stat_t *); 108bool atf_fs_stat_is_owner_executable(const atf_fs_stat_t *); 109bool atf_fs_stat_is_group_readable(const atf_fs_stat_t *); 110bool atf_fs_stat_is_group_writable(const atf_fs_stat_t *); 111bool atf_fs_stat_is_group_executable(const atf_fs_stat_t *); 112bool atf_fs_stat_is_other_readable(const atf_fs_stat_t *); 113bool atf_fs_stat_is_other_writable(const atf_fs_stat_t *); 114bool atf_fs_stat_is_other_executable(const atf_fs_stat_t *); 115 116/* --------------------------------------------------------------------- 117 * Free functions. 118 * --------------------------------------------------------------------- */ 119 120extern const int atf_fs_access_f; 121extern const int atf_fs_access_r; 122extern const int atf_fs_access_w; 123extern const int atf_fs_access_x; 124 125atf_error_t atf_fs_eaccess(const atf_fs_path_t *, int); 126atf_error_t atf_fs_exists(const atf_fs_path_t *, bool *); 127atf_error_t atf_fs_getcwd(atf_fs_path_t *); 128atf_error_t atf_fs_mkdtemp(atf_fs_path_t *); 129atf_error_t atf_fs_mkstemp(atf_fs_path_t *, int *); 130atf_error_t atf_fs_rmdir(const atf_fs_path_t *); 131atf_error_t atf_fs_unlink(const atf_fs_path_t *); 132 133#endif /* !defined(ATF_C_FS_H) */ 134