Skip to contentSkip to conversation

resend: add strerror_l() to strerror()

PATCH walter harms 2 participants 3 messages Feb 28, 2014 – Mar 1, 2014 2 messages not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

Hi list,
There is a lot of documentation missing for localisation functions. This patch adds strerror_l() to the strerror(3) page.

re,
wh

ps: this is a resend since i never got an answer for my last patch

strerror.3 renamed from strerror.3.org +44 -0
@@ -50,6 +50,10 @@
 .sp
 .BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen );
             /* GNU-specific */
+.sp
+.B #include <locale.h>
+.sp
+.BI "char *strerror_l(int " errnum, " locale_t " loc );
 .fi
 .sp
 .in -4n
@@ -133,6 +137,11 @@
 .I errnum
 is unknown).
 The string always includes a terminating null byte (\(aq\\0\(aq).
+
+To get an error message in a given locale you need
+.BR strerror_l ()
+it takes an additional arument that defines to locale in what the message is returned.
+The function is thread-safe.
 .SH RETURN VALUE
 The
 .BR strerror ()
@@ -180,6 +189,8 @@
 .LP
 The
 .BR strerror_r ()
+and
+.BR strerror_r ()
 function is thread-safe.
 .SH CONFORMING TO
 .BR strerror ()
@@ -210,6 +221,39 @@
 .B EINVAL
 if the error number is unknown.
 C99 and POSIX.1-2008 require the return value to be non-NULL.
+.sp
+.BR strerror_l ()
+is a POSIX.1-2008 requirement, but available as GNU-specific function
+atleast since glibc 2.6.1.
+.SH EXAMPLE
+The program below demonstrates the use of the
+.BR strerror* ()
+functions. The first line should be
+.I sterror_l(13)=Permission denied
+the others should print this in a locale specific version.
+.nf
+
+#include <stdio.h>
+#include <string.h>
+#include <locale.h>
+
+int main()
+{
+  int e=13;    // errornumber
+  char buf[255];
+  locale_t loc;
+
+  setlocale(LC_ALL, "");
+  loc = newlocale (LC_MESSAGES_MASK, "C", NULL);
+  printf("sterror_l(13)=%s\\n",strerror_l(e,loc));
+  freelocale (loc);
+  // this will be translated automaticly
+  printf("sterror(13)=%s\\n",strerror(e));
+  strerror_r(e,buf,sizeof(buf)-1);
+  printf("sterror(13)=%s\\n",buf);
+  return 0;
+}
+.fi
 .SH SEE ALSO
 .BR err (3),
 .BR errno (3),

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi Walter,

I spotted some typos in your patch, I thought I'd send you some feedback before Michael catches up on this...

On Fri, Feb 28, 2014 at 11:35 AM, walter harms <[email protected]> wrote:
[...]

strerror.3 line 143

Quoted 8 lines
strerror.3 renamed from strerror.3.org +4 -0
@@ -133,6 +137,11 @@
 .I errnum
 is unknown).
 The string always includes a terminating null byte (\(aq\\0\(aq).
+
+To get an error message in a given locale you need
+.BR strerror_l ()
+it takes an additional arument that defines to locale in what the message is returned.

s/arument/argument

strerror.3 line 144

Quoted 1 line
strerror.3 renamed from strerror.3.org +1 -0
+The function is thread-safe.

This sentence seems redundant, you also mention this below (ATTRIBUTES section?).

strerror.3 line 193

Quoted 9 lines
strerror.3 renamed from strerror.3.org +2 -0
 .SH RETURN VALUE
 The
 .BR strerror ()
@@ -180,6 +189,8 @@
 .LP
 The
 .BR strerror_r ()
+and
+.BR strerror_r ()

I suppose you mean strerror_l()?

strerror.3 line 227

Quoted 8 lines
strerror.3 renamed from strerror.3.org +4 -0
@@ -210,6 +221,39 @@
 .B EINVAL
 if the error number is unknown.
 C99 and POSIX.1-2008 require the return value to be non-NULL.
+.sp
+.BR strerror_l ()
+is a POSIX.1-2008 requirement, but available as GNU-specific function
+atleast since glibc 2.6.1.

s/atleast/at least

strerror.3 line 232

Quoted 5 lines
strerror.3 renamed from strerror.3.org +5 -0
+.SH EXAMPLE
+The program below demonstrates the use of the
+.BR strerror* ()
+functions. The first line should be
+.I sterror_l(13)=Permission denied

s/sterror/strerror. This is also repeated below a few times... Also, don't you need to call strerror_l() with a different locale in order to get a translated error message? You are calling strerror_l() and then strerror() and strerror_r()...

Quoted 14 lines
strerror.3 renamed from strerror.3.org +14 -0
+the others should print this in a locale specific version.
+.nf
+
+#include <stdio.h>
+#include <string.h>
+#include <locale.h>
+
+int main()
+{
+  int e=13;    // errornumber
+  char buf[255];
+  locale_t loc;
+
+  setlocale(LC_ALL, "");

strerror.3 line 256

Quoted 10 lines
strerror.3 renamed from strerror.3.org +10 -0
+  loc = newlocale (LC_MESSAGES_MASK, "C", NULL);
+  printf("sterror_l(13)=%s\\n",strerror_l(e,loc));
+  freelocale (loc);
+  // this will be translated automaticly
+  printf("sterror(13)=%s\\n",strerror(e));
+  strerror_r(e,buf,sizeof(buf)-1);
+  printf("sterror(13)=%s\\n",buf);
+  return 0;
+}
+.fi

Thanks,
Stefan.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CACKs7VBG_O4qdrkOsK9RkEUfvkMHSMnXON=a4nCtjNGNN00MKg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw

Am 28.02.2014 22:26, schrieb Stefan Puiu:

Quoted 4 lines

Hi Walter,

I spotted some typos in your patch, I thought I'd send you some feedback before Michael catches up on this...

thats good, i am terrible at finding my own typos.

Quoted 13 lines · walter harms

[...]

strerror.3 line 143

Quoted 8 lines
strerror.3 renamed from strerror.3.org +4 -0
@@ -133,6 +137,11 @@
 .I errnum
 is unknown).
 The string always includes a terminating null byte (\(aq\\0\(aq).
+
+To get an error message in a given locale you need
+.BR strerror_l ()
+it takes an additional arument that defines to locale in what the message is returned.

s/arument/argument

fixed

Quoted 5 lines

strerror.3 line 144

Quoted 1 line
strerror.3 renamed from strerror.3.org +1 -0
+The function is thread-safe.

This sentence seems redundant, you also mention this below (ATTRIBUTES section?).

This is from the original page, IMHO in this special circumstances it is resonable to repeat this

Quoted 10 lines

strerror.3 line 193

Quoted 9 lines
strerror.3 renamed from strerror.3.org +2 -0
 .SH RETURN VALUE
 The
 .BR strerror ()
@@ -180,6 +189,8 @@
 .LP
 The
 .BR strerror_r ()
+and
+.BR strerror_r ()

fixed

Quoted 13 lines

I suppose you mean strerror_l()?

strerror.3 line 227

Quoted 8 lines
strerror.3 renamed from strerror.3.org +4 -0
@@ -210,6 +221,39 @@
 .B EINVAL
 if the error number is unknown.
 C99 and POSIX.1-2008 require the return value to be non-NULL.
+.sp
+.BR strerror_l ()
+is a POSIX.1-2008 requirement, but available as GNU-specific function
+atleast since glibc 2.6.1.

s/atleast/at least

fixed

Quoted 7 lines

strerror.3 line 232

Quoted 5 lines
strerror.3 renamed from strerror.3.org +5 -0
+.SH EXAMPLE
+The program below demonstrates the use of the
+.BR strerror* ()
+functions. The first line should be
+.I sterror_l(13)=Permission denied

s/sterror/strerror. This is also repeated below a few times... Also,

fixed,

Quoted 3 lines

don't you need to call strerror_l() with a different locale in order to get a translated error message? You are calling strerror_l() and then strerror() and strerror_r()...

I do not get the point, the rationale of strerror_l is that the program specifies a locale for a error message. In contrast to the other functions that are influenced by LANG. I have changed the wording a bit to make that more clear.

re,
wh

Quoted 19 lines
Quoted 19 lines
strerror.3 renamed from strerror.3.org +19 -0
+the others should print this in a locale specific version.
+.nf
+
+#include <stdio.h>
+#include <string.h>
+#include <locale.h>
+
+int main()
+{
+  int e=13;    // errornumber
+  char buf[255];
+  locale_t loc;
+
+  setlocale(LC_ALL, "");
+  loc = newlocale (LC_MESSAGES_MASK, "C", NULL);
+  printf("sterror_l(13)=%s\\n",strerror_l(e,loc));
+  freelocale (loc);
+  // this will be translated automaticly
+  printf("sterror(13)=%s\\n",strerror(e));
Quoted 8 lines

strerror.3 line 256

Quoted 5 lines
strerror.3 renamed from strerror.3.org +5 -0
+  strerror_r(e,buf,sizeof(buf)-1);
+  printf("sterror(13)=%s\\n",buf);
+  return 0;
+}
+.fi

Thanks,
Stefan.

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html