Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
849 B
34 lines
849 B
1 year ago
|
// Protocol Buffers - Google's data interchange format
|
||
|
// Copyright 2023 Google LLC. All rights reserved.
|
||
|
//
|
||
1 year ago
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file or at
|
||
|
// https://developers.google.com/open-source/licenses/bsd
|
||
1 year ago
|
|
||
1 year ago
|
#include "upb/reflection/internal/strdup2.h"
|
||
1 year ago
|
|
||
|
#include <string.h>
|
||
|
|
||
1 year ago
|
#include "upb/mem/arena.h"
|
||
1 year ago
|
|
||
|
// Must be last.
|
||
1 year ago
|
#include "upb/port/def.inc"
|
||
1 year ago
|
|
||
|
char* upb_strdup2(const char* s, size_t len, upb_Arena* a) {
|
||
|
size_t n;
|
||
|
char* p;
|
||
|
|
||
|
// Prevent overflow errors.
|
||
|
if (len == SIZE_MAX) return NULL;
|
||
|
|
||
|
// Always null-terminate, even if binary data; but don't rely on the input to
|
||
|
// have a null-terminating byte since it may be a raw binary buffer.
|
||
|
n = len + 1;
|
||
|
p = upb_Arena_Malloc(a, n);
|
||
|
if (p) {
|
||
|
if (len != 0) memcpy(p, s, len);
|
||
|
p[len] = 0;
|
||
|
}
|
||
|
return p;
|
||
|
}
|