xref: /openbmc/phosphor-mboxd/test/tmpf.h (revision acdbdd14)
1*4fe996c2SAndrew Jeffery /* SPDX-License-Identifier: Apache-2.0 */
2*4fe996c2SAndrew Jeffery /* Copyright (C) 2018 IBM Corp. */
345cfc384SAndrew Jeffery 
445cfc384SAndrew Jeffery #ifndef MBOX_TEST_UTILS_H
545cfc384SAndrew Jeffery #define MBOX_TEST_UTILS_H
645cfc384SAndrew Jeffery 
745cfc384SAndrew Jeffery #include <linux/limits.h>
845cfc384SAndrew Jeffery 
945cfc384SAndrew Jeffery struct tmpf {
1045cfc384SAndrew Jeffery 	int fd;
1145cfc384SAndrew Jeffery 	char path[PATH_MAX];
1245cfc384SAndrew Jeffery };
1345cfc384SAndrew Jeffery 
14c3144042SAndrew Jeffery /**
15c3144042SAndrew Jeffery  * Initialise a tmpf instance for use, creating a temporary file.
16c3144042SAndrew Jeffery  *
17c3144042SAndrew Jeffery  * @tmpf: A context to initialise with the provided template
18c3144042SAndrew Jeffery  * @template_str: A file basename in mkstemp(3) template form
19c3144042SAndrew Jeffery  *
20c3144042SAndrew Jeffery  * Returns 0 on success, or -1 on error with errno set appropriately
21c3144042SAndrew Jeffery  */
2290b92fe4SRatan Gupta int tmpf_init(struct tmpf *tmpf, const char *template_str);
2345cfc384SAndrew Jeffery 
24c3144042SAndrew Jeffery /**
25c3144042SAndrew Jeffery  * Destroy a tmpf instance, closing the file descriptor and removing the
26c3144042SAndrew Jeffery  * temporary file.
27c3144042SAndrew Jeffery  */
2845cfc384SAndrew Jeffery void tmpf_destroy(struct tmpf *tmpf);
2945cfc384SAndrew Jeffery 
3045cfc384SAndrew Jeffery #endif /* MBOX_TEST_UTILS_H */
31