Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=c7100f5669a3c0d0c9753cccac1a8b396aeac1f4
commit c7100f5669a3c0d0c9753cccac1a8b396aeac1f4 Author: Michel Hermier <herm...@frugalware.org> Date: Sun Nov 24 11:29:45 2013 +0100 libpacman: Fix f_ptrcmp, add some int comparison functions. diff --git a/lib/libpacman/fmath.h b/lib/libpacman/fmath.h new file mode 100644 index 0000000..30305a3 --- /dev/null +++ b/lib/libpacman/fmath.h @@ -0,0 +1,36 @@ +/* + * fmath.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_MATH_H +#define _F_MATH_H + +#include <stdint.h> + +#define __f_intcmp(v, z) ((v) == (z) ? 0 : (v) < (z) ? -1 : 1) + +static inline +int f_signp(intptr_t p) +{ + return __f_intcmp(p, 0); +} + +#endif /* _F_MATH_H */ + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/fstdlib.h b/lib/libpacman/fstdlib.h index 53baa2d..c34f245 100644 --- a/lib/libpacman/fstdlib.h +++ b/lib/libpacman/fstdlib.h @@ -25,6 +25,7 @@ #include <stdlib.h> #include "util/log.h" +#include "fmath.h" #include "util.h" static inline @@ -48,8 +49,15 @@ void *f_zalloc(size_t size) } static inline -int f_ptrcmp(const void *ptr1, const void *ptr2) { - return (uintptr_t)ptr1 - (uintptr_t)ptr2; +intptr_t f_diffptr(const void *ptr1, const void *ptr2) +{ + return (intptr_t)ptr1 - (intptr_t)ptr2; +} + +static inline +int f_ptrcmp(const void *ptr1, const void *ptr2) +{ + return f_signp(f_diffptr(ptr1, ptr2)); } static inline _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git