~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to include/iprt/string.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#if defined(RT_OS_LINUX) && defined(__KERNEL__)
38
38
# include <linux/string.h>
39
39
#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
 
40
# include <sys/libkern.h>
40
41
  /*
41
 
   * Kludge for the FreeBSD kernel:
42
 
   *  Some of the string.h stuff clashes with sys/libkern.h, so just wrap
43
 
   *  it up while including string.h to keep things quiet. It's nothing
44
 
   *  important that's clashing, after all.
 
42
   * No memmove on versions < 7.2
 
43
   * Defining a macro using bcopy here
45
44
   */
46
 
# define strdup strdup_string_h
47
 
# include <string.h>
48
 
# undef strdup
 
45
# define memmove(dst, src, size) bcopy(src, dst, size)
49
46
#elif defined(RT_OS_SOLARIS) && defined(_KERNEL)
50
47
  /*
51
48
   * Same case as with FreeBSD kernel:
64
61
 * Supply prototypes for standard string functions provided by
65
62
 * IPRT instead of the operating environment.
66
63
 */
67
 
#if defined(RT_OS_DARWIN) && defined(KERNEL)
 
64
#if    (defined(RT_OS_DARWIN) && defined(KERNEL)) \
 
65
    || (defined(RT_OS_FREEBSD) && defined(_KERNEL))
68
66
RT_C_DECLS_BEGIN
69
67
void *memchr(const void *pv, int ch, size_t cb);
70
68
char *strpbrk(const char *pszStr, const char *pszChars);
265
263
 *                          will be allocated to hold the translated string.
266
264
 *                          If a buffer was requested it must be freed using RTUtf16Free().
267
265
 * @param   cCps            The number of code points in the unicode string. This includes the terminator.
268
 
 * @param   pcCps           Where to store the length of the translated string. (Optional)
269
 
 *                          This field will be updated even on failure, however the value is only
270
 
 *                          specified for the following two error codes. On VERR_BUFFER_OVERFLOW
271
 
 *                          and VERR_NO_STR_MEMORY it contains the required buffer space.
 
266
 * @param   pcCps           Where to store the length of the translated string,
 
267
 *                          excluding the terminator. (Optional)
 
268
 *
 
269
 *                          This may be set under some error conditions,
 
270
 *                          however, only for VERR_BUFFER_OVERFLOW and
 
271
 *                          VERR_NO_STR_MEMORY will it contain a valid string
 
272
 *                          length that can be used to resize the buffer.
272
273
 */
273
274
RTDECL(int)  RTStrToUniEx(const char *pszString, size_t cchString, PRTUNICP *ppaCps, size_t cCps, size_t *pcCps);
274
275
 
324
325
 *                          will be allocated to hold the translated string.
325
326
 *                          If a buffer was requested it must be freed using RTUtf16Free().
326
327
 * @param   cwc             The buffer size in RTUTF16s. This includes the terminator.
327
 
 * @param   pcwc            Where to store the length of the translated string. (Optional)
328
 
 *                          This field will be updated even on failure, however the value is only
329
 
 *                          specified for the following two error codes. On VERR_BUFFER_OVERFLOW
330
 
 *                          and VERR_NO_STR_MEMORY it contains the required buffer space.
 
328
 * @param   pcwc            Where to store the length of the translated string,
 
329
 *                          excluding the terminator. (Optional)
 
330
 *
 
331
 *                          This may be set under some error conditions,
 
332
 *                          however, only for VERR_BUFFER_OVERFLOW and
 
333
 *                          VERR_NO_STR_MEMORY will it contain a valid string
 
334
 *                          length that can be used to resize the buffer.
331
335
 */
332
336
RTDECL(int)  RTStrToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc);
333
337
 
792
796
 */
793
797
RTDECL(int) RTStrAPrintf(char **ppszBuffer, const char *pszFormat, ...);
794
798
 
 
799
/**
 
800
 * Allocating string printf, version 2.
 
801
 *
 
802
 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
 
803
 *          memory.
 
804
 * @param   pszFormat   The format string.
 
805
 * @param   args        The format argument.
 
806
 */
 
