003 File Manager
Current Path:
/usr/src/contrib/xz/src/common
usr
/
src
/
contrib
/
xz
/
src
/
common
/
📁
..
📄
mythread.h
(11.77 KB)
📄
sysdefs.h
(4.8 KB)
📄
tuklib_common.h
(1.86 KB)
📄
tuklib_config.h
(121 B)
📄
tuklib_cpucores.c
(2.3 KB)
📄
tuklib_cpucores.h
(606 B)
📄
tuklib_exit.c
(1.51 KB)
📄
tuklib_exit.h
(706 B)
📄
tuklib_gettext.h
(1.04 KB)
📄
tuklib_integer.h
(16.67 KB)
📄
tuklib_mbstr.h
(2.81 KB)
📄
tuklib_mbstr_fw.c
(745 B)
📄
tuklib_mbstr_width.c
(1.48 KB)
📄
tuklib_open_stdxxx.c
(1.43 KB)
📄
tuklib_open_stdxxx.h
(647 B)
📄
tuklib_physmem.c
(5.65 KB)
📄
tuklib_physmem.h
(763 B)
📄
tuklib_progname.c
(1.11 KB)
📄
tuklib_progname.h
(817 B)
Editing: tuklib_mbstr_width.c
/////////////////////////////////////////////////////////////////////////////// // /// \file tuklib_mbstr_width.c /// \brief Calculate width of a multibyte string // // Author: Lasse Collin // // This file has been put into the public domain. // You can do whatever you want with this file. // /////////////////////////////////////////////////////////////////////////////// #include "tuklib_mbstr.h" #include <string.h> #if defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH) # include <wchar.h> #endif extern size_t tuklib_mbstr_width(const char *str, size_t *bytes) { const size_t len = strlen(str); if (bytes != NULL) *bytes = len; #if !(defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)) // In single-byte mode, the width of the string is the same // as its length. return len; #else mbstate_t state; memset(&state, 0, sizeof(state)); size_t width = 0; size_t i = 0; // Convert one multibyte character at a time to wchar_t // and get its width using wcwidth(). while (i < len) { wchar_t wc; const size_t ret = mbrtowc(&wc, str + i, len - i, &state); if (ret < 1 || ret > len) return (size_t)-1; i += ret; const int wc_width = wcwidth(wc); if (wc_width < 0) return (size_t)-1; width += (size_t)wc_width; } // Require that the string ends in the initial shift state. // This way the caller can be combine the string with other // strings without needing to worry about the shift states. if (!mbsinit(&state)) return (size_t)-1; return width; #endif }
Upload File
Create Folder