Changeset b7fd2a0 in mainline for uspace/lib/c/generic/str.c


Ignore:
Timestamp:
2018-01-13T03:10:29Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a53ed3a
Parents:
36f0738
Message:

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/str.c

    r36f0738 rb7fd2a0  
    196196 *         code was invalid.
    197197 */
    198 int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
     198errno_t chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
    199199{
    200200        if (*offset >= size)
     
    839839 *                      non-ASCII bytes.
    840840 */
    841 int spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n)
     841errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n)
    842842{
    843843        size_t sidx;
     
    845845        size_t dlast;
    846846        uint8_t byte;
    847         int rc;
    848         int result;
     847        errno_t rc;
     848        errno_t result;
    849849
    850850        /* There must be space for a null terminator in the buffer. */
     
    920920 * @return EOK, if success, an error code otherwise.
    921921 */
    922 int utf16_to_str(char *dest, size_t size, const uint16_t *src)
     922errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src)
    923923{
    924924        size_t idx = 0, dest_off = 0;
    925925        wchar_t ch;
    926         int rc = EOK;
     926        errno_t rc = EOK;
    927927
    928928        /* There must be space for a null terminator in the buffer. */
     
    963963 * @return EOK, if success, an error code otherwise.
    964964 */
    965 int str_to_utf16(uint16_t *dest, size_t dlen, const char *src)
    966 {
    967         int rc = EOK;
     965errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src)
     966{
     967        errno_t rc = EOK;
    968968        size_t offset = 0;
    969969        size_t idx = 0;
     
    15391539 *
    15401540 */
    1541 static int str_uint(const char *nptr, char **endptr, unsigned int base,
     1541static errno_t str_uint(const char *nptr, char **endptr, unsigned int base,
    15421542    bool *neg, uint64_t *result)
    15431543{
     
    16601660 *
    16611661 */
    1662 int str_uint8_t(const char *nptr, const char **endptr, unsigned int base,
     1662errno_t str_uint8_t(const char *nptr, const char **endptr, unsigned int base,
    16631663    bool strict, uint8_t *result)
    16641664{
     
    16681668        char *lendptr;
    16691669        uint64_t res;
    1670         int ret = str_uint(nptr, &lendptr, base, &neg, &res);
     1670        errno_t ret = str_uint(nptr, &lendptr, base, &neg, &res);
    16711671       
    16721672        if (endptr != NULL)
     
    17071707 *
    17081708 */
    1709 int str_uint16_t(const char *nptr, const char **endptr, unsigned int base,
     1709errno_t str_uint16_t(const char *nptr, const char **endptr, unsigned int base,
    17101710    bool strict, uint16_t *result)
    17111711{
     
    17151715        char *lendptr;
    17161716        uint64_t res;
    1717         int ret = str_uint(nptr, &lendptr, base, &neg, &res);
     1717        errno_t ret = str_uint(nptr, &lendptr, base, &neg, &res);
    17181718       
    17191719        if (endptr != NULL)
     
    17541754 *
    17551755 */
    1756 int str_uint32_t(const char *nptr, const char **endptr, unsigned int base,
     1756errno_t str_uint32_t(const char *nptr, const char **endptr, unsigned int base,
    17571757    bool strict, uint32_t *result)
    17581758{
     
    17621762        char *lendptr;
    17631763        uint64_t res;
    1764         int ret = str_uint(nptr, &lendptr, base, &neg, &res);
     1764        errno_t ret = str_uint(nptr, &lendptr, base, &neg, &res);
    17651765       
    17661766        if (endptr != NULL)
     
    18011801 *
    18021802 */
    1803 int str_uint64_t(const char *nptr, const char **endptr, unsigned int base,
     1803errno_t str_uint64_t(const char *nptr, const char **endptr, unsigned int base,
    18041804    bool strict, uint64_t *result)
    18051805{
     
    18081808        bool neg;
    18091809        char *lendptr;
    1810         int ret = str_uint(nptr, &lendptr, base, &neg, result);
     1810        errno_t ret = str_uint(nptr, &lendptr, base, &neg, result);
    18111811       
    18121812        if (endptr != NULL)
     
    18401840 *
    18411841 */
    1842 int str_size_t(const char *nptr, const char **endptr, unsigned int base,
     1842errno_t str_size_t(const char *nptr, const char **endptr, unsigned int base,
    18431843    bool strict, size_t *result)
    18441844{
     
    18481848        char *lendptr;
    18491849        uint64_t res;
    1850         int ret = str_uint(nptr, &lendptr, base, &neg, &res);
     1850        errno_t ret = str_uint(nptr, &lendptr, base, &neg, &res);
    18511851       
    18521852        if (endptr != NULL)
Note: See TracChangeset for help on using the changeset viewer.