php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
gd_io_ss.c
Go to the documentation of this file.
1
2/*
3 * io_ss.c
4 *
5 * Implements the Source/Sink interface.
6 *
7 * As will all I/O modules, most functions are for local use only (called
8 * via function pointers in the I/O context).
9 *
10 * The Source/Sink model is the primary 'user' interface for alternate data
11 * sources; the IOCtx interface is intended (at least in version 1.5) to be
12 * used internally until it settles down a bit.
13 *
14 * This module just layers the Source/Sink interface on top of the IOCtx; no
15 * support is provided for tell/seek, so GD2 writing is not possible, and
16 * retrieving parts of GD2 files is also not possible.
17 *
18 * A new SS context does not need to be created with both a Source and a Sink.
19 *
20 * Written/Modified 1999, Philip Warner.
21 *
22 */
23
24#include <math.h>
25#include <string.h>
26#include <stdlib.h>
27#include "gd.h"
28#include "gdhelpers.h"
29
30/* this is used for creating images in main memory */
31
38
39typedef struct ssIOCtx *ssIOCtxPtr;
40
42
43static int sourceGetbuf (gdIOCtx *, void *, int);
44static int sourceGetchar (gdIOCtx * ctx);
45static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size);
46static void sinkPutchar (gdIOCtx * ctx, int a);
47static void gdFreeSsCtx (gdIOCtx * ctx);
48
49/* return data as a dynamic pointer */
51{
53
54 ctx = (ssIOCtxPtr) gdMalloc (sizeof (ssIOCtx));
55
56 ctx->src = src;
57 ctx->snk = snk;
58
59 ctx->ctx.getC = sourceGetchar;
60 ctx->ctx.getBuf = sourceGetbuf;
61
62 ctx->ctx.putC = sinkPutchar;
63 ctx->ctx.putBuf = sinkPutbuf;
64
65 ctx->ctx.tell = NULL;
66 ctx->ctx.seek = NULL;
67
68 ctx->ctx.gd_free = gdFreeSsCtx;
69
70 return (gdIOCtx *) ctx;
71}
72
73static void gdFreeSsCtx (gdIOCtx * ctx)
74{
75 gdFree(ctx);
76}
77
78
79static int sourceGetbuf (gdIOCtx * ctx, void *buf, int size)
80{
81 ssIOCtx *lctx;
82 int res;
83
84 lctx = (ssIOCtx *) ctx;
85
86 res = ((lctx->src->source) (lctx->src->context, buf, size));
87
88 /*
89 * Translate the return values from the Source object:
90 * 0 is EOF, -1 is error
91 */
92
93 if (res == 0) {
94 return EOF;
95 } else if (res < 0) {
96 return 0;
97 } else {
98 return res;
99 }
100}
101
102static int sourceGetchar (gdIOCtx * ctx)
103{
104 int res;
105 unsigned char buf;
106
107 res = sourceGetbuf (ctx, &buf, 1);
108
109 if (res == 1) {
110 return buf;
111 } else {
112 return EOF;
113 }
114}
115
116static int sinkPutbuf (gdIOCtx * ctx, const void *buf, int size)
117{
118 ssIOCtxPtr lctx;
119 int res;
120
121 lctx = (ssIOCtx *) ctx;
122
123 res = (lctx->snk->sink) (lctx->snk->context, buf, size);
124
125 if (res <= 0) {
126 return 0;
127 } else {
128 return res;
129 }
130}
131
132static void sinkPutchar (gdIOCtx * ctx, int a)
133{
134 unsigned char b;
135
136 b = a;
137 sinkPutbuf (ctx, &b, 1);
138}
new_type size
Definition ffi.c:4365
zend_string * res
Definition ffi.c:4692
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
struct gdSink * gdSinkPtr
struct gdSource * gdSourcePtr
struct ssIOCtx * ssIOCtxPtr
Definition gd_io_ss.c:39
gdIOCtx * gdNewSSCtx(gdSourcePtr src, gdSinkPtr snk)
Definition gd_io_ss.c:50
#define NULL
Definition gdcache.h:45
#define gdFree(ptr)
Definition gdhelpers.h:19
#define gdMalloc(size)
Definition gdhelpers.h:16
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
void(* gd_free)(struct gdIOCtx *)
Definition gd_io.h:20
int(* getBuf)(struct gdIOCtx *, void *, int)
Definition gd_io.h:12
int(* sink)(void *context, const char *buffer, int len)
Definition gd.h:656
void * context
Definition gd.h:657
int(* source)(void *context, char *buffer, int len)
Definition gd.h:389
void * context
Definition gd.h:390
gdSinkPtr snk
Definition gd_io_ss.c:36
gdIOCtx ctx
Definition gd_io_ss.c:34
gdSourcePtr src
Definition gd_io_ss.c:35
$obj a
Definition test.php:84