[LTP] [PATCH 1/6] Add safe macros for stream testing suite
Cyril Hrubis
chrubis@suse.cz
Thu Feb 19 13:31:40 CET 2026
Hi!
> Introduce the following SAFE_* macros for stream file testing:
>
> - SAFE_FREAD
> - SAFE_FWRITE
> - SAFE_FREOPEN
> - SAFE_FSEEK
> - SAFE_FTELL
> - SAFE_FILENO
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> include/safe_stdio_fn.h | 18 ++++++++++
> include/tst_safe_stdio.h | 18 ++++++++++
> lib/safe_stdio.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 123 insertions(+)
>
> diff --git a/include/safe_stdio_fn.h b/include/safe_stdio_fn.h
> index 3818a86571a6d9bc63fcf432c93683bb3298e5b2..79c08080fd16489ea5bd1606083ae900ba3b294f 100644
> --- a/include/safe_stdio_fn.h
> +++ b/include/safe_stdio_fn.h
> @@ -32,4 +32,22 @@ int safe_asprintf(const char *file, const int lineno, void (cleanup_fn)(void),
> FILE *safe_popen(const char *file, const int lineno, void (cleanup_fn)(void),
> const char *command, const char *type);
>
> +size_t safe_fread(const char *file, const int lineno, void (cleanup_fn)(void),
> + void *ptr, size_t size, size_t n, FILE *stream);
> +
> +size_t safe_fwrite(const char *file, const int lineno, void (cleanup_fn)(void),
> + const void *ptr, size_t size, size_t n, FILE *stream);
> +
> +FILE *safe_freopen(const char *file, const int lineno, void (cleanup_fn)(void),
> + const char *path, const char *mode, FILE *stream);
> +
> +int safe_fseek(const char *file, const int lineno, void (cleanup_fn)(void),
> + FILE *f, long offset, int whence);
> +
> +long safe_ftell(const char *file, const int lineno, void (cleanup_fn)(void),
> + FILE *f);
> +
> +int safe_fileno(const char *file, const int lineno, void (cleanup_fn)(void),
> + FILE *stream);
Newly added safe macros shouldn't add the cleanup_fn parameter, that is
kept only in the legacy macros that are stil used in the old library
tests.
Otherwise: Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list