Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 1923501 in mainline


Ignore:
Timestamp:
2012-05-25T04:15:57Z (9 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
master
Children:
ce683ed3
Parents:
743ce51
Message:

Bithenge: use separate functions instead of casts.

Location:
uspace/app/bithenge
Files:
2 edited

Legend:

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

    r743ce51 r1923501  
    8484}
    8585
     86static inline bithenge_sequential_blob_t *sequential_from_blob(
     87    bithenge_blob_t *base)
     88{
     89        return (bithenge_sequential_blob_t *)base;
     90}
     91
     92static inline bithenge_blob_t *blob_from_sequential(
     93    bithenge_sequential_blob_t *blob)
     94{
     95        return &blob->base;
     96}
     97
    8698static int sequential_size(bithenge_blob_t *base, aoff64_t *size)
    8799{
    88         bithenge_sequential_blob_t *blob = (bithenge_sequential_blob_t *)base;
     100        bithenge_sequential_blob_t *blob = sequential_from_blob(base);
    89101        int rc;
    90102        if (blob->ops->size) {
     
    108120    char *buffer, aoff64_t *size)
    109121{
    110         bithenge_sequential_blob_t *blob = (bithenge_sequential_blob_t *)base;
     122        bithenge_sequential_blob_t *blob = sequential_from_blob(base);
    111123        aoff64_t end = offset + *size;
    112124        if (end > blob->data_size) {
     
    124136static int sequential_destroy(bithenge_blob_t *base)
    125137{
    126         bithenge_sequential_blob_t *blob = (bithenge_sequential_blob_t *)base;
     138        bithenge_sequential_blob_t *blob = sequential_from_blob(base);
    127139        free(blob->buffer);
    128140        return blob->ops->destroy(blob);
     
    151163        // ops->size is optional
    152164
    153         int rc = bithenge_new_random_access_blob(&blob->base, &sequential_ops);
     165        int rc = bithenge_new_random_access_blob(blob_from_sequential(blob),
     166            &sequential_ops);
    154167        if (rc != EOK)
    155168                return rc;
  • uspace/app/bithenge/block.c

    r743ce51 r1923501  
    5151} block_blob_t;
    5252
     53static inline block_blob_t *block_from_blob(bithenge_blob_t *base)
     54{
     55        return (block_blob_t *)base;
     56}
     57
     58static inline bithenge_blob_t *blob_from_block(block_blob_t *blob)
     59{
     60        return &blob->base;
     61}
     62
    5363static int block_size(bithenge_blob_t *base, aoff64_t *size)
    5464{
    55         block_blob_t *blob = (block_blob_t *)base;
     65        block_blob_t *blob = block_from_blob(base);
    5666        *size = blob->size;
    5767        return EOK;
     
    6171    aoff64_t *size)
    6272{
    63         block_blob_t *blob = (block_blob_t *)base;
     73        block_blob_t *blob = block_from_blob(base);
    6474        if (offset > blob->size)
    6575                return ELIMIT;
     
    7080static int block_destroy(bithenge_blob_t *base)
    7181{
    72         block_blob_t *blob = (block_blob_t *)base;
     82        block_blob_t *blob = block_from_blob(base);
    7383        block_fini(blob->service_id);
    7484        free(blob);
     
    113123        if (!blob)
    114124                return ENOMEM;
    115         rc = bithenge_new_random_access_blob(&blob->base, &block_ops);
     125        rc = bithenge_new_random_access_blob(blob_from_block(blob),
     126            &block_ops);
    116127        if (rc != EOK) {
    117128                free(blob);
Note: See TracChangeset for help on using the changeset viewer.