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

Changeset 560d79f in mainline


Ignore:
Timestamp:
2012-03-02T14:50:25Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
76f382b
Parents:
0030eef
Message:

implement str_nsize, wstr_nsize

Location:
uspace/lib/c
Files:
2 edited

Legend:

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

    r0030eef r560d79f  
    259259       
    260260        return offset;
     261}
     262
     263/** Get size of string with size limit.
     264 *
     265 * Get the number of bytes which are used by the string @a str
     266 * (excluding the NULL-terminator), but no more than @max_size bytes.
     267 *
     268 * @param str      String to consider.
     269 * @param max_size Maximum number of bytes to measure.
     270 *
     271 * @return Number of bytes used by the string
     272 *
     273 */
     274size_t str_nsize(const char *str, size_t max_size)
     275{
     276        size_t size = 0;
     277       
     278        while ((*str++ != 0) && (size < max_size))
     279                size++;
     280       
     281        return size;
     282}
     283
     284/** Get size of wide string with size limit.
     285 *
     286 * Get the number of bytes which are used by the wide string @a str
     287 * (excluding the NULL-terminator), but no more than @max_size bytes.
     288 *
     289 * @param str      Wide string to consider.
     290 * @param max_size Maximum number of bytes to measure.
     291 *
     292 * @return Number of bytes used by the wide string
     293 *
     294 */
     295size_t wstr_nsize(const wchar_t *str, size_t max_size)
     296{
     297        return (wstr_nlength(str, max_size) * sizeof(wchar_t));
    261298}
    262299
  • uspace/lib/c/include/str.h

    r0030eef r560d79f  
    6060extern size_t str_size(const char *str);
    6161extern size_t wstr_size(const wchar_t *str);
     62
     63extern size_t str_nsize(const char *str, size_t max_size);
     64extern size_t wstr_nsize(const wchar_t *str, size_t max_size);
    6265
    6366extern size_t str_lsize(const char *str, size_t max_len);
Note: See TracChangeset for help on using the changeset viewer.