Commit f75846df authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov

ioping: add mkostemp

some crappy OSes don't have one.
Signed-off-by: default avatarKonstantin Khlebnikov <koct9i@gmail.com>
parent e890bea4
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
# define HAVE_CLOCK_GETTIME # define HAVE_CLOCK_GETTIME
# define HAVE_POSIX_FADVICE # define HAVE_POSIX_FADVICE
# define HAVE_POSIX_MEMALIGN # define HAVE_POSIX_MEMALIGN
# define HAVE_MKOSTEMP
# define HAVE_DIRECT_IO # define HAVE_DIRECT_IO
# define HAVE_LINUX_ASYNC_IO # define HAVE_LINUX_ASYNC_IO
# define HAVE_ERR_INCLUDE # define HAVE_ERR_INCLUDE
...@@ -62,6 +63,7 @@ ...@@ -62,6 +63,7 @@
# include <sys/ioctl.h> # include <sys/ioctl.h>
# define HAVE_CLOCK_GETTIME # define HAVE_CLOCK_GETTIME
# define HAVE_POSIX_MEMALIGN # define HAVE_POSIX_MEMALIGN
# define HAVE_MKOSTEMP
# define HAVE_ERR_INCLUDE # define HAVE_ERR_INCLUDE
#endif #endif
...@@ -70,6 +72,7 @@ ...@@ -70,6 +72,7 @@
# include <sys/mount.h> # include <sys/mount.h>
# include <sys/disk.h> # include <sys/disk.h>
# define HAVE_CLOCK_GETTIME # define HAVE_CLOCK_GETTIME
# define HAVE_MKOSTEMP
# define HAVE_DIRECT_IO # define HAVE_DIRECT_IO
# define HAVE_ERR_INCLUDE # define HAVE_ERR_INCLUDE
#endif #endif
...@@ -77,6 +80,7 @@ ...@@ -77,6 +80,7 @@
#ifdef __DragonFly__ #ifdef __DragonFly__
# include <sys/diskslice.h> # include <sys/diskslice.h>
# define HAVE_CLOCK_GETTIME # define HAVE_CLOCK_GETTIME
# define HAVE_MKOSTEMP
# define HAVE_ERR_INCLUDE # define HAVE_ERR_INCLUDE
#endif #endif
...@@ -88,6 +92,7 @@ ...@@ -88,6 +92,7 @@
# include <sys/mount.h> # include <sys/mount.h>
# define HAVE_CLOCK_GETTIME # define HAVE_CLOCK_GETTIME
# define HAVE_POSIX_MEMALIGN # define HAVE_POSIX_MEMALIGN
# define HAVE_MKOSTEMP
# define HAVE_ERR_INCLUDE # define HAVE_ERR_INCLUDE
#endif #endif
...@@ -114,6 +119,7 @@ ...@@ -114,6 +119,7 @@
# include <stdarg.h> # include <stdarg.h>
# include <windows.h> # include <windows.h>
# define HAVE_DIRECT_IO # define HAVE_DIRECT_IO
# define HAVE_MKOSTEMP /* not required */
#endif #endif
#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 #if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
...@@ -188,6 +194,19 @@ static inline long long now(void) ...@@ -188,6 +194,19 @@ static inline long long now(void)
#endif /* HAVE_CLOCK_GETTIME */ #endif /* HAVE_CLOCK_GETTIME */
#ifndef HAVE_MKOSTEMP
int mkostemp(char *template, int flags)
{
int fd;
fd = mkstemp(template);
if (!flags || fd < 0)
return fd;
close(fd);
return open(template, O_RDWR | flags);
}
#endif
int async = 0; int async = 0;
#ifdef __MINGW32__ #ifdef __MINGW32__
...@@ -912,10 +931,7 @@ int open_file(const char *path, const char *temp) ...@@ -912,10 +931,7 @@ int open_file(const char *path, const char *temp)
{ {
char *file_path = NULL; char *file_path = NULL;
int length, fd; int length, fd;
int flags = O_RDWR; int flags = 0;
if (!temp && !write_test)
flags = O_RDONLY;
#ifdef O_SYNC #ifdef O_SYNC
if (syncio) if (syncio)
...@@ -928,7 +944,7 @@ int open_file(const char *path, const char *temp) ...@@ -928,7 +944,7 @@ int open_file(const char *path, const char *temp)
#endif #endif
if (!temp) { if (!temp) {
fd = open(path, flags); fd = open(path, (write_test ? O_RDWR : O_RDONLY) | flags);
if (fd < 0) if (fd < 0)
goto out; goto out;
goto done; goto done;
...@@ -941,14 +957,14 @@ int open_file(const char *path, const char *temp) ...@@ -941,14 +957,14 @@ int open_file(const char *path, const char *temp)
snprintf(file_path, length, "%s/%s", path, temp); snprintf(file_path, length, "%s/%s", path, temp);
if (keep_file) { if (keep_file) {
fd = open(file_path, flags | O_CREAT, 0600); fd = open(file_path, O_RDWR | O_CREAT | flags, 0600);
if (fd < 0) if (fd < 0)
goto out; goto out;
goto done; goto done;
} }
#ifdef O_TMPFILE #ifdef O_TMPFILE
fd = open(path, flags | O_TMPFILE, 0600); fd = open(path, O_RDWR | O_TMPFILE | flags, 0600);
if (fd >= 0) if (fd >= 0)
goto done; goto done;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment