Skip to content

Commit

Permalink
fix windows binary flag required
Browse files Browse the repository at this point in the history
  • Loading branch information
U-NORTHAMERICA\jcl authored and U-NORTHAMERICA\jcl committed Sep 28, 2012
1 parent e090890 commit 8aa96c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 0 additions & 4 deletions vowpalwabbit/cache.cc
Expand Up @@ -62,7 +62,6 @@ int read_cached_features(void* in, example* ec)
return 0;
if (read_cached_tag(*input,ae) == 0)
return 0;

char* c;
unsigned char num_indices = 0;
if (buf_read(*input, c, sizeof(num_indices)) < sizeof(num_indices))
Expand All @@ -71,7 +70,6 @@ int read_cached_features(void* in, example* ec)
c += sizeof(num_indices);

all->p->input->set(c);

for (;num_indices > 0; num_indices--)
{
size_t temp;
Expand Down Expand Up @@ -156,12 +154,10 @@ void output_byte(io_buf& cache, unsigned char s)
void output_features(io_buf& cache, unsigned char index, feature* begin, feature* end)
{
char* c;

size_t storage = (end-begin) * int_size;
for (feature* i = begin; i != end; i++)
if (i->x != 1. && i->x != -1.)
storage+=sizeof(float);

buf_write(cache, c, sizeof(index) + storage + sizeof(size_t));
*(unsigned char*)c = index;
c += sizeof(index);
Expand Down
19 changes: 14 additions & 5 deletions vowpalwabbit/io.h
Expand Up @@ -43,16 +43,24 @@ class io_buf {
}

virtual int open_file(const char* name, int flag=READ){
int ret;
int ret;
switch(flag){
case READ:
#ifdef _WIN32
ret = _open(name, _O_RDONLY|_O_BINARY);
#else
ret = open(name, O_RDONLY|O_LARGEFILE);
#endif
if(ret!=-1)
push(files,ret);
break;

case WRITE:
ret = open(name, O_CREAT|O_WRONLY|O_LARGEFILE|O_TRUNC,0666);
#ifdef _WIN32
ret = _open(name, _O_CREAT|_O_WRONLY|_O_BINARY|_O_TRUNC,0666);
#else
ret = open(name, O_CREAT|O_WRONLY|O_LARGEFILE|O_TRUNC,0666);
#endif
if(ret!=-1)
push(files,ret);
break;
Expand Down Expand Up @@ -82,7 +90,7 @@ class io_buf {
void set(char *p){space.end = p;}

virtual ssize_t read_file(int f, void* buf, size_t nbytes){
return read(f, buf, (unsigned int)nbytes);
return read(f, buf, (unsigned int)nbytes);
}

size_t fill(int f) {
Expand All @@ -102,12 +110,13 @@ class io_buf {
return 0;
}

virtual ssize_t write_file(int f, const void* buf, size_t nbytes){
virtual ssize_t write_file(int f, const void* buf, size_t nbytes)
{
return write(f, buf, (unsigned int)nbytes);
}

virtual void flush() {
if (write_file(files[0], space.begin, space.index()) != (int) space.index())
if (write_file(files[0], space.begin, space.index()) != (int) space.index())
std::cerr << "error, failed to write example\n";
space.end = space.begin; }

Expand Down

0 comments on commit 8aa96c5

Please sign in to comment.