]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/raster-error.c
Move raster functions into libcups, with stubs that call back to libcups in libcupsimage.
[thirdparty/cups.git] / cups / raster-error.c
CommitLineData
dd204f7a
MS
1/*
2 * Raster error handling for CUPS.
3 *
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 2007 by Easy Software Products.
6 *
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
8 * information.
9 */
10
11/*
12 * Include necessary headers...
13 */
14
15#include <cups/cups-private.h>
16#include <cups/raster-private.h>
17
18
19/*
20 * Local structures...
21 */
22
23
24
25/*
26 * Local functions...
27 */
28
29static _cups_raster_error_t *get_error_buffer(void);
30
31
32/*
33 * '_cupsRasterAddError()' - Add an error message to the error buffer.
34 */
35
36void
37_cupsRasterAddError(const char *f, /* I - Printf-style error message */
38 ...) /* I - Additional arguments as needed */
39{
40 _cups_globals_t *cg = _cupsGlobals();
41 /* Thread globals */
42 _cups_raster_error_t *buf = &cg->raster_error;
43 /* Error buffer */
44 va_list ap; /* Pointer to additional arguments */
45 char s[2048]; /* Message string */
46 ssize_t bytes; /* Bytes in message string */
47
48
49 DEBUG_printf(("_cupsRasterAddError(f=\"%s\", ...)", f));
50
51 va_start(ap, f);
52 bytes = vsnprintf(s, sizeof(s), f, ap);
53 va_end(ap);
54
55 if (bytes <= 0)
56 return;
57
58 DEBUG_printf(("1_cupsRasterAddError: %s", s));
59
60 bytes ++;
61
62 if ((size_t)bytes >= sizeof(s))
63 return;
64
65 if (bytes > (ssize_t)(buf->end - buf->current))
66 {
67 /*
68 * Allocate more memory...
69 */
70
71 char *temp; /* New buffer */
72 size_t size; /* Size of buffer */
73
74
75 size = (size_t)(buf->end - buf->start + 2 * bytes + 1024);
76
77 if (buf->start)
78 temp = realloc(buf->start, size);
79 else
80 temp = malloc(size);
81
82 if (!temp)
83 return;
84
85 /*
86 * Update pointers...
87 */
88
89 buf->end = temp + size;
90 buf->current = temp + (buf->current - buf->start);
91 buf->start = temp;
92 }
93
94 /*
95 * Append the message to the end of the current string...
96 */
97
98 memcpy(buf->current, s, (size_t)bytes);
99 buf->current += bytes - 1;
100}
101
102
103/*
104 * '_cupsRasterClearError()' - Clear the error buffer.
105 */
106
107void
108_cupsRasterClearError(void)
109{
110 _cups_globals_t *cg = _cupsGlobals();
111 /* Thread globals */
112 _cups_raster_error_t *buf = &cg->raster_error;
113 /* Error buffer */
114
115
116 buf->current = buf->start;
117
118 if (buf->start)
119 *(buf->start) = '\0';
120}
121
122
123/*
124 * '_cupsRasterErrorString()' - Return the last error from a raster function.
125 *
126 * If there are no recent errors, NULL is returned.
127 *
128 * @since CUPS 1.3/macOS 10.5@
129 */
130
131const char * /* O - Last error */
132_cupsRasterErrorString(void)
133{
134 _cups_globals_t *cg = _cupsGlobals();
135 /* Thread globals */
136 _cups_raster_error_t *buf = &cg->raster_error;
137 /* Error buffer */
138
139
140 if (buf->current == buf->start)
141 return (NULL);
142 else
143 return (buf->start);
144}