File: string_funcs.h

package info (click to toggle)
myproxy 6.2.20-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,340 kB
  • sloc: ansic: 24,830; sh: 4,636; perl: 3,675; makefile: 272
file content (194 lines) | stat: -rw-r--r-- 4,148 bytes parent folder | download | duplicates (8)
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * string_funcs.h
 *
 * String manipulation functions.
 */

#ifndef _STRING_FUNCS_H
#define _STRING_FUNCS_H

#include <sys/types.h>
#include <stdarg.h>

/*
 * strip_char()
 *
 * Strips a given string of a given character
 */
void strip_char (char *buf, char ch);

/*
 * my_append()
 *
 * Append source string(s) to target, reallocating the buffer of the
 * target string to size.  BE SURE TO SEND NULL AS LAST ARGUMENT!
 * If *target is NULL, a new string will be allocated.
 * Uses realloc() - so target string may be relocated and pointer
 * changed.  Returns new string length or -1 on error.
 */
int
my_append(char                                   **target,
	  const char                             *source_1,
	  ... /* More source strings with terminating NULL */);


/*
 * my_strncpy()
 *
 * Copy string from source to destination, which is destination_length
 * characters long. Maximum number of characters copies will be
 * destination_length - 1. Return number of characters copied or -1 if source
 * was truncated. Result will always be NULL terminated.
 */
int
my_strncpy(char					*destination,
	   const char				*source,
	   size_t				destination_length);

/*
 * my_snprintf()
 *
 * A wrapper around my_vnsprintf() for a variable number of arguments.
 */
char *
my_snprintf(const char				*format, ...);
	     
/*
 * my_vsnprintf()
 *
 * A wrapper around vsnprintf(). For systems without vsnprintf() we just
 * do a vsprintf() and pray to the gods of memory management.
 */
char *
my_vsnprintf(const char				*format,
	     va_list				ap);

/*
 * copy_file()
 *
 * Copy source to destination, creating destination if needed.
 * Set permissions on destination to given mode.
 *
 * Returns 0 on success, -1 on error.
 */
int
copy_file(const char *source,
          const char *dest,
          const mode_t mode);

/*
 * buffer_from_file()
 *
 * Read the entire contents of a file into a buffer.
 *
 * Returns 0 on success, -1 on error, setting verror.
 */
int
buffer_from_file(const char			*path,
		 unsigned char			**pbuffer,
		 int				*pbuffer_len);

/*
 * make_path()
 *
 * Given a path, create any missing directory conponents.
 *
 * Returns 0 on success, -1 on error, setting verror.
 */
int
make_path(char                                  *path);

/*
 * b64_encode()
 *
 * Base64 encode a string.  Returns an allocated string.
 *
 * Returns 0 on success, -1 on error, setting verror.
 */
int
b64_encode(const char *input, long inlen, char **output);

/*
 * b64_decode()
 *
 * Base64 decode a string.  Returns an allocated string.
 *
 * Returns string length on success, -1 on error, setting verror.
 */
int
b64_decode(const char *input, char **output);

/*
** Return the path to the user's home directory.
*/
char *
get_home_path();

/*
** Return the path to the target trusted certificates directory,
** even if it doesn't exist (i.e., different from
** GLOBUS_GSI_SYSCONFIG_GET_CERT_DIR() which returns the certificates
** directory path only if it exists).
**/
char*
get_trusted_certs_path();

/*
** Given a filename, return the full path of that file as it would
** exist in the trusted certificates directory.
*/
char*
get_trusted_file_path(char *filename);

/*
** Return the paths to the user's certificate and key files.
*/
int
get_user_credential_filenames( char **certfile, char **keyfile );

/*
** Return the paths to the host certificate and key files.
*/
int
get_host_credential_filenames( char **certfile, char **keyfile );

/*
 * sterilize_string
 *
 * Walk through a string and make sure that is it acceptable for using
 * as part of a path.
 */
void
sterilize_string(char *string);

#ifndef HAVE_SETENV
/*
 * setenv (for platforms that don't have it)
 */
int
setenv(const char *var, const char *value, int override);
#endif

#ifndef HAVE_UNSETENV
/*
 * unsetenv (for platforms that don't have it)
 */
void
unsetenv(const char *var);
#endif

/*
 * add_entry()
 *
 * Add a entry to an array of string, allocating as needed.
 */
char **
add_entry(char **entries, const char *entry);

void
free_array_list(char ***listp);

int
join_array(char **target, char *array[], const char *sep);

#endif /* _STRING_FUNCS_H */