File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 19
19
/config.status
20
20
Makefile
21
21
/stamp-h1
22
+ ! /tests /string_utils_test /Makefile
Original file line number Diff line number Diff line change
1
+ string_utils_test : string_utils_test.o x_strlcpy.o
2
+ $(CXX ) -o $@ string_utils_test.o x_strlcpy.o -lboost_unit_test_framework-mt -lstdc++
3
+
4
+ string_utils_test.o : ../../string_utils.h ../../x_strlcpy.c
5
+ $(CXX ) -c -o $@ -I ../.. string_utils_test.cpp
6
+
7
+ x_strlcpy.o : ../../string_utils.h ../../x_strlcpy.c
8
+ $(CXX ) -c -o $@ -I ../.. ../../x_strlcpy.c
Original file line number Diff line number Diff line change 1
1
/* -*- coding: utf-8; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: t -*- */
2
2
3
- // This code and all comments, written by Daniel Trebbien, are hereby entered into the Public Domain by their author.
3
+ /* This code and all comments, written by Daniel Trebbien, are hereby entered into the Public Domain by their author. */
4
4
5
- #include <assert.h>
6
5
#include <string.h>
7
6
8
7
#include "string_utils.h"
9
8
9
+ /* This implementation is machine-verified:
10
+ https://github.com/dtrebbien/verlibc/blob/daea83474b36dc251751d100d2ba347d1aa906d6/src/string/strlcpy.c */
10
11
size_t x_strlcpy (char * __restrict dest , const char * __restrict src , size_t dest_len )
11
12
{
12
13
if (dest_len == 0 ) {
13
14
return strlen (src );
14
15
} else {
15
16
char * const dest_str_end = dest + dest_len - 1 ;
16
17
char * __restrict d = dest ;
18
+ const char * __restrict s = src ;
17
19
18
- while (d != dest_str_end )
19
- {
20
- if ((* d ++ = * src ++ ) == '\0' ) {
21
- assert (* (src - 1 ) == '\0' );
22
- assert (* (d - 1 ) == '\0' );
20
+ while (d != dest_str_end ) {
21
+ if ((* d ++ = * s ++ ) == '\0' ) {
23
22
return (d - 1 - dest );
24
23
}
25
24
}
26
25
27
26
* d = '\0' ;
28
- return (dest_len - 1 ) + strlen (src );
27
+ return (dest_len - 1 ) + strlen (s );
29
28
}
30
29
}
You can’t perform that action at this time.
0 commit comments