Permalink
Browse files

Provide fallback mkostemp() implementation

Fixes #938
  • Loading branch information...
krader1961 committed Oct 9, 2018
1 parent ddff59e commit 4384f6476f153c0cee5844138847a30b184197cd
Showing with 45 additions and 2 deletions.
  1. +1 −0 config_ast.h.in
  2. +2 −0 features/meson.build
  3. +40 −0 src/lib/libast/misc/fallbacks.c
  4. +1 −1 src/lib/libast/misc/meson.build
  5. +1 −1 src/lib/libast/path/pathtemp.c
View
@@ -102,6 +102,7 @@
#mesondefine _lib_lstat64
#mesondefine _lib_memcntl
#mesondefine _lib_mmap64
#mesondefine _lib_mkostemp
#mesondefine _lib_open64
#mesondefine _lib_opendir
#mesondefine _lib_pathnative
View
@@ -63,6 +63,8 @@ if not cc.has_function('isnanl', prefix: '#include <math.h>', args: feature_test
feature_data.set('isnanl', 'isnan')
endif
feature_data.set10('_lib_mkostemp',
cc.has_function('mkostemp', prefix: '#include <unistd.h>', args: feature_test_args))
feature_data.set10('_lib_strlcat',
cc.has_function('strlcat', prefix: '#include <string.h>', args: feature_test_args))
feature_data.set10('_lib_utimensat',
@@ -0,0 +1,40 @@
//
// This module contains fallback implementations of functions used elsewhere in the code.
// Each fallback implementation is only enabled if the system doesn't provide it.
//
#include "config_ast.h" // IWYU pragma: keep
// We keep all these includes because it's simpler and cleaner to do this than wrap them in
// `#if !_lib_mkostemp` type pragmas.
#include <stdio.h> // IWYU pragma: keep
#include <stdlib.h> // IWYU pragma: keep
#include <string.h> // IWYU pragma: keep
#include <unistd.h> // IWYU pragma: keep
#include "ast.h" // IWYU pragma: keep
#include "ast_assert.h" // IWYU pragma: keep
//
// We define this symbol, which is otherwise unused, to ensure this module isn't empty. That's
// because empty modules can cause build time warnings.
//
void do_not_use_this_fallback() {
abort();
}
#if !_lib_mkostemp
// This is a fallback in case the system doesn't provide it.
static_fn int mkostemp(char *template, int oflags) {
for (int i = 10; i; i--) {
#ifndef __clang_analyzer__
// cppcheck-suppress mktempCalled
char *tp = mktemp(template);
assert(tp);
#endif
int fd = open(template, O_CREAT | O_RDWR | O_EXCL | oflags, S_IRUSR | S_IWUSR);
if (fd != -1) return fd;
}
return -1;
}
#endif // !_lib_mkostemp
@@ -8,7 +8,7 @@ libast_files += [
'misc/sigcrit.c',
'misc/stack.c', 'misc/state.c',
'misc/stk.c', 'misc/translate.c', 'misc/univdata.c',
'misc/fts.c', 'misc/vmbusy.c'
'misc/fts.c', 'misc/vmbusy.c', 'misc/fallbacks.c'
]
if not shared_c_args.contains('-D_AST_no_spawnveg=1')
@@ -89,7 +89,7 @@ char *ast_temp_file(const char *dir, const char *prefix, int *fd, int open_flags
strcat(template, TEMPLATE);
if (fd) {
*fd = mkostemps(template, 0, open_flags);
*fd = mkostemp(template, open_flags);
if (*fd == -1) {
free(template);
return NULL;

0 comments on commit 4384f64

Please sign in to comment.