]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/raster-error.c
Drop _httpTLSSetCredentials - not implemented or used.
[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
dd204f7a
MS
19/*
20 * '_cupsRasterAddError()' - Add an error message to the error buffer.
21 */
22
23void
24_cupsRasterAddError(const char *f, /* I - Printf-style error message */
25 ...) /* I - Additional arguments as needed */
26{
27 _cups_globals_t *cg = _cupsGlobals();
28 /* Thread globals */
29 _cups_raster_error_t *buf = &cg->raster_error;
30 /* Error buffer */
31 va_list ap; /* Pointer to additional arguments */
32 char s[2048]; /* Message string */
33 ssize_t bytes; /* Bytes in message string */
34
35
36 DEBUG_printf(("_cupsRasterAddError(f=\"%s\", ...)", f));
37
38 va_start(ap, f);
39 bytes = vsnprintf(s, sizeof(s), f, ap);
40 va_end(ap);
41
42 if (bytes <= 0)
43 return;
44
45 DEBUG_printf(("1_cupsRasterAddError: %s", s));
46
47 bytes ++;
48
49 if ((size_t)bytes >= sizeof(s))
50 return;
51
52 if (bytes > (ssize_t)(buf->end - buf->current))
53 {
54 /*
55 * Allocate more memory...
56 */
57
58 char *temp; /* New buffer */
59 size_t size; /* Size of buffer */
60
61
62 size = (size_t)(buf->end - buf->start + 2 * bytes + 1024);
63
64 if (buf->start)
65 temp = realloc(buf->start, size);
66 else
67 temp = malloc(size);
68
69 if (!temp)
70 return;
71
72 /*
73 * Update pointers...
74 */
75
76 buf->end = temp + size;
77 buf->current = temp + (buf->current - buf->start);
78 buf->start = temp;
79 }
80
81 /*
82 * Append the message to the end of the current string...
83 */
84
85 memcpy(buf->current, s, (size_t)bytes);
86 buf->current += bytes - 1;
87}
88
89
90/*
91 * '_cupsRasterClearError()' - Clear the error buffer.
92 */
93
94void
95_cupsRasterClearError(void)
96{
97 _cups_globals_t *cg = _cupsGlobals();
98 /* Thread globals */
99 _cups_raster_error_t *buf = &cg->raster_error;
100 /* Error buffer */
101
102
103 buf->current = buf->start;
104
105 if (buf->start)
106 *(buf->start) = '\0';
107}
108
109
110/*
111 * '_cupsRasterErrorString()' - Return the last error from a raster function.
112 *
113 * If there are no recent errors, NULL is returned.
114 *
115 * @since CUPS 1.3/macOS 10.5@
116 */
117
118const char * /* O - Last error */
119_cupsRasterErrorString(void)
120{
121 _cups_globals_t *cg = _cupsGlobals();
122 /* Thread globals */
123 _cups_raster_error_t *buf = &cg->raster_error;
124 /* Error buffer */
125
126
127 if (buf->current == buf->start)
128 return (NULL);
129 else
130 return (buf->start);
131}