librsync  2.0.1
hex.c
1 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  *
3  * Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; either version 2.1 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #include "config.h"
21 
22 #include <assert.h>
23 #include <sys/types.h>
24 #ifdef HAVE_INTTYPES_H
25 #include <inttypes.h>
26 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 
30 #include "librsync.h"
31 
32 
33 void
34 rs_hexify(char *to_buf, void const *from, int from_len)
35 {
36  static const char hex_chars[] = "0123456789abcdef";
37  unsigned char const *from_buf = (unsigned char const *) from;
38 
39  while (from_len-- > 0) {
40  *(to_buf++) = hex_chars[((*from_buf) >> 4) & 0xf];
41  *(to_buf++) = hex_chars[(*from_buf) & 0xf];
42  from_buf++;
43  }
44 
45  *to_buf = 0;
46 }
void rs_hexify(char *to_buf, void const *from_buf, int from_len)
Convert from_len bytes at from_buf into a hex representation in to_buf, which must be twice as long p...
Definition: hex.c:34
Public header for librsync.