1 /* 2 * Copyright (c) 2001-2026 Devin Teske <dteske@FreeBSD.org> 3 * Copyright (c) 2021-2026 Faraz Vahedi <kfv@FreeBSD.org> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8 #ifndef _BSDCONF_INTERNAL_H_ 9 #define _BSDCONF_INTERNAL_H_ 10 11 #include <sys/stat.h> 12 13 #include <stdbool.h> 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include "bsdconf.h" 18 19 /* 20 * Private interfaces shared between the libbsdconf translation units. 21 * This header is deliberately not installed. 22 */ 23 24 /* String manipulation routines (bsdconf_string.c) */ 25 void bsdconf_strunexpand(char *_dst, const char *_src); 26 void bsdconf_strtolower(char *_buf); 27 int bsdconf_replaceall(char *_buf, size_t _buflen, 28 const char *_find, const char *_replace); 29 unsigned int bsdconf_strcount(const char *_source, const char *_find); 30 31 /* 32 * Parsed extent of a single statement within the in-memory copy of the file. 33 * All members are byte offsets into the buffer except as noted. A statement 34 * runs from the first byte of its directive to its terminator (newline, an 35 * inline `#' comment, or a semicolon when enabled). 36 */ 37 struct bsdconf_stmt { 38 size_t line_start; /* start of the physical line (for removal) */ 39 size_t dir_start; /* first byte of the directive */ 40 size_t dir_end; /* one past the last byte of the directive */ 41 size_t op_start; /* first byte of the assignment operator */ 42 size_t eq; /* index of the `=' (valid iff have_equals) */ 43 size_t val_start; /* first byte of the value (== val_end if none) */ 44 size_t val_end; /* one past last byte of value (ws trimmed) */ 45 size_t term; /* index of the terminator (`\n', `#', `;', EOF) */ 46 size_t line_end; /* one past the terminating newline (for removal) */ 47 uint32_t line; /* 1-based line number of the directive */ 48 enum bsdconf_op op; /* assignment operator of the statement */ 49 bool have_value; /* a value was present */ 50 bool have_equals; /* an `=' separated directive/value */ 51 }; 52 53 /* Statement scan / put helpers (bsdconf_stmt.c) */ 54 const char *bsdconf_op_token(enum bsdconf_op _op); 55 int bsdconf_writeall(int _fd, const void *_data, size_t _len); 56 char *bsdconf_readfile(int _fd, size_t _size, size_t *_lenp); 57 int bsdconf_emit(int _fd, const void *_data, size_t _len, 58 int *_last); 59 int bsdconf_ensure_tmp(int *_tmpfdp, char *_tpath, size_t _tpathsz, 60 const char *_rpath, const struct stat *_sb); 61 char *bsdconf_format_value(const struct bsdconf_option *_option, 62 bool _unquoted, bool _quote_always, bool _bsemicolon); 63 int bsdconf_value_empty(const struct bsdconf_option *_option); 64 int bsdconf_dir_matches(const char *_buf, size_t _start, 65 size_t _end, const char *_directive, bool _case_sensitive); 66 int bsdconf_scan(const char *_buf, size_t _len, size_t *_ip, 67 uint32_t *_linep, bool _bequals, bool _bsemicolon, 68 bool _strict_equals, bool _operator_equals, 69 struct bsdconf_stmt *_st); 70 71 #endif /* !_BSDCONF_INTERNAL_H_ */ 72