807
RTDECL(char *) RTStrAPrintf2V(const char *pszFormat, va_list args);
 
808
 
 
809
/**
 
810
 * Allocating string printf, version2.
 
811
 *
 
812
 * @returns Formatted string. Use RTStrFree() to free it. NULL when out of
 
813
 *          memory.
 
814
 * @param   pszFormat   The format string.
 
815
 * @param   ...         The format argument.
 
816
 */
 
817
RTDECL(char *) RTStrAPrintf2(const char *pszFormat, ...);
795
818
 
796
819
/**
797
820
 * Strips blankspaces from both ends of the string.
1028
1051
                                          const char *pszString, size_t cchString,
1029
1052
                                          size_t *poffPattern);
1030
1053
 
 
1054
/**
 
1055
 * Compares two version strings RTStrICmp fashion.
 
1056
 *
 
1057
 * The version string is split up into sections at punctuation, spaces,
 
1058
 * underscores, dashes and pluss signs.  The sections are then split up into
 
1059
 * numeric and string sub-sections.  Finally, the sub-sections are compared
 
1060
 * in a numeric or case insesntivie fashion depending on what they are.
 
1061
 *
 
1062
 * The following strings are considered to be equal: "1.0.0", "1.00.0", "1.0",
 
1063
 * "1".  These aren't: "1.0.0r993", "1.0", "1.0r993", "1.0_Beta3", "1.1"
 
1064
 *
 
1065
 * @returns < 0 if the first string less than the second string.
 
1066
 * @returns 0 if the first string identical to the second string.
 
1067
 * @returns > 0 if the first string greater than the second string.
 
1068
 *
 
1069
 * @param   pszVer1     First version string to compare.
 
1070
 * @param   pszVer2     Second version string to compare first version with.
 
1071
 */
 
1072
RTDECL(int) RTStrVersionCompare(const char *pszVer1, const char *pszVer2);
 
1073
 
1031
1074
 
1032
1075
/** @defgroup rt_str_conv   String To/From Number Conversions
1033
1076
 * @ingroup grp_rt_str
1392
1435
 * @param   ppszNext    Where to store the pointer to the first char following the number. (Optional)
1393
1436
 * @param   uBase       The base of the representation used.
1394
1437
 *                      If 0 the function will look for known prefixes before defaulting to 10.
1395
 
 * @param   pi8        Where to store the converted number. (optional)
 
1438
 * @param   pi8         Where to store the converted number. (optional)
1396
1439
 */
1397
1440
RTDECL(int) RTStrToInt8Ex(const char *pszValue, char **ppszNext, unsigned uBase, int8_t *pi8);
1398
1441
 
1425
1468
 */
1426
1469
RTDECL(int8_t) RTStrToInt8(const char *pszValue);
1427
1470
 
 
1471
/**
 
1472
 * Formats a buffer stream as hex bytes.
 
1473
 *
 
1474
 * The default is no separating spaces or line breaks or anything.
 
1475
 *
 
1476
 * @returns IPRT status code.
 
1477
 * @retval  VERR_INVALID_POINTER if any of the pointers are wrong.
 
1478
 * @retval  VERR_BUFFER_OVERFLOW if the buffer is insufficent to hold the bytes.
 
1479
 *
 
1480
 * @param   pszBuf      Output string buffer.
 
1481
 * @param   cchBuf      The size of the output buffer.
 
1482
 * @param   pv          Pointer to the bytes to stringify.
 
1483
 * @param   cb          The number of bytes to stringify.
 
1484
 * @param   fFlags      Must be zero, reserved for future use.
 
1485
 */
 
1486
RTDECL(int) RTStrPrintHexBytes(char *pszBuf, size_t cchBuf, void const *pv, size_t cb, uint32_t fFlags);
 
