njn | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame^] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Standalone libc stuff. pub_tool_libcbase.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
| 10 | Copyright (C) 2000-2005 Julian Seward |
| 11 | jseward@acm.org |
| 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_TOOL_LIBCBASE_H |
| 32 | #define __PUB_TOOL_LIBCBASE_H |
| 33 | |
| 34 | /* --------------------------------------------------------------------- |
| 35 | Char functions. |
| 36 | ------------------------------------------------------------------ */ |
| 37 | |
| 38 | extern Bool VG_(isspace) ( Char c ); |
| 39 | extern Bool VG_(isdigit) ( Char c ); |
| 40 | |
| 41 | /* --------------------------------------------------------------------- |
| 42 | Converting strings to numbers |
| 43 | ------------------------------------------------------------------ */ |
| 44 | |
| 45 | extern Long VG_(atoll) ( Char* str ); // base 10 |
| 46 | extern Long VG_(atoll36) ( Char* str ); // base 36 |
| 47 | |
| 48 | /* --------------------------------------------------------------------- |
| 49 | String functions and macros |
| 50 | ------------------------------------------------------------------ */ |
| 51 | |
| 52 | /* Use this for normal null-termination-style string comparison */ |
| 53 | #define VG_STREQ(s1,s2) (s1 != NULL && s2 != NULL \ |
| 54 | && VG_(strcmp)((s1),(s2))==0) |
| 55 | |
| 56 | extern Int VG_(strlen) ( const Char* str ); |
| 57 | extern Char* VG_(strcat) ( Char* dest, const Char* src ); |
| 58 | extern Char* VG_(strncat) ( Char* dest, const Char* src, SizeT n ); |
| 59 | extern Char* VG_(strpbrk) ( const Char* s, const Char* accpt ); |
| 60 | extern Char* VG_(strcpy) ( Char* dest, const Char* src ); |
| 61 | extern Char* VG_(strncpy) ( Char* dest, const Char* src, SizeT ndest ); |
| 62 | extern Int VG_(strcmp) ( const Char* s1, const Char* s2 ); |
| 63 | extern Int VG_(strncmp) ( const Char* s1, const Char* s2, SizeT nmax ); |
| 64 | extern Char* VG_(strstr) ( const Char* haystack, Char* needle ); |
| 65 | extern Char* VG_(strchr) ( const Char* s, Char c ); |
| 66 | extern Char* VG_(strrchr) ( const Char* s, Char c ); |
| 67 | extern Char* VG_(strdup) ( const Char* s); |
| 68 | |
| 69 | /* Like strcmp() and strncmp(), but stop comparing at any whitespace. */ |
| 70 | extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 ); |
| 71 | extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, SizeT nmax ); |
| 72 | |
| 73 | /* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the |
| 74 | last character. */ |
| 75 | extern void VG_(strncpy_safely) ( Char* dest, const Char* src, SizeT ndest ); |
| 76 | |
| 77 | /* Mini-regexp function. Searches for 'pat' in 'str'. Supports |
| 78 | * meta-symbols '*' and '?'. '\' escapes meta-symbols. */ |
| 79 | extern Bool VG_(string_match) ( const Char* pat, const Char* str ); |
| 80 | |
| 81 | /* --------------------------------------------------------------------- |
| 82 | mem* functions |
| 83 | ------------------------------------------------------------------ */ |
| 84 | |
| 85 | extern void* VG_(memcpy) ( void *d, const void *s, SizeT sz ); |
| 86 | extern void* VG_(memset) ( void *s, Int c, SizeT sz ); |
| 87 | extern Int VG_(memcmp) ( const void* s1, const void* s2, SizeT n ); |
| 88 | |
| 89 | /* --------------------------------------------------------------------- |
| 90 | Address computation helpers |
| 91 | ------------------------------------------------------------------ */ |
| 92 | |
| 93 | // Check if an address/whatever is aligned |
| 94 | #define VG_IS_4_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & ((Addr)0x3))) |
| 95 | #define VG_IS_8_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & ((Addr)0x7))) |
| 96 | #define VG_IS_16_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & ((Addr)0xf))) |
| 97 | #define VG_IS_WORD_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & ((Addr)(sizeof(Addr)-1)))) |
| 98 | #define VG_IS_PAGE_ALIGNED(aaa_p) (0 == (((Addr)(aaa_p)) & ((Addr)(VKI_PAGE_SIZE-1)))) |
| 99 | |
| 100 | /* --------------------------------------------------------------------- |
| 101 | Misc useful functions |
| 102 | ------------------------------------------------------------------ */ |
| 103 | |
| 104 | /* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */ |
| 105 | extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size, |
| 106 | Int (*compar)(void*, void*) ); |
| 107 | |
| 108 | /* Returns the base-2 logarithm of x. */ |
| 109 | extern Int VG_(log2) ( Int x ); |
| 110 | |
| 111 | #endif // __PUB_TOOL_LIBCBASE_H |
| 112 | |
| 113 | /*--------------------------------------------------------------------*/ |
| 114 | /*--- end ---*/ |
| 115 | /*--------------------------------------------------------------------*/ |