145cfc384SAndrew Jeffery /* 245cfc384SAndrew Jeffery * Mailbox Daemon Temporary File helpers 345cfc384SAndrew Jeffery * 445cfc384SAndrew Jeffery * Copyright 2017 IBM 545cfc384SAndrew Jeffery * 645cfc384SAndrew Jeffery * Licensed under the Apache License, Version 2.0 (the "License"); 745cfc384SAndrew Jeffery * you may not use this file except in compliance with the License. 845cfc384SAndrew Jeffery * You may obtain a copy of the License at 945cfc384SAndrew Jeffery * 1045cfc384SAndrew Jeffery * http://www.apache.org/licenses/LICENSE-2.0 1145cfc384SAndrew Jeffery * 1245cfc384SAndrew Jeffery * Unless required by applicable law or agreed to in writing, software 1345cfc384SAndrew Jeffery * distributed under the License is distributed on an "AS IS" BASIS, 1445cfc384SAndrew Jeffery * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1545cfc384SAndrew Jeffery * See the License for the specific language governing permissions and 1645cfc384SAndrew Jeffery * limitations under the License. 1745cfc384SAndrew Jeffery * 1845cfc384SAndrew Jeffery */ 1945cfc384SAndrew Jeffery 2045cfc384SAndrew Jeffery #ifndef MBOX_TEST_UTILS_H 2145cfc384SAndrew Jeffery #define MBOX_TEST_UTILS_H 2245cfc384SAndrew Jeffery 2345cfc384SAndrew Jeffery #include <linux/limits.h> 2445cfc384SAndrew Jeffery 2545cfc384SAndrew Jeffery struct tmpf { 2645cfc384SAndrew Jeffery int fd; 2745cfc384SAndrew Jeffery char path[PATH_MAX]; 2845cfc384SAndrew Jeffery }; 2945cfc384SAndrew Jeffery 30*c3144042SAndrew Jeffery /** 31*c3144042SAndrew Jeffery * Initialise a tmpf instance for use, creating a temporary file. 32*c3144042SAndrew Jeffery * 33*c3144042SAndrew Jeffery * @tmpf: A context to initialise with the provided template 34*c3144042SAndrew Jeffery * @template_str: A file basename in mkstemp(3) template form 35*c3144042SAndrew Jeffery * 36*c3144042SAndrew Jeffery * Returns 0 on success, or -1 on error with errno set appropriately 37*c3144042SAndrew Jeffery */ 3890b92fe4SRatan Gupta int tmpf_init(struct tmpf *tmpf, const char *template_str); 3945cfc384SAndrew Jeffery 40*c3144042SAndrew Jeffery /** 41*c3144042SAndrew Jeffery * Destroy a tmpf instance, closing the file descriptor and removing the 42*c3144042SAndrew Jeffery * temporary file. 43*c3144042SAndrew Jeffery */ 4445cfc384SAndrew Jeffery void tmpf_destroy(struct tmpf *tmpf); 4545cfc384SAndrew Jeffery 4645cfc384SAndrew Jeffery #endif /* MBOX_TEST_UTILS_H */ 47