1487
 
 
1488
/**
 
1489
 * Converts a string of hex bytes back into binary data.
 
1490
 *
 
1491
 * @returns IPRT status code.
 
1492
 * @retval  VERR_INVALID_POINTER if any of the pointers are wrong.
 
1493
 * @retval  VERR_BUFFER_OVERFLOW if the string contains too many hex bytes.
 
1494
 * @retval  VERR_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
 
1495
 *          the output buffer.
 
1496
 * @retval  VERR_UNEVEN_INPUT if the input contains a half byte.
 
1497
 * @retval  VERR_NO_DIGITS
 
1498
 * @retval  VWRN_TRAILING_CHARS
 
1499
 * @retval  VWRN_TRAILING_SPACES
 
1500
 *
 
1501
 * @param   pszHex      The string containing the hex bytes.
 
1502
 * @param   pv          Output buffer.
 
1503
 * @param   cb          The size of the output buffer.
 
1504
 * @param   fFlags      Must be zero, reserved for future use.
 
1505
 */
 
1506
RTDECL(int) RTStrConvertHexBytes(char const *pszHex, void *pv, size_t cb, uint32_t fFlags);
 
1507
 
1428
1508
/** @} */
1429
1509
 
1430
1510
 
1542
1622
 */
1543
1623
 
1544
1624
/**
1545
 
 * Free a UTF-16 string allocated by RTStrUtf8ToUtf16(), RTStrUtf8ToUtf16Ex(),
1546
 
 * RTUtf16Dup() or RTUtf16DupEx().
 
1625
 * Free a UTF-16 string allocated by RTStrToUtf16(), RTStrToUtf16Ex(),
 
1626
 * RTLatin1ToUtf16(), RTLatin1ToUtf16Ex(), RTUtf16Dup() or RTUtf16DupEx().
1547
1627
 *
1548
1628
 * @returns iprt status code.
1549
1629
 * @param   pwszString      The UTF-16 string to free. NULL is accepted.
1680
1760
 *                          will be allocated to hold the translated string.
1681
1761
 *                          If a buffer was requested it must be freed using RTUtf16Free().
1682
1762
 * @param   cch             The buffer size in chars (the type). This includes the terminator.
1683
 
 * @param   pcch            Where to store the length of the translated string. (Optional)
1684
 
 *                          This field will be updated even on failure, however the value is only
1685
 
 *                          specified for the following two error codes. On VERR_BUFFER_OVERFLOW
1686
 
 *                          and VERR_NO_STR_MEMORY it contains the required buffer space.
 
1763
 * @param   pcch            Where to store the length of the translated string,
 
1764
 *                          excluding the terminator. (Optional)
 
1765
 *
 
1766
 *                          This may be set under some error conditions,
 
1767
 *                          however, only for VERR_BUFFER_OVERFLOW and
 
1768
 *                          VERR_NO_STR_MEMORY will it contain a valid string
 
1769
 *                          length that can be used to resize the buffer.
1687
1770
 */
1688
1771
RTDECL(int)  RTUtf16ToUtf8Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch);
1689
1772
 
1716
1799
RTDECL(int) RTUtf16CalcUtf8LenEx(PCRTUTF16 pwsz, size_t cwc, size_t *pcch);
1717
1800
 
1718
1801
/**
 
1802
 * Translate a UTF-16 string into a Latin-1 (ISO-8859-1) allocating the result
 
1803
 * buffer.
 
1804
 *
 
1805
 * @returns iprt status code.
 
1806
 * @param   pwszString      UTF-16 string to convert.
 
1807
 * @param   ppszString      Receives pointer of allocated Latin1 string on
 
1808
 *                          success, and is always set to NULL on failure.
 
1809
 *                          The returned pointer must be freed using RTStrFree().
 
1810
 */
 
1811
RTDECL(int)  RTUtf16ToLatin1(PCRTUTF16 pwszString, char **ppszString);
 
