Changeset 287081caeb571486a0381ee9964198855706a208
- Timestamp:
- 24/05/08 11:24:47
(5 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1211621087 +0300
- git-parent:
[71c7fb199ac0cadd55f686d8b8dcfbfd82353215]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1211620526 +0300
- Message:
Inline strnlen() and use it
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r71c7fb1 |
r287081c |
|
| 724 | 724 | VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) ); |
|---|
| 725 | 725 | VLC_EXPORT( int64_t, vlc_strtoll, ( const char *nptr, char **endptr, int base ) ); |
|---|
| 726 | | VLC_EXPORT( size_t, vlc_strnlen, ( const char *, size_t ) ); |
|---|
| 727 | 726 | |
|---|
| 728 | 727 | struct dirent; |
|---|
| rcb63940 |
r287081c |
|
| 48 | 48 | #endif |
|---|
| 49 | 49 | |
|---|
| | 50 | #ifndef HAVE_STRNLEN |
|---|
| | 51 | static inline size_t strnlen (const char *str, size_t max) |
|---|
| | 52 | { |
|---|
| | 53 | const char *end = memchr (str, 0, max); |
|---|
| | 54 | return end ? (size_t)(end - str) : max; |
|---|
| | 55 | } |
|---|
| | 56 | #endif |
|---|
| | 57 | |
|---|
| 50 | 58 | #ifndef HAVE_STRNDUP |
|---|
| 51 | 59 | static inline char *strndup (const char *str, size_t max) |
|---|
| 52 | 60 | { |
|---|
| 53 | | const char *end = memchr (str, '\0', max); |
|---|
| 54 | | size_t len = end ? (size_t)(end - str) : max; |
|---|
| | 61 | size_t len = strnlen (str, max); |
|---|
| 55 | 62 | char *res = malloc (len + 1); |
|---|
| 56 | 63 | if (res) |
|---|
| … | … | |
| 61 | 68 | return res; |
|---|
| 62 | 69 | } |
|---|
| 63 | | #endif |
|---|
| 64 | | |
|---|
| 65 | | #ifndef HAVE_STRNLEN |
|---|
| 66 | | # define strnlen vlc_strnlen |
|---|
| 67 | 70 | #endif |
|---|
| 68 | 71 | |
|---|
| rcb63940 |
r287081c |
|
| 76 | 76 | |
|---|
| 77 | 77 | /***************************************************************************** |
|---|
| 78 | | * strnlen: |
|---|
| 79 | | *****************************************************************************/ |
|---|
| 80 | | #if !defined( HAVE_STRNLEN ) |
|---|
| 81 | | size_t vlc_strnlen( const char *psz, size_t n ) |
|---|
| 82 | | { |
|---|
| 83 | | const char *psz_end = memchr( psz, 0, n ); |
|---|
| 84 | | return psz_end ? (size_t)( psz_end - psz ) : n; |
|---|
| 85 | | } |
|---|
| 86 | | #endif |
|---|
| 87 | | |
|---|
| 88 | | /***************************************************************************** |
|---|
| 89 | 78 | * strcasecmp: compare two strings ignoring case |
|---|
| 90 | 79 | *****************************************************************************/ |
|---|
| rcb63940 |
r287081c |
|
| 443 | 443 | vlc_strlcpy |
|---|
| 444 | 444 | vlc_strncasecmp |
|---|
| 445 | | vlc_strnlen |
|---|
| 446 | 445 | vlc_strtoll |
|---|
| 447 | 446 | vlc_submodule_create |
|---|