summaryrefslogtreecommitdiffstats
path: root/include/joedog/joedog.h
blob: 56985293ea6d788e4f4f72b5e862ccb660a4dbd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef JOEDOG_H
#define JOEDOG_H 
/**
 * JOEDOG HEADER 
 *
 * Copyright (C) 2000-2006 Jeffrey Fulmer <jeff@joedog.org>
 * This file is part of Siege
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 * -- 
 */
#include <config.h>
#include <time.h>  
#include <stdarg.h>
#include <joedog/boolean.h>

/**
 * Error notification
 */
typedef enum {
  DEBUG     = 0,
  WARNING   = 1,
  ERROR     = 2,
  FATAL     = 3,
  NOTICE    = 4
} LEVEL;

void OPENLOG(char *program_name);
void CLOSELOG(void);
void SYSLOG(LEVEL L, const char *fmt, ...);
void NOTIFY(LEVEL L, const char *fmt, ...);
void VERBOSE(BOOLEAN verbose, const char *fmt, ...);

void * xrealloc(void *, size_t);
void * xmalloc (size_t);
void * xcalloc (size_t, size_t); 
char * xstrdup(const char *str);
void xfree(void *ptr); 

/**
 * Utility functions
 */
void  itoa(int, char []);
void  reverse(char []);
int   my_random(int, int);
char  *substring(char *, int, int);
float elapsed_time(clock_t);

/**
 * snprintf functions
 */
#define PORTABLE_SNPRINTF_VERSION_MAJOR 2
#define PORTABLE_SNPRINTF_VERSION_MINOR 2

#ifdef HAVE_SNPRINTF
#include <stdio.h>
#else
extern int snprintf(char *, size_t, const char *, /*args*/ ...);
extern int vsnprintf(char *, size_t, const char *, va_list);
#endif

#if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
extern int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
extern int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
#define snprintf  portable_snprintf
#define vsnprintf portable_vsnprintf
#endif

#ifndef __CYGWIN__
extern int asprintf  (char **ptr, const char *fmt, /*args*/ ...);
extern int vasprintf (char **ptr, const char *fmt, va_list ap);
extern int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
extern int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
#endif/*__CYGWIN__*/

/**
 * chomps the newline character off
 * the end of a string.
 */
char *chomp(char *str);
 
/**
 * trims the white space from the right
 * of a string.
 */
char *rtrim(char *str);

/**
 * trims the white space from the left
 * of a string.
 */
char *ltrim(char *str);

/**
 * trims the white space from the left
 * and the right sides of a string.
 */
char * trim(char *str); 

/**
 * split string *s on pattern pattern pointer
 * n_words holds the size of **
 */
char **split(char pattern, char *s, int *n_words); 

/**
 * free memory allocated by split
 */
void split_free(char **split, int length); 


/**
 * tests for empty string; warns if invalid
 */
int empty(const char *s);

/**
 * portable strsep
 */
char *xstrsep(char **stringp, const char *delim);

/**
 * string allocation
 */
char *stralloc(char *); 

#endif/* JOEDOG_H */