libdatatypes 0.3.2
Abstract datatypes for C.
Loading...
Searching...
No Matches
compare.c
Go to the documentation of this file.
1/***************************************************************************
2 begin........: June 2012
3 copyright....: Sebastian Fedrau
4 email........: sebastian.fedrau@gmail.com
5 ***************************************************************************/
6
7/***************************************************************************
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License v3 as published by
10 the Free Software Foundation.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License v3 for more details.
16 ***************************************************************************/
22#include <stdlib.h>
23#include <stdio.h>
24#include <stdint.h>
25#include <stddef.h>
26#include <assert.h>
27
28#include "datatypes.h"
29
30bool
31str_equal(const void *a, const void *b)
32{
33 assert(a != NULL);
34 assert(b != NULL);
35
36 const char *s0 = (const char *)a;
37 const char *s1 = (const char *)b;
38
39 while(*s0 && *s1)
40 {
41 if(*s0++ != *s1++)
42 {
43 return false;
44 }
45 }
46
47 return *s0 == *s1;
48}
49
50int32_t
51direct_compare(const void *a, const void *b)
52{
53 assert(a != NULL);
54 assert(b != NULL);
55
56 return (a > b) - (a < b);
57}
58
59bool
60direct_equal(const void *a, const void *b)
61{
62 assert(a != NULL);
63 assert(b != NULL);
64
65 return a == b;
66}
67
bool direct_equal(const void *a, const void *b)
Definition compare.c:60
bool str_equal(const void *a, const void *b)
Definition compare.c:31
int32_t direct_compare(const void *a, const void *b)
Definition compare.c:51
General declarations.