Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Date/time display error for non-UTF-8 locales with lpstat #1751

Closed

Description

@michaelrsweet

Version: 1.2.1
CUPS.org User: inger.altlinux

  1. cups lpstat utility uses _cupsLangPrintf() function to output results
  2. _cupsLangPrintf accepts utf8 strings only
  3. utility also uses strftime() function to perform current system time
  4. strftime() function with "%c" format will create string with my local, _ not utf8_ characters (koi8-r encoding)

As a result _cupsLangPrintf will fail and I see nothing on the screen.

How to reproduce it:
$ locale
LANG=ru_RU.KOI8-R
LC_CTYPE="ru_RU.KOI8-R"
LC_NUMERIC="ru_RU.KOI8-R"
LC_TIME="ru_RU.KOI8-R"
LC_COLLATE="ru_RU.KOI8-R"
LC_MONETARY="ru_RU.KOI8-R"
LC_MESSAGES="ru_RU.KOI8-R"
LC_PAPER="ru_RU.KOI8-R"
LC_NAME="ru_RU.KOI8-R"
LC_ADDRESS="ru_RU.KOI8-R"
LC_TELEPHONE="ru_RU.KOI8-R"
LC_MEASUREMENT="ru_RU.KOI8-R"
LC_IDENTIFICATION="ru_RU.KOI8-R"
LC_ALL=
$ lpstat -a
$

However:

$ LC_ALL=C lpstat -a
loc accepting requests since Mon Jun 5 15:35:26 2006
samsung accepting requests since Mon Jun 5 15:44:58 2006
$ LC_ALL=ru_RU.utf8 lpstat -a|iconv -futf8
loc accepting requests since �нд 05 ��н 2006 15:35:26
samsung accepting requests since �нд 05 ��н 2006 15:44:58
$

Activity

  1. michaelrsweet commented on Jun 6, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    Changing priority to match severity and summary to match actual problem...

    Looks like we are going to have to hack lpstat to force a UTF-8 locale for LC_TIME.

    Does the following produce the correct results on your system?

    LC_TIME=ru_RU.UTF-8 lpstat -a
    
  2. michaelrsweet commented on Jun 6, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: inger.altlinux

    Yes, all works well (without any additional iconv in command line)

    $ LC_TIME=ru_RU.utf8 lpstat -a
    loc accepting requests since �нд 05 ��н 2006 15:35:26
    samsung accepting requests since �нд 05 ��н 2006 15:44:58

  3. michaelrsweet commented on Jun 6, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: mike

    OK, I believe I have a fix for this now; please test the attached patch or current SVN trunk...

  4. michaelrsweet commented on Jun 7, 2006

    @michaelrsweet
    ContributorAuthor

    CUPS.org User: inger.altlinux

    works well on my system, thank you.

  5. michaelrsweet commented on Jun 7, 2006

    @michaelrsweet
    ContributorAuthor

    "str1751.patch":

    Index: lpstat.c

    --- lpstat.c (revision 5633)
    +++ lpstat.c (working copy)
    @@ -71,26 +71,59 @@
    */

    int
    -main(int argc, /* I - Number of command-line arguments */

    • char _argv[])     /_ I - Command-line arguments _/
      
      +main(int argc, /_ I - Number of command-line arguments */
    • char _argv[])         /_ I - Command-line arguments */
      
      {
    • int i, /* Looping var */
    •   status;     /\* Exit status */
      
    • http_t http; / Connection to server */
    • int num_dests; /* Number of user destinations */
    • cups_dest_t dests; / User destinations */
    • int long_status; /* Long status report? */
    • int ranking; /* Show job ranking? */
    • const char which; / Which jobs to show? */
    • char op; /* Last operation on command-line */
    • int i, /* Looping var */
    •   status;         /\* Exit status */
      
    • http_t http; / Connection to server */
    • int num_dests; /* Number of user destinations */
    • cups_dest_t dests; / User destinations */
    • int long_status; /* Long status report? */
    • int ranking; /* Show job ranking? */
    • const char which; / Which jobs to show? */
    • char op; /* Last operation on command-line */

    /*

    • Set the locale so that times, etc. are displayed properly.

    • * Unfortunately, while we need the localized time value, we don't

    • * want to use the localized charset for the time value, so we need

    • * to set LC_TIME to the locale name with .UTF-8 on the end (if

      • the locale includes a character set specifier...)
        */

      setlocale(LC_ALL, "");

    +#ifdef LC_TIME

    • {
    • const char lc_time; / Current LC_TIME value */
    • char new_lc_time[255], /* New LC_TIME value */
    •   _charset;       /_ Pointer to character set */
      
    • if ((lc_time = setlocale(LC_TIME, NULL)) == NULL)
    •  lc_time = setlocale(LC_ALL, NULL);
      
    • if (lc_time)
    • {
    •  strlcpy(new_lc_time, lc_time, sizeof(new_lc_time));
      
    •  if ((charset = strchr(new_lc_time, '.')) == NULL)
      
    •    charset = new_lc_time + strlen(new_lc_time);
      
    •  strlcpy(charset, ".UTF-8", sizeof(new_lc_time) - (charset - new_lc_time));
      
    • }
    • else
    •  strcpy(new_lc_time, "C");
      
    • setlocale(LC_TIME, new_lc_time);
    • }
      +#endif /* LC_TIME */
    • /*
    • * Parse command-line options...
    • */

    http = NULL;
    num_dests = 0;
    dests = NULL;

  6. added this to the Stable milestone on Mar 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions