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

Changeset d09f84e6 in mainline


Ignore:
Timestamp:
2009-04-02T19:59:22Z (13 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master
Children:
82bb9c1
Parents:
06b785f
Message:

Return error code from chr_encode() rather than boolean.

Location:
kernel/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/string.h

    r06b785f rd09f84e6  
    4343
    4444extern wchar_t chr_decode(const char *, size_t *, size_t);
    45 extern bool chr_encode(const wchar_t, char *, size_t *, size_t);
     45extern int chr_encode(const wchar_t, char *, size_t *, size_t);
    4646
    4747extern size_t str_size(const char *str);
  • kernel/generic/src/lib/string.c

    r06b785f rd09f84e6  
    4141#include <arch/asm.h>
    4242#include <arch.h>
     43#include <errno.h>
    4344#include <console/kconsole.h>
    4445
     
    141142 * @param sz            Size of the output buffer.
    142143 *
    143  * @return True if the character was encoded successfully or false if there
    144  *         was not enough space in the output buffer or the character code
    145  *         was invalid.
    146  */
    147 bool chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz)
     144 * @return EOK if the character was encoded successfully, EOVERFLOW if there
     145 *         was not enough space in the output buffer or EINVAL if the character
     146 *         code was invalid.
     147 */
     148int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz)
    148149{
    149150        uint32_t cc;            /* Unsigned version of ch. */
     
    154155
    155156        if (*offset >= sz)
    156                 return false;
     157                return EOVERFLOW;
    157158
    158159        if (ch < 0)
    159                 return false;
     160                return EINVAL;
    160161
    161162        /* Bit operations should only be done on unsigned numbers. */
     
    177178        } else {
    178179                /* Codes longer than 21 bits are not supported. */
    179                 return false;
     180                return EINVAL;
    180181        }
    181182
    182183        /* Check for available space in buffer. */
    183184        if (*offset + cbytes >= sz)
    184                 return false;
     185                return EOVERFLOW;
    185186
    186187        /* Encode continuation bytes. */
     
    196197        *offset += (1 + cbytes);
    197198       
    198         return true;
     199        return EOK;
    199200}
    200201
  • kernel/generic/src/printf/vsnprintf.c

    r06b785f rd09f84e6  
    3737#include <string.h>
    3838#include <memstr.h>
     39#include <errno.h>
    3940
    4041typedef struct {
     
    8788                        wchar_t uc = chr_decode(str, &index, size);
    8889
    89                         if (!chr_encode(uc, data->dst, &data->len, data->size - 1))
     90                        if (chr_encode(uc, data->dst, &data->len, data->size - 1) != EOK)
    9091                                break;
    9192                }
     
    147148                }
    148149               
    149                 if (!chr_encode(str[index], data->dst, &data->len, data->size - 1))
     150                if (chr_encode(str[index], data->dst, &data->len, data->size - 1) != EOK)
    150151                        break;
    151152               
Note: See TracChangeset for help on using the changeset viewer.