]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/raster-error.c
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-private.h"
16 #include "raster-private.h"
17 #include "debug-internal.h"
21 * '_cupsRasterAddError()' - Add an error message to the error buffer.
25 _cupsRasterAddError(const char *f
, /* I - Printf-style error message */
26 ...) /* I - Additional arguments as needed */
28 _cups_globals_t
*cg
= _cupsGlobals();
30 _cups_raster_error_t
*buf
= &cg
->raster_error
;
32 va_list ap
; /* Pointer to additional arguments */
33 char s
[2048]; /* Message string */
34 ssize_t bytes
; /* Bytes in message string */
37 DEBUG_printf(("_cupsRasterAddError(f=\"%s\", ...)", f
));
40 bytes
= vsnprintf(s
, sizeof(s
), f
, ap
);
46 DEBUG_printf(("1_cupsRasterAddError: %s", s
));
50 if ((size_t)bytes
>= sizeof(s
))
53 if (bytes
> (ssize_t
)(buf
->end
- buf
->current
))
56 * Allocate more memory...
59 char *temp
; /* New buffer */
60 size_t size
; /* Size of buffer */
63 size
= (size_t)(buf
->end
- buf
->start
+ 2 * bytes
+ 1024);
66 temp
= realloc(buf
->start
, size
);
77 buf
->end
= temp
+ size
;
78 buf
->current
= temp
+ (buf
->current
- buf
->start
);
83 * Append the message to the end of the current string...
86 memcpy(buf
->current
, s
, (size_t)bytes
);
87 buf
->current
+= bytes
- 1;
92 * '_cupsRasterClearError()' - Clear the error buffer.
96 _cupsRasterClearError(void)
98 _cups_globals_t
*cg
= _cupsGlobals();
100 _cups_raster_error_t
*buf
= &cg
->raster_error
;
104 buf
->current
= buf
->start
;
107 *(buf
->start
) = '\0';
112 * '_cupsRasterErrorString()' - Return the last error from a raster function.
114 * If there are no recent errors, NULL is returned.
116 * @since CUPS 1.3/macOS 10.5@
119 const char * /* O - Last error */
120 _cupsRasterErrorString(void)
122 _cups_globals_t
*cg
= _cupsGlobals();
124 _cups_raster_error_t
*buf
= &cg
->raster_error
;
128 if (buf
->current
== buf
->start
)