blob: a4e387b15b7d99c83743ad60723072997d1fa358 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <zircon/types.h>
#include <fbl/string_buffer.h>
namespace fdio_internal {
// PATH_MAX is defined in POSIX as being inclusive of the null terminator
// (unlike NAME_MAX and other constants which are exclusive). See the
// "Rationale" section of
// for
// more background on this choice. fbl::StringBuffer allocates space for a null
// terminator in addition to the requested size.
using PathBuffer = fbl::StringBuffer<PATH_MAX - 1>;
// Cleans an input path, transforming it to out, according to the
// rules defined by "Lexical File Names in Plan 9 or Getting Dot-Dot Right",
// accessible at:
// Code heavily inspired by Go's filepath.Clean function, from:
// If the input cannot be parsed, returns false. Otherwise populates |out| with
// a clean path and sets is_dir to 'true' if the path is a directory.
bool CleanPath(const char* in, PathBuffer* out, bool* is_dir);
} // namespace fdio_internal