Back out dependencies on lib/System/Path.h
[oota-llvm.git] / lib / System / Path.cpp
1 //===- Path.cpp - Path Operating System Concept -----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // Copyright (C) 2004 eXtensible Systems, Inc. All Rights Reserved.
6 //
7 // This program is open source software; you can redistribute it and/or modify
8 // it under the terms of the University of Illinois Open Source License. See
9 // LICENSE.TXT (distributed with this software) for details.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE.
14 //
15 //===----------------------------------------------------------------------===//
16 // 
17 // This file implements the common Path concept for a variety of platforms.
18 // A path is simply the name of some file system storage place. Paths can be
19 // either directories or files.
20 //
21 //===----------------------------------------------------------------------===//
22 /// @file lib/System/Path.cpp
23 /// @author Reid Spencer <raspencer@x10sys.com> (original author)
24 /// @version \verbatim $Id$ \endverbatim
25 /// @date 2004/08/14
26 /// @since 1.4
27 /// @brief Defines the llvm::sys::Path class.
28 //===----------------------------------------------------------------------===//
29
30 #include "llvm/System/Path.h"
31
32 namespace llvm {
33 namespace sys {
34
35 ErrorCode
36 Path::append_directory( const std::string& dirname ) throw() {
37   this->append( dirname );
38   make_directory();
39   return NOT_AN_ERROR;
40 }
41
42 ErrorCode
43 Path::append_file( const std::string& filename ) throw() {
44   this->append( filename );
45   return NOT_AN_ERROR;
46 }
47
48 ErrorCode
49 Path::create( bool create_parents)throw() {
50   ErrorCode result ( NOT_AN_ERROR );
51   if ( is_directory() ) {
52     if ( create_parents ) {
53       result = this->create_directories( );
54     } else {
55       result = this->create_directory( );
56     }
57   } else if ( is_file() ) {
58     if ( create_parents ) {
59       result = this->create_directories( );
60     }
61     if ( result ) {
62       result = this->create_file( );
63     }
64   } else {
65     result = ErrorCode(ERR_SYS_INVALID_ARG);
66   }
67   return result;
68 }
69
70 ErrorCode
71 Path::remove() throw() {
72   ErrorCode result( NOT_AN_ERROR );
73   if ( is_directory() ) {
74     if ( exists() ) 
75       this->remove_directory( );
76   } else if ( is_file() ) {
77     if ( exists() ) this->remove_file( );
78   } else {
79     result = ErrorCode(ERR_SYS_INVALID_ARG);
80   }
81   return result;
82 }
83
84 }
85 }
86
87 // Include the platform specific portions of this class
88 #include "linux/Path.cpp" 
89
90 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab