]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/utils/utils.h
daemonizing and hushing warnings; logger reopens files instead of writing blindly...
[OpenSRF.git] / src / utils / utils.h
1 /*
2 Copyright (C) 2005  Georgia Public Library Service 
3 Bill Erickson <highfalutin@gmail.com>
4 Mike Rylander <mrylander@gmail.com>
5
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.
10
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.
15 */
16
17 #ifndef UTILS_H
18 #define UTILS_H
19
20 #include <stdarg.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <sys/time.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26
27 #define BUFFER_MAX_SIZE 10485760 
28
29 int daemonize();
30
31 void* safe_malloc(int size);
32
33 // ---------------------------------------------------------------------------------
34 // Generic growing buffer. Add data all you want
35 // ---------------------------------------------------------------------------------
36 struct growing_buffer_struct {
37         char *buf;
38         int n_used;
39         int size;
40 };
41 typedef struct growing_buffer_struct growing_buffer;
42
43 growing_buffer* buffer_init( int initial_num_bytes);
44
45 // XXX This isn't defined in utils.c!! removing for now...
46 //int buffer_addchar(growing_buffer* gb, char c);
47
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);
54
55
56 /* string escape utility method.  escapes unicode embeded characters.
57         escapes the usual \n, \t, etc. 
58         for example, if you provide a string like so:
59
60         hello,
61                 you
62
63         you would get back:
64         hello,\n\tyou
65  
66  */
67 char* uescape( const char* string, int size, int full_escape );
68
69 /* utility methods */
70 int set_fl( int fd, int flags );
71 int clr_fl( int fd, int flags );
72
73
74
75 // Utility method
76 double get_timestamp_millis();
77
78
79
80
81 #endif