Changeset 61bfc370 in mainline for uspace/lib/c


Ignore:
Timestamp:
2011-01-07T18:57:55Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e08a733
Parents:
7c34b28f
Message:
  • make measured_string and other network-related data types binary-safe
  • fix several network-related routines binary-safe (replace clearly suspicious use of str_lcmp() with bcmp())
  • rename spawn() to net_spawn()
Location:
uspace/lib/c
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/char_map.c

    r7c34b28f r61bfc370  
    6565 */
    6666static int
    67 char_map_add_item(char_map_t *map, const char *identifier, size_t length,
     67char_map_add_item(char_map_t *map, const uint8_t *identifier, size_t length,
    6868    const int value)
    6969{
     
    139139 */
    140140int
    141 char_map_add(char_map_t *map, const char *identifier, size_t length,
     141char_map_add(char_map_t *map, const uint8_t *identifier, size_t length,
    142142    const int value)
    143143{
     
    200200 */
    201201static char_map_t *
    202 char_map_find_node(const char_map_t *map, const char *identifier,
     202char_map_find_node(const char_map_t *map, const uint8_t *identifier,
    203203    size_t length)
    204204{
     
    241241 * @return              CHAR_MAP_NULL if the key is not assigned a value.
    242242 */
    243 int char_map_exclude(char_map_t *map, const char *identifier, size_t length)
     243int char_map_exclude(char_map_t *map, const uint8_t *identifier, size_t length)
    244244{
    245245        char_map_t *node;
     
    269269 *  @return             CHAR_MAP_NULL if the key is not assigned a value.
    270270 */
    271 int char_map_find(const char_map_t *map, const char *identifier, size_t length)
     271int char_map_find(const char_map_t *map, const uint8_t *identifier, size_t length)
    272272{
    273273        char_map_t *node;
     
    329329 */
    330330int
    331 char_map_update(char_map_t *map, const char *identifier, const size_t length,
     331char_map_update(char_map_t *map, const uint8_t *identifier, const size_t length,
    332332    const int value)
    333333{
  • uspace/lib/c/generic/adt/measured_strings.c

    r7c34b28f r61bfc370  
    5959 */
    6060measured_string_t *
    61 measured_string_create_bulk(const char *string, size_t length)
     61measured_string_create_bulk(const uint8_t *string, size_t length)
    6262{
    6363        measured_string_t *new;
     
    6868        }
    6969        new = (measured_string_t *) malloc(sizeof(measured_string_t) +
    70             (sizeof(char) * (length + 1)));
     70            (sizeof(uint8_t) * (length + 1)));
    7171        if (!new)
    7272                return NULL;
    7373
    7474        new->length = length;
    75         new->value = ((char *) new) + sizeof(measured_string_t);
     75        new->value = ((uint8_t *) new) + sizeof(measured_string_t);
    7676        // append terminating zero explicitly - to be safe
    7777        memcpy(new->value, string, new->length);
     
    9797        new = (measured_string_t *) malloc(sizeof(measured_string_t));
    9898        if (new) {
    99                 new->value = (char *) malloc(source->length + 1);
     99                new->value = (uint8_t *) malloc(source->length + 1);
    100100                if (new->value) {
    101101                        new->length = source->length;
     
    131131 */
    132132int
    133 measured_strings_receive(measured_string_t **strings, char **data,
     133measured_strings_receive(measured_string_t **strings, uint8_t **data,
    134134    size_t count)
    135135{
     
    137137        size_t index;
    138138        size_t length;
    139         char *next;
     139        uint8_t *next;
    140140        ipc_callid_t callid;
    141141        int rc;
     
    311311 */
    312312int
    313 measured_strings_return(int phone, measured_string_t **strings, char **data,
     313measured_strings_return(int phone, measured_string_t **strings, uint8_t **data,
    314314    size_t count)
    315315{
    316316        size_t *lengths;
    317317        size_t index;
    318         char *next;
     318        uint8_t *next;
    319319        int rc;
    320320
  • uspace/lib/c/generic/mem.c

    r7c34b28f r61bfc370  
    222222/** Compare two memory areas.
    223223 *
    224  * @param s1            Pointer to the first area to compare.
    225  * @param s2            Pointer to the second area to compare.
    226  * @param len           Size of the first area in bytes. Both areas must have
    227  *                      the same length.
    228  * @return              If len is 0, return zero. If the areas match, return
    229  *                      zero. Otherwise return non-zero.
    230  */
    231 int bcmp(const char *s1, const char *s2, size_t len)
    232 {
    233         for (; len && *s1++ == *s2++; len--)
    234                 ;
     224 * @param s1  Pointer to the first area to compare.
     225 * @param s2  Pointer to the second area to compare.
     226 * @param len Size of the first area in bytes. Both areas must have
     227 *            the same length.
     228 *
     229 * @return If len is 0, return zero. If the areas match, return
     230 *         zero. Otherwise return non-zero.
     231 *
     232 */
     233int bcmp(const void *s1, const void *s2, size_t len)
     234{
     235        uint8_t *u1 = (uint8_t *) s1;
     236        uint8_t *u2 = (uint8_t *) s2;
     237       
     238        for (; (len != 0) && (*u1++ == *u2++); len--);
     239       
    235240        return len;
    236241}
  • uspace/lib/c/include/adt/char_map.h

    r7c34b28f r61bfc370  
    4141
    4242/** Invalid assigned value used also if an&nbsp;entry does not exist. */
    43 #define CHAR_MAP_NULL   (-1)
     43#define CHAR_MAP_NULL  (-1)
    4444
    4545/** Type definition of the character string to integer map.
    4646 *  @see char_map
    4747 */
    48 typedef struct char_map char_map_t;
     48typedef struct char_map char_map_t;
    4949
    5050/** Character string to integer map item.
     
    5656struct char_map {
    5757        /** Actually mapped character. */
    58         char c;
     58        uint8_t c;
    5959        /** Stored integral value. */
    6060        int value;
     
    7171extern int char_map_initialize(char_map_t *);
    7272extern void char_map_destroy(char_map_t *);
    73 extern int char_map_exclude(char_map_t *, const char *, size_t);
    74 extern int char_map_add(char_map_t *, const char *, size_t, const int);
    75 extern int char_map_find(const char_map_t *, const char *, size_t);
    76 extern int char_map_update(char_map_t *, const char *, size_t, const int);
     73extern int char_map_exclude(char_map_t *, const uint8_t *, size_t);
     74extern int char_map_add(char_map_t *, const uint8_t *, size_t, const int);
     75extern int char_map_find(const char_map_t *, const uint8_t *, size_t);
     76extern int char_map_update(char_map_t *, const uint8_t *, size_t, const int);
    7777
    7878#endif
  • uspace/lib/c/include/adt/generic_char_map.h

    r7c34b28f r61bfc370  
    6262        }; \
    6363        \
    64         int name##_add(name##_t *, const char *, const size_t, type *); \
     64        int name##_add(name##_t *, const uint8_t *, const size_t, type *); \
    6565        int name##_count(name##_t *); \
    6666        void name##_destroy(name##_t *); \
    67         void name##_exclude(name##_t *, const char *, const size_t); \
    68         type *name##_find(name##_t *, const char *, const size_t); \
     67        void name##_exclude(name##_t *, const uint8_t *, const size_t); \
     68        type *name##_find(name##_t *, const uint8_t *, const size_t); \
    6969        int name##_initialize(name##_t *); \
    7070        int name##_is_valid(name##_t *);
     
    7474 * Should follow declaration with the same parameters.
    7575 *
    76  * @param[in] name      Name of the map.
    77  * @param[in] type      Inner object type.
     76 * @param[in] name Name of the map.
     77 * @param[in] type Inner object type.
     78 *
    7879 */
    7980#define GENERIC_CHAR_MAP_IMPLEMENT(name, type) \
    8081        GENERIC_FIELD_IMPLEMENT(name##_items, type) \
    8182        \
    82         int name##_add(name##_t *map, const char *name, const size_t length, \
     83        int name##_add(name##_t *map, const uint8_t *name, const size_t length, \
    8384             type *value) \
    8485        { \
     
    112113        } \
    113114        \
    114         void name##_exclude(name##_t *map, const char *name, \
     115        void name##_exclude(name##_t *map, const uint8_t *name, \
    115116            const size_t length) \
    116117        { \
     
    124125        } \
    125126        \
    126         type *name##_find(name##_t *map, const char *name, \
     127        type *name##_find(name##_t *map, const uint8_t *name, \
    127128            const size_t length) \
    128129        { \
  • uspace/lib/c/include/adt/measured_strings.h

    r7c34b28f r61bfc370  
    5454struct measured_string {
    5555        /** Character string data. */
    56         char *value;
     56        uint8_t *value;
    5757        /** Character string length. */
    5858        size_t length;
    5959};
    6060
    61 extern measured_string_t *measured_string_create_bulk(const char *, size_t);
     61extern measured_string_t *measured_string_create_bulk(const uint8_t *, size_t);
    6262extern measured_string_t *measured_string_copy(measured_string_t *);
    63 extern int measured_strings_receive(measured_string_t **, char **, size_t);
     63extern int measured_strings_receive(measured_string_t **, uint8_t **, size_t);
    6464extern int measured_strings_reply(const measured_string_t *, size_t);
    65 extern int measured_strings_return(int, measured_string_t **, char **, size_t);
     65extern int measured_strings_return(int, measured_string_t **, uint8_t **, size_t);
    6666extern int measured_strings_send(int, const measured_string_t *, size_t);
    6767
  • uspace/lib/c/include/mem.h

    r7c34b28f r61bfc370  
    4444extern void *memmove(void *, const void *, size_t);
    4545
    46 extern int bcmp(const char *, const char *, size_t);
     46extern int bcmp(const void *, const void *, size_t);
    4747
    4848#endif
Note: See TracChangeset for help on using the changeset viewer.