Changeset 978ccaf1 in mainline for uspace/app/bithenge/blob.c


Ignore:
Timestamp:
2012-06-27T03:35:43Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
600f5d1
Parents:
04a7435f
Message:

Bithenge: various cleanup and tweaks

File:
1 edited

Legend:

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

    r04a7435f r978ccaf1  
    4949 * @return EOK on success or an error code from errno.h.
    5050 */
    51 int bithenge_new_random_access_blob(bithenge_blob_t *blob,
     51int bithenge_init_random_access_blob(bithenge_blob_t *blob,
    5252    const bithenge_random_access_blob_ops_t *ops)
    5353{
     
    8585}
    8686
    87 static inline bithenge_sequential_blob_t *sequential_from_blob(
     87static inline bithenge_sequential_blob_t *blob_as_sequential(
    8888    bithenge_blob_t *base)
    8989{
     
    9191}
    9292
    93 static inline bithenge_blob_t *blob_from_sequential(
     93static inline bithenge_blob_t *sequential_as_blob(
    9494    bithenge_sequential_blob_t *blob)
    9595{
     
    9999static int sequential_size(bithenge_blob_t *base, aoff64_t *size)
    100100{
    101         bithenge_sequential_blob_t *blob = sequential_from_blob(base);
     101        bithenge_sequential_blob_t *blob = blob_as_sequential(base);
    102102        int rc;
    103103        if (blob->ops->size) {
     
    121121    char *buffer, aoff64_t *size)
    122122{
    123         bithenge_sequential_blob_t *blob = sequential_from_blob(base);
     123        bithenge_sequential_blob_t *blob = blob_as_sequential(base);
    124124        aoff64_t end = offset + *size;
    125125        if (end > blob->data_size) {
     
    135135}
    136136
    137 static int sequential_destroy(bithenge_blob_t *base)
    138 {
    139         bithenge_sequential_blob_t *blob = sequential_from_blob(base);
     137static void sequential_destroy(bithenge_blob_t *base)
     138{
     139        bithenge_sequential_blob_t *blob = blob_as_sequential(base);
    140140        free(blob->buffer);
    141         return blob->ops->destroy(blob);
     141        blob->ops->destroy(blob);
    142142}
    143143
     
    155155 * @return EOK on success or an error code from errno.h.
    156156 */
    157 int bithenge_new_sequential_blob(bithenge_sequential_blob_t *blob,
     157int bithenge_init_sequential_blob(bithenge_sequential_blob_t *blob,
    158158    const bithenge_sequential_blob_ops_t *ops)
    159159{
     
    164164        // ops->size is optional
    165165
    166         int rc = bithenge_new_random_access_blob(blob_from_sequential(blob),
     166        int rc = bithenge_init_random_access_blob(sequential_as_blob(blob),
    167167            &sequential_ops);
    168168        if (rc != EOK)
     
    182182} memory_blob_t;
    183183
    184 static inline memory_blob_t *memory_from_blob(bithenge_blob_t *base)
     184static inline memory_blob_t *blob_as_memory(bithenge_blob_t *base)
    185185{
    186186        return (memory_blob_t *)base;
    187187}
    188188
    189 static inline bithenge_blob_t *blob_from_memory(memory_blob_t *blob)
     189static inline bithenge_blob_t *memory_as_blob(memory_blob_t *blob)
    190190{
    191191        return &blob->base;
     
    194194static int memory_size(bithenge_blob_t *base, aoff64_t *size)
    195195{
    196         memory_blob_t *blob = memory_from_blob(base);
     196        memory_blob_t *blob = blob_as_memory(base);
    197197        *size = blob->size;
    198198        return EOK;
     
    202202    aoff64_t *size)
    203203{
    204         memory_blob_t *blob = memory_from_blob(base);
     204        memory_blob_t *blob = blob_as_memory(base);
    205205        if (offset > blob->size)
    206206                return ELIMIT;
     
    210210}
    211211
    212 static int memory_destroy(bithenge_blob_t *base)
    213 {
    214         memory_blob_t *blob = memory_from_blob(base);
     212static void memory_destroy(bithenge_blob_t *base)
     213{
     214        memory_blob_t *blob = blob_as_memory(base);
    215215        if (blob->needs_free)
    216216                free((void *)blob->buffer);
    217217        free(blob);
    218         return EOK;
    219218}
    220219
     
    244243        if (!blob)
    245244                return ENOMEM;
    246         rc = bithenge_new_random_access_blob(blob_from_memory(blob),
     245        rc = bithenge_init_random_access_blob(memory_as_blob(blob),
    247246            &memory_ops);
    248247        if (rc != EOK) {
     
    259258        blob->size = len;
    260259        blob->needs_free = true;
    261         *out = bithenge_blob_as_node(blob_from_memory(blob));
     260        *out = bithenge_blob_as_node(memory_as_blob(blob));
    262261        return EOK;
    263262}
     
    283282        if (!blob)
    284283                return ENOMEM;
    285         rc = bithenge_new_random_access_blob(blob_from_memory(blob),
     284        rc = bithenge_init_random_access_blob(memory_as_blob(blob),
    286285            &memory_ops);
    287286        if (rc != EOK) {
     
    292291        blob->size = len;
    293292        blob->needs_free = needs_free;
    294         *out = bithenge_blob_as_node(blob_from_memory(blob));
     293        *out = bithenge_blob_as_node(memory_as_blob(blob));
    295294        return EOK;
    296295}
     
    340339}
    341340
    342 static int subblob_destroy(bithenge_blob_t *base)
     341static void subblob_destroy(bithenge_blob_t *base)
    343342{
    344343        subblob_t *blob = blob_as_subblob(base);
    345344        bithenge_blob_dec_ref(blob->source);
    346345        free(blob);
    347         return EOK;
    348346}
    349347
     
    404402                goto error;
    405403        }
    406         rc = bithenge_new_random_access_blob(subblob_as_blob(blob),
     404        rc = bithenge_init_random_access_blob(subblob_as_blob(blob),
    407405            &subblob_ops);
    408406        if (rc != EOK)
Note: See TracChangeset for help on using the changeset viewer.