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

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


Ignore:
Timestamp:
2009-12-03T19:25:17Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
9510be2
Parents:
cb3d641a (diff), 22e6802 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/lib/string.c

    rcb3d641a rfbcfc4da  
    537537 * null-terminated and containing only complete characters.
    538538 *
    539  * @param dst   Destination buffer.
     539 * @param dest   Destination buffer.
    540540 * @param count Size of the destination buffer (must be > 0).
    541541 * @param src   Source string.
     
    571571 * have to be null-terminated.
    572572 *
    573  * @param dst   Destination buffer.
     573 * @param dest   Destination buffer.
    574574 * @param count Size of the destination buffer (must be > 0).
    575575 * @param src   Source string.
     
    596596}
    597597
    598 /** Copy NULL-terminated wide string to string
    599  *
    600  * Copy source wide string @a src to destination buffer @a dst.
    601  * No more than @a size bytes are written. NULL-terminator is always
    602  * written after the last succesfully copied character (i.e. if the
    603  * destination buffer is has at least 1 byte, it will be always
    604  * NULL-terminated).
    605  *
    606  * @param src   Source wide string.
    607  * @param dst   Destination buffer.
    608  * @param count Size of the destination buffer.
    609  *
    610  */
    611 void wstr_nstr(char *dst, const wchar_t *src, size_t size)
    612 {
    613         /* No space for the NULL-terminator in the buffer */
    614         if (size == 0)
    615                 return;
    616        
     598/** Convert wide string to string.
     599 *
     600 * Convert wide string @a src to string. The output is written to the buffer
     601 * specified by @a dest and @a size. @a size must be non-zero and the string
     602 * written will always be well-formed.
     603 *
     604 * @param dest  Destination buffer.
     605 * @param size  Size of the destination buffer.
     606 * @param src   Source wide string.
     607 */
     608void wstr_to_str(char *dest, size_t size, const wchar_t *src)
     609{
    617610        wchar_t ch;
    618         size_t src_idx = 0;
    619         size_t dst_off = 0;
     611        size_t src_idx;
     612        size_t dest_off;
     613
     614        /* There must be space for a null terminator in the buffer. */
     615        ASSERT(size > 0);
     616
     617        src_idx = 0;
     618        dest_off = 0;
    620619       
    621620        while ((ch = src[src_idx++]) != 0) {
    622                 if (chr_encode(ch, dst, &dst_off, size) != EOK)
     621                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
    623622                        break;
    624623        }
    625        
    626         if (dst_off >= size)
    627                 dst[size - 1] = 0;
    628         else
    629                 dst[dst_off] = 0;
     624
     625        dest[dest_off] = '\0';
    630626}
    631627
Note: See TracChangeset for help on using the changeset viewer.