php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
gd_io.c
Go to the documentation of this file.
1
2
3/*
4 * io.c
5 *
6 * Implements the simple I/O 'helper' routines.
7 *
8 * Not really essential, but these routines were used extensively in GD,
9 * so they were moved here. They also make IOCtx calls look better...
10 *
11 * Written (or, at least, moved) 1999, Philip Warner.
12 *
13 */
14
15#include <math.h>
16#include <string.h>
17#include <stdlib.h>
18#include "gd.h"
19
20/* Use this for commenting out debug-print statements. */
21/* Just use the first '#define' to allow all the prints... */
22/*#define IO_DBG(s) (s) */
23#define IO_DBG(s)
24
25
26#define GD_IO_EOF_CHK(r) \
27 if (r == EOF) { \
28 return 0; \
29 } \
30
31/*
32 * Write out a word to the I/O context pointer
33 */
34void Putword (int w, gdIOCtx * ctx)
35{
36 unsigned char buf[2];
37
38 buf[0] = w & 0xff;
39 buf[1] = (w / 256) & 0xff;
40 (ctx->putBuf) (ctx, (char *) buf, 2);
41}
42
43void Putchar (int c, gdIOCtx * ctx)
44{
45 (ctx->putC) (ctx, c & 0xff);
46}
47
48void gdPutC (const unsigned char c, gdIOCtx * ctx)
49{
50 (ctx->putC) (ctx, c);
51}
52
53void gdPutWord (int w, gdIOCtx * ctx)
54{
55 IO_DBG (gd_error("Putting word..."));
56 (ctx->putC) (ctx, (unsigned char) (w >> 8));
57 (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
58 IO_DBG (gd_error("put."));
59}
60
61void gdPutInt (int w, gdIOCtx * ctx)
62{
63 IO_DBG (gd_error("Putting int..."));
64 (ctx->putC) (ctx, (unsigned char) (w >> 24));
65 (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
66 (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
67 (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
68 IO_DBG (gd_error("put."));
69}
70
71int gdGetC (gdIOCtx * ctx)
72{
73 return ((ctx->getC) (ctx));
74}
75
76int gdGetByte (int *result, gdIOCtx * ctx)
77{
78 int r;
79 r = (ctx->getC) (ctx);
81 *result = r;
82 return 1;
83}
84
85int gdGetWord (int *result, gdIOCtx * ctx)
86{
87 int r;
88 r = (ctx->getC) (ctx);
90 *result = r << 8;
91 r = (ctx->getC) (ctx);
93 *result += r;
94 return 1;
95}
96
97
98int gdGetWordLSB(signed short int *result, gdIOCtx *ctx)
99{
100 int high = 0, low = 0;
101 low = (ctx->getC) (ctx);
102 if (low == EOF) {
103 return 0;
104 }
105
106 high = (ctx->getC) (ctx);
107 if (high == EOF) {
108 return 0;
109 }
110
111 if (result) {
112 *result = (high << 8) | low;
113 }
114
115 return 1;
116}
117
118int gdGetInt (int *result, gdIOCtx * ctx)
119{
120 unsigned int r;
121 r = (ctx->getC) (ctx);
122 GD_IO_EOF_CHK(r);
123 *result = r << 24;
124
125 r = (ctx->getC) (ctx);
126 GD_IO_EOF_CHK(r);
127 *result += r << 16;
128
129 r = (ctx->getC) (ctx);
130 if (r == EOF) {
131 return 0;
132 }
133 *result += r << 8;
134
135 r = (ctx->getC) (ctx);
136 GD_IO_EOF_CHK(r);
137 *result += r;
138
139 return 1;
140}
141
142int gdGetIntLSB(signed int *result, gdIOCtx *ctx)
143{
144 unsigned int c;
145 unsigned int r = 0;
146
147 c = (ctx->getC) (ctx);
148 if (c == EOF) {
149 return 0;
150 }
151 r |= (c << 24);
152 r >>= 8;
153
154 c = (ctx->getC) (ctx);
155 if (c == EOF) {
156 return 0;
157 }
158 r |= (c << 24);
159 r >>= 8;
160
161 c = (ctx->getC) (ctx);
162 if (c == EOF) {
163 return 0;
164 }
165 r |= (c << 24);
166 r >>= 8;
167
168 c = (ctx->getC) (ctx);
169 if (c == EOF) {
170 return 0;
171 }
172 r |= (c << 24);
173
174 if (result) {
175 *result = (signed int)r;
176 }
177
178 return 1;
179}
180
181int gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
182{
183 IO_DBG (gd_error("Putting buf..."));
184 return (ctx->putBuf) (ctx, buf, size);
185 IO_DBG (gd_error("put."));
186}
187
188int gdGetBuf (void *buf, int size, gdIOCtx * ctx)
189{
190 return (ctx->getBuf) (ctx, buf, size);
191}
192
193int gdSeek (gdIOCtx * ctx, const int pos)
194{
195 IO_DBG (gd_error("Seeking..."));
196 return ((ctx->seek) (ctx, pos));
197 IO_DBG (gd_error("Done."));
198}
199
200long gdTell (gdIOCtx * ctx)
201{
202 IO_DBG (gd_error("Telling..."));
203 return ((ctx->tell) (ctx));
204 IO_DBG (gd_error ("told."));
205}
new_type size
Definition ffi.c:4365
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
void gdPutInt(int w, gdIOCtx *ctx)
Definition gd_io.c:61
#define GD_IO_EOF_CHK(r)
Definition gd_io.c:26
void Putword(int w, gdIOCtx *ctx)
Definition gd_io.c:34
int gdGetIntLSB(signed int *result, gdIOCtx *ctx)
Definition gd_io.c:142
long gdTell(gdIOCtx *ctx)
Definition gd_io.c:200
int gdGetBuf(void *buf, int size, gdIOCtx *ctx)
Definition gd_io.c:188
int gdSeek(gdIOCtx *ctx, const int pos)
Definition gd_io.c:193
void Putchar(int c, gdIOCtx *ctx)
Definition gd_io.c:43
int gdGetC(gdIOCtx *ctx)
Definition gd_io.c:71
int gdGetByte(int *result, gdIOCtx *ctx)
Definition gd_io.c:76
int gdGetInt(int *result, gdIOCtx *ctx)
Definition gd_io.c:118
int gdPutBuf(const void *buf, int size, gdIOCtx *ctx)
Definition gd_io.c:181
int gdGetWord(int *result, gdIOCtx *ctx)
Definition gd_io.c:85
#define IO_DBG(s)
Definition gd_io.c:23
void gdPutWord(int w, gdIOCtx *ctx)
Definition gd_io.c:53
void gdPutC(const unsigned char c, gdIOCtx *ctx)
Definition gd_io.c:48
int gdGetWordLSB(signed short int *result, gdIOCtx *ctx)
Definition gd_io.c:98
void gd_error(const char *format,...)
Definition gd.c:103
unsigned const char * pos
Definition php_ffi.h:52
int(* seek)(struct gdIOCtx *, const int)
Definition gd_io.h:17
void(* putC)(struct gdIOCtx *, int)
Definition gd_io.h:14
long(* tell)(struct gdIOCtx *)
Definition gd_io.h:18
int(* getC)(struct gdIOCtx *)
Definition gd_io.h:11
int(* putBuf)(struct gdIOCtx *, const void *, int)
Definition gd_io.h:15
int(* getBuf)(struct gdIOCtx *, void *, int)
Definition gd_io.h:12
bool result