3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "file-util.h"
28 /****************************************************************************/
29 /* Append ".glabels" extension to filename if needed. */
30 /****************************************************************************/
32 gl_file_util_add_extension (const gchar *orig_filename)
34 gchar *new_filename, *extension;
36 extension = strrchr (orig_filename, '.');
37 if (extension == NULL) {
38 new_filename = g_strconcat (orig_filename, ".glabels", NULL);
40 if (g_ascii_strcasecmp (extension, ".glabels") != 0) {
42 g_strconcat (orig_filename, ".glabels", NULL);
44 new_filename = g_strdup (orig_filename);
52 /****************************************************************************/
53 /* Remove ".glabels" extension from filename if needed. */
54 /****************************************************************************/
56 gl_file_util_remove_extension (const gchar *orig_filename)
58 gchar *new_filename, *extension;
60 new_filename = g_strdup (orig_filename);
62 extension = strrchr (new_filename, '.');
63 if (extension != NULL) {
64 if (g_ascii_strcasecmp (extension, ".glabels") == 0) {
65 *extension = 0; /* truncate string, rm extension */
73 /****************************************************************************/
74 /* Make sure we have an absolute path to filename. */
75 /****************************************************************************/
77 gl_file_util_make_absolute (const gchar *filename)
79 gchar *pwd, *absolute_filename;
81 if (g_path_is_absolute (filename)) {
82 absolute_filename = g_strdup (filename);
84 pwd = g_get_current_dir ();
85 absolute_filename = g_build_filename (pwd, filename, NULL);
89 return absolute_filename;
93 /****************************************************************************/
94 /* Test for given extension. */
95 /****************************************************************************/
97 gl_file_util_is_extension (const gchar *filename,
98 const gchar *ext_test)
102 ext = strrchr (filename, '.');
105 return (g_ascii_strcasecmp (ext, ext_test) == 0);
114 * Local Variables: -- emacs
116 * c-basic-offset: 8 -- emacs
117 * tab-width: 8 -- emacs
118 * indent-tabs-mode: nil -- emacs