提交 af824783 authored 作者: Anthony Minessale's avatar Anthony Minessale

indent pass MODAPP-202

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11335 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 d88a0fbe
...@@ -23,71 +23,73 @@ ...@@ -23,71 +23,73 @@
#include "bits.h" #include "bits.h"
#include "arraylist.h" #include "arraylist.h"
struct array_list* struct array_list *array_list_new(array_list_free_fn * free_fn)
array_list_new(array_list_free_fn *free_fn)
{ {
struct array_list *this; struct array_list *this;
if(!(this = calloc(1, sizeof(struct array_list)))) return NULL; if (!(this = calloc(1, sizeof(struct array_list))))
this->size = ARRAY_LIST_DEFAULT_SIZE; return NULL;
this->length = 0; this->size = ARRAY_LIST_DEFAULT_SIZE;
this->free_fn = free_fn; this->length = 0;
if(!(this->array = calloc(sizeof(void*), this->size))) { this->free_fn = free_fn;
free(this); if (!(this->array = calloc(sizeof(void *), this->size))) {
return NULL; free(this);
} return NULL;
return this; }
return this;
} }
extern void extern void array_list_free(struct array_list *this)
array_list_free(struct array_list *this)
{ {
int i; int i;
for(i = 0; i < this->length; i++) for (i = 0; i < this->length; i++)
if(this->array[i]) this->free_fn(this->array[i]); if (this->array[i])
free(this->array); this->free_fn(this->array[i]);
free(this); free(this->array);
free(this);
} }
void* void *array_list_get_idx(struct array_list *this, int i)
array_list_get_idx(struct array_list *this, int i)
{ {
if(i >= this->length) return NULL; if (i >= this->length)
return this->array[i]; return NULL;
return this->array[i];
} }
static int array_list_expand_internal(struct array_list *this, int max) static int array_list_expand_internal(struct array_list *this, int max)
{ {
void *t; void *t;
int new_size; int new_size;
if(max < this->size) return 0; if (max < this->size)
new_size = max(this->size << 1, max); return 0;
if(!(t = realloc(this->array, new_size*sizeof(void*)))) return -1; new_size = max(this->size << 1, max);
this->array = t; if (!(t = realloc(this->array, new_size * sizeof(void *))))
(void)memset(this->array + this->size, 0, (new_size-this->size)*sizeof(void*)); return -1;
this->size = new_size; this->array = t;
return 0; (void) memset(this->array + this->size, 0, (new_size - this->size) * sizeof(void *));
this->size = new_size;
return 0;
} }
int int array_list_put_idx(struct array_list *this, int idx, void *data)
array_list_put_idx(struct array_list *this, int idx, void *data)
{ {
if(array_list_expand_internal(this, idx)) return -1; if (array_list_expand_internal(this, idx))
if(this->array[idx]) this->free_fn(this->array[idx]); return -1;
this->array[idx] = data; if (this->array[idx])
if(this->length <= idx) this->length = idx + 1; this->free_fn(this->array[idx]);
return 0; this->array[idx] = data;
if (this->length <= idx)
this->length = idx + 1;
return 0;
} }
int int array_list_add(struct array_list *this, void *data)
array_list_add(struct array_list *this, void *data)
{ {
return array_list_put_idx(this, this->length, data); return array_list_put_idx(this, this->length, data);
} }
int int array_list_length(struct array_list *this)
array_list_length(struct array_list *this)
{ {
return this->length; return this->length;
} }
...@@ -16,30 +16,23 @@ ...@@ -16,30 +16,23 @@
typedef void (array_list_free_fn) (void *data); typedef void (array_list_free_fn) (void *data);
struct array_list struct array_list {
{ void **array;
void **array; int length;
int length; int size;
int size; array_list_free_fn *free_fn;
array_list_free_fn *free_fn;
}; };
extern struct array_list* extern struct array_list *array_list_new(array_list_free_fn * free_fn);
array_list_new(array_list_free_fn *free_fn);
extern void extern void array_list_free(struct array_list *al);
array_list_free(struct array_list *al);
extern void* extern void *array_list_get_idx(struct array_list *al, int i);
array_list_get_idx(struct array_list *al, int i);
extern int extern int array_list_put_idx(struct array_list *al, int i, void *data);
array_list_put_idx(struct array_list *al, int i, void *data);
extern int extern int array_list_add(struct array_list *al, void *data);
array_list_add(struct array_list *al, void *data);
extern int extern int array_list_length(struct array_list *al);
array_list_length(struct array_list *al);
#endif #endif
...@@ -33,48 +33,55 @@ ...@@ -33,48 +33,55 @@
static int _syslog = 0; static int _syslog = 0;
static int _debug = 0; static int _debug = 0;
void mc_set_debug(int debug) { _debug = debug; } void mc_set_debug(int debug)
int mc_get_debug() { return _debug; } {
_debug = debug;
}
int mc_get_debug()
{
return _debug;
}
extern void mc_set_syslog(int syslog) extern void mc_set_syslog(int syslog)
{ {
_syslog = syslog; _syslog = syslog;
} }
void mc_abort(const char *msg, ...) void mc_abort(const char *msg, ...)
{ {
va_list ap; va_list ap;
va_start(ap, msg); va_start(ap, msg);
#if HAVE_VSYSLOG #if HAVE_VSYSLOG
if(_syslog) { if (_syslog) {
vsyslog(LOG_ERR, msg, ap); vsyslog(LOG_ERR, msg, ap);
} else } else
#endif #endif
vprintf(msg, ap); vprintf(msg, ap);
exit(1); exit(1);
} }
void mc_debug(const char *msg, ...) void mc_debug(const char *msg, ...)
{ {
va_list ap; va_list ap;
if(_debug) { if (_debug) {
va_start(ap, msg); va_start(ap, msg);
#if HAVE_VSYSLOG #if HAVE_VSYSLOG
if(_syslog) { if (_syslog) {
vsyslog(LOG_DEBUG, msg, ap); vsyslog(LOG_DEBUG, msg, ap);
} else } else
#endif #endif
vprintf(msg, ap); vprintf(msg, ap);
} }
} }
void mc_error(const char *msg, ...) void mc_error(const char *msg, ...)
{ {
va_list ap; va_list ap;
va_start(ap, msg); va_start(ap, msg);
#if HAVE_VSYSLOG #if HAVE_VSYSLOG
if(_syslog) { if (_syslog) {
vsyslog(LOG_ERR, msg, ap); vsyslog(LOG_ERR, msg, ap);
} else } else
#endif #endif
...@@ -83,12 +90,12 @@ void mc_error(const char *msg, ...) ...@@ -83,12 +90,12 @@ void mc_error(const char *msg, ...)
void mc_info(const char *msg, ...) void mc_info(const char *msg, ...)
{ {
va_list ap; va_list ap;
va_start(ap, msg); va_start(ap, msg);
#if HAVE_VSYSLOG #if HAVE_VSYSLOG
if(_syslog) { if (_syslog) {
vsyslog(LOG_INFO, msg, ap); vsyslog(LOG_INFO, msg, ap);
} else } else
#endif #endif
vfprintf(stderr, msg, ap); vfprintf(stderr, msg, ap);
} }
...@@ -74,65 +74,65 @@ do {\ ...@@ -74,65 +74,65 @@ do {\
#define STATUS_CODE_LEN 4 #define STATUS_CODE_LEN 4
typedef enum tokens { typedef enum tokens {
VERSION, VERSION,
STATUS_CODE, STATUS_CODE,
PHRASE, PHRASE,
HEADER, HEADER,
NEWLINE, NEWLINE,
SYNTAX_ERROR SYNTAX_ERROR
} token_t; } token_t;
typedef enum accept_states { typedef enum accept_states {
ASWR, ASWR,
ASNR, ASNR,
NOAS NOAS
} accept_state_t; } accept_state_t;
typedef struct state_machines { typedef struct state_machines {
accept_state_t (*state)(char, struct state_machines *); accept_state_t(*state) (char, struct state_machines *);
int pos; int pos;
char *buf; char *buf;
ssize_t buf_len; ssize_t buf_len;
int stop; int stop;
token_t token; token_t token;
} state_machine_t; } state_machine_t;
typedef enum http_methods { typedef enum http_methods {
GET, GET,
HEAD, HEAD,
POST, POST,
DELETE, DELETE,
PUT PUT
} http_method_t; } http_method_t;
typedef struct http_headers { typedef struct http_headers {
char *field_name; char *field_name;
char *value; char *value;
} http_header_t; } http_header_t;
typedef struct http_requests { typedef struct http_requests {
http_method_t method; http_method_t method;
char *version; char *version;
char *url; char *url;
http_header_t *headers; http_header_t *headers;
ssize_t header_len; ssize_t header_len;
char *body; char *body;
ssize_t body_len; ssize_t body_len;
} http_request_t; } http_request_t;
typedef struct http_responses { typedef struct http_responses {
char *version; char *version;
int status_code; int status_code;
char *phrase; char *phrase;
http_header_t *headers; http_header_t *headers;
ssize_t header_len; ssize_t header_len;
char *body; char *body;
int body_len; int body_len;
} http_response_t; } http_response_t;
token_t get_next_token(state_machine_t *sm); token_t get_next_token(state_machine_t * sm);
int http_parse_response(char *buf, ssize_t buf_len, http_response_t *response); int http_parse_response(char *buf, ssize_t buf_len, http_response_t * response);
int http_req(http_request_t *req, http_response_t *res); int http_req(http_request_t * req, http_response_t * res);
void free_http_response(http_response_t *response); void free_http_response(http_response_t * response);
#endif #endif
...@@ -27,5 +27,4 @@ extern "C" { ...@@ -27,5 +27,4 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif
...@@ -35,13 +35,13 @@ struct json_object_iter; ...@@ -35,13 +35,13 @@ struct json_object_iter;
/* supported object types */ /* supported object types */
enum json_type { enum json_type {
json_type_null, json_type_null,
json_type_boolean, json_type_boolean,
json_type_double, json_type_double,
json_type_int, json_type_int,
json_type_object, json_type_object,
json_type_array, json_type_array,
json_type_string json_type_string
}; };
/* reference counting functions */ /* reference counting functions */
...@@ -50,7 +50,7 @@ enum json_type { ...@@ -50,7 +50,7 @@ enum json_type {
* Increment the reference count of json_object * Increment the reference count of json_object
* @param obj the json_object instance * @param obj the json_object instance
*/ */
extern struct json_object* json_object_get(struct json_object *obj); extern struct json_object *json_object_get(struct json_object *obj);
/** /**
* Decrement the reference count of json_object and free if it reaches zero * Decrement the reference count of json_object and free if it reaches zero
...@@ -90,7 +90,7 @@ extern enum json_type json_object_get_type(struct json_object *obj); ...@@ -90,7 +90,7 @@ extern enum json_type json_object_get_type(struct json_object *obj);
* @param obj the json_object instance * @param obj the json_object instance
* @returns a string in JSON format * @returns a string in JSON format
*/ */
extern char* json_object_to_json_string(struct json_object *obj); extern char *json_object_to_json_string(struct json_object *obj);
/* object type methods */ /* object type methods */
...@@ -98,13 +98,13 @@ extern char* json_object_to_json_string(struct json_object *obj); ...@@ -98,13 +98,13 @@ extern char* json_object_to_json_string(struct json_object *obj);
/** Create a new empty object /** Create a new empty object
* @returns a json_object of type json_type_object * @returns a json_object of type json_type_object
*/ */
extern struct json_object* json_object_new_object(); extern struct json_object *json_object_new_object();
/** Get the hashtable of a json_object of type json_type_object /** Get the hashtable of a json_object of type json_type_object
* @param obj the json_object instance * @param obj the json_object instance
* @returns a linkhash * @returns a linkhash
*/ */
extern struct lh_table* json_object_get_object(struct json_object *obj); extern struct lh_table *json_object_get_object(struct json_object *obj);
/** Add an object field to a json_object of type json_type_object /** Add an object field to a json_object of type json_type_object
* *
...@@ -116,16 +116,14 @@ extern struct lh_table* json_object_get_object(struct json_object *obj); ...@@ -116,16 +116,14 @@ extern struct lh_table* json_object_get_object(struct json_object *obj);
* @param key the object field name (a private copy will be duplicated) * @param key the object field name (a private copy will be duplicated)
* @param val a json_object or NULL member to associate with the given field * @param val a json_object or NULL member to associate with the given field
*/ */
extern void json_object_object_add(struct json_object* obj, char *key, extern void json_object_object_add(struct json_object *obj, char *key, struct json_object *val);
struct json_object *val);
/** Get the json_object associate with a given object field /** Get the json_object associate with a given object field
* @param obj the json_object instance * @param obj the json_object instance
* @param key the object field name * @param key the object field name
* @returns the json_object associated with the given field name * @returns the json_object associated with the given field name
*/ */
extern struct json_object* json_object_object_get(struct json_object* obj, extern struct json_object *json_object_object_get(struct json_object *obj, char *key);
char *key);
/** Delete the given json_object field /** Delete the given json_object field
* *
...@@ -134,7 +132,7 @@ extern struct json_object* json_object_object_get(struct json_object* obj, ...@@ -134,7 +132,7 @@ extern struct json_object* json_object_object_get(struct json_object* obj,
* @param obj the json_object instance * @param obj the json_object instance
* @param key the object field name * @param key the object field name
*/ */
extern void json_object_object_del(struct json_object* obj, char *key); extern void json_object_object_del(struct json_object *obj, char *key);
/** Iterate through all keys and values of an object /** Iterate through all keys and values of an object
* @param obj the json_object instance * @param obj the json_object instance
...@@ -165,13 +163,13 @@ extern void json_object_object_del(struct json_object* obj, char *key); ...@@ -165,13 +163,13 @@ extern void json_object_object_del(struct json_object* obj, char *key);
/** Create a new empty json_object of type json_type_array /** Create a new empty json_object of type json_type_array
* @returns a json_object of type json_type_array * @returns a json_object of type json_type_array
*/ */
extern struct json_object* json_object_new_array(); extern struct json_object *json_object_new_array();
/** Get the arraylist of a json_object of type json_type_array /** Get the arraylist of a json_object of type json_type_array
* @param obj the json_object instance * @param obj the json_object instance
* @returns an arraylist * @returns an arraylist
*/ */
extern struct array_list* json_object_get_array(struct json_object *obj); extern struct array_list *json_object_get_array(struct json_object *obj);
/** Get the length of a json_object of type json_type_array /** Get the length of a json_object of type json_type_array
* @param obj the json_object instance * @param obj the json_object instance
...@@ -188,8 +186,7 @@ extern int json_object_array_length(struct json_object *obj); ...@@ -188,8 +186,7 @@ extern int json_object_array_length(struct json_object *obj);
* @param obj the json_object instance * @param obj the json_object instance
* @param val the json_object to be added * @param val the json_object to be added
*/ */
extern int json_object_array_add(struct json_object *obj, extern int json_object_array_add(struct json_object *obj, struct json_object *val);
struct json_object *val);
/** Insert or replace an element at a specified index in an array (a json_object of type json_type_array) /** Insert or replace an element at a specified index in an array (a json_object of type json_type_array)
* *
...@@ -206,16 +203,14 @@ extern int json_object_array_add(struct json_object *obj, ...@@ -206,16 +203,14 @@ extern int json_object_array_add(struct json_object *obj,
* @param idx the index to insert the element at * @param idx the index to insert the element at
* @param val the json_object to be added * @param val the json_object to be added
*/ */
extern int json_object_array_put_idx(struct json_object *obj, int idx, extern int json_object_array_put_idx(struct json_object *obj, int idx, struct json_object *val);
struct json_object *val);
/** Get the element at specificed index of the array (a json_object of type json_type_array) /** Get the element at specificed index of the array (a json_object of type json_type_array)
* @param obj the json_object instance * @param obj the json_object instance
* @param idx the index to get the element at * @param idx the index to get the element at
* @returns the json_object at the specified index (or NULL) * @returns the json_object at the specified index (or NULL)
*/ */
extern struct json_object* json_object_array_get_idx(struct json_object *obj, extern struct json_object *json_object_array_get_idx(struct json_object *obj, int idx);
int idx);
/* boolean type methods */ /* boolean type methods */
...@@ -223,7 +218,7 @@ extern struct json_object* json_object_array_get_idx(struct json_object *obj, ...@@ -223,7 +218,7 @@ extern struct json_object* json_object_array_get_idx(struct json_object *obj,
* @param b a boolean TRUE or FALSE (0 or 1) * @param b a boolean TRUE or FALSE (0 or 1)
* @returns a json_object of type json_type_boolean * @returns a json_object of type json_type_boolean
*/ */
extern struct json_object* json_object_new_boolean(boolean b); extern struct json_object *json_object_new_boolean(boolean b);
/** Get the boolean value of a json_object /** Get the boolean value of a json_object
* *
...@@ -245,7 +240,7 @@ extern boolean json_object_get_boolean(struct json_object *obj); ...@@ -245,7 +240,7 @@ extern boolean json_object_get_boolean(struct json_object *obj);
* @param i the integer * @param i the integer
* @returns a json_object of type json_type_int * @returns a json_object of type json_type_int
*/ */
extern struct json_object* json_object_new_int(int i); extern struct json_object *json_object_new_int(int i);
/** Get the int value of a json_object /** Get the int value of a json_object
* *
...@@ -265,7 +260,7 @@ extern int json_object_get_int(struct json_object *obj); ...@@ -265,7 +260,7 @@ extern int json_object_get_int(struct json_object *obj);
* @param d the double * @param d the double
* @returns a json_object of type json_type_double * @returns a json_object of type json_type_double
*/ */
extern struct json_object* json_object_new_double(double d); extern struct json_object *json_object_new_double(double d);
/** Get the double value of a json_object /** Get the double value of a json_object
* *
...@@ -288,9 +283,9 @@ extern double json_object_get_double(struct json_object *obj); ...@@ -288,9 +283,9 @@ extern double json_object_get_double(struct json_object *obj);
* @param s the string * @param s the string
* @returns a json_object of type json_type_string * @returns a json_object of type json_type_string
*/ */
extern struct json_object* json_object_new_string(char *s); extern struct json_object *json_object_new_string(char *s);
extern struct json_object* json_object_new_string_len(char *s, int len); extern struct json_object *json_object_new_string_len(char *s, int len);
/** Get the string value of a json_object /** Get the string value of a json_object
* *
...@@ -303,6 +298,6 @@ extern struct json_object* json_object_new_string_len(char *s, int len); ...@@ -303,6 +298,6 @@ extern struct json_object* json_object_new_string_len(char *s, int len);
* @param obj the json_object instance * @param obj the json_object instance
* @returns a string * @returns a string
*/ */
extern char* json_object_get_string(struct json_object *obj); extern char *json_object_get_string(struct json_object *obj);
#endif #endif
...@@ -12,30 +12,27 @@ ...@@ -12,30 +12,27 @@
#ifndef _json_object_private_h_ #ifndef _json_object_private_h_
#define _json_object_private_h_ #define _json_object_private_h_
typedef void (json_object_delete_fn)(struct json_object *o); typedef void (json_object_delete_fn) (struct json_object * o);
typedef int (json_object_to_json_string_fn)(struct json_object *o, typedef int (json_object_to_json_string_fn) (struct json_object * o, struct printbuf * pb);
struct printbuf *pb);
struct json_object struct json_object {
{ enum json_type o_type;
enum json_type o_type; json_object_delete_fn *_delete;
json_object_delete_fn *_delete; json_object_to_json_string_fn *_to_json_string;
json_object_to_json_string_fn *_to_json_string; int _ref_count;
int _ref_count; struct printbuf *_pb;
struct printbuf *_pb; union data {
union data { boolean c_boolean;
boolean c_boolean; double c_double;
double c_double; int c_int;
int c_int; struct lh_table *c_object;
struct lh_table *c_object; struct array_list *c_array;
struct array_list *c_array; char *c_string;
char *c_string; } o;
} o;
}; };
/* CAW: added for ANSI C iteration correctness */ /* CAW: added for ANSI C iteration correctness */
struct json_object_iter struct json_object_iter {
{
char *key; char *key;
struct json_object *val; struct json_object *val;
struct lh_entry *entry; struct lh_entry *entry;
......
...@@ -15,75 +15,72 @@ ...@@ -15,75 +15,72 @@
#include "json_object.h" #include "json_object.h"
enum json_tokener_error { enum json_tokener_error {
json_tokener_success, json_tokener_success,
json_tokener_continue, json_tokener_continue,
json_tokener_error_depth, json_tokener_error_depth,
json_tokener_error_parse_eof, json_tokener_error_parse_eof,
json_tokener_error_parse_unexpected, json_tokener_error_parse_unexpected,
json_tokener_error_parse_null, json_tokener_error_parse_null,
json_tokener_error_parse_boolean, json_tokener_error_parse_boolean,
json_tokener_error_parse_number, json_tokener_error_parse_number,
json_tokener_error_parse_array, json_tokener_error_parse_array,
json_tokener_error_parse_object_key_name, json_tokener_error_parse_object_key_name,
json_tokener_error_parse_object_key_sep, json_tokener_error_parse_object_key_sep,
json_tokener_error_parse_object_value_sep, json_tokener_error_parse_object_value_sep,
json_tokener_error_parse_string, json_tokener_error_parse_string,
json_tokener_error_parse_comment json_tokener_error_parse_comment
}; };
enum json_tokener_state { enum json_tokener_state {
json_tokener_state_eatws, json_tokener_state_eatws,
json_tokener_state_start, json_tokener_state_start,
json_tokener_state_finish, json_tokener_state_finish,
json_tokener_state_null, json_tokener_state_null,
json_tokener_state_comment_start, json_tokener_state_comment_start,
json_tokener_state_comment, json_tokener_state_comment,
json_tokener_state_comment_eol, json_tokener_state_comment_eol,
json_tokener_state_comment_end, json_tokener_state_comment_end,
json_tokener_state_string, json_tokener_state_string,
json_tokener_state_string_escape, json_tokener_state_string_escape,
json_tokener_state_escape_unicode, json_tokener_state_escape_unicode,
json_tokener_state_boolean, json_tokener_state_boolean,
json_tokener_state_number, json_tokener_state_number,
json_tokener_state_array, json_tokener_state_array,
json_tokener_state_array_add, json_tokener_state_array_add,
json_tokener_state_array_sep, json_tokener_state_array_sep,
json_tokener_state_object_field_start, json_tokener_state_object_field_start,
json_tokener_state_object_field, json_tokener_state_object_field,
json_tokener_state_object_field_end, json_tokener_state_object_field_end,
json_tokener_state_object_value, json_tokener_state_object_value,
json_tokener_state_object_value_add, json_tokener_state_object_value_add,
json_tokener_state_object_sep json_tokener_state_object_sep
}; };
struct json_tokener_srec struct json_tokener_srec {
{ enum json_tokener_state state, saved_state;
enum json_tokener_state state, saved_state; struct json_object *obj;
struct json_object *obj; struct json_object *current;
struct json_object *current; char *obj_field_name;
char *obj_field_name;
}; };
#define JSON_TOKENER_MAX_DEPTH 32 #define JSON_TOKENER_MAX_DEPTH 32
struct json_tokener struct json_tokener {
{ char *str;
char *str; struct printbuf *pb;
struct printbuf *pb; int depth, is_double, st_pos, char_offset;
int depth, is_double, st_pos, char_offset; enum json_tokener_error err;
enum json_tokener_error err; unsigned int ucs_char;
unsigned int ucs_char; char quote_char;
char quote_char; struct json_tokener_srec stack[JSON_TOKENER_MAX_DEPTH];
struct json_tokener_srec stack[JSON_TOKENER_MAX_DEPTH];
}; };
extern const char* json_tokener_errors[]; extern const char *json_tokener_errors[];
extern struct json_tokener* json_tokener_new(); extern struct json_tokener *json_tokener_new();
extern void json_tokener_free(struct json_tokener *tok); extern void json_tokener_free(struct json_tokener *tok);
extern void json_tokener_reset(struct json_tokener *tok); extern void json_tokener_reset(struct json_tokener *tok);
extern struct json_object* json_tokener_parse(char *str); extern struct json_object *json_tokener_parse(char *str);
extern struct json_object* json_tokener_parse_ex(struct json_tokener *tok, extern struct json_object *json_tokener_parse_ex(struct json_tokener *tok, char *str, int len);
char *str, int len);
#endif #endif
...@@ -51,71 +51,69 @@ ...@@ -51,71 +51,69 @@
#include "json_tokener.h" #include "json_tokener.h"
#include "json_util.h" #include "json_util.h"
struct json_object* json_object_from_file(char *filename) struct json_object *json_object_from_file(char *filename)
{ {
struct printbuf *pb; struct printbuf *pb;
struct json_object *obj; struct json_object *obj;
char buf[JSON_FILE_BUF_SIZE]; char buf[JSON_FILE_BUF_SIZE];
int fd, ret; int fd, ret;
if((fd = open(filename, O_RDONLY)) < 0) { if ((fd = open(filename, O_RDONLY)) < 0) {
mc_error("json_object_from_file: error reading file %s: %s\n", mc_error("json_object_from_file: error reading file %s: %s\n", filename, strerror(errno));
filename, strerror(errno)); return error_ptr(-1);
return error_ptr(-1); }
} if (!(pb = printbuf_new())) {
if(!(pb = printbuf_new())) { mc_error("json_object_from_file: printbuf_new failed\n");
mc_error("json_object_from_file: printbuf_new failed\n"); return error_ptr(-1);
return error_ptr(-1); }
} while ((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) {
while((ret = read(fd, buf, JSON_FILE_BUF_SIZE)) > 0) { printbuf_memappend(pb, buf, ret);
printbuf_memappend(pb, buf, ret); }
} close(fd);
close(fd); if (ret < 0) {
if(ret < 0) { mc_abort("json_object_from_file: error reading file %s: %s\n", filename, strerror(errno));
mc_abort("json_object_from_file: error reading file %s: %s\n", printbuf_free(pb);
filename, strerror(errno)); return error_ptr(-1);
printbuf_free(pb); }
return error_ptr(-1); obj = json_tokener_parse(pb->buf);
} printbuf_free(pb);
obj = json_tokener_parse(pb->buf); return obj;
printbuf_free(pb);
return obj;
} }
int json_object_to_file(char *filename, struct json_object *obj) int json_object_to_file(char *filename, struct json_object *obj)
{ {
char *json_str; char *json_str;
int fd, ret; int fd, ret;
unsigned int wpos, wsize; unsigned int wpos, wsize;
if(!obj) { if (!obj) {
mc_error("json_object_to_file: object is null\n"); mc_error("json_object_to_file: object is null\n");
return -1; return -1;
} }
if((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) { if ((fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644)) < 0) {
mc_error("json_object_to_file: error opening file %s: %s\n", mc_error("json_object_to_file: error opening file %s: %s\n", filename, strerror(errno));
filename, strerror(errno)); return -1;
return -1; }
}
if (!(json_str = json_object_to_json_string(obj))) {
if(!(json_str = json_object_to_json_string(obj))) { return -1; } return -1;
}
wsize = (unsigned int)(strlen(json_str) & UINT_MAX); /* CAW: probably unnecessary, but the most 64bit safe */
wpos = 0; wsize = (unsigned int) (strlen(json_str) & UINT_MAX); /* CAW: probably unnecessary, but the most 64bit safe */
while(wpos < wsize) { wpos = 0;
if((ret = write(fd, json_str + wpos, wsize-wpos)) < 0) { while (wpos < wsize) {
close(fd); if ((ret = write(fd, json_str + wpos, wsize - wpos)) < 0) {
mc_error("json_object_to_file: error writing file %s: %s\n", close(fd);
filename, strerror(errno)); mc_error("json_object_to_file: error writing file %s: %s\n", filename, strerror(errno));
return -1; return -1;
} }
/* because of the above check for ret < 0, we can safely cast and add */ /* because of the above check for ret < 0, we can safely cast and add */
wpos += (unsigned int)ret; wpos += (unsigned int) ret;
} }
close(fd); close(fd);
return 0; return 0;
} }
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define JSON_FILE_BUF_SIZE 4096 #define JSON_FILE_BUF_SIZE 4096
/* utlitiy functions */ /* utlitiy functions */
extern struct json_object* json_object_from_file(char *filename); extern struct json_object *json_object_from_file(char *filename);
extern int json_object_to_file(char *filename, struct json_object *obj); extern int json_object_to_file(char *filename, struct json_object *obj);
#endif #endif
...@@ -31,7 +31,7 @@ void lh_abort(const char *msg, ...) ...@@ -31,7 +31,7 @@ void lh_abort(const char *msg, ...)
uint32_t lh_ptr_hash(void *k) uint32_t lh_ptr_hash(void *k)
{ {
/* CAW: refactored to be 64bit nice */ /* CAW: refactored to be 64bit nice */
return (uint32_t)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX); return (uint32_t) ((((ptrdiff_t) k * LH_PRIME) >> 4) & ULONG_MAX);
} }
int lh_ptr_equal(void *k1, void *k2) int lh_ptr_equal(void *k1, void *k2)
...@@ -42,48 +42,47 @@ int lh_ptr_equal(void *k1, void *k2) ...@@ -42,48 +42,47 @@ int lh_ptr_equal(void *k1, void *k2)
uint32_t lh_char_hash(void *k) uint32_t lh_char_hash(void *k)
{ {
unsigned int h = 0; unsigned int h = 0;
const char* data = k; const char *data = k;
while( *data!=0 ) h = h*129 + (unsigned int)(*data++) + LH_PRIME; while (*data != 0)
h = h * 129 + (unsigned int) (*data++) + LH_PRIME;
return h; return h;
} }
int lh_char_equal(void *k1, void *k2) int lh_char_equal(void *k1, void *k2)
{ {
return (strcmp((char*)k1, (char*)k2) == 0); return (strcmp((char *) k1, (char *) k2) == 0);
} }
struct lh_table* lh_table_new(int size, char *name, struct lh_table *lh_table_new(int size, char *name, lh_entry_free_fn * free_fn, lh_hash_fn * hash_fn, lh_equal_fn * equal_fn)
lh_entry_free_fn *free_fn,
lh_hash_fn *hash_fn,
lh_equal_fn *equal_fn)
{ {
int i; int i;
struct lh_table *t; struct lh_table *t;
t = calloc(1, sizeof(struct lh_table)); t = calloc(1, sizeof(struct lh_table));
if(!t) lh_abort("lh_table_new: calloc failed\n"); if (!t)
lh_abort("lh_table_new: calloc failed\n");
t->count = 0; t->count = 0;
t->size = size; t->size = size;
t->name = name; t->name = name;
t->table = calloc(size, sizeof(struct lh_entry)); t->table = calloc(size, sizeof(struct lh_entry));
if(!t->table) lh_abort("lh_table_new: calloc failed\n"); if (!t->table)
lh_abort("lh_table_new: calloc failed\n");
t->free_fn = free_fn; t->free_fn = free_fn;
t->hash_fn = hash_fn; t->hash_fn = hash_fn;
t->equal_fn = equal_fn; t->equal_fn = equal_fn;
for(i = 0; i < size; i++) t->table[i].k = LH_EMPTY; for (i = 0; i < size; i++)
t->table[i].k = LH_EMPTY;
return t; return t;
} }
struct lh_table* lh_kchar_table_new(int size, char *name, struct lh_table *lh_kchar_table_new(int size, char *name, lh_entry_free_fn * free_fn)
lh_entry_free_fn *free_fn)
{ {
return lh_table_new(size, name, free_fn, lh_char_hash, lh_char_equal); return lh_table_new(size, name, free_fn, lh_char_hash, lh_char_equal);
} }
struct lh_table* lh_kptr_table_new(int size, char *name, struct lh_table *lh_kptr_table_new(int size, char *name, lh_entry_free_fn * free_fn)
lh_entry_free_fn *free_fn)
{ {
return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal); return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal);
} }
...@@ -95,7 +94,7 @@ void lh_table_resize(struct lh_table *t, int new_size) ...@@ -95,7 +94,7 @@ void lh_table_resize(struct lh_table *t, int new_size)
new_t = lh_table_new(new_size, t->name, NULL, t->hash_fn, t->equal_fn); new_t = lh_table_new(new_size, t->name, NULL, t->hash_fn, t->equal_fn);
ent = t->head; ent = t->head;
while(ent) { while (ent) {
lh_table_insert(new_t, ent->k, ent->v); lh_table_insert(new_t, ent->k, ent->v);
ent = ent->next; ent = ent->next;
} }
...@@ -111,8 +110,8 @@ void lh_table_resize(struct lh_table *t, int new_size) ...@@ -111,8 +110,8 @@ void lh_table_resize(struct lh_table *t, int new_size)
void lh_table_free(struct lh_table *t) void lh_table_free(struct lh_table *t)
{ {
struct lh_entry *c; struct lh_entry *c;
for(c = t->head; c != NULL; c = c->next) { for (c = t->head; c != NULL; c = c->next) {
if(t->free_fn) { if (t->free_fn) {
t->free_fn(c); t->free_fn(c);
} }
} }
...@@ -126,22 +125,25 @@ int lh_table_insert(struct lh_table *t, void *k, void *v) ...@@ -126,22 +125,25 @@ int lh_table_insert(struct lh_table *t, void *k, void *v)
uint32_t h, n; uint32_t h, n;
t->inserts++; t->inserts++;
if(t->count > t->size * 0.66) lh_table_resize(t, t->size * 2); if (t->count > t->size * 0.66)
lh_table_resize(t, t->size * 2);
h = t->hash_fn(k); h = t->hash_fn(k);
n = h % t->size; n = h % t->size;
while( 1 ) { while (1) {
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) break; if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED)
break;
t->collisions++; t->collisions++;
if(++n == t->size) n = 0; if (++n == t->size)
n = 0;
} }
t->table[n].k = k; t->table[n].k = k;
t->table[n].v = v; t->table[n].v = v;
t->count++; t->count++;
if(t->head == NULL) { if (t->head == NULL) {
t->head = t->tail = &t->table[n]; t->head = t->tail = &t->table[n];
t->table[n].next = t->table[n].prev = NULL; t->table[n].next = t->table[n].prev = NULL;
} else { } else {
...@@ -155,43 +157,50 @@ int lh_table_insert(struct lh_table *t, void *k, void *v) ...@@ -155,43 +157,50 @@ int lh_table_insert(struct lh_table *t, void *k, void *v)
} }
struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k) struct lh_entry *lh_table_lookup_entry(struct lh_table *t, void *k)
{ {
uint32_t h = t->hash_fn(k); uint32_t h = t->hash_fn(k);
uint32_t n = h % t->size; uint32_t n = h % t->size;
t->lookups++; t->lookups++;
while( 1 ) { while (1) {
if(t->table[n].k == LH_EMPTY) return NULL; if (t->table[n].k == LH_EMPTY)
if(t->table[n].k != LH_FREED && return NULL;
t->equal_fn(t->table[n].k, k)) return &t->table[n]; if (t->table[n].k != LH_FREED && t->equal_fn(t->table[n].k, k))
if(++n == t->size) n = 0; return &t->table[n];
if (++n == t->size)
n = 0;
} }
return NULL; return NULL;
} }
void* lh_table_lookup(struct lh_table *t, void *k) void *lh_table_lookup(struct lh_table *t, void *k)
{ {
struct lh_entry *e = lh_table_lookup_entry(t, k); struct lh_entry *e = lh_table_lookup_entry(t, k);
if(e) return e->v; if (e)
return e->v;
return NULL; return NULL;
} }
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e) int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
{ {
ptrdiff_t n = (ptrdiff_t)(e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy negative case... */ ptrdiff_t n = (ptrdiff_t) (e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy negative case... */
/* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */ /* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */
if(n < 0) { return -2; } if (n < 0) {
return -2;
}
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) return -1; if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED)
return -1;
t->count--; t->count--;
if(t->free_fn) t->free_fn(e); if (t->free_fn)
t->free_fn(e);
t->table[n].v = NULL; t->table[n].v = NULL;
t->table[n].k = LH_FREED; t->table[n].k = LH_FREED;
if(t->tail == &t->table[n] && t->head == &t->table[n]) { if (t->tail == &t->table[n] && t->head == &t->table[n]) {
t->head = t->tail = NULL; t->head = t->tail = NULL;
} else if (t->head == &t->table[n]) { } else if (t->head == &t->table[n]) {
t->head->next->prev = NULL; t->head->next->prev = NULL;
...@@ -211,7 +220,7 @@ int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e) ...@@ -211,7 +220,7 @@ int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
int lh_table_delete(struct lh_table *t, void *k) int lh_table_delete(struct lh_table *t, void *k)
{ {
struct lh_entry *e = lh_table_lookup_entry(t, k); struct lh_entry *e = lh_table_lookup_entry(t, k);
if(!e) return -1; if (!e)
return -1;
return lh_table_delete_entry(t, e); return lh_table_delete_entry(t, e);
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* it under the terms of the MIT license. See COPYING for details. * it under the terms of the MIT license. See COPYING for details.
* *
*/ */
#ifndef _linkhash_h_ #ifndef _linkhash_h_
#define _linkhash_h_ #define _linkhash_h_
#include <inttypes.h> #include <inttypes.h>
...@@ -33,11 +33,11 @@ struct lh_entry; ...@@ -33,11 +33,11 @@ struct lh_entry;
/** /**
* callback function prototypes * callback function prototypes
*/ */
typedef void (lh_entry_free_fn) (struct lh_entry *e); typedef void (lh_entry_free_fn) (struct lh_entry * e);
/** /**
* callback function prototypes * callback function prototypes
*/ */
typedef uint32_t (lh_hash_fn) (void *k); typedef uint32_t(lh_hash_fn) (void *k);
/** /**
* callback function prototypes * callback function prototypes
*/ */
...@@ -171,10 +171,7 @@ for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp) ...@@ -171,10 +171,7 @@ for(entry = table->head; entry && ((tmp = entry->next) || 1); entry = tmp)
* and C strings respectively. * and C strings respectively.
* @return a pointer onto the linkhash table. * @return a pointer onto the linkhash table.
*/ */
extern struct lh_table* lh_table_new(int size, char *name, extern struct lh_table *lh_table_new(int size, char *name, lh_entry_free_fn * free_fn, lh_hash_fn * hash_fn, lh_equal_fn * equal_fn);
lh_entry_free_fn *free_fn,
lh_hash_fn *hash_fn,
lh_equal_fn *equal_fn);
/** /**
* Convenience function to create a new linkhash * Convenience function to create a new linkhash
...@@ -184,8 +181,7 @@ extern struct lh_table* lh_table_new(int size, char *name, ...@@ -184,8 +181,7 @@ extern struct lh_table* lh_table_new(int size, char *name,
* @param free_fn callback function used to free memory for entries. * @param free_fn callback function used to free memory for entries.
* @return a pointer onto the linkhash table. * @return a pointer onto the linkhash table.
*/ */
extern struct lh_table* lh_kchar_table_new(int size, char *name, extern struct lh_table *lh_kchar_table_new(int size, char *name, lh_entry_free_fn * free_fn);
lh_entry_free_fn *free_fn);
/** /**
...@@ -196,8 +192,7 @@ extern struct lh_table* lh_kchar_table_new(int size, char *name, ...@@ -196,8 +192,7 @@ extern struct lh_table* lh_kchar_table_new(int size, char *name,
* @param free_fn callback function used to free memory for entries. * @param free_fn callback function used to free memory for entries.
* @return a pointer onto the linkhash table. * @return a pointer onto the linkhash table.
*/ */
extern struct lh_table* lh_kptr_table_new(int size, char *name, extern struct lh_table *lh_kptr_table_new(int size, char *name, lh_entry_free_fn * free_fn);
lh_entry_free_fn *free_fn);
/** /**
...@@ -224,7 +219,7 @@ extern int lh_table_insert(struct lh_table *t, void *k, void *v); ...@@ -224,7 +219,7 @@ extern int lh_table_insert(struct lh_table *t, void *k, void *v);
* @param k a pointer to the key to lookup * @param k a pointer to the key to lookup
* @return a pointer to the record structure of the value or NULL if it does not exist. * @return a pointer to the record structure of the value or NULL if it does not exist.
*/ */
extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k); extern struct lh_entry *lh_table_lookup_entry(struct lh_table *t, void *k);
/** /**
* Lookup a record into the table * Lookup a record into the table
...@@ -232,7 +227,7 @@ extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k); ...@@ -232,7 +227,7 @@ extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k);
* @param k a pointer to the key to lookup * @param k a pointer to the key to lookup
* @return a pointer to the found value or NULL if it does not exist. * @return a pointer to the found value or NULL if it does not exist.
*/ */
extern void* lh_table_lookup(struct lh_table *t, void *k); extern void *lh_table_lookup(struct lh_table *t, void *k);
/** /**
......
...@@ -25,44 +25,44 @@ ...@@ -25,44 +25,44 @@
#include "debug.h" #include "debug.h"
#include "printbuf.h" #include "printbuf.h"
struct printbuf* printbuf_new() struct printbuf *printbuf_new()
{ {
struct printbuf *p; struct printbuf *p;
if(!(p = calloc(1, sizeof(struct printbuf)))) return NULL; if (!(p = calloc(1, sizeof(struct printbuf))))
p->size = 32; return NULL;
p->bpos = 0; p->size = 32;
if(!(p->buf = malloc(p->size))) { p->bpos = 0;
free(p); if (!(p->buf = malloc(p->size))) {
return NULL; free(p);
} return NULL;
return p; }
return p;
} }
int printbuf_memappend(struct printbuf *p, char *buf, int size) int printbuf_memappend(struct printbuf *p, char *buf, int size)
{ {
char *t; char *t;
if(p->size - p->bpos <= size) { if (p->size - p->bpos <= size) {
int new_size = max(p->size * 2, p->bpos + size + 8); int new_size = max(p->size * 2, p->bpos + size + 8);
#ifdef PRINTBUF_DEBUG #ifdef PRINTBUF_DEBUG
mc_debug("printbuf_memappend: realloc " mc_debug("printbuf_memappend: realloc " "bpos=%d wrsize=%d old_size=%d new_size=%d\n", p->bpos, size, p->size, new_size);
"bpos=%d wrsize=%d old_size=%d new_size=%d\n",
p->bpos, size, p->size, new_size);
#endif /* PRINTBUF_DEBUG */ #endif /* PRINTBUF_DEBUG */
if(!(t = realloc(p->buf, new_size))) return -1; if (!(t = realloc(p->buf, new_size)))
p->size = new_size; return -1;
p->buf = t; p->size = new_size;
} p->buf = t;
memcpy(p->buf + p->bpos, buf, size); }
p->bpos += size; memcpy(p->buf + p->bpos, buf, size);
p->buf[p->bpos]= '\0'; p->bpos += size;
return size; p->buf[p->bpos] = '\0';
return size;
} }
#if !HAVE_VSNPRINTF && defined(WIN32) #if !HAVE_VSNPRINTF && defined(WIN32)
# define vsnprintf _vsnprintf # define vsnprintf _vsnprintf
#elif !HAVE_VSNPRINTF /* !HAVE_VSNPRINTF */ #elif !HAVE_VSNPRINTF /* !HAVE_VSNPRINTF */
# error Need vsnprintf! # error Need vsnprintf!
#endif /* !HAVE_VSNPRINTF && defined(WIN32) */ #endif /* !HAVE_VSNPRINTF && defined(WIN32) */
...@@ -76,22 +76,26 @@ static int vasprintf(char **buf, const char *fmt, va_list ap) ...@@ -76,22 +76,26 @@ static int vasprintf(char **buf, const char *fmt, va_list ap)
int chars; int chars;
char *b; char *b;
if(!buf) { return -1; } if (!buf) {
return -1;
}
#ifdef WIN32 #ifdef WIN32
chars = _vscprintf(fmt, ap)+1; chars = _vscprintf(fmt, ap) + 1;
#else /* !defined(WIN32) */ #else /* !defined(WIN32) */
/* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite /* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite
our buffer like on some 64bit sun systems.... but hey, its time to move on */ our buffer like on some 64bit sun systems.... but hey, its time to move on */
chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap)+1; chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap) + 1;
if(chars < 0) { chars *= -1; } /* CAW: old glibc versions have this problem */ if (chars < 0) {
chars *= -1;
} /* CAW: old glibc versions have this problem */
#endif /* defined(WIN32) */ #endif /* defined(WIN32) */
b = (char*)malloc(sizeof(char)*chars); b = (char *) malloc(sizeof(char) * chars);
if(!b) { return -1; } if (!b) {
return -1;
}
if((chars = vsprintf(b, fmt, ap)) < 0) if ((chars = vsprintf(b, fmt, ap)) < 0) {
{
free(b); free(b);
} else { } else {
*buf = b; *buf = b;
...@@ -103,42 +107,43 @@ static int vasprintf(char **buf, const char *fmt, va_list ap) ...@@ -103,42 +107,43 @@ static int vasprintf(char **buf, const char *fmt, va_list ap)
int sprintbuf(struct printbuf *p, const char *msg, ...) int sprintbuf(struct printbuf *p, const char *msg, ...)
{ {
va_list ap; va_list ap;
char *t; char *t;
int size; int size;
char buf[128]; char buf[128];
/* user stack buffer first */ /* user stack buffer first */
va_start(ap, msg); va_start(ap, msg);
size = vsnprintf(buf, 128, msg, ap); size = vsnprintf(buf, 128, msg, ap);
va_end(ap); va_end(ap);
/* if string is greater than stack buffer, then use dynamic string /* if string is greater than stack buffer, then use dynamic string
with vasprintf. Note: some implementation of vsnprintf return -1 with vasprintf. Note: some implementation of vsnprintf return -1
if output is truncated whereas some return the number of bytes that if output is truncated whereas some return the number of bytes that
would have been writen - this code handles both cases. */ would have been writen - this code handles both cases. */
if(size == -1 || size > 127) { if (size == -1 || size > 127) {
int ret; int ret;
va_start(ap, msg); va_start(ap, msg);
if((size = vasprintf(&t, msg, ap)) == -1) return -1; if ((size = vasprintf(&t, msg, ap)) == -1)
va_end(ap); return -1;
ret = printbuf_memappend(p, t, size); va_end(ap);
free(t); ret = printbuf_memappend(p, t, size);
return ret; free(t);
} else { return ret;
return printbuf_memappend(p, buf, size); } else {
} return printbuf_memappend(p, buf, size);
}
} }
void printbuf_reset(struct printbuf *p) void printbuf_reset(struct printbuf *p)
{ {
p->buf[0] = '\0'; p->buf[0] = '\0';
p->bpos = 0; p->bpos = 0;
} }
void printbuf_free(struct printbuf *p) void printbuf_free(struct printbuf *p)
{ {
if(p) { if (p) {
free(p->buf); free(p->buf);
free(p); free(p);
} }
} }
...@@ -15,24 +15,19 @@ ...@@ -15,24 +15,19 @@
#undef PRINTBUF_DEBUG #undef PRINTBUF_DEBUG
struct printbuf { struct printbuf {
char *buf; char *buf;
int bpos; int bpos;
int size; int size;
}; };
extern struct printbuf* extern struct printbuf *printbuf_new();
printbuf_new();
extern int extern int printbuf_memappend(struct printbuf *p, char *buf, int size);
printbuf_memappend(struct printbuf *p, char *buf, int size);
extern int extern int sprintbuf(struct printbuf *p, const char *msg, ...);
sprintbuf(struct printbuf *p, const char *msg, ...);
extern void extern void printbuf_reset(struct printbuf *p);
printbuf_reset(struct printbuf *p);
extern void extern void printbuf_free(struct printbuf *p);
printbuf_free(struct printbuf *p);
#endif #endif
...@@ -39,4 +39,3 @@ char *url_encode(char *url, size_t l); ...@@ -39,4 +39,3 @@ char *url_encode(char *url, size_t l);
char *url_decode(char *url, size_t l); char *url_decode(char *url, size_t l);
#endif #endif
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论