Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions libscws/xdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#include "config.h"
#endif

#ifdef WIN32
# include "config_win32.h"
#include "config_win32.h"
#endif

#include "xdb.h"
#include "lock.h"
#include <stdio.h>
#include <stdlib.h>
#ifndef WIN32
# include <unistd.h>
#include <sys/file.h>
#include <unistd.h>
#endif
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

#ifdef HAVE_FLOCK
# include <sys/file.h>
#include <sys/file.h>
#endif

#ifdef HAVE_MMAP
# include <sys/mman.h>
#include <sys/mman.h>
#endif

static int _xdb_hasher(xdb_t x, const char *s, int len)
Expand All @@ -57,8 +58,10 @@ static void _xdb_read_data(xdb_t x, void *buf, unsigned int off, int len)

if (x->fd >= 0)
{
lseek(x->fd, off, SEEK_SET);
read(x->fd, buf, len);
if (lseek(x->fd, off, SEEK_SET) == -1)
return;
if (read(x->fd, buf, len) != len)
return;
}
else
{
Expand Down Expand Up @@ -132,7 +135,11 @@ xdb_t xdb_open(const char *fpath, int mode)
return NULL;

/* try to open & check the file */
#ifdef WIN32
if ((x->fd = open(fpath, mode == 'w' ? O_RDWR|O_BINARY : O_RDONLY|O_BINARY)) < 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O_BINARY: the 'binary' mode flag on Windows, this flag only exist in Windows platform.
Ref : https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx

#else //WIN32
if ((x->fd = open(fpath, mode == 'w' ? O_RDWR : O_RDONLY)) < 0)
#endif //WIN32
{
#ifdef DEBUG
perror("Failed to open the XDB file");
Expand Down