mirror of
				https://github.com/stedolan/jq.git
				synced 2024-05-11 05:55:39 +00:00 
			
		
		
		
	Add mkstemp() for mingw build
This commit is contained in:
		@@ -86,6 +86,7 @@ if test "x$valgrind_cmd" = "x" ; then
 | 
			
		||||
    AC_MSG_WARN([valgrind is required to test jq.])
 | 
			
		||||
fi
 | 
			
		||||
AC_CHECK_FUNCS(memmem)
 | 
			
		||||
AC_CHECK_FUNCS(mkstemp)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
dnl Don't attempt to build docs if there's no Ruby lying around
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								util.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								util.c
									
									
									
									
									
								
							@@ -1,9 +1,13 @@
 | 
			
		||||
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_MEMMEM
 | 
			
		||||
#define _GNU_SOURCE
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#endif
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#ifndef WIN32
 | 
			
		||||
#include <pwd.h>
 | 
			
		||||
#endif
 | 
			
		||||
@@ -15,6 +19,27 @@
 | 
			
		||||
#include "util.h"
 | 
			
		||||
#include "jv.h"
 | 
			
		||||
 | 
			
		||||
#ifndef HAVE_MKSTEMP
 | 
			
		||||
int mkstemp(char *template) {
 | 
			
		||||
  size_t len = strlen(template);
 | 
			
		||||
  int tries=5;
 | 
			
		||||
  int fd;
 | 
			
		||||
 | 
			
		||||
  // mktemp() truncates template when it fails
 | 
			
		||||
  char *s = alloca(len + 1);
 | 
			
		||||
  assert(s != NULL);
 | 
			
		||||
  strcpy(s, template);
 | 
			
		||||
 | 
			
		||||
  do {
 | 
			
		||||
    // Restore template
 | 
			
		||||
    strcpy(template, s);
 | 
			
		||||
    (void) mktemp(template);
 | 
			
		||||
    fd = open(template, O_CREAT | O_EXCL | O_RDWR, 0600);
 | 
			
		||||
  } while (fd == -1 && tries-- > 0);
 | 
			
		||||
  return fd;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
jv expand_path(jv path) {
 | 
			
		||||
  assert(jv_get_kind(path) == JV_KIND_STRING);
 | 
			
		||||
  const char *pstr = jv_string_value(path);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user