Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/plugins/python/regress/iohelpers.h
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2020 Robert Manner <[email protected]>
5
*
6
* Permission to use, copy, modify, and distribute this software for any
7
* purpose with or without fee is hereby granted, provided that the above
8
* copyright notice and this permission notice appear in all copies.
9
*
10
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
19
#ifndef PYTHON_IO_HELPERS
20
#define PYTHON_IO_HELPERS
21
22
#include <config.h>
23
24
#include <stdio.h>
25
#include <stdlib.h>
26
#ifdef HAVE_STDBOOL_H
27
# include <stdbool.h>
28
#else
29
# include <compat/stdbool.h>
30
#endif /* HAVE_STDBOOL_H */
31
#include <string.h>
32
#include <stdarg.h>
33
#include <signal.h>
34
#include <pwd.h>
35
36
#include <sudo_compat.h>
37
38
#define MAX_OUTPUT (2 << 16)
39
40
int rmdir_recursive(const char *path);
41
42
int fwriteall(const char *file_path, const char *string);
43
int freadall(const char *file_path, char *output, size_t max_len);
44
45
// allocates new string with the content of 'string' but 'old' replaced to 'new'
46
// The allocated array will be dest_length size and null terminated correctly.
47
char *str_replaced(const char *string, size_t dest_length, const char *old, const char *new);
48
49
// same, but "string" must be able to store 'max_length' number of characters including the null terminator
50
void str_replace_in_place(char *string, size_t max_length, const char *old, const char *new);
51
52
int vsnprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, va_list args);
53
int snprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, ...);
54
55
int str_array_count(char **str_array);
56
void str_array_snprint(char *out_str, size_t max_len, char **str_array, int array_len);
57
58
#endif
59
60