blob: e1a98adc29677015eb2930abbfd70fcd5a9b2b05 [file] [log] [blame]
Neels Hofmeyr73d14af2017-10-24 23:26:53 +02001/* 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 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 * $Id: dbd_helper.c,v 1.44 2011/08/09 11:14:14 mhoenicka Exp $
26 */
27
28#include <sys/types.h>
29
30size_t _dbd_decode_binary(const unsigned char *in, unsigned char *out){
31 int i, e;
32 unsigned char c;
33 e = *(in++);
34 i = 0;
35 while( (c = *(in++))!=0 ){
36 if( c==1 ){
37 c = *(in++) - 1;
38 }
39 out[i++] = c + e;
40 }
41 return (size_t)i;
42}