]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/raster-error.c
8bba1275d0e815c986e1b5887c3a0187409efb41
2 * Raster error handling for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 2007 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include <cups/cups-private.h>
16 #include <cups/raster-private.h>
20 * '_cupsRasterAddError()' - Add an error message to the error buffer.
24 _cupsRasterAddError(const char *f
, /* I - Printf-style error message */
25 ...) /* I - Additional arguments as needed */
27 _cups_globals_t
*cg
= _cupsGlobals();
29 _cups_raster_error_t
*buf
= &cg
->raster_error
;
31 va_list ap
; /* Pointer to additional arguments */
32 char s
[2048]; /* Message string */
33 ssize_t bytes
; /* Bytes in message string */
36 DEBUG_printf(("_cupsRasterAddError(f=\"%s\", ...)", f
));
39 bytes
= vsnprintf(s
, sizeof(s
), f
, ap
);
45 DEBUG_printf(("1_cupsRasterAddError: %s", s
));
49 if ((size_t)bytes
>= sizeof(s
))
52 if (bytes
> (ssize_t
)(buf
->end
- buf
->current
))
55 * Allocate more memory...
58 char *temp
; /* New buffer */
59 size_t size
; /* Size of buffer */
62 size
= (size_t)(buf
->end
- buf
->start
+ 2 * bytes
+ 1024);
65 temp
= realloc(buf
->start
, size
);
76 buf
->end
= temp
+ size
;
77 buf
->current
= temp
+ (buf
->current
- buf
->start
);
82 * Append the message to the end of the current string...
85 memcpy(buf
->current
, s
, (size_t)bytes
);
86 buf
->current
+= bytes
- 1;
91 * '_cupsRasterClearError()' - Clear the error buffer.
95 _cupsRasterClearError(void)
97 _cups_globals_t
*cg
= _cupsGlobals();
99 _cups_raster_error_t
*buf
= &cg
->raster_error
;
103 buf
->current
= buf
->start
;
106 *(buf
->start
) = '\0';
111 * '_cupsRasterErrorString()' - Return the last error from a raster function.
113 * If there are no recent errors, NULL is returned.
115 * @since CUPS 1.3/macOS 10.5@
118 const char * /* O - Last error */
119 _cupsRasterErrorString(void)
121 _cups_globals_t
*cg
= _cupsGlobals();
123 _cups_raster_error_t
*buf
= &cg
->raster_error
;
127 if (buf
->current
== buf
->start
)