aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-08-25 06:20:07 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-08-25 06:20:07 +0000
commitb89a2237ea79e0576fdb426b124f1940f53da159 (patch)
treebd6277d71a8627ffce532b7e1fefd49d3f310f78 /lib
parent17f130c61e268b39044870b66b58d7575d7ba784 (diff)
downloadexternal_llvm-b89a2237ea79e0576fdb426b124f1940f53da159.zip
external_llvm-b89a2237ea79e0576fdb426b124f1940f53da159.tar.gz
external_llvm-b89a2237ea79e0576fdb426b124f1940f53da159.tar.bz2
Initial implementation of the Path operating system concept.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16048 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/System/Linux/Path.cpp20
-rw-r--r--lib/System/Makefile13
-rw-r--r--lib/System/Path.cpp60
-rw-r--r--lib/System/Unix/Path.cpp138
-rw-r--r--lib/System/Unix/Path.inc138
-rw-r--r--lib/System/Unix/Unix.h34
6 files changed, 403 insertions, 0 deletions
diff --git a/lib/System/Linux/Path.cpp b/lib/System/Linux/Path.cpp
new file mode 100644
index 0000000..5c73d01
--- /dev/null
+++ b/lib/System/Linux/Path.cpp
@@ -0,0 +1,20 @@
+//===- llvm/System/Linux/Path.cpp - Linux Path Implementation ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Linux specific implementation of the Path class.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Linux specific code
+//=== and must not be generic UNIX code (see ../Unix)
+//===----------------------------------------------------------------------===//
+
+// Th..Th..Th..Tha's All Folks!
+#include "../Unix/Path.cpp"
diff --git a/lib/System/Makefile b/lib/System/Makefile
new file mode 100644
index 0000000..b4493ec
--- /dev/null
+++ b/lib/System/Makefile
@@ -0,0 +1,13 @@
+##===- lib/Bytecode/Reader/Makefile ------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file was developed by the LLVM research group and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+LEVEL = ../..
+LIBRARYNAME = system
+BUILD_ARCHIVE = 1
+
+include $(LEVEL)/Makefile.common
diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp
new file mode 100644
index 0000000..e32842d
--- /dev/null
+++ b/lib/System/Path.cpp
@@ -0,0 +1,60 @@
+//===-- Path.cpp - Implement OS Path Concept --------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This header file implements the operating system Path concept.
+//
+//===----------------------------------------------------------------------===//
+#include "llvm/System/Path.h"
+
+namespace llvm {
+namespace sys {
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only TRULY operating system
+//=== independent code.
+//===----------------------------------------------------------------------===//
+
+bool
+Path::is_valid() const {
+ if ( empty() ) return false;
+ return true;
+}
+
+void
+Path::fill( char* buffer, unsigned bufflen ) const {
+ unsigned pathlen = length();
+ assert( bufflen > pathlen && "Insufficient buffer size" );
+ unsigned copylen = pathlen <? (bufflen - 1);
+ this->copy(buffer, copylen, 0 );
+ buffer[ copylen ] = 0;
+}
+
+void
+Path::make_directory() {
+ char end[2];
+ end[0] = '/';
+ end[1] = 0;
+ if ( empty() )
+ this->assign( end );
+ else if ( (*this)[length()-1] != '/')
+ this->append( end );
+}
+
+void
+Path::make_file() {
+ if ( (*this)[length()-1] == '/')
+ this->erase( this->length()-1, 1 );
+}
+
+// Include the truly platform-specific parts of this class.
+#include "platform/Path.cpp"
+}
+}
+
+// vim: sw=2
diff --git a/lib/System/Unix/Path.cpp b/lib/System/Unix/Path.cpp
new file mode 100644
index 0000000..9253f8c
--- /dev/null
+++ b/lib/System/Unix/Path.cpp
@@ -0,0 +1,138 @@
+//===- llvm/System/Unix/Path.cpp - Unix Path Implementation -----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Unix specific portion of the Path class.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only generic UNIX code that
+//=== is guaranteed to work on all UNIX variants.
+//===----------------------------------------------------------------------===//
+
+#include "Unix.h"
+#include <sys/stat.h>
+#include <fcntl.h>
+
+bool
+Path::is_file() const {
+ if (!empty() && ((*this)[length()-1] != '/'))
+ return true;
+ return false;
+}
+
+bool
+Path::is_directory() const {
+ if ((!empty()) && ((*this)[length()-1] == '/'))
+ return true;
+ return false;
+}
+
+void
+Path::create( bool create_parents) {
+ if ( is_directory() ) {
+ if ( create_parents )
+ this->create_directories( );
+ this->create_directory( );
+ } else if ( is_file() ) {
+ if ( create_parents )
+ this->create_directories( );
+ this->create_file( );
+ }
+}
+
+void
+Path::remove() {
+ if ( is_directory() ) {
+ if ( exists() )
+ this->remove_directory( );
+ } else if ( is_file() )
+ if ( exists() )
+ this->remove_file( );
+}
+
+bool
+Path::exists() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ return 0 == access(pathname, F_OK );
+}
+
+void
+Path::create_directory( ) {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if (0 != mkdir(pathname, S_IRWXU | S_IRWXG))
+ ThrowErrno(pathname);
+}
+
+void
+Path::create_directories() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+
+ char * next = index(pathname,'/');
+ if ( pathname[0] == '/')
+ next = index(&pathname[1],'/');
+ while ( next != 0 )
+ {
+ *next = 0;
+ if (0 != access(pathname, F_OK | R_OK))
+ if (0 != mkdir(pathname, S_IRWXU | S_IRWXG))
+ ThrowErrno(pathname);
+ char* save = next;
+ next = index(pathname,'/');
+ *save = '/';
+ }
+}
+
+void
+Path::remove_directory()
+{
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if ( 0 != rmdir(pathname))
+ ThrowErrno(pathname);
+}
+
+void
+Path::create_file() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if (0 != creat(pathname, S_IRUSR | S_IWUSR))
+ ThrowErrno(pathname);
+}
+
+void
+Path::remove_file() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if (0 != unlink(pathname))
+ ThrowErrno(pathname);
+}
+
+// vim: sw=2
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
new file mode 100644
index 0000000..9253f8c
--- /dev/null
+++ b/lib/System/Unix/Path.inc
@@ -0,0 +1,138 @@
+//===- llvm/System/Unix/Path.cpp - Unix Path Implementation -----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Unix specific portion of the Path class.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only generic UNIX code that
+//=== is guaranteed to work on all UNIX variants.
+//===----------------------------------------------------------------------===//
+
+#include "Unix.h"
+#include <sys/stat.h>
+#include <fcntl.h>
+
+bool
+Path::is_file() const {
+ if (!empty() && ((*this)[length()-1] != '/'))
+ return true;
+ return false;
+}
+
+bool
+Path::is_directory() const {
+ if ((!empty()) && ((*this)[length()-1] == '/'))
+ return true;
+ return false;
+}
+
+void
+Path::create( bool create_parents) {
+ if ( is_directory() ) {
+ if ( create_parents )
+ this->create_directories( );
+ this->create_directory( );
+ } else if ( is_file() ) {
+ if ( create_parents )
+ this->create_directories( );
+ this->create_file( );
+ }
+}
+
+void
+Path::remove() {
+ if ( is_directory() ) {
+ if ( exists() )
+ this->remove_directory( );
+ } else if ( is_file() )
+ if ( exists() )
+ this->remove_file( );
+}
+
+bool
+Path::exists() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ return 0 == access(pathname, F_OK );
+}
+
+void
+Path::create_directory( ) {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if (0 != mkdir(pathname, S_IRWXU | S_IRWXG))
+ ThrowErrno(pathname);
+}
+
+void
+Path::create_directories() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+
+ char * next = index(pathname,'/');
+ if ( pathname[0] == '/')
+ next = index(&pathname[1],'/');
+ while ( next != 0 )
+ {
+ *next = 0;
+ if (0 != access(pathname, F_OK | R_OK))
+ if (0 != mkdir(pathname, S_IRWXU | S_IRWXG))
+ ThrowErrno(pathname);
+ char* save = next;
+ next = index(pathname,'/');
+ *save = '/';
+ }
+}
+
+void
+Path::remove_directory()
+{
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if ( 0 != rmdir(pathname))
+ ThrowErrno(pathname);
+}
+
+void
+Path::create_file() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if (0 != creat(pathname, S_IRUSR | S_IWUSR))
+ ThrowErrno(pathname);
+}
+
+void
+Path::remove_file() {
+ char pathname[MAXPATHLEN];
+ this->fill(pathname,MAXPATHLEN);
+ int lastchar = this->length() - 1 ;
+ if (pathname[lastchar] == '/')
+ pathname[lastchar] = 0;
+ if (0 != unlink(pathname))
+ ThrowErrno(pathname);
+}
+
+// vim: sw=2
diff --git a/lib/System/Unix/Unix.h b/lib/System/Unix/Unix.h
new file mode 100644
index 0000000..83d2865
--- /dev/null
+++ b/lib/System/Unix/Unix.h
@@ -0,0 +1,34 @@
+//===- llvm/System/Unix/Unix.h - Common Unix Include File -----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines things specific to Unix implementations.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only generic UNIX code that
+//=== is guaranteed to work on all UNIX variants.
+//===----------------------------------------------------------------------===//
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/param.h>
+
+inline void ThrowErrno(const std::string& prefix) {
+#if defined __USE_XOPEN2K || defined __USE_MISC
+ char buffer[MAXPATHLEN];
+ strerror_r(errno,buffer, MAXPATHLEN);
+ throw prefix + ": " + buffer;
+#else
+ throw prefix + ": " + strerror(errno);
+#endif
+}