From 4b8f935084dc873dfe9ba1656b291159744994b2 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 14 Sep 2013 11:20:32 +0300 Subject: [PATCH] cosmetix --- src/util.c | 86 ++++++++++++++++++++++++++++++-------------------------------- src/util.h | 12 +++++---- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/util.c b/src/util.c index c9722ed..baec701 100644 --- a/src/util.c +++ b/src/util.c @@ -1,90 +1,88 @@ /* logjam - a GTK client for LiveJournal. * Copyright (C) 2000-2003 Evan Martin - * - * vim: tabstop=4 shiftwidth=4 noexpandtab : */ - #include "glib-all.h" -#include + #include +#include +#include +#include +#include #include -#include #include #include -#include -#include #include "util.h" -void -string_replace(char **dest, char *src) { + +void string_replace (char **dest, char *src) { if (*dest) g_free(*dest); *dest = src; } -gboolean -verify_dir(const char *path, GError **err) { + +gboolean verify_dir (const char *path, GError **err) { /* mode 0700 so other people can't peek at passwords! */ if (mkdir(path, 0700) < 0 && errno != EEXIST) { - g_set_error(err, 0, 0, /* FIXME domain */ - _("Failed to create directory '%s': %s"), - path, g_strerror(errno)); + g_set_error(err, 0, 0, /* FIXME domain */ _("Failed to create directory '%s': %s"), path, g_strerror(errno)); return FALSE; } return TRUE; } -gboolean -verify_path(char *path, int include_last, GError **err) { - int i, len, reallen; +static gboolean verify_path_ex (char *path, int include_last, GError **err) { + int i, len, reallen; len = reallen = (int)strlen(path); if (!include_last) { - for (i = len-1; i > 0; i--) - if (path[i] == G_DIR_SEPARATOR) - break; - if (i > 0) { - len = i; - path[len] = 0; - } + for (i = len-1; i > 0; --i) if (path[i] == G_DIR_SEPARATOR) break; + if (i > 0) { len = i; path[len] = 0; } } - /* the common case is that the path already exists. */ + /* the common case is that the path already exists */ if (!verify_dir(path, NULL)) { - /* otherwise, start creating parent directories until we succeed. */ - for (i = len-1; i > 0; i--) { + /* otherwise, start creating parent directories until we succeed */ + for (i = len-1; i > 0; --i) { if (path[i] == G_DIR_SEPARATOR) { path[i] = 0; - if (verify_dir(path, NULL)) { - path[i] = G_DIR_SEPARATOR; - break; - } + if (verify_dir(path, NULL)) { path[i] = G_DIR_SEPARATOR; break; } path[i] = G_DIR_SEPARATOR; } } - /* once a parent dir succeeded, create the subdirectories we needed. */ - i++; - for ( ; i < len; i++) { + /* once a parent dir succeeded, create the subdirectories we needed */ + ++i; + for (; i < len; ++i) { if (path[i] == G_DIR_SEPARATOR) { path[i] = 0; - if (!verify_dir(path, err)) - return FALSE; + if (!verify_dir(path, err)) return FALSE; path[i] = G_DIR_SEPARATOR; } } - if (!verify_dir(path, err)) - return FALSE; + if (!verify_dir(path, err)) return FALSE; } - if (!include_last) - path[len] = G_DIR_SEPARATOR; + if (!include_last) path[len] = G_DIR_SEPARATOR; return TRUE; } -void -xml_escape(char **text) { + +static void _xfree_ptr (void *p) { + void **pp = (void **)p; + if (*pp) free(*pp); +} + + +gboolean verify_path (const char *path, int include_last, GError **err) { + if (path != NULL) { + __attribute__((cleanup(_xfree_ptr))) char *p = strdup(path); + return verify_path_ex(p, include_last, err); + } + return FALSE; +} + + +void xml_escape (char **text) { char *esc; - if (!text || !*text) - return; + if (!text || !*text) return; esc = g_markup_escape_text(*text, -1); g_free(*text); *text = esc; diff --git a/src/util.h b/src/util.h index e97a671..37cb440 100644 --- a/src/util.h +++ b/src/util.h @@ -4,11 +4,13 @@ #ifndef __LOGJAM_UTIL_H__ #define __LOGJAM_UTIL_H__ -void string_replace(char **dest, char *src); -gboolean verify_dir(const char *path, GError ** err); -gboolean verify_path(char *path, gboolean include_last, GError ** err); +extern void string_replace (char **dest, char *src); -void xml_escape(char **text); +extern gboolean verify_dir (const char *path, GError **err); +extern gboolean verify_path (const char *path, gboolean include_last, GError **err); -#endif /* __logjam_util_h__ */ +extern void xml_escape (char **text); + + +#endif -- 2.11.4.GIT