1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
14 #include <sys/types.h>
21 string_replace(char **dest
, char *src
) {
22 if (*dest
) g_free(*dest
);
27 verify_dir(const char *path
, GError
**err
) {
28 /* mode 0700 so other people can't peek at passwords! */
29 if (mkdir(path
, 0700) < 0 && errno
!= EEXIST
) {
30 g_set_error(err
, 0, 0, /* FIXME domain */
31 _("Failed to create directory '%s': %s"),
32 path
, g_strerror(errno
));
39 verify_path(char *path
, int include_last
, GError
**err
) {
42 len
= reallen
= (int)strlen(path
);
44 for (i
= len
-1; i
> 0; i
--)
45 if (path
[i
] == G_DIR_SEPARATOR
)
52 /* the common case is that the path already exists. */
53 if (!verify_dir(path
, NULL
)) {
54 /* otherwise, start creating parent directories until we succeed. */
55 for (i
= len
-1; i
> 0; i
--) {
56 if (path
[i
] == G_DIR_SEPARATOR
) {
58 if (verify_dir(path
, NULL
)) {
59 path
[i
] = G_DIR_SEPARATOR
;
62 path
[i
] = G_DIR_SEPARATOR
;
65 /* once a parent dir succeeded, create the subdirectories we needed. */
67 for ( ; i
< len
; i
++) {
68 if (path
[i
] == G_DIR_SEPARATOR
) {
70 if (!verify_dir(path
, err
))
72 path
[i
] = G_DIR_SEPARATOR
;
75 if (!verify_dir(path
, err
))
79 path
[len
] = G_DIR_SEPARATOR
;
84 xml_escape(char **text
) {
88 esc
= g_markup_escape_text(*text
, -1);