|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
|
24 * Use is subject to license terms. |
|
25 */ |
|
26 |
|
27 |
|
28 #ifndef _FSEXAM_HELPER_H_ |
|
29 #define _FSEXAM_HELPER_H_ |
|
30 |
|
31 #define FREE(p) if (p) { \ |
|
32 free (p); \ |
|
33 p = NULL; \ |
|
34 } |
|
35 |
|
36 /*========================================================================= |
|
37 * Function Name: str_isascii |
|
38 * |
|
39 * Parameters: |
|
40 * |
|
41 * Desc: |
|
42 * Determine whether the parameter str contains only ascii characters. |
|
43 * |
|
44 * Return value: |
|
45 * Return True if str contain only ASCII |
|
46 * Otherwise False |
|
47 * |
|
48 * Author: Yandong Yao 2006/08/24 |
|
49 ========================================================================*/ |
|
50 gboolean str_isascii (const gchar *str, gint len); |
|
51 |
|
52 /*============================================================================ |
|
53 * Function Name: get_abs_path |
|
54 * |
|
55 * Parameters: |
|
56 * const gchar *file: the path |
|
57 * |
|
58 * Desc: |
|
59 * Convert relative path to absolute path, eliminate all '.', '..' |
|
60 * in the path |
|
61 * |
|
62 * Return value: |
|
63 * If the file exist, then return its absolute path |
|
64 * if not exist or error occur, then return NULL. |
|
65 * |
|
66 * As we can't determine whether the path is abs path already unless |
|
67 * traverse the whole string, so we always return a new string which |
|
68 * you need free when don't use them any more. |
|
69 * |
|
70 * Author: Yandong Yao 2006/08/24 |
|
71 ============================================================================*/ |
|
72 gchar * get_abs_path (const gchar *file); |
|
73 |
|
74 /*============================================================================ |
|
75 * Function Name: file_exist |
|
76 * |
|
77 * Parameters: |
|
78 * |
|
79 * Desc: |
|
80 * Determine whether file exist and S_ISREG || s_ISDIR || S_ISLNK |
|
81 * |
|
82 * Return value: |
|
83 * Return True if file exist and S_ISREG || s_ISDIR || S_ISLNK |
|
84 * Otherwise return False. |
|
85 * |
|
86 * Author: Yandong Yao 2006/08/24 |
|
87 ===========================================================================*/ |
|
88 gboolean file_exist (gchar *file); |
|
89 |
|
90 /*============================================================================ |
|
91 * Function Name: str_chomp |
|
92 * |
|
93 * Parameters: |
|
94 * |
|
95 * Desc: |
|
96 * Remove trailing newline '\n' |
|
97 * Remove heading space |
|
98 * |
|
99 * Return value: |
|
100 * Return the original string, won't allocate any new memory |
|
101 * |
|
102 * Author: Yandong Yao 2006/08/24 |
|
103 ===========================================================================*/ |
|
104 gchar * str_chomp (gchar *str); |
|
105 |
|
106 /*==================================================================== |
|
107 * Function Name: str_compress |
|
108 * |
|
109 * Parameters: |
|
110 * gchar *string: the original string, null terminated. |
|
111 * gboolean *tab: whether contain '\t' before the first non-space char |
|
112 * |
|
113 * Desc: |
|
114 * str_compress() function will remove any heading or tailing space. |
|
115 * The modification is in-place, so it will change the original string. |
|
116 * |
|
117 * if string contain '\t' before first non-space char, then *tab = TRUE; |
|
118 * |
|
119 * Return value: |
|
120 * The new start position in original string |
|
121 * |
|
122 * Exception: |
|
123 * |
|
124 * Author: Yandong Yao 2006/08/30 |
|
125 ========================================================================*/ |
|
126 gchar *str_compress (gchar *string, gboolean *tab); |
|
127 |
|
128 /*==================================================================== |
|
129 * Function Name: str_split |
|
130 * |
|
131 * Parameters: |
|
132 * gchar *str: The original string |
|
133 * gchar **str1: pointer to the first string |
|
134 * gchar **str2: pointer to the second string |
|
135 * |
|
136 * Desc: |
|
137 * Split the original string into two separate string according to space |
|
138 * chars. If there is no space,the *str2 = NULL; |
|
139 * |
|
140 * Return value: |
|
141 * N/A |
|
142 * |
|
143 * Author: Yandong Yao 2006/08/31 |
|
144 ========================================================================*/ |
|
145 void str_split (gchar *str, gchar **str1, gchar **str2); |
|
146 |
|
147 /*=================================================================== |
|
148 * Function Name: list_free |
|
149 * |
|
150 * Parameters: |
|
151 * gpointer data: the data stored in GList or GSList |
|
152 * gpointer user_data: arbitrary user data |
|
153 * |
|
154 * Desc: |
|
155 * This function is just a wrap of g_free, so that it can be |
|
156 * used as g_list_foreach to free the glist data memory |
|
157 * |
|
158 * Return value: |
|
159 * |
|
160 * Author: Yandong Yao 2006/10/17 |
|
161 ======================================================================*/ |
|
162 void list_free (gpointer data, gpointer user_data); |
|
163 |
|
164 void list_print (gpointer data, gpointer user_data); |
|
165 |
|
166 /*=================================================================== |
|
167 * Function Name: encoding_string_parse |
|
168 * |
|
169 * Parameters: |
|
170 * const gchar *encoding_string: one string contain encoding name |
|
171 * separated by ',' or ':' |
|
172 * |
|
173 * Desc: |
|
174 * Split ',' or ':' separated encoding string into encoding list |
|
175 * |
|
176 * Return value: |
|
177 * GSList *, need free when don't use at more |
|
178 * |
|
179 * Author: Yandong Yao 2006/11/15 |
|
180 ==========================================================================*/ |
|
181 GSList *encoding_string_parse (const gchar *encoding_string); |
|
182 |
|
183 gchar *get_abs_path_for_symlink_target (const gchar *symlink); |
|
184 |
|
185 void hash_print (gpointer key, gpointer value, gpointer data); |
|
186 |
|
187 |
|
188 void fsexam_list_free (GList *list); |
|
189 void fsexam_slist_free (GSList *list); |
|
190 void fsexam_hash_remove_all (GHashTable *hash); |
|
191 |
|
192 gchar *get_sample_text (const gchar *contents, guint *length); |
|
193 |
|
194 GList *remove_string_from_list (GList *list, const gchar *str); |
|
195 GSList *remove_string_from_slist (GSList *list, const gchar *str); |
|
196 |
|
197 gboolean fsexam_is_subpath (const gchar *path1, const gchar *path2); |
|
198 |
|
199 /* |
|
200 * get the display name |
|
201 */ |
|
202 gchar *fsexam_filename_display_name (const gchar *filename); |
|
203 |
|
204 /* |
|
205 * get the display name: this func will anaylize '/' |
|
206 */ |
|
207 gchar *fsexam_filename_display_basename (const gchar *filename); |
|
208 |
|
209 /* |
|
210 * escape string |
|
211 */ |
|
212 gchar *fsexam_string_escape (const gchar *string); |
|
213 |
|
214 gchar *fsexam_print_hex (const gchar *str); |
|
215 |
|
216 #ifndef HAVE_STRLCPY |
|
217 size_t strlcpy (char *dst, const char *src, size_t len); |
|
218 #endif |
|
219 |
|
220 #ifndef HAVE_STRLCAT |
|
221 size_t strlcat (char *dst, const char *src, size_t dstsize); |
|
222 #endif |
|
223 |
|
224 #ifdef HAVE_NO_GLIB_2_8 |
|
225 gboolean g_file_set_contents (const gchar *filename, const gchar *contents, |
|
226 gssize length, GError **error); |
|
227 #endif |
|
228 |
|
229 #endif //_FSEXAM_HELPER_H_ |