3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/lib/security/credentials/alts/check_gcp_environment.h"
27 #include <grpc/support/alloc.h>
28 #include <grpc/support/log.h>
30 const size_t kBiosDataBufferSize = 256;
32 static char* trim(const char* src) {
37 size_t start = 0, end = strlen(src) - 1;
38 /* find the last character that is not a whitespace. */
39 while (end != 0 && isspace(src[end])) {
42 /* find the first character that is not a whitespace. */
43 while (start < strlen(src) && isspace(src[start])) {
47 des = static_cast<char*>(
48 gpr_zalloc(sizeof(char) * (end - start + 2 /* '\0' */)));
49 memcpy(des, src + start, end - start + 1);
57 char* read_bios_file(const char* bios_file) {
58 FILE* fp = fopen(bios_file, "r");
60 gpr_log(GPR_ERROR, "BIOS data file cannot be opened.");
63 char buf[kBiosDataBufferSize + 1];
64 size_t ret = fread(buf, sizeof(char), kBiosDataBufferSize, fp);
66 char* trimmed_buf = trim(buf);
71 } // namespace internal
72 } // namespace grpc_core