lkml.org 
[lkml]   [2021]   [May]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v5 1/3] perf report: compile tips.txt in perf binary
Date
> that still does not solve that we set MAX_TIPS and have
> no way of checking that's still valid
>
> how about something like below (completely untested):

Yes, looks good, i've tested it.
>
>
> static const char *perf_tip(void)
> {
> char *start = _binary_Documentation_tips_txt_start;
> char *tok, *tmp, *prev;
> int pick, size;
>
> size = _binary_Documentation_tips_txt_end - start;
> pick = random() % size;
>
> _binary_Documentation_tips_txt_start[size - 1] = 0;
>
> for (tok = strtok_r(start, "\n", &tmp); tok;
> tok = strtok_r(NULL, "\n", &tmp)) {
> if (pick < (tok - start))
> return prev;
> prev = tok;
> }
>
> return prev;
> }
>
> this way you wouldn't need array with MAX_TIPS defined

\
 
 \ /
  Last update: 2021-05-21 12:25    [W:0.850 / U:1.580 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site