v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
file-utils.cc
Go to the documentation of this file.
1// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <stdlib.h>
8#include <string.h>
9
11
12namespace v8 {
13namespace base {
14
15std::unique_ptr<char[]> RelativePath(const char* exec_path, const char* name) {
16 DCHECK(exec_path);
17 size_t basename_start = strlen(exec_path);
18 while (basename_start > 0 &&
19 !OS::isDirectorySeparator(exec_path[basename_start - 1])) {
20 --basename_start;
21 }
22 size_t name_length = strlen(name);
23 auto buffer = std::make_unique<char[]>(basename_start + name_length + 1);
24 if (basename_start > 0) memcpy(buffer.get(), exec_path, basename_start);
25 memcpy(buffer.get() + basename_start, name, name_length);
26 return buffer;
27}
28
29} // namespace base
30} // namespace v8
static bool isDirectorySeparator(const char ch)
std::unique_ptr< char[]> RelativePath(const char *exec_path, const char *name)
Definition file-utils.cc:15
#define DCHECK(condition)
Definition logging.h:482