blob: c03433541aca646860566a99bc0d206829ea6263 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Yves Gerey2e00abc2018-10-05 15:39:24 +020010
Steve Anton10542f22019-01-11 09:11:00 -080011#include "rtc_base/string_utils.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000012
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013namespace rtc {
14
Niels Möllerd1892522018-10-17 13:39:01 +020015size_t strcpyn(char* buffer,
16 size_t buflen,
17 const char* source,
18 size_t srclen /* = SIZE_UNKNOWN */) {
19 if (buflen <= 0)
20 return 0;
21
22 if (srclen == SIZE_UNKNOWN) {
23 srclen = strlen(source);
24 }
25 if (srclen >= buflen) {
26 srclen = buflen - 1;
27 }
28 memcpy(buffer, source, srclen);
29 buffer[srclen] = 0;
30 return srclen;
31}
32
Jonas Olsson74395342018-04-03 12:22:07 +020033std::string ToHex(const int i) {
34 char buffer[50];
35 snprintf(buffer, sizeof(buffer), "%x", i);
36
37 return std::string(buffer);
38}
39
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000040} // namespace rtc