php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
gd_io_file.c
Go to the documentation of this file.
1
2/*
3 * io_file.c
4 *
5 * Implements the file 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 * Most functions are just 'wrappers' for standard file functions.
11 *
12 * Written/Modified 1999, Philip Warner.
13 *
14 */
15
16/* For platforms with incomplete ANSI defines. Fortunately,
17 SEEK_SET is defined to be zero by the standard. */
18
19#ifndef SEEK_SET
20#define SEEK_SET 0
21#endif /* SEEK_SET */
22
23#include <math.h>
24#include <string.h>
25#include <stdlib.h>
26#include "gd.h"
27#include "gdhelpers.h"
28
29/* this is used for creating images in main memory */
30
31typedef struct fileIOCtx
32{
34 FILE *f;
36
37gdIOCtx *newFileCtx (FILE * f);
38
39static int fileGetbuf (gdIOCtx *, void *, int);
40static int filePutbuf (gdIOCtx *, const void *, int);
41static void filePutchar (gdIOCtx *, int);
42static int fileGetchar (gdIOCtx * ctx);
43
44static int fileSeek (struct gdIOCtx *, const int);
45static long fileTell (struct gdIOCtx *);
46static void gdFreeFileCtx (gdIOCtx * ctx);
47
48/* return data as a dynamic pointer */
50{
51 fileIOCtx *ctx;
52
53 ctx = (fileIOCtx *) gdMalloc(sizeof (fileIOCtx));
54
55 ctx->f = f;
56
57 ctx->ctx.getC = fileGetchar;
58 ctx->ctx.putC = filePutchar;
59
60 ctx->ctx.getBuf = fileGetbuf;
61 ctx->ctx.putBuf = filePutbuf;
62
63 ctx->ctx.tell = fileTell;
64 ctx->ctx.seek = fileSeek;
65
66 ctx->ctx.gd_free = gdFreeFileCtx;
67
68 return (gdIOCtx *) ctx;
69}
70
71static void gdFreeFileCtx (gdIOCtx * ctx)
72{
73 gdFree(ctx);
74}
75
76
77static int filePutbuf (gdIOCtx * ctx, const void *buf, int size)
78{
79 fileIOCtx *fctx;
80 fctx = (fileIOCtx *) ctx;
81
82 return fwrite(buf, 1, size, fctx->f);
83
84}
85
86static int fileGetbuf (gdIOCtx * ctx, void *buf, int size)
87{
88 fileIOCtx *fctx;
89 fctx = (fileIOCtx *) ctx;
90
91 return fread(buf, 1, size, fctx->f);
92}
93
94static void filePutchar (gdIOCtx * ctx, int a)
95{
96 unsigned char b;
97 fileIOCtx *fctx;
98 fctx = (fileIOCtx *) ctx;
99
100 b = a;
101
102 putc (b, fctx->f);
103}
104
105static int fileGetchar (gdIOCtx * ctx)
106{
107 fileIOCtx *fctx;
108 fctx = (fileIOCtx *) ctx;
109
110 return getc (fctx->f);
111}
112
113
114static int fileSeek (struct gdIOCtx *ctx, const int pos)
115{
116 fileIOCtx *fctx;
117 fctx = (fileIOCtx *) ctx;
118
119 return (fseek (fctx->f, pos, SEEK_SET) == 0);
120}
121
122static long fileTell (struct gdIOCtx *ctx)
123{
124 fileIOCtx *fctx;
125 fctx = (fileIOCtx *) ctx;
126
127 return ftell (fctx->f);
128}
fseek($stream, int $offset, int $whence=SEEK_SET)
fwrite($stream, string $data, ?int $length=null)
ftell($stream)
fread($stream, int $length)
new_type size
Definition ffi.c:4365
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
#define SEEK_SET
Definition gd_io_file.c:20
gdIOCtx * gdNewFileCtx(FILE *f)
Definition gd_io_file.c:49
gdIOCtx * newFileCtx(FILE *f)
#define gdFree(ptr)
Definition gdhelpers.h:19
#define gdMalloc(size)
Definition gdhelpers.h:16
unsigned const char * pos
Definition php_ffi.h:52
gdIOCtx ctx
Definition gd_io_file.c:33
FILE * f
Definition gd_io_file.c:34
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
$obj a
Definition test.php:84