Changeset 978ccaf1 in mainline for uspace/app/bithenge/blob.c
- Timestamp:
- 2012-06-27T03:35:43Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 600f5d1
- Parents:
- 04a7435f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/blob.c
r04a7435f r978ccaf1 49 49 * @return EOK on success or an error code from errno.h. 50 50 */ 51 int bithenge_ new_random_access_blob(bithenge_blob_t *blob,51 int bithenge_init_random_access_blob(bithenge_blob_t *blob, 52 52 const bithenge_random_access_blob_ops_t *ops) 53 53 { … … 85 85 } 86 86 87 static inline bithenge_sequential_blob_t * sequential_from_blob(87 static inline bithenge_sequential_blob_t *blob_as_sequential( 88 88 bithenge_blob_t *base) 89 89 { … … 91 91 } 92 92 93 static inline bithenge_blob_t * blob_from_sequential(93 static inline bithenge_blob_t *sequential_as_blob( 94 94 bithenge_sequential_blob_t *blob) 95 95 { … … 99 99 static int sequential_size(bithenge_blob_t *base, aoff64_t *size) 100 100 { 101 bithenge_sequential_blob_t *blob = sequential_from_blob(base);101 bithenge_sequential_blob_t *blob = blob_as_sequential(base); 102 102 int rc; 103 103 if (blob->ops->size) { … … 121 121 char *buffer, aoff64_t *size) 122 122 { 123 bithenge_sequential_blob_t *blob = sequential_from_blob(base);123 bithenge_sequential_blob_t *blob = blob_as_sequential(base); 124 124 aoff64_t end = offset + *size; 125 125 if (end > blob->data_size) { … … 135 135 } 136 136 137 static intsequential_destroy(bithenge_blob_t *base)138 { 139 bithenge_sequential_blob_t *blob = sequential_from_blob(base);137 static void sequential_destroy(bithenge_blob_t *base) 138 { 139 bithenge_sequential_blob_t *blob = blob_as_sequential(base); 140 140 free(blob->buffer); 141 returnblob->ops->destroy(blob);141 blob->ops->destroy(blob); 142 142 } 143 143 … … 155 155 * @return EOK on success or an error code from errno.h. 156 156 */ 157 int bithenge_ new_sequential_blob(bithenge_sequential_blob_t *blob,157 int bithenge_init_sequential_blob(bithenge_sequential_blob_t *blob, 158 158 const bithenge_sequential_blob_ops_t *ops) 159 159 { … … 164 164 // ops->size is optional 165 165 166 int rc = bithenge_ new_random_access_blob(blob_from_sequential(blob),166 int rc = bithenge_init_random_access_blob(sequential_as_blob(blob), 167 167 &sequential_ops); 168 168 if (rc != EOK) … … 182 182 } memory_blob_t; 183 183 184 static inline memory_blob_t * memory_from_blob(bithenge_blob_t *base)184 static inline memory_blob_t *blob_as_memory(bithenge_blob_t *base) 185 185 { 186 186 return (memory_blob_t *)base; 187 187 } 188 188 189 static inline bithenge_blob_t * blob_from_memory(memory_blob_t *blob)189 static inline bithenge_blob_t *memory_as_blob(memory_blob_t *blob) 190 190 { 191 191 return &blob->base; … … 194 194 static int memory_size(bithenge_blob_t *base, aoff64_t *size) 195 195 { 196 memory_blob_t *blob = memory_from_blob(base);196 memory_blob_t *blob = blob_as_memory(base); 197 197 *size = blob->size; 198 198 return EOK; … … 202 202 aoff64_t *size) 203 203 { 204 memory_blob_t *blob = memory_from_blob(base);204 memory_blob_t *blob = blob_as_memory(base); 205 205 if (offset > blob->size) 206 206 return ELIMIT; … … 210 210 } 211 211 212 static intmemory_destroy(bithenge_blob_t *base)213 { 214 memory_blob_t *blob = memory_from_blob(base);212 static void memory_destroy(bithenge_blob_t *base) 213 { 214 memory_blob_t *blob = blob_as_memory(base); 215 215 if (blob->needs_free) 216 216 free((void *)blob->buffer); 217 217 free(blob); 218 return EOK;219 218 } 220 219 … … 244 243 if (!blob) 245 244 return ENOMEM; 246 rc = bithenge_ new_random_access_blob(blob_from_memory(blob),245 rc = bithenge_init_random_access_blob(memory_as_blob(blob), 247 246 &memory_ops); 248 247 if (rc != EOK) { … … 259 258 blob->size = len; 260 259 blob->needs_free = true; 261 *out = bithenge_blob_as_node( blob_from_memory(blob));260 *out = bithenge_blob_as_node(memory_as_blob(blob)); 262 261 return EOK; 263 262 } … … 283 282 if (!blob) 284 283 return ENOMEM; 285 rc = bithenge_ new_random_access_blob(blob_from_memory(blob),284 rc = bithenge_init_random_access_blob(memory_as_blob(blob), 286 285 &memory_ops); 287 286 if (rc != EOK) { … … 292 291 blob->size = len; 293 292 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)); 295 294 return EOK; 296 295 } … … 340 339 } 341 340 342 static intsubblob_destroy(bithenge_blob_t *base)341 static void subblob_destroy(bithenge_blob_t *base) 343 342 { 344 343 subblob_t *blob = blob_as_subblob(base); 345 344 bithenge_blob_dec_ref(blob->source); 346 345 free(blob); 347 return EOK;348 346 } 349 347 … … 404 402 goto error; 405 403 } 406 rc = bithenge_ new_random_access_blob(subblob_as_blob(blob),404 rc = bithenge_init_random_access_blob(subblob_as_blob(blob), 407 405 &subblob_ops); 408 406 if (rc != EOK)
Note:
See TracChangeset
for help on using the changeset viewer.