]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #10947 time output without century for locale that use multi bytes utf8
authorAlain Spineux <alain@baculasystems.com>
Wed, 5 Jun 2024 16:08:10 +0000 (18:08 +0200)
committerEric Bollengier <eric@baculasystems.com>
Wed, 4 Dec 2024 08:14:25 +0000 (09:14 +0100)
- in Korean strftime("%b") is a 3 unicode char encoded in 5 bytes (in utf8)
- before
Daemon started 28- 5<EC><9B>2024 15:55, conf reloaded 28- 5월-2024 19:03:10
-after
Daemon started 28- 5월-24 15:55, conf reloaded 28- 5월-2024 19:03:10

bacula/src/lib/btime.c

index 2b6d9b530e1ad5484327a5d494bc06e3c97cbfb2..e02861df5990d10c1784a447e85161806854423b 100644 (file)
@@ -123,8 +123,11 @@ char *bstrftime_nc(char *dt, int maxlen, utime_t utime)
    /* NOTE! since the compiler complains about %y, I use %y and cut the century */
    strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm);
    /* overlay the century */
-   p = dt+7;
-   q = dt+9;
+   /* search for the second -, because %b can be multi-byte utf8 and more than 3 bytes */
+   p = dt + 3; // starting at first byte of %b
+   while (*p != '-') p++;
+   p++;
+   q = p+2;
    while (*q) {
       *p++ = *q++;
    }
@@ -154,7 +157,10 @@ char *bstrftime_gmt_iso8601(char *dt, int maxlen, utime_t utime)
    return dt;
 }
 
-/* Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time */
+/* Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time
+ * Warning If you don't know the timezone and don't specify the right
+ * "saving time" you cannot always get the right value.  (Alain 2024)
+ * */
 utime_t str_to_utime(char *str)
 {
    struct tm tm;