Neels Hofmeyr | 73d14af | 2017-10-24 23:26:53 +0200 | [diff] [blame] | 1 | /* This function is blatantly copied from libdbi, from |
| 2 | * https://sourceforge.net/p/libdbi/libdbi/ci/master/tree/src/dbd_helper.c |
| 3 | * to save having to depend on the entire libdbi just for KI BLOB decoding. |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * libdbi - database independent abstraction layer for C. |
| 8 | * Copyright (C) 2001-2003, David Parker and Mark Tobenkin. |
| 9 | * http://libdbi.sourceforge.net |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Lesser General Public |
| 13 | * License as published by the Free Software Foundation; either |
| 14 | * version 2.1 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Lesser General Public License for more details. |
| 20 | * |
Neels Hofmeyr | 73d14af | 2017-10-24 23:26:53 +0200 | [diff] [blame] | 21 | * $Id: dbd_helper.c,v 1.44 2011/08/09 11:14:14 mhoenicka Exp $ |
| 22 | */ |
| 23 | |
| 24 | #include <sys/types.h> |
| 25 | |
| 26 | size_t _dbd_decode_binary(const unsigned char *in, unsigned char *out){ |
| 27 | int i, e; |
| 28 | unsigned char c; |
| 29 | e = *(in++); |
| 30 | i = 0; |
| 31 | while( (c = *(in++))!=0 ){ |
| 32 | if( c==1 ){ |
| 33 | c = *(in++) - 1; |
| 34 | } |
| 35 | out[i++] = c + e; |
| 36 | } |
| 37 | return (size_t)i; |
| 38 | } |