2 Copyright (C) 2005 Georgia Public Library Service
3 Bill Erickson <highfalutin@gmail.com>
4 Mike Rylander <mrylander@gmail.com>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
27 #define BUFFER_MAX_SIZE 10485760
31 void* safe_malloc(int size);
33 // ---------------------------------------------------------------------------------
34 // Generic growing buffer. Add data all you want
35 // ---------------------------------------------------------------------------------
36 struct growing_buffer_struct {
41 typedef struct growing_buffer_struct growing_buffer;
43 growing_buffer* buffer_init( int initial_num_bytes);
45 // XXX This isn't defined in utils.c!! removing for now...
46 //int buffer_addchar(growing_buffer* gb, char c);
48 int buffer_add(growing_buffer* gb, char* c);
49 int buffer_fadd(growing_buffer* gb, const char* format, ... );
50 int buffer_reset( growing_buffer* gb);
51 char* buffer_data( growing_buffer* gb);
52 int buffer_free( growing_buffer* gb );
53 int buffer_add_char(growing_buffer* gb, char c);
55 /* returns the size needed to fill in the vsnprintf buffer.
56 * ! this calls va_end on the va_list argument*
58 long va_list_size(const char* format, va_list);
61 /* string escape utility method. escapes unicode embeded characters.
62 escapes the usual \n, \t, etc.
63 for example, if you provide a string like so:
72 char* uescape( const char* string, int size, int full_escape );
75 int set_fl( int fd, int flags );
76 int clr_fl( int fd, int flags );
81 double get_timestamp_millis();
84 /* returns true if the whole string is a number */
85 int stringisnum(char* s);
87 /* reads a file and returns the string version of the file
88 user is responsible for freeing the returned char*
90 char* file_to_string(char* filename);