11//
22// Debugging functions for CUPS.
33//
4- // Copyright © 2022-2024 by OpenPrinting.
4+ // Copyright © 2022-2026 by OpenPrinting.
55// Copyright © 2008-2018 by Apple Inc.
66//
77// Licensed under Apache License v2.0. See the file "LICENSE" for more
@@ -85,14 +85,15 @@ _cups_debug_printf(const char *format, // I - Printf-style format string
8585 char buffer [2048 ]; // Output buffer
8686 ssize_t bytes ; // Number of bytes in buffer
8787 int level ; // Log level in message
88+ int myerrno = errno ;// Copy of errno value
8889
8990
9091 // See if we need to do any logging...
9192 if (!debug_init )
9293 _cups_debug_set (getenv ("CUPS_DEBUG_LOG" ), getenv ("CUPS_DEBUG_LEVEL" ), getenv ("CUPS_DEBUG_FILTER" ), 0 );
9394
9495 if (_cups_debug_fd < 0 )
95- return ;
96+ goto done ;
9697
9798 // Filter as needed...
9899 if (isdigit (format [0 ]))
@@ -101,15 +102,15 @@ _cups_debug_printf(const char *format, // I - Printf-style format string
101102 level = 0 ;
102103
103104 if (level > _cups_debug_level )
104- return ;
105+ goto done ;
105106
106107 cupsMutexLock (& debug_init_mutex );
107108 if (debug_filter )
108109 result = regexec (debug_filter , format , 0 , NULL , 0 );
109110 cupsMutexUnlock (& debug_init_mutex );
110111
111112 if (result )
112- return ;
113+ goto done ;
113114
114115 // Format the message...
115116 gettimeofday (& curtime , NULL );
@@ -133,6 +134,10 @@ _cups_debug_printf(const char *format, // I - Printf-style format string
133134 cupsMutexLock (& debug_log_mutex );
134135 write (_cups_debug_fd , buffer , (size_t )bytes );
135136 cupsMutexUnlock (& debug_log_mutex );
137+
138+ done :
139+
140+ errno = myerrno ;
136141}
137142
138143
@@ -148,14 +153,15 @@ _cups_debug_puts(const char *s) // I - String to output
148153 char buffer [2048 ]; // Output buffer
149154 ssize_t bytes ; // Number of bytes in buffer
150155 int level ; // Log level in message
156+ int myerrno = errno ;// Copy of errno value
151157
152158
153159 // See if we need to do any logging...
154160 if (!debug_init )
155161 _cups_debug_set (getenv ("CUPS_DEBUG_LOG" ), getenv ("CUPS_DEBUG_LEVEL" ), getenv ("CUPS_DEBUG_FILTER" ), 0 );
156162
157163 if (_cups_debug_fd < 0 )
158- return ;
164+ goto done ;
159165
160166 // Filter as needed...
161167 if (isdigit (s [0 ]))
@@ -164,15 +170,15 @@ _cups_debug_puts(const char *s) // I - String to output
164170 level = 0 ;
165171
166172 if (level > _cups_debug_level )
167- return ;
173+ goto done ;
168174
169175 cupsMutexLock (& debug_init_mutex );
170176 if (debug_filter )
171177 result = regexec (debug_filter , s , 0 , NULL , 0 );
172178 cupsMutexUnlock (& debug_init_mutex );
173179
174180 if (result )
175- return ;
181+ goto done ;
176182
177183 // Format the message...
178184 gettimeofday (& curtime , NULL );
@@ -192,6 +198,10 @@ _cups_debug_puts(const char *s) // I - String to output
192198 cupsMutexLock (& debug_log_mutex );
193199 write (_cups_debug_fd , buffer , (size_t )bytes );
194200 cupsMutexUnlock (& debug_log_mutex );
201+
202+ done :
203+
204+ errno = myerrno ;
195205}
196206
197207
0 commit comments