Remove libsystem dependency 32/131932/3
authorSunmin Lee <sunm.lee@samsung.com>
Wed, 31 May 2017 05:35:17 +0000 (14:35 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Thu, 8 Jun 2017 10:02:11 +0000 (19:02 +0900)
To simplify package dependency,
get required functions from libsystem and include in itself.

Change-Id: I0020415027cccdc6c501294e9edb17cba7e03ecc
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
configure.ac
packaging/initrd-recovery.spec
src/shared/log.c

index f13d339..ec19e21 100644 (file)
@@ -74,7 +74,6 @@ AC_ARG_ENABLE([recovery-gui],
 if test "x$enable_recovery_gui" == "xyes"; then
         M4_DEFINES="$M4_DEFINES -DRECOVERY_GUI"
         AC_SUBST([OUR_CFLAGS], "$OUR_CFLAGS -DRECOVERY_GUI")
-       PKG_CHECK_MODULES(LIBSYSTEM, [libsystem])
        PKG_CHECK_MODULES(LIBPNG, [libpng])
        PKG_CHECK_MODULES(VCONF_INTERNAL_KEYS, [vconf-internal-keys])
 fi
index 45693c3..53eaf60 100644 (file)
@@ -12,7 +12,6 @@ Source1001:     initrd-recovery.manifest
 BuildRequires:  autoconf
 BuildRequires:  automake
 BuildRequires:  libtool
-BuildRequires:  pkgconfig(libsystem)
 
 Requires:       system-recovery
 
@@ -31,7 +30,6 @@ BuildRequires:  kernel-headers-tizen-dev
 BuildRequires:  pkgconfig(libpng)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(vconf-internal-keys)
-BuildRequires:  pkgconfig(libsystem)
 
 %description -n system-recovery
 A simple initrd menu for system recovery.
index 554f720..45b10f0 100644 (file)
 #include <assert.h>
 #include <limits.h>
 #include <time.h>
-
-#include <libsystem/libsystem.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "log.h"
 
 #define FILEBUF 1024
 
+static inline void __cleanup_free_func(void *p) {
+        free(*(void**) p);
+}
+
+static inline bool isempty(const char *p) {
+        return !p || !p[0];
+}
+
+#define _cleanup_(x) __attribute__((cleanup(x)))
+
+#define _cleanup_free_ _cleanup_(__cleanup_free_func)
+
+#define new(t, n) ((t*) malloc(sizeof(t) * (n)))
+
+#define FOREACH_WORD_SEPARATOR(word, length, s, separator, state)       \
+        for ((state) = NULL, (word) = split((s), &(length), (separator), &(state)); (word); (word) = split((s), &(length), (separator), &(state)))
+
+#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
+
 static FILE *log_f[LOG_TYPE_MAX];
 static int stdout_bak = -1;
 static int stderr_bak = -1;
@@ -57,6 +76,78 @@ int get_log_level(void) {
         return log_level;
 }
 
+static bool __quote_complete(char *str, size_t l, char q) {
+        char *s, *s2;
+
+        assert(str);
+
+        if (!l)
+                return true;
+
+        s = strchr(str, q);
+        if (!s || (s - str) > l)
+                return true;
+
+        s = strchr(s + 1, q);
+        if (!s || (s - str) > l)
+                return false;
+
+        s2 = strchr(s + 1, q);
+        if (!s2 || (s2 - str) > l)
+                return true;
+
+        return __quote_complete(s + 1, l - (s + 1 - str), q);
+}
+
+#define QUOTES "\"\'"
+static bool quote_complete(char *str, size_t l) {
+        char quotes[] = QUOTES;
+        int i;
+
+        assert(str);
+
+        if (!l)
+                return true;
+
+        for (i = 0; quotes[i]; i++) {
+                if (!__quote_complete(str, l, quotes[i]))
+                        return false;
+        }
+
+        return true;
+}
+
+static char *split(const char *c, size_t *l, const char *separator, char **state) {
+        bool separator_include_quotes;
+        char *current;
+        size_t s;
+
+        assert(c);
+        assert(l);
+        assert(separator);
+        assert(state);
+
+        current = *state ? *state : (char *) c;
+        if (!*current || *c == 0)
+                return NULL;
+
+        *l = 0;
+        separator_include_quotes = !!strspn(separator, QUOTES);
+        current += strspn(current, separator);
+
+        while ((s = strcspn(current + *l, separator))) {
+                *l += s;
+                if (separator_include_quotes ||
+                    quote_complete(current, *l))
+                        break;
+                (*l)++;
+        }
+
+        *state = current + *l;
+
+        return (char *) current;
+}
+
 static int stdpath_dup_and_backup(FILE *f) {
         int r, fd;