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