Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 */ |
| 2 | /* Copyright (C) 2018 IBM Corp. */ |
Andrew Jeffery | 45cfc38 | 2017-04-12 14:15:50 +0930 | [diff] [blame] | 3 | |
| 4 | #ifndef MBOX_TEST_UTILS_H |
| 5 | #define MBOX_TEST_UTILS_H |
| 6 | |
| 7 | #include <linux/limits.h> |
| 8 | |
| 9 | struct tmpf { |
| 10 | int fd; |
| 11 | char path[PATH_MAX]; |
| 12 | }; |
| 13 | |
Andrew Jeffery | c314404 | 2018-02-26 13:24:52 +1030 | [diff] [blame] | 14 | /** |
| 15 | * Initialise a tmpf instance for use, creating a temporary file. |
| 16 | * |
| 17 | * @tmpf: A context to initialise with the provided template |
| 18 | * @template_str: A file basename in mkstemp(3) template form |
| 19 | * |
| 20 | * Returns 0 on success, or -1 on error with errno set appropriately |
| 21 | */ |
Ratan Gupta | 90b92fe | 2017-05-05 17:34:00 +0530 | [diff] [blame] | 22 | int tmpf_init(struct tmpf *tmpf, const char *template_str); |
Andrew Jeffery | 45cfc38 | 2017-04-12 14:15:50 +0930 | [diff] [blame] | 23 | |
Andrew Jeffery | c314404 | 2018-02-26 13:24:52 +1030 | [diff] [blame] | 24 | /** |
| 25 | * Destroy a tmpf instance, closing the file descriptor and removing the |
| 26 | * temporary file. |
| 27 | */ |
Andrew Jeffery | 45cfc38 | 2017-04-12 14:15:50 +0930 | [diff] [blame] | 28 | void tmpf_destroy(struct tmpf *tmpf); |
| 29 | |
| 30 | #endif /* MBOX_TEST_UTILS_H */ |