Path: blob/linux/compat/jansson/jansson_private.h
1201 views
/*1* Copyright (c) 2009-2013 Petri Lehtinen <[email protected]>2*3* Jansson is free software; you can redistribute it and/or modify4* it under the terms of the MIT license. See LICENSE for details.5*/67#ifndef JANSSON_PRIVATE_H8#define JANSSON_PRIVATE_H910#include <stddef.h>11#include "jansson.h"12#include "hashtable.h"13#include "strbuffer.h"1415#define container_of(ptr_, type_, member_) \16((type_ *)((char *)ptr_ - offsetof(type_, member_)))1718/* On some platforms, max() may already be defined */19#ifndef max20#define max(a, b) ((a) > (b) ? (a) : (b))21#endif2223/* va_copy is a C99 feature. In C89 implementations, it's sometimes24available as __va_copy. If not, memcpy() should do the trick. */25#ifndef va_copy26#ifdef __va_copy27#define va_copy __va_copy28#else29#define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list))30#endif31#endif3233typedef struct {34json_t json;35hashtable_t hashtable;36size_t serial;37int visited;38} json_object_t;3940typedef struct {41json_t json;42size_t size;43size_t entries;44json_t **table;45int visited;46} json_array_t;4748typedef struct {49json_t json;50char *value;51} json_string_t;5253typedef struct {54json_t json;55double value;56} json_real_t;5758typedef struct {59json_t json;60json_int_t value;61} json_integer_t;6263#define json_to_object(json_) container_of(json_, json_object_t, json)64#define json_to_array(json_) container_of(json_, json_array_t, json)65#define json_to_string(json_) container_of(json_, json_string_t, json)66#define json_to_real(json_) container_of(json_, json_real_t, json)67#define json_to_integer(json_) container_of(json_, json_integer_t, json)6869void jsonp_error_init(json_error_t *error, const char *source);70void jsonp_error_set_source(json_error_t *error, const char *source);71void jsonp_error_set(json_error_t *error, int line, int column,72size_t position, const char *msg, ...);73void jsonp_error_vset(json_error_t *error, int line, int column,74size_t position, const char *msg, va_list ap);7576/* Locale independent string<->double conversions */77int jsonp_strtod(strbuffer_t *strbuffer, double *out);78int jsonp_dtostr(char *buffer, size_t size, double value);7980/* Wrappers for custom memory functions */81void* jsonp_malloc(size_t size);82void jsonp_free(void *ptr);83char *jsonp_strndup(const char *str, size_t length);84char *jsonp_strdup(const char *str);8586/* Windows compatibility */87#ifdef _WIN3288#define snprintf _snprintf89#define vsnprintf _vsnprintf90#endif9192#endif939495