This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][PATCH] Locale convenience funtions


Dear, glibc locale maintainers.
 
I'd like to discuss about additional functions for locale convenience which are supported by the other libc library (eg. bsd libc library).
For example, to support a snprintf_l convenience funciton, I think we can write an implemantation as the following patch set.
And likewise the other functions too. (asprintf_l, fprintf_l, printf_l, sprintf_l, vasprintf_l, vfprintf_l, vprintf_l, vsnprintf_l, vsprintf_l)
Please let me know whether this approach is acceptable or not.
 
Regards,
Seung-yeon Choe.
s.choe@samsung.com

diff -Naur glibc-2.17/libio/stdio.h glibc-2.17_snprintf/libio/stdio.h
--- glibc-2.17/libio/stdio.h    2012-12-25 12:02:13.000000000 +0900
+++ glibc-2.17_snprintf/libio/stdio.h   2013-06-10 17:23:49.021522380 +0900
@@ -416,6 +416,12 @@
      __attribute__ ((__format__ (__printf__, 2, 3)));
 #endif
+#ifdef __USE_GNU
+/* Locale convenience functions */
+extern int snprintf_l (char *__restrict __s, size_t __maxlen, locale_t loc,
+                     const char *__restrict __format, ...)
+     __THROWNL __attribute__ ((__format__ (__printf__, 4, 5)));
+#endif
 __BEGIN_NAMESPACE_STD
 /* Read formatted input from STREAM.
diff -Naur glibc-2.17/stdio-common/snprintf_l.c glibc-2.17_snprintf/stdio-common/snprintf_l.c
--- glibc-2.17/stdio-common/snprintf_l.c        1970-01-01 09:00:00.000000000 +0900
+++ glibc-2.17_snprintf/stdio-common/snprintf_l.c       2013-06-10 17:21:43.049522395 +0900
@@ -0,0 +1,40 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <xlocale.h>
+
+int
+__snprintf_l (char *s, size_t maxlen, locale_t loc, const char *format, ...)
+{
+  va_list arg;
+  int done;
+  locale_t old_loc = uselocale (loc);
+
+  va_start (arg, format);
+  done = __vsnprintf (s, maxlen, format, arg);
+  va_end (arg);
+
+  uselocale (old_loc);
+  return done;
+}
+ldbl_weak_alias (__snprintf_l, snprintf_l)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]