Changeset da0fef6 in mainline for uspace/app/bithenge/file.c


Ignore:
Timestamp:
2012-06-23T18:24:21Z (13 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03b2b2c
Parents:
d5070ef
Message:

Bithenge: port to Linux and allow choosing a data source

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/file.c

    rd5070ef rda0fef6  
    3939#include <errno.h>
    4040#include <fcntl.h>
    41 #include <macros.h>
    4241#include <stdio.h>
    4342#include <stdlib.h>
    4443#include <sys/stat.h>
     44#include <sys/types.h>
     45#include <unistd.h>
    4546#include "blob.h"
    4647#include "file.h"
     48#include "os.h"
    4749
    4850typedef struct {
     
    7678        if (offset > blob->size)
    7779                return ELIMIT;
    78         *size = min(*size, blob->size - offset);
    79         int rc = lseek(blob->fd, offset, SEEK_SET);
    80         if (rc != EOK)
    81                 return rc;
    82         return read(blob->fd, buffer, *size);
     80        if (lseek(blob->fd, offset, SEEK_SET) < 0)
     81                return errno;
     82
     83        ssize_t amount_read;
     84        aoff64_t remaining_size = *size;
     85        *size = 0;
     86        do {
     87                amount_read = read(blob->fd, buffer, remaining_size);
     88                if (amount_read < 0)
     89                        return errno;
     90                buffer += amount_read;
     91                *size += amount_read;
     92                remaining_size -= amount_read;
     93        } while (remaining_size && amount_read);
     94        return EOK;
    8395}
    8496
     
    125137        }
    126138        blob->fd = fd;
     139#ifdef __HELENOS__
    127140        blob->size = stat.size;
     141#else
     142        blob->size = stat.st_size;
     143#endif
    128144        blob->needs_close = needs_close;
    129145        *out = bithenge_blob_as_node(blob_from_file(blob));
Note: See TracChangeset for help on using the changeset viewer.