Some glibc foo and foo_r APIs

The ctime(3), this being thread-unsafe, is now replaced by its thread-safe counterpart ctime_r(3); this is just one example of a generic trend in modern glibc:

  • The older, thread (MT-unsafe) unsafe function is called foo
  • Has a counterpart, the newer, thread (MT-Safe) safe foo_r API

To give the reader an appreciation of this, we enumerate some (not all!) of the glibc foo_r style of APIs:

asctime_r(3) crypt_r(3) ctime_r(3) drand48_r(3)

getpwnam_r(3) getpwuid_r(3) getrpcbyname_r(3) getrpcbynumber_r(3) getrpcent_r(3) getservbyname_r(3)

seed48_r(3) setkey_r(3) srand48_r(3) srandom_r(3) strerror_r(3) strtok_r(3)

getdate_r(3) getgrent_r(3) getgrgid_r(3) getgrnam_r(3) gethostbyaddr_r(3) gethostbyname2_r(3) ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.