Skip to content
Open
Changes from all 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
23 changes: 15 additions & 8 deletions libscws/xdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@
*/

#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

#ifndef O_BINARY
#define O_BINARY 0
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unify the O_BINARY macro for all platforms at the beginning of xdb.c


static int _xdb_hasher(xdb_t x, const char *s, int len)
Expand All @@ -57,8 +62,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 +139,7 @@ xdb_t xdb_open(const char *fpath, int mode)
return NULL;

/* try to open & check the file */
if ((x->fd = open(fpath, mode == 'w' ? O_RDWR : O_RDONLY)) < 0)
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.

The "#ifdef WIN32" around open(...O_BINARY...) no longer needed.

{
#ifdef DEBUG
perror("Failed to open the XDB file");
Expand Down