gd-libgd / src / gd_io.c

pajoye a9b03ad 
mattias 16e401d 


mattias 493f11e 
mattias 16e401d 

mattias 493f11e 
mattias 16e401d 
pierre 1cdea74 
pierre 084ba37 
pierre b0243fe 
mattias 4b3804e 
pierre b0243fe 

pierre 084ba37 









pajoye 8fe1fe2 
mattias 16e401d 
pajoye 8fe1fe2 

pierre 084ba37 



mattias 16e401d 
pierre 084ba37 
mattias 16e401d 



pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 
pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 
pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 



pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 





pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 
pierre 084ba37 

mattias 16e401d 


pajoye a9b03ad 
mattias 16e401d 



pierre 084ba37 
mattias 16e401d 
pierre 084ba37 
mattias 16e401d 
pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 
















pierre 084ba37 

pajoye a9b03ad 
scottmac 4bcea8f 
Takeshi Abe 7382fae 
scottmac 1a022a5 

pierrejoye e20413b 
scottmac 4bcea8f 

scottmac 1a022a5 

pierrejoye e20413b 
scottmac 4bcea8f 

scottmac 1a022a5 
scottmac 4bcea8f 





mattias 16e401d 
pierre 084ba37 
mattias 16e401d 






























pierre 084ba37 

pajoye a9b03ad 
scottmac 4bcea8f 
scottmac 1a022a5 

mattias 16e401d 
scottmac 1a022a5 

pierrejoye e20413b 
scottmac 4bcea8f 



scottmac 1a022a5 

pierrejoye e20413b 
scottmac 4bcea8f 



scottmac 1a022a5 

pierrejoye e20413b 
scottmac 4bcea8f 



scottmac 1a022a5 

pierrejoye e20413b 
scottmac 4bcea8f 


scottmac 1a022a5 

scottmac 4bcea8f 




mattias 16e401d 
pierre 084ba37 
mattias 16e401d 


pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 
pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 


pierre 084ba37 

mattias 16e401d 
pierre 084ba37 
mattias 16e401d 


pierre 084ba37 
/*
 * io.c
 *
 * Implements the simple I/O 'helper' routines.
 *
 * Not really essential, but these routines were used extensively in GD,
 * so they were moved here. They also make IOCtx calls look better...
 *
 * Written (or, at least, moved) 1999, Philip Warner.
 */

#ifdef HAVE_CONFIG_H
#	include "config.h"
#endif

#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "gd.h"

/* Use this for commenting out debug-print statements. */
/* Just use the first '#define' to allow all the prints... */
/*#define IO_DBG(s) (s) */
#define IO_DBG(s)

#define GD_IO_EOF_CHK(r) \
	if(r == EOF) { \
		return 0; \
	}

/*
 * Write out a word to the I/O context pointer
 */
void Putword(int w, gdIOCtx *ctx)
{
	unsigned char buf[2];
	buf[0] = w & 0xff;
	buf[1] = (w / 256) & 0xff;
	(ctx->putBuf)(ctx, (char *)buf, 2);
}

void Putchar(int c, gdIOCtx *ctx)
{
	(ctx->putC)(ctx, c & 0xff);
}

void gdPutC(const unsigned char c, gdIOCtx *ctx)
{
	(ctx->putC)(ctx, c);
}

void gdPutWord (int w, gdIOCtx *ctx)
{
	IO_DBG(printf("Putting word...\n"));
	(ctx->putC)(ctx, (unsigned char)(w >> 8));
	(ctx->putC)(ctx, (unsigned char)(w & 0xFF));
	IO_DBG(printf("put.\n"));
}

void gdPutInt (int w, gdIOCtx *ctx)
{
	IO_DBG(printf("Putting int...\n"));
	(ctx->putC)(ctx, (unsigned char) (w >> 24));
	(ctx->putC)(ctx, (unsigned char) ((w >> 16) & 0xFF));
	(ctx->putC)(ctx, (unsigned char) ((w >> 8) & 0xFF));
	(ctx->putC)(ctx, (unsigned char) (w & 0xFF));
	IO_DBG(printf("put.\n"));
}

int gdGetC(gdIOCtx *ctx)
{
	return ((ctx->getC)(ctx));
}

int gdGetByte(int *result, gdIOCtx *ctx)
{
	int r;

	r = (ctx->getC)(ctx);
	if(r == EOF) {
		return 0;
	}

	*result = r;

	return 1;
}

int gdGetWord(int *result, gdIOCtx *ctx)
{
	int r;

	r = (ctx->getC)(ctx);
	if(r == EOF) {
		return 0;
	}

	*result = r << 8;

	r = (ctx->getC)(ctx);
	if(r == EOF) {
		return 0;
	}

	*result += r;

	return 1;
}

int gdGetWordLSB(signed short int *result, gdIOCtx *ctx)
{
	int high = 0, low = 0;
	low = (ctx->getC) (ctx);
	if (low == EOF) {
		return 0;
	}

	high = (ctx->getC) (ctx);
	if (high == EOF) {
		return 0;
	}

	if (result) {
		*result = (high << 8) | low;
	}

	return 1;
}

int gdGetInt(int *result, gdIOCtx *ctx)
{
	int r;

	r = (ctx->getC)(ctx);
	if(r == EOF) {
		return 0;
	}

	*result = r << 24;

	r = (ctx->getC)(ctx);
	if(r == EOF) {
		return 0;
	}

	*result += r << 16;

	r = (ctx->getC)(ctx);
	if(r == EOF) {
		return 0;
	}

	*result += r << 8;

	r = (ctx->getC)(ctx);
	if(r == EOF) {
		return 0;
	}

	*result += r;

	return 1;
}

int gdGetIntLSB(signed int *result, gdIOCtx *ctx)
{
	int c = 0;
	unsigned int r = 0;

	c = (ctx->getC) (ctx);
	if (c == EOF) {
		return 0;
	}
	r |= (c << 24);
	r >>= 8;

	c = (ctx->getC) (ctx);
	if (c == EOF) {
		return 0;
	}
	r |= (c << 24);
	r >>= 8;

	c = (ctx->getC) (ctx);
	if (c == EOF) {
		return 0;
	}
	r |= (c << 24);
	r >>= 8;

	c = (ctx->getC) (ctx);
	if (c == EOF) {
		return 0;
	}
	r |= (c << 24);

	if (result) {
		*result = (signed int)r;
	}

	return 1;
}

int gdPutBuf(const void *buf, int size, gdIOCtx *ctx)
{
	IO_DBG(printf("Putting buf...\n"));
	return (ctx->putBuf)(ctx, buf, size);
	IO_DBG(printf("put.\n"));
}

int gdGetBuf(void *buf, int size, gdIOCtx *ctx)
{
	return (ctx->getBuf)(ctx, buf, size);
}

int gdSeek(gdIOCtx *ctx, const int pos)
{
	IO_DBG(printf("Seeking...\n"));
	return ((ctx->seek)(ctx, pos));
	IO_DBG(printf("Done.\n"));
}

long gdTell(gdIOCtx *ctx)
{
	IO_DBG(printf("Telling...\n"));
	return ((ctx->tell)(ctx));
	IO_DBG(printf("told.\n"));
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.