Michael J. Spencer | dffde99 | 2010-11-29 22:28:51 +0000 | [diff] [blame] | 1 | //===- llvm/Support/Unix/PathV2.cpp - Unix Path Implementation --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Unix specific implementation of the PathV2 API. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | //=== WARNING: Implementation here must contain only generic UNIX code that |
| 16 | //=== is guaranteed to work on *all* UNIX variants. |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
| 19 | #include "Unix.h" |
| 20 | |
| 21 | namespace llvm { |
| 22 | namespace sys { |
| 23 | namespace path { |
| 24 | |
| 25 | error_code current_path(SmallVectorImpl<char> &result) { |
| 26 | long size = ::pathconf(".", _PC_PATH_MAX); |
| 27 | result.reserve(size + 1); |
| 28 | result.set_size(size + 1); |
| 29 | |
| 30 | if (::getcwd(result.data(), result.size()) == 0) |
| 31 | return error_code(errno, system_category()); |
| 32 | |
| 33 | result.set_size(strlen(result.data())); |
| 34 | return make_error_code(errc::success); |
| 35 | } |
| 36 | |
| 37 | } // end namespace path |
| 38 | } // end namespace sys |
| 39 | } // end namespace llvm |