Initial implementation of the Path operating system concept.
[oota-llvm.git] / lib / System / Path.cpp
1 //===-- Path.cpp - Implement OS Path Concept --------------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the 
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 //  This header file implements the operating system Path concept.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "llvm/System/Path.h"
14
15 namespace llvm {
16 namespace sys {
17
18 //===----------------------------------------------------------------------===//
19 //=== WARNING: Implementation here must contain only TRULY operating system
20 //===          independent code. 
21 //===----------------------------------------------------------------------===//
22
23 bool
24 Path::is_valid() const {
25   if ( empty() ) return false;
26   return true;
27 }
28
29 void 
30 Path::fill( char* buffer, unsigned bufflen ) const {
31   unsigned pathlen = length();
32   assert( bufflen > pathlen && "Insufficient buffer size" );
33   unsigned copylen = pathlen <? (bufflen - 1);
34   this->copy(buffer, copylen, 0 );
35   buffer[ copylen ] = 0;
36 }
37
38 void
39 Path::make_directory() {
40   char end[2];
41   end[0] = '/';
42   end[1] = 0;
43   if ( empty() )
44     this->assign( end );
45   else if ( (*this)[length()-1] != '/')
46     this->append( end );
47 }
48
49 void
50 Path::make_file() {
51   if ( (*this)[length()-1] == '/')
52     this->erase( this->length()-1, 1 );
53 }
54
55 // Include the truly platform-specific parts of this class.
56 #include "platform/Path.cpp"
57 }
58 }
59
60 // vim: sw=2