Streaming Security for the C Standard Library on OS X

Is there a definitive list of features that are thread safe in the Mac OS X implementation in the C standard library?

There is a good answer here regarding glibc and f*() functions, but I have not found such a resource regarding OS X Is there such a thing?

For example, strptime() and strftime() thread safe? printf() ? These are the ones that may have internal buffers that I would not want to mess up. :)

+8
c thread-safety standard-library macos
source share
2 answers

The Single Unix specification provides a fairly short list of functions that may be unsafe (except that functions in the Legacy Feature Group may be unsafe even though they are not listed). The list includes strtok() , which Dave mentions in his answer, but does not include strptime() , not strftime() , not printf() .

https://stackoverflow.com/questions/664433/ ... claims that in response to a question that is pretty similar to this, OS X supports the above aspect of the specification, so I think this is probably the best list to use. (You will probably also be interested in the rest of this question, and in another answer to it, by the way.)

+3
source share

Any function that seems to have some magical ability to remember will most likely not be thread safe. Any function that returns a pointer that you do not expect free() is very often not thread safe.

Many of the functions you really need to worry about returning char* or struct foo* . Although this is not an ideal rule, it often points to a function that has some kind of static storage and is not thread safe.

strtok() is a simple example of is, and it succeeded in strtok_r() , which is thread safe. For many unsafe functions, there is function_r() (r for reentrant).

+2
source share

All Articles