OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2007-2009 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 |
| 33 #ifndef INCLUDED_NVUTIL_H |
| 34 #define INCLUDED_NVUTIL_H |
| 35 |
| 36 //########################################################################### |
| 37 //############################### INCLUDES ################################## |
| 38 //########################################################################### |
| 39 |
| 40 #include "nvcommon.h" |
| 41 #include "nvos.h" |
| 42 |
| 43 #if defined(__cplusplus) |
| 44 extern "C" |
| 45 { |
| 46 #endif |
| 47 |
| 48 //########################################################################### |
| 49 //############################### PROTOTYPES ################################ |
| 50 //########################################################################### |
| 51 |
| 52 /** |
| 53 * parse a string into an unsigned integer. |
| 54 * |
| 55 * @param s - pointer to the string (null-terminated) |
| 56 * @param endptr - if not NULL this returns pointing to the first character |
| 57 * in the string that was not used in the conversion. |
| 58 * @param base - must be 0, 10, or 16. |
| 59 * 10: the number is parsed as a base 10 number |
| 60 * 16: the number is parsed as a base 16 number (0x ignored) |
| 61 * 0: base 10 unless there is a leading 0x |
| 62 */ |
| 63 unsigned long int |
| 64 NvUStrtoul( |
| 65 const char *s, |
| 66 char **endptr, |
| 67 int base); |
| 68 |
| 69 /** |
| 70 * Sames NvUStrtoul, execpt can parse a 64 bit unsigned integer. |
| 71 */ |
| 72 unsigned long long int |
| 73 NvUStrtoull( |
| 74 const char *s, |
| 75 char **endptr, |
| 76 int base); |
| 77 |
| 78 /** |
| 79 * parse a string into a signed integer. |
| 80 * |
| 81 * @param s - pointer to the string (null-terminated) |
| 82 * @param endptr - if not NULL this returns pointing to the first character |
| 83 * in the string that was not used in the conversion. |
| 84 * @param base - must be 0, 10, or 16. |
| 85 * 10: the number is parsed as a base 10 number |
| 86 * 16: the number is parsed as a base 16 number (0x ignored) |
| 87 * 0: base 10 unless there is a leading 0x |
| 88 */ |
| 89 long int |
| 90 NvUStrtol( |
| 91 const char *s, |
| 92 char **endptr, |
| 93 int base); |
| 94 |
| 95 /** |
| 96 * concatenate 2 strings. |
| 97 * |
| 98 * Note: dest is always left null terminated even if src exceeds n. |
| 99 * |
| 100 * @param dest - string to concatenate to |
| 101 * @param src - string to add to the end of dest |
| 102 * @param n - At most n chars from src (plus a NUL) are appended to dest |
| 103 */ |
| 104 void |
| 105 NvUStrncat( |
| 106 char *dest, |
| 107 const char *src, |
| 108 size_t n); |
| 109 |
| 110 /** |
| 111 * returns a pointer to the first occurence of str2 in str1. |
| 112 * |
| 113 * This function returns NULL if no match is found. If the length of str2 is |
| 114 * zero, then str1 is returned. |
| 115 * |
| 116 * @param str1 - string to be scanned |
| 117 * @param str2 - string containing the sequence of characters to match |
| 118 */ |
| 119 char * |
| 120 NvUStrstr( |
| 121 const char *str1, |
| 122 const char *str2); |
| 123 |
| 124 /** |
| 125 * converts strings between code pages |
| 126 * |
| 127 * @param pDest - the destination buffer |
| 128 * @param DestCodePage - the target code page |
| 129 * @param DestSize - size of the destination buffer, in bytes |
| 130 * @param pSrc - the source string |
| 131 * @param SrcSize - the size of the source buffer, in bytes, or zero if the |
| 132 * string is NULL-terminated |
| 133 * @param SrcCodePage - the source string's code page |
| 134 * |
| 135 * @returns The length of the destination string and NULL termination, in bytes |
| 136 * |
| 137 * If pDest is NULL, this function will return the number of bytes, including |
| 138 * NULL termination, of the destination buffer required to store the converted |
| 139 * string. |
| 140 * |
| 141 * If pDest is specified, up to DestSize bytes of the code-page converted |
| 142 * string will be written to it. If the destination buffer is too small to |
| 143 * store the converted string, the string will be truncated and a |
| 144 * NULL-terminator added. |
| 145 * |
| 146 * If either SrcCodePage or DestCodePage is NvOsCodePage_Unknown, the system's |
| 147 * default code page will be used for the conversion. |
| 148 */ |
| 149 size_t |
| 150 NvUStrlConvertCodePage(void *pDest, |
| 151 size_t DestSize, |
| 152 NvOsCodePage DestCodePage, |
| 153 const void *pSrc, |
| 154 size_t SrcSize, |
| 155 NvOsCodePage SrcCodePage); |
| 156 |
| 157 /** |
| 158 * dynamically allocate zeroed memory (uses NvOsAlloc()) |
| 159 * |
| 160 * @param size number of bytes to allocate |
| 161 * @returns NULL on failure |
| 162 * @returns pointer to zeroed memory on success (must be freed with NvOsFree) |
| 163 */ |
| 164 static NV_INLINE void * |
| 165 NvUAlloc0(size_t size) |
| 166 { |
| 167 void *p = NvOsAlloc(size); |
| 168 if (p) |
| 169 NvOsMemset(p,0,size); |
| 170 return p; |
| 171 } |
| 172 |
| 173 /** |
| 174 * Finds the lowest set bit. |
| 175 * |
| 176 * @param bits The bits to look through |
| 177 * @param nBits The number of bits wide |
| 178 */ |
| 179 NvU32 |
| 180 NvULowestBitSet( NvU32 bits, NvU32 nBits ); |
| 181 |
| 182 #if defined(__cplusplus) |
| 183 } |
| 184 #endif |
| 185 |
| 186 #endif // INCLUDED_NVUTIL_H |
OLD | NEW |