Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=912d627a8f342994b1a640254d4ed536c6c5b16a

commit 912d627a8f342994b1a640254d4ed536c6c5b16a
Author: Michel Hermier <herm...@frugalware.org>
Date:   Sat Nov 16 22:03:31 2013 +0100

libpacman: Move some util.h to fstdlib.h and fstring.h.

diff --git a/lib/libpacman/fstdlib.h b/lib/libpacman/fstdlib.h
index bea2601..53baa2d 100644
--- a/lib/libpacman/fstdlib.h
+++ b/lib/libpacman/fstdlib.h
@@ -21,14 +21,45 @@
#ifndef _F_STDLIB_H
#define _F_STDLIB_H

-#include <stdlib.h>
#include <stdint.h>
+#include <stdlib.h>
+
+#include "util/log.h"
+#include "util.h"
+
+static inline
+void *f_malloc(size_t size)
+{
+       void *ptr = malloc(size);
+       if(ptr == NULL) {
+               _pacman_log(PM_LOG_ERROR, _("malloc failure: could not allocate 
%d bytes"), size);
+               RET_ERR(PM_ERR_MEMORY, NULL);
+       }
+       return ptr;
+}

-static
+static inline
+void *f_zalloc(size_t size)
+{
+       void *ptr = f_malloc(size);
+       if(ptr != NULL)
+               memset(ptr, 0, size);
+       return ptr;
+}
+
+static inline
int f_ptrcmp(const void *ptr1, const void *ptr2) {
return (uintptr_t)ptr1 - (uintptr_t)ptr2;
}

+static inline
+void f_ptrswap(void **ptr1, void **ptr2)
+{
+       void *tmp = *ptr2;
+       *ptr2 = *ptr1;
+       *ptr1 = tmp;
+}
+
#endif /* _F_STDLIB_H */

/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/fstring.h b/lib/libpacman/fstring.h
new file mode 100644
index 0000000..8188027
--- /dev/null
+++ b/lib/libpacman/fstring.h
@@ -0,0 +1,40 @@
+/*
+ *  fstring.h
+ *
+ *  Copyright (c) 2013 by Michel Hermier <herm...@frugalware.org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+#ifndef _F_STRING_H
+#define _F_STRING_H
+
+#include <string.h>
+
+static inline
+int f_strempty(const char *s)
+{
+       return s != NULL ? s[0] == '\0' : !0;
+}
+
+static inline
+size_t f_strlen(const char *s)
+{
+       return s != NULL ? strlen(s) : 0;
+}
+
+#endif /* _F_STRING_H */
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/util.h b/lib/libpacman/util.h
index 0f1b8d0..103de74 100644
--- a/lib/libpacman/util.h
+++ b/lib/libpacman/util.h
@@ -59,6 +59,9 @@
#define STARTSTR "START "
#define DONESTR "DONE "

+#include "fstdlib.h"
+#include "fstring.h"
+
char *_pacman_basename(const char *path);
int _pacman_makepath(char *path);
int _pacman_copyfile(char *src, char *dest);
@@ -83,40 +86,11 @@ char* strsep(char** str, const char* delims);
char* mkdtemp(char *template);
#endif

-static inline int _pacman_strempty(const char *s)
-{
-       return s != NULL ? s[0] == '\0' : !0;
-}
-
-static inline size_t _pacman_strlen(const char *s)
-{
-       return s != NULL ? strlen(s) : 0;
-}
-
-static inline void *_pacman_malloc(size_t size)
-{
-       void *ptr = malloc(size);
-       if(ptr == NULL) {
-               _pacman_log(PM_LOG_ERROR, _("malloc failure: could not allocate 
%d bytes"), size);
-               RET_ERR(PM_ERR_MEMORY, NULL);
-       }
-       return ptr;
-}
-
-static inline void *_pacman_zalloc(size_t size)
-{
-       void *ptr = _pacman_malloc(size);
-       if(ptr != NULL)
-               memset(ptr, 0, size);
-       return ptr;
-}
-
-static inline void _pacman_ptrswap(void **ptr1, void **ptr2)
-{
-       void *tmp = *ptr2;
-       *ptr2 = *ptr1;
-       *ptr1 = tmp;
-}
+#define _pacman_strempty f_strempty
+#define _pacman_strlen f_strlen
+#define _pacman_malloc f_malloc
+#define _pacman_zalloc f_zalloc
+#define _pacman_ptrswap f_ptrswap

#endif /* _PACMAN_UTIL_H */
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to