blob: 9232e3ee066b0754a2b145645d48c333f6ae2a66 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301/* SPDX-License-Identifier: Apache-2.0 */
2/* Copyright (C) 2018 IBM Corp. */
Andrew Jeffery45cfc382017-04-12 14:15:50 +09303
4#ifndef MBOX_TEST_UTILS_H
5#define MBOX_TEST_UTILS_H
6
7#include <linux/limits.h>
8
9struct tmpf {
10 int fd;
11 char path[PATH_MAX];
12};
13
Andrew Jefferyc3144042018-02-26 13:24:52 +103014/**
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 Gupta90b92fe2017-05-05 17:34:00 +053022int tmpf_init(struct tmpf *tmpf, const char *template_str);
Andrew Jeffery45cfc382017-04-12 14:15:50 +093023
Andrew Jefferyc3144042018-02-26 13:24:52 +103024/**
25 * Destroy a tmpf instance, closing the file descriptor and removing the
26 * temporary file.
27 */
Andrew Jeffery45cfc382017-04-12 14:15:50 +093028void tmpf_destroy(struct tmpf *tmpf);
29
30#endif /* MBOX_TEST_UTILS_H */