1812
 
 
1813
/**
 
1814
 * Translates UTF-16 to Latin-1 (ISO-8859-1) using buffer provided by the caller
 
1815
 * or a fittingly sized buffer allocated by the function.
 
1816
 *
 
1817
 * @returns iprt status code.
 
1818
 * @param   pwszString      The UTF-16 string to convert.
 
1819
 * @param   cwcString       The number of RTUTF16 items to translate from
 
1820
 *                          pwszString. The translation will stop when reaching
 
1821
 *                          cwcString or the terminator ('\\0'). Use RTSTR_MAX
 
1822
 *                          to translate the entire string.
 
1823
 * @param   ppsz            Pointer to the pointer to the Latin-1 string. The
 
1824
 *                          buffer can optionally be preallocated by the caller.
 
1825
 *
 
1826
 *                          If cch is zero, *ppsz is undefined.
 
1827
 *
 
1828
 *                          If cch is non-zero and *ppsz is not NULL, then this
 
1829
 *                          will be used as the output buffer.
 
1830
 *                          VERR_BUFFER_OVERFLOW will be returned if this is
 
1831
 *                          insufficient.
 
1832
 *
 
1833
 *                          If cch is zero or *ppsz is NULL, then a buffer of
 
1834
 *                          sufficent size is allocated. cch can be used to
 
1835
 *                          specify a minimum size of this buffer. Use
 
1836
 *                          RTUtf16Free() to free the result.
 
1837
 *
 
1838
 * @param   cch             The buffer size in chars (the type). This includes
 
1839
 *                          the terminator.
 
1840
 * @param   pcch            Where to store the length of the translated string,
 
1841
 *                          excluding the terminator. (Optional)
 
1842
 *
 
1843
 *                          This may be set under some error conditions,
 
1844
 *                          however, only for VERR_BUFFER_OVERFLOW and
 
1845
 *                          VERR_NO_STR_MEMORY will it contain a valid string
 
1846
 *                          length that can be used to resize the buffer.
 
1847
 */
 
1848
RTDECL(int)  RTUtf16ToLatin1Ex(PCRTUTF16 pwszString, size_t cwcString, char **ppsz, size_t cch, size_t *pcch);
 
1849
 
 
1850
/**
 
1851
 * Calculates the length of the UTF-16 string in Latin-1 (ISO-8859-1) chars.
 
1852
 *
 
1853
 * This function will validate the string, and incorrectly encoded UTF-16
 
1854
 * strings will be rejected. The primary purpose of this function is to
 
1855
 * help allocate buffers for RTUtf16ToLatin1() of the correct size. For most
 
1856
 * other purposes RTUtf16ToLatin1Ex() should be used.
 
1857
 *
 
1858
 * @returns Number of char (bytes).
 
1859
 * @returns 0 if the string was incorrectly encoded.
 
1860
 * @param   pwsz        The UTF-16 string.
 
1861
 */
 
1862
RTDECL(size_t) RTUtf16CalcLatin1Len(PCRTUTF16 pwsz);
 
1863
 
 
1864
/**
 
1865
 * Calculates the length of the UTF-16 string in Latin-1 (ISO-8859-1) chars.
 
1866
 *
 
1867
 * This function will validate the string, and incorrectly encoded UTF-16
 
1868
 * strings will be rejected.
 
1869
 *
 
1870
 * @returns iprt status code.
 
1871
 * @param   pwsz        The string.
 
1872
 * @param   cwc         The max string length. Use RTSTR_MAX to process the
 
1873
 *                      entire string.
 
1874
 * @param   pcch        Where to store the string length (in bytes). Optional.
 
1875
 *                      This is undefined on failure.
 
1876
 */
 
1877
RTDECL(int) RTUtf16CalcLatin1LenEx(PCRTUTF16 pwsz, size_t cwc, size_t *pcch);
 
