FreeBSD regtest: add fakes for FreeBSD < 13
[valgrind.git] / coregrind / m_gdbserver / remote-utils-shared.c
blobd0e11b302c8fcffad8283969b7651b956a58bf5d
1 /* Shared remote utility routines for the remote server for GDB.
2 Copyright (C) 1986, 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2011
4 Free Software Foundation, Inc.
6 This file is based on parts of GDB.
7 It has been modified to integrate it in valgrind
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
24 /* Note this is shared code between vgdb.c and m_gdbserver/server.c.
25 It is used directly by vgdb.c using libc functions.
26 There is another file m_gdbserver/remote-utils-shared-gdbserver.c
27 which first redefines the libc functions to use valgrind VG_ variants
28 that is used with server.c. */
30 #include "remote-utils-shared.h"
32 /* When included through remote-utils-shared-gdbserver.c strlen
33 is already defined to make to VG_(strlen). Otherwise we are
34 building for vgdb, which will use the standard libc functions. */
35 #ifndef strlen
36 #include <string.h>
37 #endif
39 /* Convert number NIB to a hex digit. */
40 int tohex (int nib)
42 if (nib < 10)
43 return '0' + nib;
44 else
45 return 'a' + nib - 10;
48 int hexify (char *hex, const char *bin, int count)
50 int i;
52 /* May use a length, or a nul-terminated string as input. */
53 if (count == 0)
54 count = strlen (bin);
56 for (i = 0; i < count; i++) {
57 *hex++ = tohex ((*bin >> 4) & 0xf);
58 *hex++ = tohex (*bin++ & 0xf);
60 *hex = 0;
61 return i;