Changeset d09f84e6 in mainline for kernel/generic/src/lib/string.c


Ignore:
Timestamp:
2009-04-02T19:59:22Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
82bb9c1
Parents:
06b785f
Message:

Return error code from chr_encode() rather than boolean.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.