Name n3594 - add streq() Principles - Codify existing practice to address evident deficiencies. - Enable secure programming Category Standardize common APIs Author Alejandro Colomar Cc: Yair Lenga Cc: Joseph Myers History This paper is an alternative to n3455 from Yair Lenga. r0 (2025-06-09): - Initial draft. Description strcmp(3) is too confusing, and many projects come up with a wrapper streq() to do one of the common operations with it: Compare two strings for equality, returning a boolean. By developing such a wrapper in shadow utils, and replacing code that used strcmp(3) to use the wrapper, I've found and fixed several bugs. Prior art Many projects define this API, either as a macro or as a function. Here's an example implementation: bool streq(const char *s1, const char *s2) { return strcmp(s1, s2) == 0; } Proposed wording Based on N3550. 7.28.4 String handling :: Comparison functions ## New section after 7.28.4.3 ("The strcmp function"): +7.28.4.3+1 The streq function + +Synopsis +1 #include + bool streq(const char *s1, const char *s2); + +Description +2 The streq function + compares the strings pointed to by + s1 and s2. + +Returns +3 The streq function returns true + if the strings are equal. 7.33.4.5 Wide string comparison functions ## New section after 7.33.4.5.2 ("The wcscmp function"): +7.33.4.5.2+1 The wcseq function + +Synopsis +1 #include + bool wcseq(const wchar_t *s1, const wchar_t *s2); + +Description +2 The wcseq function + is equivalent to + streq, + except that it handles wide strings.