Thanks for all answers. I don't entirely understand most of them though as I'm not really familiar with the implications of TLS or how to use it correctly. Also, do we need per-thread or per-task data here?
You would expect getopt() to be used only on the many thread since that is the only thread that receives argc and argv.
A faithful, bug-for-bug, implementation would require a per task, but AFAIK there would be no real problem with per thread either.
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.
Except that NuttX is a standards based OS and we avoid non-standard interfaces like the plague. Using TLS is 100% transparent and 100% compatible. Why would you adopt a non-standard solution when a better, fully compliant implementation is readily available?