blob: e8c13464bd14fe7a99a8fc77faaea560e564a2d6 [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
Ali Tofigh7fa90572022-03-17 15:47:49 +010013#include "absl/strings/string_view.h"
14
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000015namespace rtc {
16
Niels Möllerd1892522018-10-17 13:39:01 +020017size_t strcpyn(char* buffer,
18 size_t buflen,
19 const char* source,
20 size_t srclen /* = SIZE_UNKNOWN */) {
21 if (buflen <= 0)
22 return 0;
23
24 if (srclen == SIZE_UNKNOWN) {
25 srclen = strlen(source);
26 }
27 if (srclen >= buflen) {
28 srclen = buflen - 1;
29 }
30 memcpy(buffer, source, srclen);
31 buffer[srclen] = 0;
32 return srclen;
33}
34
Jonas Olsson74395342018-04-03 12:22:07 +020035std::string ToHex(const int i) {
36 char buffer[50];
37 snprintf(buffer, sizeof(buffer), "%x", i);
38
39 return std::string(buffer);
40}
41
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000042} // namespace rtc