1 //--------------------------------------------------------------------------
2 // Copyright (C) 2020-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // sigsafe.h author Michael Altizer <mialtize@cisco.com>
19 
20 #ifndef SIGSAFE_H
21 #define SIGSAFE_H
22 
23 #include <cstddef>
24 #include <cstdint>
25 
26 class SigSafePrinter
27 {
28 public:
29     SigSafePrinter(char *buf, size_t size);
SigSafePrinter(int fd)30     SigSafePrinter(int fd) : fd(fd) { }
31 
32     void hex_dump(const uint8_t* data, unsigned len);
33     void printf(const char* format, ...);
34 
35 private:
36     void write_string(const char* str);
37 
38 private:
39     char* buf = nullptr;
40     size_t buf_size = 0;
41     size_t buf_idx = 0;
42     int fd = -1;
43 };
44 
45 #endif
46 
47