[LEDE-DEV] [PATCH] libubox: replace strtok with strsep

John Crispin john at phrozen.org
Fri Dec 16 01:58:42 PST 2016



On 14/12/2016 06:43, Rosen Penev wrote:
> strsep is re-entrant whereas strtok not necessarily so.
> 
> Signed-off by: Rosen Penev <rosenp at gmail.com>
> ---
>  ulog.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/ulog.c b/ulog.c
> index 296605d..985d366 100644
> --- a/ulog.c
> +++ b/ulog.c
> @@ -39,8 +39,8 @@ static const char *ulog_default_ident(void)
>  	if ((self = fopen("/proc/self/status", "r")) != NULL) {
>  		while (fgets(line, sizeof(line), self)) {
>  			if (!strncmp(line, "Name:", 5)) {
> -				strtok(line, "\t\n");
> -				p = strtok(NULL, "\t\n");
> +				strsep(&line, "\t\n");
> +				p = strsep(&line, "\t\n");

Hi,

i agree that using strsep() is a nice api however i fail to see why the
original code would fail. according to the man page it is re-entrant,
specially if called as done here. can you elaborate a bit why you think
it is not re-entrant ?

	John

>  				break;
>  			}
>  		}
> 



More information about the Lede-dev mailing list