11//
22// Localized printf/puts functions for CUPS.
33//
4- // Copyright © 2022 by OpenPrinting.
4+ // Copyright © 2022-2024 by OpenPrinting.
55// Copyright © 2007-2014 by Apple Inc.
66// Copyright © 2002-2007 by Easy Software Products.
77//
@@ -110,6 +110,7 @@ cupsLangPuts(FILE *fp, // I - File to write to
110110 const char * message ) // I - Message string to use
111111{
112112 ssize_t bytes ; // Number of bytes formatted
113+ size_t length = 0 ; // Total length
113114 char output [8192 ]; // Message buffer
114115 _cups_globals_t * cg = _cupsGlobals (); // Global data
115116
@@ -122,12 +123,14 @@ cupsLangPuts(FILE *fp, // I - File to write to
122123 cg -> lang_default = cupsLangDefault ();
123124
124125 // Transcode to the destination charset...
125- bytes = cupsUTF8ToCharset (output , cupsLangGetString (cg -> lang_default , message ), sizeof (output ) - 4 , cg -> lang_encoding );
126- bytes += cupsUTF8ToCharset (output + bytes , "\n" , sizeof (output ) - (size_t )bytes , cg -> lang_encoding );
126+ if ((bytes = cupsUTF8ToCharset (output , cupsLangGetString (cg -> lang_default , message ), sizeof (output ) - 4 , cg -> lang_encoding )) > 0 )
127+ length += (size_t )bytes ;
128+ if ((bytes = cupsUTF8ToCharset (output + length , "\n" , sizeof (output ) - length , cg -> lang_encoding )) > 0 )
129+ length += (size_t )bytes ;
127130
128131 // Write the string and return the number of bytes written...
129- if (bytes > 0 )
130- return ((ssize_t )fwrite (output , 1 , ( size_t ) bytes , fp ));
132+ if (length > 0 )
133+ return ((ssize_t )fwrite (output , 1 , length , fp ));
131134 else
132135 return (bytes );
133136}
0 commit comments