]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/hex.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / hex.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2008-2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
7c673cae
FG
15#include "common/hex.h"
16
7c673cae
FG
17void hex2str(const char *s, int len, char *buf, int dest_len)
18{
19 int pos = 0;
20 for (int i=0; i<len && pos<dest_len; i++) {
21 if (i && !(i%8))
22 pos += snprintf(&buf[pos], dest_len-pos, " ");
23 if (i && !(i%16))
24 pos += snprintf(&buf[pos], dest_len-pos, "\n");
25 pos += snprintf(&buf[pos], dest_len-pos, "%.2x ", (int)(unsigned char)s[i]);
26 }
27}
28
11fdf7f2 29std::string hexdump(const std::string &msg, const char *s, int len)
7c673cae
FG
30{
31 int buf_len = len*4;
32 char buf[buf_len];
33 hex2str(s, len, buf, buf_len);
34 return buf;
35}