Grid Community Toolkit  6.2.1705709074 (tag: v6.2.20240202)
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
string_funcs.h
1 /*
2  * string_funcs.h
3  *
4  * String manipulation functions.
5  */
6 
7 #ifndef _STRING_FUNCS_H
8 #define _STRING_FUNCS_H
9 
10 #include <sys/types.h>
11 #include <stdarg.h>
12 
13 /*
14  * strip_char()
15  *
16  * Strips a given string of a given character
17  */
18 void strip_char (char *buf, char ch);
19 
20 /*
21  * my_append()
22  *
23  * Append source string(s) to target, reallocating the buffer of the
24  * target string to size. BE SURE TO SEND NULL AS LAST ARGUMENT!
25  * If *target is NULL, a new string will be allocated.
26  * Uses realloc() - so target string may be relocated and pointer
27  * changed. Returns new string length or -1 on error.
28  */
29 int
30 my_append(char **target,
31  const char *source_1,
32  ... /* More source strings with terminating NULL */);
33 
34 
35 /*
36  * my_strncpy()
37  *
38  * Copy string from source to destination, which is destination_length
39  * characters long. Maximum number of characters copies will be
40  * destination_length - 1. Return number of characters copied or -1 if source
41  * was truncated. Result will always be NULL terminated.
42  */
43 int
44 my_strncpy(char *destination,
45  const char *source,
46  size_t destination_length);
47 
48 /*
49  * my_snprintf()
50  *
51  * A wrapper around my_vnsprintf() for a variable number of arguments.
52  */
53 char *
54 my_snprintf(const char *format, ...);
55 
56 /*
57  * my_vsnprintf()
58  *
59  * A wrapper around vsnprintf(). For systems without vsnprintf() we just
60  * do a vsprintf() and pray to the gods of memory management.
61  */
62 char *
63 my_vsnprintf(const char *format,
64  va_list ap);
65 
66 /*
67  * copy_file()
68  *
69  * Copy source to destination, creating destination if needed.
70  * Set permissions on destination to given mode.
71  *
72  * Returns 0 on success, -1 on error.
73  */
74 int
75 copy_file(const char *source,
76  const char *dest,
77  const mode_t mode);
78 
79 /*
80  * buffer_from_file()
81  *
82  * Read the entire contents of a file into a buffer.
83  *
84  * Returns 0 on success, -1 on error, setting verror.
85  */
86 int
87 buffer_from_file(const char *path,
88  unsigned char **pbuffer,
89  int *pbuffer_len);
90 
91 /*
92  * make_path()
93  *
94  * Given a path, create any missing directory conponents.
95  *
96  * Returns 0 on success, -1 on error, setting verror.
97  */
98 int
99 make_path(char *path);
100 
101 /*
102  * b64_encode()
103  *
104  * Base64 encode a string. Returns an allocated string.
105  *
106  * Returns 0 on success, -1 on error, setting verror.
107  */
108 int
109 b64_encode(const char *input, long inlen, char **output);
110 
111 /*
112  * b64_decode()
113  *
114  * Base64 decode a string. Returns an allocated string.
115  *
116  * Returns string length on success, -1 on error, setting verror.
117  */
118 int
119 b64_decode(const char *input, char **output);
120 
121 /*
122 ** Return the path to the user's home directory.
123 */
124 char *
125 get_home_path();
126 
127 /*
128 ** Return the path to the target trusted certificates directory,
129 ** even if it doesn't exist (i.e., different from
130 ** GLOBUS_GSI_SYSCONFIG_GET_CERT_DIR() which returns the certificates
131 ** directory path only if it exists).
132 **/
133 char*
134 get_trusted_certs_path();
135 
136 /*
137 ** Given a filename, return the full path of that file as it would
138 ** exist in the trusted certificates directory.
139 */
140 char*
141 get_trusted_file_path(char *filename);
142 
143 /*
144 ** Return the paths to the user's certificate and key files.
145 */
146 int
147 get_user_credential_filenames( char **certfile, char **keyfile );
148 
149 /*
150 ** Return the paths to the host certificate and key files.
151 */
152 int
153 get_host_credential_filenames( char **certfile, char **keyfile );
154 
155 /*
156  * sterilize_string
157  *
158  * Walk through a string and make sure that is it acceptable for using
159  * as part of a path.
160  */
161 void
162 sterilize_string(char *string);
163 
164 #ifndef HAVE_SETENV
165 /*
166  * setenv (for platforms that don't have it)
167  */
168 int
169 setenv(const char *var, const char *value, int override);
170 #endif
171 
172 #ifndef HAVE_UNSETENV
173 /*
174  * unsetenv (for platforms that don't have it)
175  */
176 void
177 unsetenv(const char *var);
178 #endif
179 
180 /*
181  * add_entry()
182  *
183  * Add a entry to an array of string, allocating as needed.
184  */
185 char **
186 add_entry(char **entries, const char *entry);
187 
188 void
189 free_array_list(char ***listp);
190 
191 int
192 join_array(char **target, char *array[], const char *sep);
193 
194 #endif /* _STRING_FUNCS_H */