diff options
author | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-13 14:33:40 +0000 |
---|---|---|
committer | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-13 14:33:40 +0000 |
commit | 954d58c4d2bd4499ed61da01ee22684669e12f28 (patch) | |
tree | b4e80cfdeea18ecc3fde0aef5cb46754575f3486 /base/string_util.h | |
parent | 4794938ba46c128bd207c4f4509f86b1aceb1284 (diff) | |
download | chromium_src-954d58c4d2bd4499ed61da01ee22684669e12f28.zip chromium_src-954d58c4d2bd4499ed61da01ee22684669e12f28.tar.gz chromium_src-954d58c4d2bd4499ed61da01ee22684669e12f28.tar.bz2 |
Implement an interface compatible wcslcpy and strlcpy. Possibly slightly
slower than the OpenBSD implementation, but a bit clearer and fits our style.
Move file_util_posix to use it now that we have it everywhere.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util.h')
-rw-r--r-- | base/string_util.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/base/string_util.h b/base/string_util.h index 17c1793..5faa9cf 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -83,6 +83,15 @@ inline int swprintf(wchar_t* buffer, size_t size, const wchar_t* format, ...) { return result; } +// BSD-style safe and consistent string copy functions. +// Copies |src| to |dst|, where |dst_size| is the total allocated size of |dst|. +// Copies at most |dst_size|-1 characters, and always NULL terminates |dst|, as +// long as |dst_size| is not 0. Returns the length of |src| in characters. +// If the return value is >= dst_size, then the output was truncated. +// NOTE: All sizes are in number of characters, NOT in bytes. +size_t strlcpy(char* dst, const char* src, size_t dst_size); +size_t wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size); + } // namespace base #if defined(OS_WIN) |