Re: [LTP] [PATCH] Add tst_tmpdir_path() and tst_tmpdir_mkpath()

Petr Vorel
2024-07-17T08:26:09Z

Hi Cyril,

> - tst_tmpdir_path() creates a singleton string copy of the library
> internal path and returns pointer to it on all subsequent calls.

> - tst_tmpdir_mkpath() constructs a path from the temporary directory
> path and printf-like format paramters.

> - both functions use guarded buffers to allocate the memory, which
> especially means that there is no reason to free these strings at
> the program end.

> - all new library tests are converted to the new API

> + macro is added for new library that fails compilation if old API
> function is used

> This should solve the absolute temporary directory path handling once
> for all.

Thanks for this! No need for free(), no need to use asprintf() :).

...

> +/**
> + * tst_tmpdir_path - Returns a pointer to a tmpdir path.
> + *
> + * The returned path is allocated and initialized the first time this function is
> + * called, each subsequent call will return the same pointer.
> + *
> + * @return A newly allocated path. The memory is freed automatically at the end
Return must be 'return:', otherwise it's not recognised.

* return: A newly allocated path. The memory is freed automatically at the end

> + * of the test. If allocation fails the function calls tst_brk() and
> + * exits the test.
> + */
> +char *tst_tmpdir_path(void);
> +
> +/**
> + * tst_tmpdir_mkpath - Construct an absolute path pointing to a file inside tmpdir.
> + *
> + * Constructs a path inside tmpdir i.e. adds a prefix pointing to the current
> + * test tmpdir to the string build by the printf-like format.
> + *
> + * @fmt A printf-like format string.
> + * @... A printf-like parameter list.
NOTE: parameters need ':', otherwise it will not be recognised.

* @fmt: A printf-like format string.
* @...: A printf-like parameter list.

> + *
> + * @return A newly allocated path. The memory is freed automatically at the end
and here 'return:' as well

It's always safer to generate docs and check it.

With these fixes:
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr