Skip to content

Commit

Permalink
writer: fix ubuntu problems
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jan 22, 2012
1 parent 5d7ce83 commit 70a1a46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <fcntl.h> /* open */
#include <unistd.h> /* close, write, read */
#include <sys/stat.h> /* S_IWUSR, S_IRUSR */
#include <stdlib.h> /* malloc, free */
#include <stdio.h> /* sprintf */
#include <string.h> /* memset */
Expand All @@ -21,8 +22,8 @@ int bp__writer_create(bp__writer_t* w, const char* filename) {
memcpy(w->filename, filename, filename_length);

w->fd = open(filename,
O_RDWR | O_APPEND | O_CREAT | O_EXLOCK,
S_IWRITE | S_IREAD);
O_RDWR | O_APPEND | O_CREAT,
S_IWUSR | S_IRUSR);
if (w->fd == -1) goto error;

/* Determine filesize */
Expand Down Expand Up @@ -97,7 +98,7 @@ int bp__writer_read(bp__writer_t* w,
const uint64_t offset,
uint64_t* size,
void** data) {
ssize_t read;
ssize_t bytes_read;
char* cdata;

if (w->filesize < offset + *size) return BP_EFILEREAD_OOB;
Expand All @@ -111,8 +112,10 @@ int bp__writer_read(bp__writer_t* w,
cdata = malloc(*size);
if (cdata == NULL) return BP_EALLOC;

read = pread(w->fd, cdata, (size_t) *size, (off_t) offset);
if ((uint64_t) read != *size) {
if (lseek(w->fd, (off_t) offset, SEEK_SET) == -1) return BP_EFILE;

bytes_read = read(w->fd, cdata, (size_t) *size);
if ((uint64_t) bytes_read != *size) {
free(cdata);
return BP_EFILEREAD;
}
Expand Down
2 changes: 1 addition & 1 deletion test/corruption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TEST_START("database corruption test", "db-corrupt")
assert(bp_close(&db) == BP_OK);

/* corrupt file by zeroing last 2k bytes of it */
fd = open(__db_file, O_RDWR, S_IWRITE | S_IREAD);
fd = open(__db_file, O_RDWR, S_IWUSR | S_IRUSR);
assert(fd != -1);

char buff[13589];
Expand Down
2 changes: 2 additions & 0 deletions test/test.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <bplus.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/stat.h>

#include <assert.h>

Expand Down

0 comments on commit 70a1a46

Please sign in to comment.