ucx/utils.c

changeset 244
98dc2d3a9b1d
parent 225
a1a068c2c4ef
child 250
b7d1317b138e
     1.1 --- a/ucx/utils.c	Sat Jul 15 19:20:06 2017 +0200
     1.2 +++ b/ucx/utils.c	Sat Jul 15 20:46:18 2017 +0200
     1.3 @@ -33,15 +33,15 @@
     1.4  #include <errno.h>
     1.5  
     1.6  /* COPY FUCNTIONS */
     1.7 -void* ucx_strcpy(void* s, void* data) {
     1.8 -    char *str = (char*) s;
     1.9 +void* ucx_strcpy(const void* s, void* data) {
    1.10 +    const char *str = (const char*) s;
    1.11      size_t n = 1+strlen(str);
    1.12      char *cpy = (char*) malloc(n);
    1.13      memcpy(cpy, str, n);
    1.14      return cpy;
    1.15  }
    1.16  
    1.17 -void* ucx_memcpy(void* m, void* n) {
    1.18 +void* ucx_memcpy(const void* m, void* n) {
    1.19      size_t k = *((size_t*)n);
    1.20      void *cpy = malloc(k);
    1.21      memcpy(cpy, m, k);
    1.22 @@ -87,17 +87,17 @@
    1.23  
    1.24  /* COMPARE FUNCTIONS */
    1.25  
    1.26 -int ucx_strcmp(void *s1, void *s2, void *data) {
    1.27 -    return strcmp((char*)s1, (char*)s2);
    1.28 +int ucx_strcmp(const void *s1, const void *s2, void *data) {
    1.29 +    return strcmp((const char*)s1, (const char*)s2);
    1.30  }
    1.31  
    1.32 -int ucx_strncmp(void *s1, void *s2, void *n) {
    1.33 -    return strncmp((char*)s1, (char*)s2, *((size_t*) n));
    1.34 +int ucx_strncmp(const void *s1, const void *s2, void *n) {
    1.35 +    return strncmp((const char*)s1, (const char*)s2, *((size_t*) n));
    1.36  }
    1.37  
    1.38 -int ucx_intcmp(void *i1, void *i2, void *data) {
    1.39 -   int a = *((int*) i1);
    1.40 -   int b = *((int*) i2);
    1.41 +int ucx_intcmp(const void *i1, const void *i2, void *data) {
    1.42 +   int a = *((const int*) i1);
    1.43 +   int b = *((const int*) i2);
    1.44     if (a == b) {
    1.45         return 0;
    1.46     } else {
    1.47 @@ -105,9 +105,9 @@
    1.48     }
    1.49  }
    1.50  
    1.51 -int ucx_floatcmp(void *f1, void *f2, void *epsilon) {
    1.52 -   float a = *((float*) f1);
    1.53 -   float b = *((float*) f2);
    1.54 +int ucx_floatcmp(const void *f1, const void *f2, void *epsilon) {
    1.55 +   float a = *((const float*) f1);
    1.56 +   float b = *((const float*) f2);
    1.57     float e = !epsilon ? 1e-6f : *((float*)epsilon);
    1.58     if (fabsf(a - b) < e) {
    1.59         return 0;
    1.60 @@ -116,9 +116,9 @@
    1.61     }
    1.62  }
    1.63  
    1.64 -int ucx_doublecmp(void *d1, void *d2, void *epsilon) {
    1.65 -   double a = *((float*) d1);
    1.66 -   double b = *((float*) d2);
    1.67 +int ucx_doublecmp(const void *d1, const void *d2, void *epsilon) {
    1.68 +   double a = *((const double*) d1);
    1.69 +   double b = *((const double*) d2);
    1.70     double e = !epsilon ? 1e-14 : *((double*)epsilon);
    1.71     if (fabs(a - b) < e) {
    1.72         return 0;
    1.73 @@ -127,9 +127,9 @@
    1.74     }
    1.75  }
    1.76  
    1.77 -int ucx_ptrcmp(void *ptr1, void *ptr2, void *data) {
    1.78 -    intptr_t p1 = (intptr_t) ptr1;
    1.79 -    intptr_t p2 = (intptr_t) ptr2;
    1.80 +int ucx_ptrcmp(const void *ptr1, const void *ptr2, void *data) {
    1.81 +    const intptr_t p1 = (const intptr_t) ptr1;
    1.82 +    const intptr_t p2 = (const intptr_t) ptr2;
    1.83      if (p1 == p2) {
    1.84          return 0;
    1.85      } else {
    1.86 @@ -137,7 +137,7 @@
    1.87      }
    1.88  }
    1.89  
    1.90 -int ucx_memcmp(void *ptr1, void *ptr2, void *n) {
    1.91 +int ucx_memcmp(const void *ptr1, const void *ptr2, void *n) {
    1.92      return memcmp(ptr1, ptr2, *((size_t*)n));
    1.93  }
    1.94  

mercurial