summaryrefslogtreecommitdiffstats
path: root/src/core/wchar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/wchar.c')
-rw-r--r--src/core/wchar.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/core/wchar.c b/src/core/wchar.c
index 860322820..27a608bf4 100644
--- a/src/core/wchar.c
+++ b/src/core/wchar.c
@@ -22,6 +22,7 @@
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+FILE_SECBOOT ( PERMITTED );
/**
* @file
@@ -36,12 +37,25 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* Calculate length of wide-character string
*
* @v string String
- * @ret len Length (excluding terminating NUL)
+ * @v max Maximum length (in wide characters)
+ * @ret len Length (in wide characters, excluding terminating NUL)
*/
-size_t wcslen ( const wchar_t *string ) {
+size_t wcsnlen ( const wchar_t *string, size_t max ) {
size_t len = 0;
- while ( *(string++) )
+ while ( max-- && *(string++) )
len++;
return len;
}
+
+/**
+ * Calculate length of wide-character string
+ *
+ * @v string String
+ * @ret len Length (in wide characters, excluding terminating NUL)
+ */
+size_t wcslen ( const wchar_t *string ) {
+
+ return wcsnlen ( string, ( ( ~( ( size_t ) 0 ) ) /
+ sizeof ( string[0] ) ) );
+}