What I'm thinking is that, besides the TLS based solution, adding a non-standard getopt() seems to be a good option anyway, since it is a lightweight solution to this particular function.
Why do you think TLS is not lightweight. It is very lightweight. The non-standard, non-portable approach is essentially the same computationally.