1878
 
 
1879
/**
1719
1880
 * Get the unicode code point at the given string position.
1720
1881
 *
1721
1882
 * @returns unicode code point.
1893
2054
 
1894
2055
/** @} */
1895
2056
 
 
2057
 
 
2058
/** @defgroup rt_str_latin1     Latin-1 (ISO-8859-1) String Manipulation
 
2059
 * @ingroup grp_rt_str
 
2060
 * @{
 
2061
 */
 
2062
 
 
2063
/**
 
2064
 * Calculates the length of the Latin-1 (ISO-8859-1) string in RTUTF16 items.
 
2065
 *
 
2066
 * @returns Number of RTUTF16 items.
 
2067
 * @param   psz             The Latin-1 string.
 
2068
 */
 
2069
RTDECL(size_t) RTLatin1CalcUtf16Len(const char *psz);
 
2070
 
 
2071
/**
 
2072
 * Calculates the length of the Latin-1 (ISO-8859-1) string in RTUTF16 items.
 
2073
 *
 
2074
 * @returns iprt status code.
 
2075
 * @param   psz             The Latin-1 string.
 
2076
 * @param   cch             The max string length. Use RTSTR_MAX to process the
 
2077
 *                          entire string.
 
2078
 * @param   pcwc            Where to store the string length. Optional.
 
2079
 *                          This is undefined on failure.
 
2080
 */
 
2081
RTDECL(int) RTLatin1CalcUtf16LenEx(const char *psz, size_t cch, size_t *pcwc);
 
2082
 
 
2083
/**
 
2084
 * Translate a Latin-1 (ISO-8859-1) string into a UTF-16 allocating the result
 
2085
 * buffer.
 
2086
 *
 
2087
 * @returns iprt status code.
 
2088
 * @param   pszString       The Latin-1 string to convert.
 
2089
 * @param   ppwszString     Receives pointer to the allocated UTF-16 string. The
 
2090
 *                          returned string must be freed using RTUtf16Free().
 
2091
 */
 
2092
RTDECL(int) RTLatin1ToUtf16(const char *pszString, PRTUTF16 *ppwszString);
 
2093
 
 
2094
/**
 
2095
 * Translates pszString from Latin-1 (ISO-8859-1) to UTF-16, allocating the
 
2096
 * result buffer if requested.
 
2097
 *
 
2098
 * @returns iprt status code.
 
2099
 * @param   pszString       The Latin-1 string to convert.
 
2100
 * @param   cchString       The maximum size in chars (the type) to convert.
 
2101
 *                          The conversion stops when it reaches cchString or
 
2102
 *                          the string terminator ('\\0').
 
2103
 *                          Use RTSTR_MAX to translate the entire string.
 
2104
 * @param   ppwsz           If cwc is non-zero, this must either be pointing
 
2105
 *                          to pointer to a buffer of the specified size, or
 
2106
 *                          pointer to a NULL pointer.
 
2107
 *                          If *ppwsz is NULL or cwc is zero a buffer of at
 
2108
 *                          least cwc items will be allocated to hold the
 
2109
 *                          translated string. If a buffer was requested it
 
2110
 *                          must be freed using RTUtf16Free().
 
2111
 * @param   cwc             The buffer size in RTUTF16s. This includes the
 
2112
 *                          terminator.
 
2113
 * @param   pcwc            Where to store the length of the translated string,
 
2114
 *                          excluding the terminator. (Optional)
 
2115
 *
 
2116
 *                          This may be set under some error conditions,
 
2117
 *                          however, only for VERR_BUFFER_OVERFLOW and
 
2118
 *                          VERR_NO_STR_MEMORY will it contain a valid string
 
2119
 *                          length that can be used to resize the buffer.
 
2120
 */
 
2121
RTDECL(int) RTLatin1ToUtf16Ex(const char *pszString, size_t cchString, PRTUTF16 *ppwsz, size_t cwc, size_t *pcwc);
 
2122
 
 
2123
/** @} */
 
2124
 
 
2125
 
1896
2126
RT_C_DECLS_END
1897
2127
 
1898
2128
/** @} */