26 #include "dbus-sysdeps.h" 27 #include "dbus-internals.h" 28 #include "dbus-string.h" 29 #include "dbus-test.h" 35 #elif (defined __APPLE__) 36 # include <crt_externs.h> 37 # define environ (*_NSGetEnviron()) 38 #elif HAVE_DECL_ENVIRON && defined(HAVE_UNISTD_H) 41 extern char **environ;
58 for (length = 0; environ[length] !=
NULL; length++);
65 if (environment ==
NULL)
68 for (i = 0; environ[i] !=
NULL; i++)
72 if (environment[i] ==
NULL)
76 if (environ[i] !=
NULL)
85 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 87 check_dirname (
const char *filename,
102 _dbus_warn (
"For filename \"%s\" got dirname \"%s\" and expected \"%s\"",
104 _dbus_string_get_const_data (&d),
113 check_path_absolute (
const char *path,
122 _dbus_warn (
"For path \"%s\" expected absolute = %d got %d",
134 _dbus_sysdeps_test (
void)
137 check_dirname (
"foo\\bar",
"foo");
138 check_dirname (
"foo\\\\bar",
"foo");
139 check_dirname (
"foo/\\/bar",
"foo");
140 check_dirname (
"foo\\bar/",
"foo");
141 check_dirname (
"foo//bar\\",
"foo");
142 check_dirname (
"foo\\bar/",
"foo");
143 check_dirname (
"foo/bar\\\\",
"foo");
144 check_dirname (
"\\foo",
"\\");
145 check_dirname (
"\\\\foo",
"\\");
146 check_dirname (
"\\",
"\\");
147 check_dirname (
"\\\\",
"\\");
148 check_dirname (
"\\/",
"\\");
149 check_dirname (
"/\\/",
"/");
150 check_dirname (
"c:\\foo\\bar",
"c:\\foo");
151 check_dirname (
"c:\\foo",
"c:\\");
152 check_dirname (
"c:/foo",
"c:/");
153 check_dirname (
"c:\\",
"c:\\");
154 check_dirname (
"c:/",
"c:/");
155 check_dirname (
"",
".");
157 check_dirname (
"foo",
".");
158 check_dirname (
"foo/bar",
"foo");
159 check_dirname (
"foo//bar",
"foo");
160 check_dirname (
"foo///bar",
"foo");
161 check_dirname (
"foo/bar/",
"foo");
162 check_dirname (
"foo//bar/",
"foo");
163 check_dirname (
"foo///bar/",
"foo");
164 check_dirname (
"foo/bar//",
"foo");
165 check_dirname (
"foo//bar////",
"foo");
166 check_dirname (
"foo///bar///////",
"foo");
167 check_dirname (
"/foo",
"/");
168 check_dirname (
"////foo",
"/");
169 check_dirname (
"/foo/bar",
"/foo");
170 check_dirname (
"/foo//bar",
"/foo");
171 check_dirname (
"/foo///bar",
"/foo");
172 check_dirname (
"/",
"/");
173 check_dirname (
"///",
"/");
174 check_dirname (
"",
".");
178 check_path_absolute (
"c:/",
TRUE);
179 check_path_absolute (
"c:/foo",
TRUE);
180 check_path_absolute (
"",
FALSE);
181 check_path_absolute (
"foo",
FALSE);
182 check_path_absolute (
"foo/bar",
FALSE);
183 check_path_absolute (
"",
FALSE);
184 check_path_absolute (
"foo\\bar",
FALSE);
185 check_path_absolute (
"c:\\",
TRUE);
186 check_path_absolute (
"c:\\foo",
TRUE);
187 check_path_absolute (
"c:",
TRUE);
188 check_path_absolute (
"c:\\foo\\bar",
TRUE);
189 check_path_absolute (
"\\",
TRUE);
190 check_path_absolute (
"/",
TRUE);
192 check_path_absolute (
"/",
TRUE);
193 check_path_absolute (
"/foo",
TRUE);
194 check_path_absolute (
"",
FALSE);
195 check_path_absolute (
"foo",
FALSE);
196 check_path_absolute (
"foo/bar",
FALSE);
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_bool_t _dbus_string_get_dirname(const DBusString *filename, DBusString *dirname)
Get the directory name from a complete filename.
dbus_bool_t _dbus_path_is_absolute(const DBusString *filename)
Checks whether the filename is an absolute path.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
#define dbus_new0(type, count)
Safe macro for using dbus_malloc0().
dbus_bool_t _dbus_string_equal_c_str(const DBusString *a, const char *c_str)
Checks whether a string is equal to a C string.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
void dbus_free_string_array(char **str_array)
Frees a NULL-terminated array of strings.
char ** _dbus_get_environment(void)
Gets a NULL-terminated list of key=value pairs from the environment.
#define FALSE
Expands to "0".
char * _dbus_strdup(const char *str)
Duplicates a string.