Skip to content

Commit e1143d7

Browse files
committed
core-builtin: add and use built in shim wrapper for strchr
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent 051a5ef commit e1143d7

15 files changed

Lines changed: 60 additions & 23 deletions

Makefile.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,7 @@ functions: \
26392639
BUILTIN_SQRTL \
26402640
BUILTIN_STDC_ROTATE_LEFT \
26412641
BUILTIN_STDC_ROTATE_RIGHT \
2642+
BUILTIN_STRCHR \
26422643
BUILTIN_STRCMP \
26432644
BUILTIN_STRDUP \
26442645
BUILTIN_STRNCMP \
@@ -3724,6 +3725,9 @@ BUILTIN_STDC_ROTATE_RIGHT:
37243725
BUILTIN_SQRTL:
37253726
$(call check,test-mathfunc,HAVE_BUILTIN_SQRTL,__builtin_sqrtl,$(LIB_M),-DMATHFUNC=__builtin_sqrtl)
37263727

3728+
BUILTIN_STRCHR:
3729+
$(call check,test-builtin-strchr,HAVE_BUILTIN_STRCHR,__builtin_strchr)
3730+
37273731
BUILTIN_STRCMP:
37283732
$(call check,test-builtin-strcmp,HAVE_BUILTIN_STRCMP,__builtin_strcmp)
37293733

core-builtin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
#define shim_strdup(str) strdup((str))
6262
#endif
6363

64+
#if defined(HAVE_BUILTIN_STRCHR)
65+
#define shim_strchr(str, c) __builtin_strchr((str), (c))
66+
#else
67+
#define shim_strchr(str, c) strchr((str), (c))
68+
#endif
69+
6470
#if defined(HAVE_BUILTIN_STRCMP)
6571
#define shim_strcmp(s1, s2) __builtin_strcmp((s1), (s2))
6672
#else

core-cpu-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int stress_get_string_from_file(
7171
if (UNLIKELY(ret < 0))
7272
return -1;
7373

74-
ptr = strchr(tmp, '\n');
74+
ptr = shim_strchr(tmp, '\n');
7575
if (ptr)
7676
*ptr = '\0';
7777

@@ -261,7 +261,7 @@ static int stress_cpu_cache_get_alpha(
261261
} else {
262262
continue;
263263
}
264-
ptr = strchr(buffer, ':');
264+
ptr = shim_strchr(buffer, ':');
265265
if (!ptr)
266266
continue;
267267
ptr++;
@@ -687,7 +687,7 @@ static int stress_cpu_cache_get_sh4(stress_cpu_cache_cpu_t *cpu)
687687

688688
(void)shim_memset(buffer, 0, sizeof(buffer));
689689
while ((cpu->cache_count < 2) && fgets(buffer, sizeof(buffer), fp) != NULL) {
690-
const char *ptr = strchr(buffer, ':');
690+
const char *ptr = shim_strchr(buffer, ':');
691691

692692
if (ptr &&
693693
(shim_strncmp("cache size", buffer + 1, 10) == 0) &&

core-cpuidle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void stress_cpuidle_init(void)
149149
(void)snprintf(path, sizeof(path), "%s/%s/name", cpuidle_path, cpuidle_d->d_name);
150150
if (stress_fs_file_read(path, data, sizeof(data)) < 1)
151151
continue;
152-
ptr = strchr(data, '\n');
152+
ptr = shim_strchr(data, '\n');
153153
if (ptr)
154154
*ptr = '\0';
155155

@@ -244,7 +244,7 @@ static void stress_cpuidle_read_cstates(
244244
(void)snprintf(path, sizeof(path), "%s/%s/name", cpuidle_path, cpuidle_d->d_name);
245245
if (stress_fs_file_read(path, cstate, sizeof(cstate)) < 1)
246246
continue;
247-
ptr = strchr(cstate, '\n');
247+
ptr = shim_strchr(cstate, '\n');
248248
if (ptr)
249249
*ptr = '\0';
250250

core-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ char *stress_proc_self_exe_get(char *path, const size_t path_len)
16731673
(void)stress_proc_self_exe_path_get;
16741674

16751675
/* A plain filename is invalid if the program has been found in the PATH */
1676-
if (!strchr(program_invocation_name, '/'))
1676+
if (!shim_strchr(program_invocation_name, '/'))
16771677
return NULL;
16781678

16791679
/* this may return the wrong name if it's been argv modified */

core-job.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
static inline void stress_str_chop(char *str, const char ch)
3737
{
38-
char * const ptr = strchr(str, ch);
38+
char * const ptr = shim_strchr(str, ch);
3939

4040
if (ptr)
4141
*ptr = '\0';

core-klog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ void stress_klog_start(void)
164164
const char *msg;
165165
bool dump_procs = false;
166166

167-
ptr = strchr(buf, '\n');
167+
ptr = shim_strchr(buf, '\n');
168168
if (ptr)
169169
*ptr = '\0';
170170

171-
ptr = strchr(buf, ';');
171+
ptr = shim_strchr(buf, ';');
172172
if (!ptr)
173173
continue;
174174
ptr++;

core-signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void stress_dump_map_info(uint8_t *fault_addr)
262262
char *ptr2;
263263

264264
/* truncate to first \n found */
265-
ptr1 = strchr(buf, (int)'\n');
265+
ptr1 = shim_strchr(buf, (int)'\n');
266266
if (ptr1)
267267
*ptr1 = '\0';
268268

stress-af-alg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void MLOCKED_TEXT stress_af_alg_alarm_handler(int signum)
159159
static stress_crypto_type_t name_to_type(const char *buffer, const size_t buffer_len)
160160
{
161161
const char *end = buffer + shim_strnlen(buffer, buffer_len);
162-
const char *ptr = strchr(buffer, ':');
162+
const char *ptr = shim_strchr(buffer, ':');
163163
size_t i;
164164

165165
if (UNLIKELY(!ptr))
@@ -1377,8 +1377,8 @@ static int stress_af_alg(stress_args_t *args)
13771377
*/
13781378
static char *dup_field(char *buffer)
13791379
{
1380-
const char *ptr = strchr(buffer, ':');
1381-
char *eol = strchr(buffer, '\n');
1380+
const char *ptr = shim_strchr(buffer, ':');
1381+
char *eol = shim_strchr(buffer, '\n');
13821382

13831383
if (!ptr)
13841384
return NULL;
@@ -1394,7 +1394,7 @@ static char *dup_field(char *buffer)
13941394
*/
13951395
static int CONST int_field(const char *buffer)
13961396
{
1397-
const char *ptr = strchr(buffer, ':');
1397+
const char *ptr = shim_strchr(buffer, ':');
13981398

13991399
if (!ptr)
14001400
return -1;
@@ -1408,7 +1408,7 @@ static int CONST int_field(const char *buffer)
14081408
*/
14091409
static bool CONST bool_field(const char *buffer)
14101410
{
1411-
const char *ptr = strchr(buffer, ':');
1411+
const char *ptr = shim_strchr(buffer, ':');
14121412

14131413
if (!ptr)
14141414
return false;

stress-cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static inline void stress_cgroup_remove_nl(char *str)
6767
{
6868
char *ptr;
6969

70-
ptr = strchr(str, '\n');
70+
ptr = shim_strchr(str, '\n');
7171
if (ptr)
7272
*ptr = '\0';
7373
}

0 commit comments

Comments
 (0)