Coverage Report

Created: 2026-06-02 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/main/php_ini_builder.h
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Authors: Max Kellermann <max.kellermann@ionos.com>                   |
12
   +----------------------------------------------------------------------+
13
*/
14
15
#ifndef PHP_INI_BUILDER_H
16
#define PHP_INI_BUILDER_H
17
18
#include "php.h"
19
20
/**
21
 * A class which helps with constructing INI entries from the command
22
 * line.
23
 */
24
struct php_ini_builder {
25
  char *value;
26
  size_t length;
27
};
28
29
BEGIN_EXTERN_C()
30
31
static inline void php_ini_builder_init(struct php_ini_builder *b)
32
0
{
33
0
  b->value = NULL;
34
0
  b->length = 0;
35
0
}
36
37
static inline void php_ini_builder_deinit(struct php_ini_builder *b)
38
0
{
39
0
  free(b->value);
40
0
}
41
42
/**
43
 * Null-terminate the buffer and return it.
44
 */
45
static inline char *php_ini_builder_finish(struct php_ini_builder *b)
46
0
{
47
0
  if (b->value != NULL) {
48
0
    /* null-terminate the string */
49
0
    b->value[b->length] = '\0';
50
0
  }
51
0
52
0
  return b->value;
53
0
}
54
55
/**
56
 * Make room for more data.
57
 *
58
 * @param delta the number of bytes to be appended
59
 */
60
static inline void php_ini_builder_realloc(struct php_ini_builder *b, size_t delta)
61
0
{
62
  /* reserve enough space for the null terminator */
63
  b->value = perealloc(b->value, b->length + delta + 1, true);
64
0
}
65
66
/**
67
 * Prepend a string.
68
 *
69
 * @param src the source string
70
 * @param length the size of the source string
71
 */
72
PHPAPI void php_ini_builder_prepend(struct php_ini_builder *b, const char *src, size_t length);
73
74
#define php_ini_builder_prepend_literal(b, l) php_ini_builder_prepend(b, l, strlen(l))
75
76
/**
77
 * Append an unquoted name/value pair.
78
 */
79
PHPAPI void php_ini_builder_unquoted(struct php_ini_builder *b, const char *name, size_t name_length, const char *value, size_t value_length);
80
81
/**
82
 * Append a quoted name/value pair.
83
 */
84
PHPAPI void php_ini_builder_quoted(struct php_ini_builder *b, const char *name, size_t name_length, const char *value, size_t value_length);
85
86
/**
87
 * Parse an INI entry from the command-line option "--define".
88
 */
89
PHPAPI void php_ini_builder_define(struct php_ini_builder *b, const char *arg);
90
91
END_EXTERN_C()
92
93
#endif