Changeset 0d1a8fd in mainline for uspace/app/bithenge/transform.c
- Timestamp:
- 2012-06-24T18:44:34Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f2da0bb
- Parents:
- 03b2b2c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/transform.c
r03b2b2c r0d1a8fd 35 35 */ 36 36 37 #include <assert.h> 37 38 #include <errno.h> 39 #include <stdlib.h> 38 40 #include "blob.h" 39 41 #include "transform.h" … … 41 43 static int transform_indestructible(bithenge_transform_t *xform) 42 44 { 43 return EINVAL; 45 assert(false); 46 return EOK; 44 47 } 45 48 … … 64 67 } 65 68 66 static int uint32le_prefix_length(bithenge_transform_t *xform, 67 bithenge_blob_t *blob, aoff64_t *out) 69 static int uint32be_apply(bithenge_transform_t *xform, bithenge_node_t *in, 70 bithenge_node_t **out) 71 { 72 int rc; 73 if (bithenge_node_type(in) != BITHENGE_NODE_BLOB) 74 return EINVAL; 75 bithenge_blob_t *blob = bithenge_node_as_blob(in); 76 77 // Try to read 5 bytes and fail if the blob is too long. 78 uint32_t val[2]; 79 aoff64_t size = sizeof(val[0]) + 1; 80 rc = bithenge_blob_read(blob, 0, (char *)val, &size); 81 if (rc != EOK) 82 return rc; 83 if (size != 4) 84 return EINVAL; 85 86 return bithenge_new_integer_node(out, uint32_t_be2host(val[0])); 87 } 88 89 static int prefix_length_4(bithenge_transform_t *xform, bithenge_blob_t *blob, 90 aoff64_t *out) 68 91 { 69 92 *out = 4; … … 73 96 static const bithenge_transform_ops_t uint32le_ops = { 74 97 .apply = uint32le_apply, 75 .prefix_length = uint32le_prefix_length,98 .prefix_length = prefix_length_4, 76 99 .destroy = transform_indestructible, 77 100 }; 78 101 79 static bithenge_transform_t uint32le_transform = { 102 static const bithenge_transform_ops_t uint32be_ops = { 103 .apply = uint32be_apply, 104 .prefix_length = prefix_length_4, 105 .destroy = transform_indestructible, 106 }; 107 108 /** The little-endian 32-bit unsigned integer transform. */ 109 bithenge_transform_t bithenge_uint32le_transform = { 80 110 &uint32le_ops, 1 81 111 }; 82 112 83 /** Create a little-endian 32-bit unsigned integer transform. 84 * @param out Holds the transform. 85 * @return EOK on success or an error code from errno.h. */ 86 int bithenge_uint32le_transform(bithenge_transform_t **out) 87 { 88 *out = &uint32le_transform; 89 return EOK; 90 } 113 /** The big-endian 32-bit unsigned integer transform. */ 114 bithenge_transform_t bithenge_uint32be_transform = { 115 &uint32be_ops, 1 116 }; 117 118 static bithenge_named_transform_t primitive_transforms[] = { 119 {"uint32le", &bithenge_uint32le_transform}, 120 {"uint32be", &bithenge_uint32be_transform}, 121 {NULL, NULL} 122 }; 123 124 /** An array of named built-in transforms. */ 125 bithenge_named_transform_t *bithenge_primitive_transforms = primitive_transforms; 91 126 92 127 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.