View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002013 | 1003.1(2024)/Issue8 | System Interfaces | public | 2026-11-29 14:16 | 2026-11-29 14:16 |
| Reporter | romanzilka | Assigned To | |||
| Priority | normal | Severity | Editorial | Type | Enhancement Request |
| Status | New | Resolution | Open | ||
| Name | Roman Žilka | ||||
| Organization | |||||
| User Reference | |||||
| Section | strerror_r | ||||
| Page Number | 0 | ||||
| Line Number | 0 | ||||
| Interp Status | |||||
| Final Accepted Text | |||||
| Summary | 0002013: Necessity of strerror_r() | ||||
| Description | Consider the simple programming task: in a multi-threaded environment, obtain the error string corresponding to an error number using any of the standard strerror*() function(s). The string is to follow the current locale (thread-specific one, if set, global, if not). Assumptions: 1. strerror() is thread-safe, 2. strerror_l()'s output buffer can never become ovewritten or invalidated by strerror() (see issue 2011), 3. strerror_l()'s output buffer in a thread can never become ovewritten or invalidated by strerror_l() in another thread (though this is not what thread-safety is defined as). These complications would not change the meaning of this issue. The informative part of the section on strerror*() of the standard declares strerror_r() unnecessary and recommends strerror_l().
const locale_t curloc = uselocale(0);
if (curloc == LC_GLOBAL_LOCALE) {
curloc = duplocale(curloc);
if (! curloc) fatal();
}
result = strerror_l(errnr, curloc);
freelocale(curloc);
The possibility of ENOMEM in duplocale() makes this path unusable. Let's try to involve strerror() then. It vaguely appears, after all, that the purpose of the *_l() functions in general is not the simple case when the current locale is called for.
const locale_t curloc = uselocale(0);
if (curloc != LC_GLOBAL_LOCALE)
result = strerror_l(errnr, curloc);
else result = strerror(errnr);
// at this point, because of strerror(), result may point to an invalid string [CX]or even be an invalid pointer[/CX]
fatal();
Again, this path is unusable. Hence, strerror_r() is necessary, or at least useful. its target buffer can concievably be allocated on the stack. | ||||
| Desired Action | 1. Change the sentence: "Applications should use strerror_l() rather than strerror() or strerror_r() to avoid thread safety and possible alternative (non-conforming) versions of these functions in some implementations." to "Application developers are advised that implementations exist which provide a non-conforming strerror_r() by default and a conforming one after implementation-specific configuration." Alternatively, remove the sentence altogether. Also see issue 2012. 2. Remove the sentence "The strerror_l() function is required to be thread-safe, thereby eliminating the need for an equivalent to the strerror_r() function." Also note that it may be slightly incorrect either way: the intention, I suppose, was "... thereby eliminating the need for the strerror_r() function." | ||||
| Tags | No tags attached. | ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-29 14:16 | romanzilka | New Issue |