File: | eel/eel-vfs-extensions.c |
Warning: | line 136, column 14 Out of bound memory access (access exceeds upper limit of memory block) |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ | |||
2 | ||||
3 | /* eel-vfs-extensions.c - cafe-vfs extensions. Its likely some of these will | |||
4 | be part of cafe-vfs in the future. | |||
5 | ||||
6 | Copyright (C) 1999, 2000 Eazel, Inc. | |||
7 | ||||
8 | The Cafe Library is free software; you can redistribute it and/or | |||
9 | modify it under the terms of the GNU Library General Public License as | |||
10 | published by the Free Software Foundation; either version 2 of the | |||
11 | License, or (at your option) any later version. | |||
12 | ||||
13 | The Cafe Library is distributed in the hope that it will be useful, | |||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
16 | Library General Public License for more details. | |||
17 | ||||
18 | You should have received a copy of the GNU Library General Public | |||
19 | License along with the Cafe Library; see the file COPYING.LIB. If not, | |||
20 | write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | |||
21 | Boston, MA 02110-1301, USA. | |||
22 | ||||
23 | Authors: Darin Adler <darin@eazel.com> | |||
24 | Pavel Cisler <pavel@eazel.com> | |||
25 | Mike Fleming <mfleming@eazel.com> | |||
26 | John Sullivan <sullivan@eazel.com> | |||
27 | */ | |||
28 | ||||
29 | #include <config.h> | |||
30 | #include "eel-vfs-extensions.h" | |||
31 | #include "eel-glib-extensions.h" | |||
32 | #include "eel-lib-self-check-functions.h" | |||
33 | #include <glib.h> | |||
34 | #include <glib/gi18n-lib.h> | |||
35 | #include <gio/gio.h> | |||
36 | ||||
37 | #include "eel-string.h" | |||
38 | ||||
39 | #include <string.h> | |||
40 | #include <stdlib.h> | |||
41 | ||||
42 | gboolean | |||
43 | eel_uri_is_trash (const char *uri) | |||
44 | { | |||
45 | return eel_istr_has_prefix (uri, "trash:"); | |||
46 | } | |||
47 | ||||
48 | gboolean | |||
49 | eel_uri_is_search (const char *uri) | |||
50 | { | |||
51 | return eel_istr_has_prefix (uri, EEL_SEARCH_URI"x-baul-search:"); | |||
52 | } | |||
53 | ||||
54 | gboolean | |||
55 | eel_uri_is_desktop (const char *uri) | |||
56 | { | |||
57 | return eel_istr_has_prefix (uri, EEL_DESKTOP_URI"x-baul-desktop:"); | |||
58 | } | |||
59 | ||||
60 | char * | |||
61 | eel_make_valid_utf8 (const char *name) | |||
62 | { | |||
63 | GString *string; | |||
64 | const char *remainder, *invalid; | |||
65 | int remaining_bytes; | |||
66 | ||||
67 | string = NULL((void*)0); | |||
68 | remainder = name; | |||
69 | remaining_bytes = strlen (name); | |||
70 | ||||
71 | while (remaining_bytes != 0) | |||
72 | { | |||
73 | int valid_bytes; | |||
74 | ||||
75 | if (g_utf8_validate (remainder, remaining_bytes, &invalid)) | |||
76 | { | |||
77 | break; | |||
78 | } | |||
79 | valid_bytes = invalid - remainder; | |||
80 | ||||
81 | if (string == NULL((void*)0)) | |||
82 | { | |||
83 | string = g_string_sized_new (remaining_bytes); | |||
84 | } | |||
85 | g_string_append_len (string, remainder, valid_bytes)g_string_append_len_inline (string, remainder, valid_bytes); | |||
86 | g_string_append_c (string, '?')g_string_append_c_inline (string, '?'); | |||
87 | ||||
88 | remaining_bytes -= valid_bytes + 1; | |||
89 | remainder = invalid + 1; | |||
90 | } | |||
91 | ||||
92 | if (string == NULL((void*)0)) | |||
93 | { | |||
94 | return g_strdup (name)g_strdup_inline (name); | |||
95 | } | |||
96 | ||||
97 | g_string_append (string, remainder)(__builtin_constant_p (remainder) ? __extension__ ({ const char * const __val = (remainder); g_string_append_len_inline (string , __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + ! (__val))) : (gssize) -1); }) : g_string_append_len_inline (string , remainder, (gssize) -1)); | |||
98 | g_string_append (string, _(" (invalid Unicode)"))(__builtin_constant_p (((char *) g_dgettext ("baul", " (invalid Unicode)" ))) ? __extension__ ({ const char * const __val = (((char *) g_dgettext ("baul", " (invalid Unicode)"))); g_string_append_len_inline (string, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val ) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (string, ((char *) g_dgettext ("baul", " (invalid Unicode)") ), (gssize) -1)); | |||
99 | g_assert (g_utf8_validate (string->str, -1, NULL))do { if (g_utf8_validate (string->str, -1, ((void*)0))) ; else g_assertion_message_expr ("Eel", "eel-vfs-extensions.c", 99, ((const char*) (__func__)), "g_utf8_validate (string->str, -1, NULL)" ); } while (0); | |||
100 | ||||
101 | return g_string_free (string, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((string ), ((0))) : g_string_free_and_steal (string)) : (g_string_free ) ((string), ((0)))); | |||
102 | } | |||
103 | ||||
104 | char * | |||
105 | eel_filename_strip_extension (const char * filename_with_extension) | |||
106 | { | |||
107 | char *filename, *end, *end2; | |||
108 | ||||
109 | if (filename_with_extension
| |||
110 | { | |||
111 | return NULL((void*)0); | |||
112 | } | |||
113 | ||||
114 | filename = g_strdup (filename_with_extension)g_strdup_inline (filename_with_extension); | |||
115 | ||||
116 | end = strrchr (filename, '.'); | |||
117 | ||||
118 | if (end && end != filename) | |||
119 | { | |||
120 | if (strcmp (end, ".gz") == 0 || | |||
121 | strcmp (end, ".bz2") == 0 || | |||
122 | strcmp (end, ".sit") == 0 || | |||
123 | strcmp (end, ".Z") == 0) | |||
124 | { | |||
125 | end2 = end - 1; | |||
126 | while (end2 > filename && | |||
127 | *end2 != '.') | |||
128 | { | |||
129 | end2--; | |||
130 | } | |||
131 | if (end2 != filename) | |||
132 | { | |||
133 | end = end2; | |||
134 | } | |||
135 | } | |||
136 | *end = '\0'; | |||
| ||||
137 | } | |||
138 | ||||
139 | return filename; | |||
140 | } | |||
141 | ||||
142 | void | |||
143 | eel_filename_get_rename_region (const char *filename, | |||
144 | int *start_offset, | |||
145 | int *end_offset) | |||
146 | { | |||
147 | char *filename_without_extension; | |||
148 | ||||
149 | g_return_if_fail (start_offset != NULL)do { if ((start_offset != ((void*)0))) { } else { g_return_if_fail_warning ("Eel", ((const char*) (__func__)), "start_offset != NULL"); return; } } while (0); | |||
| ||||
150 | g_return_if_fail (end_offset != NULL)do { if ((end_offset != ((void*)0))) { } else { g_return_if_fail_warning ("Eel", ((const char*) (__func__)), "end_offset != NULL"); return ; } } while (0); | |||
151 | ||||
152 | *start_offset = 0; | |||
153 | *end_offset = 0; | |||
154 | ||||
155 | g_return_if_fail (filename != NULL)do { if ((filename != ((void*)0))) { } else { g_return_if_fail_warning ("Eel", ((const char*) (__func__)), "filename != NULL"); return ; } } while (0); | |||
156 | ||||
157 | filename_without_extension = eel_filename_strip_extension (filename); | |||
158 | *end_offset = g_utf8_strlen (filename_without_extension, -1); | |||
159 | ||||
160 | g_free (filename_without_extension); | |||
161 | } |