Mercurial > geeqie
annotate src/ui_fileops.c @ 1788:6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
The behavior changed, data is first written to a temporary file,
which is unlinked in case of error, then the tempfile is renamed
to the final name.
Size of buffer was increased from 4k to 16k.
| author | zas_ |
|---|---|
| date | Sun, 10 Jan 2010 14:23:29 +0000 |
| parents | 192d4752fd06 |
| children | 956aab097ea7 |
| rev | line source |
|---|---|
| 9 | 1 /* |
| 2 * (SLIK) SimpLIstic sKin functions | |
|
69
31759d770628
Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents:
40
diff
changeset
|
3 * (C) 2006 John Ellis |
| 1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
| 9 | 5 * |
| 6 * Author: John Ellis | |
| 7 * | |
| 8 * This software is released under the GNU General Public License (GNU GPL). | |
| 9 * Please read the included file COPYING for more information. | |
| 10 * This software comes with no warranty of any kind, use at your own risk! | |
| 11 */ | |
| 12 | |
| 13 #ifdef HAVE_CONFIG_H | |
| 14 # include "config.h" | |
| 15 #endif | |
| 16 | |
| 17 #include <pwd.h> | |
| 18 #include <stdio.h> | |
| 19 #include <stdlib.h> | |
| 20 #include <string.h> | |
| 21 #include <unistd.h> | |
| 22 #include <sys/param.h> | |
| 23 #include <dirent.h> | |
| 24 #include <utime.h> | |
| 25 | |
| 26 #include <glib.h> | |
| 27 #include <gtk/gtk.h> /* for locale warning dialog */ | |
| 28 | |
| 281 | 29 #include "main.h" |
| 9 | 30 #include "ui_fileops.h" |
| 31 | |
| 32 #include "ui_utildlg.h" /* for locale warning dialog */ | |
|
1642
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
33 #include "md5-util.h" |
| 9 | 34 |
| 35 /* | |
| 36 *----------------------------------------------------------------------------- | |
| 37 * generic file information and manipulation routines (public) | |
| 38 *----------------------------------------------------------------------------- | |
| 442 | 39 */ |
| 9 | 40 |
| 41 | |
| 42 | |
| 43 void print_term(const gchar *text_utf8) | |
| 44 { | |
| 45 gchar *text_l; | |
| 46 | |
| 47 text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL); | |
| 1555 | 48 fputs((text_l) ? text_l : text_utf8, stderr); |
| 9 | 49 g_free(text_l); |
| 50 } | |
| 51 | |
| 52 static void encoding_dialog(const gchar *path); | |
| 53 | |
| 1448 | 54 static gboolean encoding_dialog_idle(gpointer data) |
| 9 | 55 { |
| 56 gchar *path = data; | |
| 57 | |
| 58 encoding_dialog(path); | |
| 59 g_free(path); | |
| 60 | |
| 61 return FALSE; | |
| 62 } | |
| 63 | |
| 64 static gint encoding_dialog_delay(gpointer data) | |
| 65 { | |
| 66 g_idle_add(encoding_dialog_idle, data); | |
| 67 | |
| 68 return 0; | |
| 69 } | |
| 70 | |
| 71 static void encoding_dialog(const gchar *path) | |
| 72 { | |
| 1437 | 73 static gboolean warned_user = FALSE; |
| 9 | 74 GenericDialog *gd; |
| 75 GString *string; | |
| 76 const gchar *lc; | |
| 77 const gchar *bf; | |
| 78 | |
| 79 /* check that gtk is initialized (loop is level > 0) */ | |
| 80 if (gtk_main_level() == 0) | |
| 81 { | |
| 82 /* gtk not initialized */ | |
| 83 gtk_init_add(encoding_dialog_delay, g_strdup(path)); | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 if (warned_user) return; | |
| 88 warned_user = TRUE; | |
| 89 | |
| 90 lc = getenv("LANG"); | |
| 91 bf = getenv("G_BROKEN_FILENAMES"); | |
| 92 | |
| 93 string = g_string_new(""); | |
|
989
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
94 g_string_append(string, _("One or more filenames are not encoded with the preferred locale character set.\n")); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
95 g_string_append_printf(string, _("Operations on, and display of these files with %s may not succeed.\n"), PACKAGE); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
96 g_string_append(string, "\n"); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
97 g_string_append(string, _("If your filenames are not encoded in utf-8, try setting the environment variable G_BROKEN_FILENAMES=1\n")); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
98 if (bf) |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
99 g_string_append_printf(string, _("It appears G_BROKEN_FILENAMES is set to %s\n"), bf); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
100 else |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
101 g_string_append(string, _("It appears G_BROKEN_FILENAMES is not set\n")); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
102 g_string_append(string, "\n"); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
103 g_string_append_printf(string, _("The locale appears to be set to \"%s\"\n(set by the LANG environment variable)\n"), (lc) ? lc : "undefined"); |
| 9 | 104 if (lc && (strstr(lc, "UTF-8") || strstr(lc, "utf-8"))) |
| 105 { | |
| 106 gchar *name; | |
| 107 name = g_convert(path, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); | |
|
989
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
108 string = g_string_append(string, _("\nPreferred encoding appears to be UTF-8, however the file:\n")); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
109 g_string_append_printf(string, "\"%s\"\n", (name) ? name : _("[name not displayable]")); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
110 |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
111 if (g_utf8_validate(path, -1, NULL)) |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
112 g_string_append_printf(string, _("\"%s\" is encoded in valid UTF-8."), (name) ? name : _("[name not displayable]")); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
113 else |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
114 g_string_append_printf(string, _("\"%s\" is not encoded in valid UTF-8."), (name) ? name : _("[name not displayable]")); |
|
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
115 g_string_append(string, "\n"); |
| 9 | 116 g_free(name); |
| 117 } | |
| 118 | |
|
989
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
119 gd = generic_dialog_new(_("Filename encoding locale mismatch"), |
|
1174
0bea79d87065
Drop useless wmclass stuff. Gtk will take care of it and as said in the documentation using gtk_window_set_wmclass() is sort of pointless.
zas_
parents:
1164
diff
changeset
|
120 "locale warning", NULL, TRUE, NULL, NULL); |
| 9 | 121 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE); |
| 122 | |
| 123 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING, | |
|
989
50e1f5e54c1a
Fix untranslated messages. French translation and POTFILES.in were updated.
zas_
parents:
983
diff
changeset
|
124 _("Filename encoding locale mismatch"), string->str); |
| 9 | 125 |
| 126 gtk_widget_show(gd->dialog); | |
| 127 | |
| 128 g_string_free(string, TRUE); | |
| 129 } | |
| 130 | |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
131 #if GQ_DEBUG_PATH_UTF8 |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
132 gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line) |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
133 #else |
| 9 | 134 gchar *path_to_utf8(const gchar *path) |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
135 #endif |
| 9 | 136 { |
| 137 gchar *utf8; | |
| 138 GError *error = NULL; | |
| 139 | |
| 140 if (!path) return NULL; | |
| 141 | |
| 142 utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error); | |
| 143 if (error) | |
| 144 { | |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
145 #if GQ_DEBUG_PATH_UTF8 |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
146 log_printf("%s:%d: Unable to convert filename to UTF-8:\n%s\n%s\n", file, line, path, error->message); |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
147 #else |
|
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
148 log_printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message); |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
149 #endif |
| 9 | 150 g_error_free(error); |
| 151 encoding_dialog(path); | |
| 152 } | |
| 153 if (!utf8) | |
| 154 { | |
| 155 /* just let it through, but bad things may happen */ | |
| 156 utf8 = g_strdup(path); | |
| 157 } | |
| 158 | |
| 159 return utf8; | |
| 160 } | |
| 161 | |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
162 #if GQ_DEBUG_PATH_UTF8 |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
163 gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line) |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
164 #else |
| 9 | 165 gchar *path_from_utf8(const gchar *utf8) |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
166 #endif |
| 9 | 167 { |
| 168 gchar *path; | |
| 169 GError *error = NULL; | |
| 170 | |
| 171 if (!utf8) return NULL; | |
| 172 | |
| 173 path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error); | |
| 174 if (error) | |
| 175 { | |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
176 #if GQ_DEBUG_PATH_UTF8 |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
177 log_printf("%s:%d: Unable to convert filename to locale from UTF-8:\n%s\n%s\n", file, line, utf8, error->message); |
|
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
178 #else |
|
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
179 log_printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message); |
|
1386
4da6d326919c
Add debug versions of path_to_utf8() and path_from_utf8() which allows to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
zas_
parents:
1360
diff
changeset
|
180 #endif |
| 9 | 181 g_error_free(error); |
| 182 } | |
| 183 if (!path) | |
| 184 { | |
| 185 /* if invalid UTF-8, text probaby still in original form, so just copy it */ | |
| 186 path = g_strdup(utf8); | |
| 187 } | |
| 188 | |
| 189 return path; | |
| 190 } | |
| 191 | |
|
998
d2701a5864c5
Fixed segfault when is run inside directory with non valid uft-8 image
bruclik
parents:
990
diff
changeset
|
192 /* first we try the HOME environment var, if that doesn't work, we try g_get_homedir(). */ |
| 9 | 193 const gchar *homedir(void) |
| 194 { | |
| 195 static gchar *home = NULL; | |
| 196 | |
| 197 if (!home) | |
| 198 home = path_to_utf8(getenv("HOME")); | |
|
998
d2701a5864c5
Fixed segfault when is run inside directory with non valid uft-8 image
bruclik
parents:
990
diff
changeset
|
199 |
| 9 | 200 if (!home) |
|
998
d2701a5864c5
Fixed segfault when is run inside directory with non valid uft-8 image
bruclik
parents:
990
diff
changeset
|
201 home = path_to_utf8(g_get_home_dir()); |
| 9 | 202 |
| 203 return home; | |
| 204 } | |
| 205 | |
|
1149
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
206 static gchar *xdg_dir_get(const gchar *key, const gchar *fallback) |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
207 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
208 gchar *dir = getenv(key); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
209 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
210 if (!dir || dir[0] == '\0') |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
211 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
212 return g_build_filename(homedir(), fallback, NULL); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
213 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
214 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
215 return path_to_utf8(dir); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
216 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
217 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
218 const gchar *xdg_data_home_get(void) |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
219 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
220 static const gchar *xdg_data_home = NULL; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
221 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
222 if (xdg_data_home) return xdg_data_home; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
223 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
224 xdg_data_home = xdg_dir_get("XDG_DATA_HOME", ".local/share"); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
225 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
226 return xdg_data_home; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
227 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
228 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
229 const gchar *xdg_config_home_get(void) |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
230 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
231 static const gchar *xdg_config_home = NULL; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
232 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
233 if (xdg_config_home) return xdg_config_home; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
234 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
235 xdg_config_home = xdg_dir_get("XDG_CONFIG_HOME", ".config"); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
236 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
237 return xdg_config_home; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
238 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
239 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
240 const gchar *xdg_cache_home_get(void) |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
241 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
242 static const gchar *xdg_cache_home = NULL; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
243 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
244 if (xdg_cache_home) return xdg_cache_home; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
245 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
246 xdg_cache_home = xdg_dir_get("XDG_CACHE_HOME", ".cache"); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
247 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
248 return xdg_cache_home; |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
249 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
250 |
|
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
251 const gchar *get_rc_dir(void) |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
252 { |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
253 static gchar *rc_dir = NULL; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
254 |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
255 if (rc_dir) return rc_dir; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
256 |
|
1149
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
257 if (USE_XDG) |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
258 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
259 rc_dir = g_build_filename(xdg_config_home_get(), GQ_APPNAME_LC, NULL); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
260 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
261 else |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
262 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
263 rc_dir = g_build_filename(homedir(), GQ_RC_DIR, NULL); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
264 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
265 |
|
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
266 return rc_dir; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
267 } |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
268 |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
269 const gchar *get_collections_dir(void) |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
270 { |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
271 static gchar *collections_dir = NULL; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
272 |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
273 if (collections_dir) return collections_dir; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
274 |
|
1149
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
275 if (USE_XDG) |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
276 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
277 collections_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_COLLECTIONS_DIR, NULL); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
278 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
279 else |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
280 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
281 collections_dir = g_build_filename(get_rc_dir(), GQ_COLLECTIONS_DIR, NULL); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
282 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
283 |
|
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
284 return collections_dir; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
285 } |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
286 |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
287 const gchar *get_trash_dir(void) |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
288 { |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
289 static gchar *trash_dir = NULL; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
290 |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
291 if (trash_dir) return trash_dir; |
|
1149
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
292 |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
293 if (USE_XDG) |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
294 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
295 trash_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_TRASH_DIR, NULL); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
296 } |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
297 else |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
298 { |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
299 trash_dir = g_build_filename(get_rc_dir(), GQ_TRASH_DIR, NULL); |
|
c4fcf8001574
Implement preliminary support for XDG Base Directory Specification.
zas_
parents:
1148
diff
changeset
|
300 } |
|
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
301 |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
302 return trash_dir; |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
303 } |
|
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1055
diff
changeset
|
304 |
| 1448 | 305 gboolean stat_utf8(const gchar *s, struct stat *st) |
| 9 | 306 { |
| 307 gchar *sl; | |
| 1448 | 308 gboolean ret; |
| 9 | 309 |
| 310 if (!s) return FALSE; | |
| 311 sl = path_from_utf8(s); | |
| 312 ret = (stat(sl, st) == 0); | |
| 313 g_free(sl); | |
| 314 | |
| 315 return ret; | |
| 316 } | |
| 317 | |
| 1448 | 318 gboolean lstat_utf8(const gchar *s, struct stat *st) |
|
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
319 { |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
320 gchar *sl; |
| 1448 | 321 gboolean ret; |
|
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
322 |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
323 if (!s) return FALSE; |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
324 sl = path_from_utf8(s); |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
325 ret = (lstat(sl, st) == 0); |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
326 g_free(sl); |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
327 |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
328 return ret; |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
329 } |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
330 |
| 1448 | 331 gboolean isname(const gchar *s) |
| 9 | 332 { |
| 333 struct stat st; | |
| 334 | |
| 335 return stat_utf8(s, &st); | |
| 336 } | |
| 337 | |
| 1448 | 338 gboolean isfile(const gchar *s) |
| 9 | 339 { |
| 340 struct stat st; | |
| 341 | |
| 342 return (stat_utf8(s, &st) && S_ISREG(st.st_mode)); | |
| 343 } | |
| 344 | |
| 1448 | 345 gboolean isdir(const gchar *s) |
| 9 | 346 { |
| 347 struct stat st; | |
| 442 | 348 |
| 1198 | 349 return (stat_utf8(s, &st) && S_ISDIR(st.st_mode)); |
| 9 | 350 } |
| 351 | |
| 1448 | 352 gboolean islink(const gchar *s) |
|
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
353 { |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
354 struct stat st; |
| 442 | 355 |
| 1198 | 356 return (lstat_utf8(s, &st) && S_ISLNK(st.st_mode)); |
|
40
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
357 } |
|
dcc04a6a58bf
Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
358 |
| 9 | 359 gint64 filesize(const gchar *s) |
| 360 { | |
| 361 struct stat st; | |
| 442 | 362 |
| 9 | 363 if (!stat_utf8(s, &st)) return 0; |
| 983 | 364 return st.st_size; |
| 9 | 365 } |
| 366 | |
| 367 time_t filetime(const gchar *s) | |
| 368 { | |
| 442 | 369 struct stat st; |
| 9 | 370 |
| 371 if (!stat_utf8(s, &st)) return 0; | |
| 372 return st.st_mtime; | |
| 373 } | |
| 374 | |
| 1448 | 375 gboolean filetime_set(const gchar *s, time_t tval) |
| 9 | 376 { |
| 1437 | 377 gboolean ret = FALSE; |
| 9 | 378 |
| 379 if (tval > 0) | |
| 380 { | |
| 381 struct utimbuf ut; | |
| 382 gchar *sl; | |
| 383 | |
| 384 ut.actime = ut.modtime = tval; | |
| 385 | |
| 386 sl = path_from_utf8(s); | |
| 387 ret = (utime(sl, &ut) == 0); | |
| 388 g_free(sl); | |
| 389 } | |
| 390 | |
| 391 return ret; | |
| 392 } | |
| 393 | |
|
1360
721ffb823d6e
Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents:
1356
diff
changeset
|
394 gboolean is_readable_file(const gchar *s) |
|
721ffb823d6e
Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents:
1356
diff
changeset
|
395 { |
|
721ffb823d6e
Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents:
1356
diff
changeset
|
396 if (!s || !s[0] || !isfile(s)) return FALSE; |
|
721ffb823d6e
Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents:
1356
diff
changeset
|
397 return access_file(s, R_OK); |
|
721ffb823d6e
Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents:
1356
diff
changeset
|
398 } |
|
721ffb823d6e
Introduce is_readable_file() which test if file exists, is regular and readable.
zas_
parents:
1356
diff
changeset
|
399 |
| 1448 | 400 gboolean access_file(const gchar *s, gint mode) |
| 9 | 401 { |
| 402 gchar *sl; | |
| 403 gint ret; | |
| 404 | |
|
1356
681e79dd0820
Slightly modify access_file() and use it to test profile files existence and read access.
zas_
parents:
1307
diff
changeset
|
405 if (!s || !s[0]) return FALSE; |
| 9 | 406 |
| 407 sl = path_from_utf8(s); | |
| 408 ret = (access(sl, mode) == 0); | |
| 409 g_free(sl); | |
| 410 | |
| 411 return ret; | |
| 412 } | |
| 413 | |
| 1448 | 414 gboolean unlink_file(const gchar *s) |
| 9 | 415 { |
| 416 gchar *sl; | |
| 1448 | 417 gboolean ret; |
| 9 | 418 |
| 419 if (!s) return FALSE; | |
| 420 | |
| 421 sl = path_from_utf8(s); | |
| 422 ret = (unlink(sl) == 0); | |
| 423 g_free(sl); | |
| 424 | |
| 425 return ret; | |
| 426 } | |
| 427 | |
| 1448 | 428 gboolean symlink_utf8(const gchar *source, const gchar *target) |
| 9 | 429 { |
| 430 gchar *sl; | |
| 431 gchar *tl; | |
| 1448 | 432 gboolean ret; |
| 9 | 433 |
| 434 if (!source || !target) return FALSE; | |
| 435 | |
| 436 sl = path_from_utf8(source); | |
| 437 tl = path_from_utf8(target); | |
| 438 | |
| 439 ret = (symlink(sl, tl) == 0); | |
| 440 | |
| 441 g_free(sl); | |
| 442 g_free(tl); | |
| 443 | |
| 444 return ret; | |
| 445 } | |
| 446 | |
| 1448 | 447 gboolean mkdir_utf8(const gchar *s, gint mode) |
| 9 | 448 { |
| 449 gchar *sl; | |
| 1448 | 450 gboolean ret; |
| 9 | 451 |
| 452 if (!s) return FALSE; | |
| 453 | |
| 454 sl = path_from_utf8(s); | |
| 455 ret = (mkdir(sl, mode) == 0); | |
| 456 g_free(sl); | |
| 457 return ret; | |
| 458 } | |
| 459 | |
| 1448 | 460 gboolean rmdir_utf8(const gchar *s) |
| 9 | 461 { |
| 462 gchar *sl; | |
| 1448 | 463 gboolean ret; |
| 9 | 464 |
| 465 if (!s) return FALSE; | |
| 466 | |
| 467 sl = path_from_utf8(s); | |
| 468 ret = (rmdir(sl) == 0); | |
| 469 g_free(sl); | |
| 470 | |
| 471 return ret; | |
| 472 } | |
| 473 | |
| 1448 | 474 gboolean copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime) |
| 9 | 475 { |
| 476 struct stat st; | |
| 477 gchar *sl, *tl; | |
| 1437 | 478 gboolean ret = FALSE; |
| 9 | 479 |
| 480 if (!s || !t) return FALSE; | |
| 481 | |
| 482 sl = path_from_utf8(s); | |
| 483 tl = path_from_utf8(t); | |
| 484 | |
| 485 if (stat(sl, &st) == 0) | |
| 486 { | |
| 487 struct utimbuf tb; | |
| 488 | |
| 489 ret = TRUE; | |
| 490 | |
| 491 /* set the dest file attributes to that of source (ignoring errors) */ | |
| 492 | |
| 493 if (perms && chown(tl, st.st_uid, st.st_gid) < 0) ret = FALSE; | |
| 494 if (perms && chmod(tl, st.st_mode) < 0) ret = FALSE; | |
| 495 | |
| 496 tb.actime = st.st_atime; | |
| 497 tb.modtime = st.st_mtime; | |
| 498 if (mtime && utime(tl, &tb) < 0) ret = FALSE; | |
| 499 } | |
| 500 | |
| 501 g_free(sl); | |
| 502 g_free(tl); | |
| 503 | |
| 504 return ret; | |
| 505 } | |
| 506 | |
| 507 /* paths are in filesystem encoding */ | |
| 1448 | 508 static gboolean hard_linked(const gchar *a, const gchar *b) |
| 9 | 509 { |
| 510 struct stat sta; | |
| 511 struct stat stb; | |
| 512 | |
| 513 if (stat(a, &sta) != 0 || stat(b, &stb) != 0) return FALSE; | |
| 514 | |
| 515 return (sta.st_dev == stb.st_dev && | |
| 516 sta.st_ino == stb.st_ino); | |
| 517 } | |
| 518 | |
| 1448 | 519 gboolean copy_file(const gchar *s, const gchar *t) |
| 9 | 520 { |
| 521 FILE *fi = NULL; | |
| 522 FILE *fo = NULL; | |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
523 gchar *sl = NULL; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
524 gchar *tl = NULL; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
525 gchar *randname = NULL; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
526 gchar buf[16384]; |
|
704
839525c4e85f
Use size_t instead of gint, it silents a signed vs unsigned warning.
zas_
parents:
703
diff
changeset
|
527 size_t b; |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
528 gint ret = FALSE; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
529 gint fd = -1; |
| 9 | 530 |
| 531 sl = path_from_utf8(s); | |
| 532 tl = path_from_utf8(t); | |
| 533 | |
| 534 if (hard_linked(sl, tl)) | |
| 535 { | |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
536 ret = TRUE; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
537 goto end; |
| 9 | 538 } |
| 539 | |
| 540 fi = fopen(sl, "rb"); | |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
541 if (!fi) goto end; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
542 |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
543 /* First we write to a temporary file, then we rename it on success, |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
544 and attributes from original file are copied */ |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
545 randname = g_strconcat(tl, ".tmp_XXXXXX", NULL); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
546 if (!randname) goto end; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
547 |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
548 fd = g_mkstemp(randname); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
549 if (fd == -1) goto end; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
550 |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
551 fo = fdopen(fd, "wb"); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
552 if (!fo) { |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
553 close(fd); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
554 goto end; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
555 } |
| 9 | 556 |
|
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
557 while ((b = fread(buf, sizeof(gchar), sizeof(buf), fi)) && b != 0) |
| 9 | 558 { |
|
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
998
diff
changeset
|
559 if (fwrite(buf, sizeof(gchar), b, fo) != b) |
| 9 | 560 { |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
561 unlink(randname); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
562 goto end; |
| 9 | 563 } |
| 564 } | |
| 565 | |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
566 fclose(fi); fi = NULL; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
567 fclose(fo); fo = NULL; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
568 |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
569 if (rename(randname, tl) < 0) { |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
570 unlink(randname); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
571 goto end; |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
572 } |
| 9 | 573 |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
574 ret = copy_file_attributes(s, t, TRUE, TRUE); |
| 9 | 575 |
|
1788
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
576 end: |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
577 if (fi) fclose(fi); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
578 if (fo) fclose(fo); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
579 if (sl) g_free(sl); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
580 if (tl) g_free(tl); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
581 if (randname) g_free(randname); |
|
6a88c55c6f68
copy_file(): remove incomplete file on error (bug 2890715)
zas_
parents:
1719
diff
changeset
|
582 return ret; |
| 9 | 583 } |
| 584 | |
| 1448 | 585 gboolean move_file(const gchar *s, const gchar *t) |
| 9 | 586 { |
| 587 gchar *sl, *tl; | |
| 1437 | 588 gboolean ret = TRUE; |
| 9 | 589 |
| 590 if (!s || !t) return FALSE; | |
| 591 | |
| 592 sl = path_from_utf8(s); | |
| 593 tl = path_from_utf8(t); | |
| 594 if (rename(sl, tl) < 0) | |
| 595 { | |
| 596 /* this may have failed because moving a file across filesystems | |
| 597 was attempted, so try copy and delete instead */ | |
| 598 if (copy_file(s, t)) | |
| 599 { | |
| 600 if (unlink(sl) < 0) | |
| 601 { | |
| 602 /* err, now we can't delete the source file so return FALSE */ | |
| 603 ret = FALSE; | |
| 604 } | |
| 605 } | |
| 606 else | |
| 607 { | |
| 608 ret = FALSE; | |
| 609 } | |
| 610 } | |
| 611 g_free(sl); | |
| 612 g_free(tl); | |
| 613 | |
| 614 return ret; | |
| 615 } | |
| 616 | |
| 1448 | 617 gboolean rename_file(const gchar *s, const gchar *t) |
| 9 | 618 { |
| 619 gchar *sl, *tl; | |
| 1448 | 620 gboolean ret; |
| 9 | 621 |
| 622 if (!s || !t) return FALSE; | |
| 623 | |
| 624 sl = path_from_utf8(s); | |
| 625 tl = path_from_utf8(t); | |
| 626 ret = (rename(sl, tl) == 0); | |
| 627 g_free(sl); | |
| 628 g_free(tl); | |
| 629 | |
| 630 return ret; | |
| 631 } | |
| 632 | |
| 633 gchar *get_current_dir(void) | |
| 634 { | |
| 635 gchar *pathl; | |
| 636 gchar *path8; | |
| 637 | |
| 638 pathl = g_get_current_dir(); | |
| 639 path8 = path_to_utf8(pathl); | |
| 640 g_free(pathl); | |
| 641 | |
| 642 return path8; | |
| 643 } | |
| 644 | |
|
576
9dc0513837b5
dropped path_list functions, use filelist functions everywhere
nadvornik
parents:
545
diff
changeset
|
645 void string_list_free(GList *list) |
| 9 | 646 { |
| 647 g_list_foreach(list, (GFunc)g_free, NULL); | |
| 648 g_list_free(list); | |
| 649 } | |
| 650 | |
|
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1229
diff
changeset
|
651 GList *string_list_copy(const GList *list) |
| 9 | 652 { |
| 653 GList *new_list = NULL; | |
| 1249 | 654 GList *work = (GList *) list; |
| 9 | 655 |
| 656 while (work) | |
| 657 { | |
| 658 gchar *path; | |
| 442 | 659 |
| 9 | 660 path = work->data; |
| 661 work = work->next; | |
| 442 | 662 |
| 9 | 663 new_list = g_list_prepend(new_list, g_strdup(path)); |
| 664 } | |
| 442 | 665 |
| 9 | 666 return g_list_reverse(new_list); |
| 667 } | |
| 668 | |
| 1448 | 669 gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gboolean pad) |
| 9 | 670 { |
| 671 gchar *unique; | |
| 672 gint n = 1; | |
| 673 | |
| 674 if (!ext) ext = ""; | |
| 675 if (!divider) divider = ""; | |
| 676 | |
| 677 unique = g_strconcat(path, ext, NULL); | |
| 678 while (isname(unique)) | |
| 679 { | |
| 680 g_free(unique); | |
| 681 if (pad) | |
| 682 { | |
| 683 unique = g_strdup_printf("%s%s%03d%s", path, divider, n, ext); | |
| 684 } | |
| 685 else | |
| 686 { | |
| 687 unique = g_strdup_printf("%s%s%d%s", path, divider, n, ext); | |
| 688 } | |
| 689 n++; | |
| 690 if (n > 999) | |
| 691 { | |
| 692 /* well, we tried */ | |
| 693 g_free(unique); | |
| 694 return NULL; | |
| 695 } | |
| 696 } | |
| 697 | |
| 698 return unique; | |
| 699 } | |
| 700 | |
| 701 gchar *unique_filename_simple(const gchar *path) | |
| 702 { | |
| 703 gchar *unique; | |
| 704 const gchar *name; | |
| 705 const gchar *ext; | |
| 706 | |
| 707 if (!path) return NULL; | |
| 708 | |
| 709 name = filename_from_path(path); | |
| 710 if (!name) return NULL; | |
| 711 | |
| 712 ext = extension_from_path(name); | |
| 713 | |
| 714 if (!ext) | |
| 715 { | |
| 716 unique = unique_filename(path, NULL, "_", TRUE); | |
| 717 } | |
| 718 else | |
| 719 { | |
| 720 gchar *base; | |
| 721 | |
| 722 base = remove_extension_from_path(path); | |
| 723 unique = unique_filename(base, ext, "_", TRUE); | |
| 724 g_free(base); | |
| 725 } | |
| 726 | |
| 727 return unique; | |
| 728 } | |
| 729 | |
| 730 const gchar *filename_from_path(const gchar *path) | |
| 731 { | |
| 732 const gchar *base; | |
| 733 | |
| 734 if (!path) return NULL; | |
| 735 | |
| 701 | 736 base = strrchr(path, G_DIR_SEPARATOR); |
| 9 | 737 if (base) return base + 1; |
| 738 | |
| 739 return path; | |
| 740 } | |
| 741 | |
| 742 gchar *remove_level_from_path(const gchar *path) | |
| 743 { | |
| 543 | 744 gint p = 0, n = -1; |
| 9 | 745 |
| 746 if (!path) return NULL; | |
| 747 | |
| 543 | 748 while (path[p]) |
| 749 { | |
| 701 | 750 if (path[p] == G_DIR_SEPARATOR) n = p; |
| 543 | 751 p++; |
| 752 } | |
| 753 if (n <= 0) n++; | |
| 754 | |
| 755 return g_strndup(path, (gsize) n); | |
| 9 | 756 } |
| 757 | |
| 758 const gchar *extension_from_path(const gchar *path) | |
| 759 { | |
| 760 if (!path) return NULL; | |
| 761 return strrchr(path, '.'); | |
| 762 } | |
| 763 | |
| 1448 | 764 gboolean file_extension_match(const gchar *path, const gchar *ext) |
| 9 | 765 { |
| 766 gint p; | |
| 767 gint e; | |
| 768 | |
| 769 if (!path) return FALSE; | |
| 770 if (!ext) return TRUE; | |
| 771 | |
| 772 p = strlen(path); | |
| 773 e = strlen(ext); | |
| 774 | |
|
605
651ae2be1031
Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents:
576
diff
changeset
|
775 /* FIXME: utf8 */ |
| 1307 | 776 return (p > e && g_ascii_strncasecmp(path + p - e, ext, e) == 0); |
| 9 | 777 } |
| 778 | |
| 779 gchar *remove_extension_from_path(const gchar *path) | |
| 780 { | |
| 544 | 781 gint p = 0, n = -1; |
| 9 | 782 |
| 783 if (!path) return NULL; | |
| 784 | |
| 544 | 785 while (path[p]) |
| 786 { | |
| 787 if (path[p] == '.') n = p; | |
| 788 p++; | |
| 789 } | |
| 790 if (n < 0) n = p; | |
| 791 | |
| 792 return g_strndup(path, (gsize) n); | |
| 9 | 793 } |
| 794 | |
| 795 void parse_out_relatives(gchar *path) | |
| 796 { | |
| 797 gint s, t; | |
| 798 | |
| 799 if (!path) return; | |
| 800 | |
| 801 s = t = 0; | |
| 802 | |
| 803 while (path[s] != '\0') | |
| 804 { | |
| 919 | 805 if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.') |
| 9 | 806 { |
| 919 | 807 /* /. occurence, let's see more */ |
| 808 gint p = s + 2; | |
| 809 | |
| 810 if (path[p] == G_DIR_SEPARATOR || path[p] == '\0') | |
| 811 { | |
| 812 /* /./ or /., just skip this part */ | |
| 813 s = p; | |
| 814 continue; | |
| 815 } | |
| 816 else if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0')) | |
| 817 { | |
| 818 /* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */ | |
| 819 s = p + 1; | |
| 820 if (t > 0) t--; | |
| 821 while (path[t] != G_DIR_SEPARATOR && t > 0) t--; | |
| 822 continue; | |
| 823 } | |
| 9 | 824 } |
| 919 | 825 |
| 826 if (s != t) path[t] = path[s]; | |
| 827 t++; | |
| 828 s++; | |
| 9 | 829 } |
| 919 | 830 |
| 701 | 831 if (t == 0 && path[t] == G_DIR_SEPARATOR) t++; |
| 832 if (t > 1 && path[t-1] == G_DIR_SEPARATOR) t--; | |
| 9 | 833 path[t] = '\0'; |
| 834 } | |
| 835 | |
| 1448 | 836 gboolean file_in_path(const gchar *name) |
| 9 | 837 { |
| 838 gchar *path; | |
| 839 gchar *namel; | |
| 840 gint p, l; | |
| 1437 | 841 gboolean ret = FALSE; |
| 9 | 842 |
| 843 if (!name) return FALSE; | |
| 844 path = g_strdup(getenv("PATH")); | |
| 845 if (!path) return FALSE; | |
| 846 namel = path_from_utf8(name); | |
| 847 | |
| 848 p = 0; | |
| 849 l = strlen(path); | |
| 850 while (p < l && !ret) | |
| 851 { | |
| 852 gchar *f; | |
| 853 gint e = p; | |
| 854 while (path[e] != ':' && path[e] != '\0') e++; | |
| 855 path[e] = '\0'; | |
| 856 e++; | |
| 703 | 857 f = g_build_filename(path + p, namel, NULL); |
| 9 | 858 if (isfile(f)) ret = TRUE; |
| 859 g_free(f); | |
| 860 p = e; | |
| 861 } | |
| 862 g_free(namel); | |
| 863 g_free(path); | |
| 864 | |
| 865 return ret; | |
| 866 } | |
|
1148
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
867 |
| 1164 | 868 gboolean recursive_mkdir_if_not_exists(const gchar *path, mode_t mode) |
|
1148
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
869 { |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
870 if (!path) return FALSE; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
871 |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
872 if (!isdir(path)) |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
873 { |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
874 gchar *npath = g_strdup(path); |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
875 gchar *p = npath; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
876 |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
877 while (p[0] != '\0') |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
878 { |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
879 p++; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
880 if (p[0] == G_DIR_SEPARATOR || p[0] == '\0') |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
881 { |
| 1437 | 882 gboolean end = TRUE; |
|
1148
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
883 |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
884 if (p[0] != '\0') |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
885 { |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
886 p[0] = '\0'; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
887 end = FALSE; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
888 } |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
889 |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
890 if (!isdir(npath)) |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
891 { |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
892 DEBUG_1("creating sub dir:%s", npath); |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
893 if (!mkdir_utf8(npath, mode)) |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
894 { |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
895 log_printf("create dir failed: %s\n", npath); |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
896 g_free(npath); |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
897 return FALSE; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
898 } |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
899 } |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
900 |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
901 if (!end) p[0] = G_DIR_SEPARATOR; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
902 } |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
903 } |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
904 g_free(npath); |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
905 } |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
906 |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
907 return TRUE; |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
908 } |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
909 |
|
1642
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
910 /* does filename utf8 to filesystem encoding first */ |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
911 gboolean md5_get_digest_from_file_utf8(const gchar *path, guchar digest[16]) |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
912 { |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
913 gboolean success; |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
914 gchar *pathl; |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
915 |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
916 pathl = path_from_utf8(path); |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
917 success = md5_get_digest_from_file(pathl, digest); |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
918 g_free(pathl); |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
919 |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
920 return success; |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
921 } |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
922 |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
923 |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
924 gchar *md5_text_from_file_utf8(const gchar *path, const gchar *error_text) |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
925 { |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
926 guchar digest[16]; |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
927 |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
928 if (!md5_get_digest_from_file_utf8(path, digest)) return g_strdup(error_text); |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
929 |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
930 return md5_digest_to_text(digest); |
|
51d70f62338c
Fix up compilation using make -jN: sometimes it fails due to order of headers inclusion.
zas_
parents:
1555
diff
changeset
|
931 } |
|
1148
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
932 |
|
95860439070b
Replace cache_ensure_dir_exists() by new recursive_mkdir_if_not_exists().
zas_
parents:
1145
diff
changeset
|
933 |
|
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1000
diff
changeset
|
934 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |
