From 7ed28d2f501a4920b792bee9da3d61814f024a4c Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Tue, 7 Oct 2025 05:38:30 -0500 Subject: add mkstemp for msvc builds --- tests/compat/mkstemp.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/compat/mkstemp.c (limited to 'tests/compat') diff --git a/tests/compat/mkstemp.c b/tests/compat/mkstemp.c new file mode 100644 index 0000000..fe3d15a --- /dev/null +++ b/tests/compat/mkstemp.c @@ -0,0 +1,52 @@ +/* +musl as a whole is licensed under the following standard MIT license: + +---------------------------------------------------------------------- +Copyright © 2005-2020 Rich Felker, et al. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +---------------------------------------------------------------------- +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +int mkstemp(char *template) +{ + int fd; +retry: + if (!_mktemp(template)) return -1; + fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600); + if (fd >= 0) return fd; + if (errno == EEXIST) { + /* this is safe because mktemp verified + * that we have a valid template string */ + strcpy(template+strlen(template)-6, "XXXXXX"); + goto retry; + } + return -1; +} -- cgit v1.2.3-55-g6feb