Source

gd-libgd / src / gdhelpers.c

pierre b0243fe 



pierre 22d55c5 


pierre b623f93 
pierre 22d55c5 




pierre 1cdea74 

pierre 22d55c5 
pierrejoye e20413b 





pierre 22d55c5 
pierrejoye e20413b 


pierre 22d55c5 
pierrejoye e20413b 



pierre 22d55c5 
pierrejoye e20413b 




























pierre 22d55c5 

Ondřej Surý f0ddf2e 
pierre 1cdea74 
pierre 22d55c5 
pierrejoye e20413b 
pierre 22d55c5 

Ondřej Surý f0ddf2e 
pierre 1cdea74 
pierre 22d55c5 
pierrejoye e20413b 
pierre 22d55c5 

Ondřej Surý f0ddf2e 
pierre 1cdea74 
pierre 22d55c5 
pierrejoye e20413b 
pierre 22d55c5 

Ondřej Surý f0ddf2e 








pierre 1b2f5c4 
pierre 22d55c5 
pierrejoye e20413b 
pierre 22d55c5 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

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

/* TBB: gd_strtok_r is not portable; provide an implementation */

#define SEP_TEST (separators[*((unsigned char *) s)])

char *
gd_strtok_r (char *s, char *sep, char **state)
{
	char separators[256];
	char *result = 0;
	memset (separators, 0, sizeof (separators));
	while (*sep) {
		separators[*((unsigned char *) sep)] = 1;
		sep++;
	}
	if (!s) {
		/* Pick up where we left off */
		s = *state;
	}
	/* 1. EOS */
	if (!(*s)) {
		*state = s;
		return 0;
	}
	/* 2. Leading separators, if any */
	if (SEP_TEST) {
		do {
			s++;
		} while (SEP_TEST);
		/* 2a. EOS after separators only */
		if (!(*s)) {
			*state = s;
			return 0;
		}
	}
	/* 3. A token */
	result = s;
	do {
		/* 3a. Token at end of string */
		if (!(*s)) {
			*state = s;
			return result;
		}
		s++;
	} while (!SEP_TEST);
	/* 4. Terminate token and skip trailing separators */
	*s = '\0';
	do {
		s++;
	} while (SEP_TEST);
	/* 5. Return token */
	*state = s;
	return result;
}

inline void *
gdCalloc (size_t nmemb, size_t size)
{
	return calloc (nmemb, size);
}

inline void *
gdMalloc (size_t size)
{
	return malloc (size);
}

inline void *
gdRealloc (void *ptr, size_t size)
{
	return realloc (ptr, size);
}

inline void *
gdReallocEx (void *ptr, size_t size)
{
	void *newPtr = gdRealloc (ptr, size);
	if (!newPtr && ptr)
		gdFree(ptr);
	return newPtr;
}

BGD_DECLARE(void) gdFree (void *ptr)
{
	free (ptr);
}
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.