/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2020 Robert Manner <[email protected]>4*5* Permission to use, copy, modify, and distribute this software for any6* purpose with or without fee is hereby granted, provided that the above7* copyright notice and this permission notice appear in all copies.8*9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16*/1718#ifndef PYTHON_IO_HELPERS19#define PYTHON_IO_HELPERS2021#include <config.h>2223#include <stdio.h>24#include <stdlib.h>25#ifdef HAVE_STDBOOL_H26# include <stdbool.h>27#else28# include <compat/stdbool.h>29#endif /* HAVE_STDBOOL_H */30#include <string.h>31#include <stdarg.h>32#include <signal.h>33#include <pwd.h>3435#include <sudo_compat.h>3637#define MAX_OUTPUT (2 << 16)3839int rmdir_recursive(const char *path);4041int fwriteall(const char *file_path, const char *string);42int freadall(const char *file_path, char *output, size_t max_len);4344// allocates new string with the content of 'string' but 'old' replaced to 'new'45// The allocated array will be dest_length size and null terminated correctly.46char *str_replaced(const char *string, size_t dest_length, const char *old, const char *new);4748// same, but "string" must be able to store 'max_length' number of characters including the null terminator49void str_replace_in_place(char *string, size_t max_length, const char *old, const char *new);5051int vsnprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, va_list args);52int snprintf_append(char * restrict output, size_t max_output_len, const char * restrict fmt, ...);5354int str_array_count(char **str_array);55void str_array_snprint(char *out_str, size_t max_len, char **str_array, int array_len);5657#endif585960