diff options
| author | David M. Syzdek <david@syzdek.net> | 2023-01-09 18:24:05 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2023-01-09 18:33:39 -0900 |
| commit | 7e5f22309800eaea1c7965f02dcb3e81d654e894 (patch) | |
| tree | b34249a0eb05d1daab4757df9cee861c54af4720 | |
| parent | 2c537f473283080b16c19b32f816211012168d4a (diff) | |
| download | otputils-7e5f22309800eaea1c7965f02dcb3e81d654e894.tar.gz otputils-7e5f22309800eaea1c7965f02dcb3e81d654e894.tar.bz2 otputils-7e5f22309800eaea1c7965f02dcb3e81d654e894.tar.xz otputils-7e5f22309800eaea1c7965f02dcb3e81d654e894.zip | |
libotputil: adding otputil_bvcmp()
| -rw-r--r-- | include/otputil.h | 6 | ||||
| -rw-r--r-- | lib/libotputil/libotputil.c | 39 | ||||
| -rw-r--r-- | lib/libotputil/libotputil.sym | 1 |
3 files changed, 46 insertions, 0 deletions
diff --git a/include/otputil.h b/include/otputil.h index 95f9d00..88b3708 100644 --- a/include/otputil.h +++ b/include/otputil.h | |||
| @@ -213,6 +213,12 @@ otputil_bvbase32( | |||
| 213 | const otputil_bv_t * bv ); | 213 | const otputil_bv_t * bv ); |
| 214 | 214 | ||
| 215 | 215 | ||
| 216 | _OTPUTIL_F int | ||
| 217 | otputil_bvcmp( | ||
| 218 | const void * a, | ||
| 219 | const void * b ); | ||
| 220 | |||
| 221 | |||
| 216 | _OTPUTIL_F otputil_bv_t * | 222 | _OTPUTIL_F otputil_bv_t * |
| 217 | otputil_bvdup( | 223 | otputil_bvdup( |
| 218 | const otputil_bv_t * bv ); | 224 | const otputil_bv_t * bv ); |
diff --git a/lib/libotputil/libotputil.c b/lib/libotputil/libotputil.c index f80ccc1..85e33c3 100644 --- a/lib/libotputil/libotputil.c +++ b/lib/libotputil/libotputil.c | |||
| @@ -262,6 +262,45 @@ otputil_bvbase32( | |||
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | 264 | ||
| 265 | int | ||
| 266 | otputil_bvcmp( | ||
| 267 | const void * a, | ||
| 268 | const void * b ) | ||
| 269 | { | ||
| 270 | const otputil_bv_t * x; | ||
| 271 | const otputil_bv_t * y; | ||
| 272 | const uint8_t * x_val; | ||
| 273 | const uint8_t * y_val; | ||
| 274 | size_t pos; | ||
| 275 | size_t len; | ||
| 276 | |||
| 277 | x = *((const otputil_bv_t * const *)a); | ||
| 278 | y = *((const otputil_bv_t * const *)b); | ||
| 279 | |||
| 280 | // compare pointers | ||
| 281 | if ( (!(x)) && (!(y)) ) | ||
| 282 | return(0); | ||
| 283 | if (!(x)) | ||
| 284 | return(-1); | ||
| 285 | if (!(y)) | ||
| 286 | return(1); | ||
| 287 | |||
| 288 | x_val = x->bv_val; | ||
| 289 | y_val = y->bv_val; | ||
| 290 | len = (x->bv_len < y->bv_len) ? x->bv_len : y->bv_len; | ||
| 291 | for(pos = 0; (pos < len); pos++) | ||
| 292 | { | ||
| 293 | if (x_val[pos] == y_val[pos]) | ||
| 294 | continue; | ||
| 295 | return( (x_val[pos] < y_val[pos]) ? -1 : 1 ); | ||
| 296 | }; | ||
| 297 | |||
| 298 | if (x->bv_len == y->bv_len) | ||
| 299 | return(0); | ||
| 300 | return( (x->bv_len < y->bv_len) ? -1 : 1 ); | ||
| 301 | } | ||
| 302 | |||
| 303 | |||
| 265 | otputil_bv_t * | 304 | otputil_bv_t * |
| 266 | otputil_bvdup( | 305 | otputil_bvdup( |
| 267 | const otputil_bv_t * bv ) | 306 | const otputil_bv_t * bv ) |
diff --git a/lib/libotputil/libotputil.sym b/lib/libotputil/libotputil.sym index 240a3dd..b90e76b 100644 --- a/lib/libotputil/libotputil.sym +++ b/lib/libotputil/libotputil.sym | |||
| @@ -65,6 +65,7 @@ otputil_dict_rfc2289_sha1 | |||
| 65 | otputil_base32bv | 65 | otputil_base32bv |
| 66 | otputil_bvalloc | 66 | otputil_bvalloc |
| 67 | otputil_bvbase32 | 67 | otputil_bvbase32 |
| 68 | otputil_bvcmp | ||
| 68 | otputil_bvdup | 69 | otputil_bvdup |
| 69 | otputil_bvfree | 70 | otputil_bvfree |
| 70 | # error functions | 71 | # error functions |
