diff options
| author | Brent Cook <busterb@gmail.com> | 2025-10-07 05:38:30 -0500 |
|---|---|---|
| committer | Brent Cook <busterb@gmail.com> | 2025-10-07 05:38:30 -0500 |
| commit | 7ed28d2f501a4920b792bee9da3d61814f024a4c (patch) | |
| tree | b5ff3f835188bb8ba3a00a9d7185a3762ffa6c15 | |
| parent | 659e87fe1cf3348a4e9f1bacfe205316fefd8a51 (diff) | |
| download | portable-7ed28d2f501a4920b792bee9da3d61814f024a4c.tar.gz portable-7ed28d2f501a4920b792bee9da3d61814f024a4c.tar.bz2 portable-7ed28d2f501a4920b792bee9da3d61814f024a4c.zip | |
add mkstemp for msvc builds
| -rw-r--r-- | include/compat/unistd.h | 2 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 21 | ||||
| -rw-r--r-- | tests/compat/mkstemp.c | 52 |
3 files changed, 63 insertions, 12 deletions
diff --git a/include/compat/unistd.h b/include/compat/unistd.h index 63c07fc..544cb27 100644 --- a/include/compat/unistd.h +++ b/include/compat/unistd.h | |||
| @@ -45,6 +45,8 @@ static inline unsigned int sleep(unsigned int seconds) | |||
| 45 | Sleep(seconds * 1000); | 45 | Sleep(seconds * 1000); |
| 46 | return seconds; | 46 | return seconds; |
| 47 | } | 47 | } |
| 48 | |||
| 49 | int mkstemp(char *template); | ||
| 48 | #endif | 50 | #endif |
| 49 | 51 | ||
| 50 | int ftruncate(int fd, off_t length); | 52 | int ftruncate(int fd, off_t length); |
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 55529cd..7f9b93c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
| @@ -82,6 +82,9 @@ endfunction() | |||
| 82 | 82 | ||
| 83 | # XXX - should probably be in their own static lib | 83 | # XXX - should probably be in their own static lib |
| 84 | set(TEST_HELPER_SRC test.c test_util.c) | 84 | set(TEST_HELPER_SRC test.c test_util.c) |
| 85 | if(WIN32) | ||
| 86 | set(TEST_HELPER_SRC ${TEST_HELPER_SRC} compat/mkstemp.c) | ||
| 87 | endif() | ||
| 85 | 88 | ||
| 86 | # aeadtest | 89 | # aeadtest |
| 87 | add_executable(aeadtest aeadtest.c) | 90 | add_executable(aeadtest aeadtest.c) |
| @@ -555,12 +558,9 @@ prepare_emscripten_test_target(lhash_test) | |||
| 555 | add_platform_test(lhash_test lhash_test) | 558 | add_platform_test(lhash_test lhash_test) |
| 556 | 559 | ||
| 557 | # md_test | 560 | # md_test |
| 558 | # XXX - ftruncate and mkstemp missing from Windows | 561 | add_executable(md_test md_test.c ${TEST_HELPER_SRC}) |
| 559 | if(NOT WIN32) | 562 | target_link_libraries(md_test ${OPENSSL_TEST_LIBS}) |
| 560 | add_executable(md_test md_test.c ${TEST_HELPER_SRC}) | 563 | add_platform_test(md_test md_test) |
| 561 | target_link_libraries(md_test ${OPENSSL_TEST_LIBS}) | ||
| 562 | add_platform_test(md_test md_test) | ||
| 563 | endif() | ||
| 564 | 564 | ||
| 565 | # mlkem_tests | 565 | # mlkem_tests |
| 566 | add_executable(mlkem_tests mlkem_tests.c parse_test_file.c) | 566 | add_executable(mlkem_tests mlkem_tests.c parse_test_file.c) |
| @@ -742,12 +742,9 @@ endif() | |||
| 742 | set_tests_properties(servertest PROPERTIES ENVIRONMENT "srcdir=${TEST_SOURCE_DIR}") | 742 | set_tests_properties(servertest PROPERTIES ENVIRONMENT "srcdir=${TEST_SOURCE_DIR}") |
| 743 | 743 | ||
| 744 | # sha_test | 744 | # sha_test |
| 745 | # XXX - ftruncate and mkstemp missing from Windows | 745 | add_executable(sha_test sha_test.c ${TEST_HELPER_SRC}) |
| 746 | if(NOT WIN32) | 746 | target_link_libraries(sha_test ${OPENSSL_TEST_LIBS}) |
| 747 | add_executable(sha_test sha_test.c ${TEST_HELPER_SRC}) | 747 | add_platform_test(sha_test sha_test) |
| 748 | target_link_libraries(sha_test ${OPENSSL_TEST_LIBS}) | ||
| 749 | add_platform_test(sha_test sha_test) | ||
| 750 | endif() | ||
| 751 | 748 | ||
| 752 | # shutdowntest | 749 | # shutdowntest |
| 753 | set(SHUTDOWNTEST_SRC shutdowntest.c) | 750 | set(SHUTDOWNTEST_SRC shutdowntest.c) |
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 @@ | |||
| 1 | /* | ||
| 2 | musl as a whole is licensed under the following standard MIT license: | ||
| 3 | |||
| 4 | ---------------------------------------------------------------------- | ||
| 5 | Copyright © 2005-2020 Rich Felker, et al. | ||
| 6 | |||
| 7 | Permission is hereby granted, free of charge, to any person obtaining | ||
| 8 | a copy of this software and associated documentation files (the | ||
| 9 | "Software"), to deal in the Software without restriction, including | ||
| 10 | without limitation the rights to use, copy, modify, merge, publish, | ||
| 11 | distribute, sublicense, and/or sell copies of the Software, and to | ||
| 12 | permit persons to whom the Software is furnished to do so, subject to | ||
| 13 | the following conditions: | ||
| 14 | |||
| 15 | The above copyright notice and this permission notice shall be | ||
| 16 | included in all copies or substantial portions of the Software. | ||
| 17 | |||
| 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 21 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 25 | ---------------------------------------------------------------------- | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <string.h> | ||
| 29 | #include <stdio.h> | ||
| 30 | #include <stdlib.h> | ||
| 31 | #include <fcntl.h> | ||
| 32 | #include <unistd.h> | ||
| 33 | #include <limits.h> | ||
| 34 | #include <errno.h> | ||
| 35 | |||
| 36 | #include <io.h> | ||
| 37 | |||
| 38 | int mkstemp(char *template) | ||
| 39 | { | ||
| 40 | int fd; | ||
| 41 | retry: | ||
| 42 | if (!_mktemp(template)) return -1; | ||
| 43 | fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600); | ||
| 44 | if (fd >= 0) return fd; | ||
| 45 | if (errno == EEXIST) { | ||
| 46 | /* this is safe because mktemp verified | ||
| 47 | * that we have a valid template string */ | ||
| 48 | strcpy(template+strlen(template)-6, "XXXXXX"); | ||
| 49 | goto retry; | ||
| 50 | } | ||
| 51 | return -1; | ||
| 52 | } | ||
