0

In my parse() I used this code snipped I found on google in order to extract the method:

char* method = strtok(line, " ");

I'm getting the following error:

/usr/include/string.h:348:39: note: passing argument to parameter '__s' here extern char *strtok (char *__restrict __s, const char *__restrict __delim)

Is there a way to work around it, or do I have to try a different approach using strstr ecc. as per specs?

thx

1

You are getting that error because line is declared a const char*. Review the man page for strtok, specifically [emphasis added]:

Be cautious when using these functions. If you do use them, note that:

  • These functions modify their first argument.
  • These functions cannot be used on constant strings.
  • The identity of the delimiting byte is lost.
  • The strtok() function uses a static buffer while parsing, so it's not thread safe. Use strtok_r() if this matters to you.

You will need to decide how best to approach this.

1
  • I've implemented parse(): 1. making a copy of 'const char *line' using strdupa(). 2. parsing request-line using strtok_r(). – gado007 Feb 28 '16 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .