blob: 0d6c7fbd152cb4a429849b26f0d19d009d5e856b [file] [log] [blame]
Reid Spencer8e665952004-08-29 05:24:01 +00001//===- llvm/System/AIX/Path.cpp - AIX Path Implementation -------*- 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//
Misha Brukman9c02f5c2004-10-18 17:39:45 +000010// This file provides the AIX-specific implementation of the Path class.
Reid Spencer8e665952004-08-29 05:24:01 +000011//
12//===----------------------------------------------------------------------===//
13
Reid Spencer8e665952004-08-29 05:24:01 +000014// Include the generic unix implementation
15#include "../Unix/Path.cpp"
Misha Brukman9c02f5c2004-10-18 17:39:45 +000016#include <sys/stat.h>
Reid Spencer8e665952004-08-29 05:24:01 +000017
18namespace llvm {
19using namespace sys;
20
Reid Spencerbd4dd5c2004-08-29 19:25:54 +000021//===----------------------------------------------------------------------===//
22//=== WARNING: Implementation here must contain only AIX specific code
23//=== and must not be generic UNIX code (see ../Unix/Path.cpp)
24//===----------------------------------------------------------------------===//
25
Reid Spencer8e665952004-08-29 05:24:01 +000026bool
27Path::is_valid() const {
28 if (path.empty())
29 return false;
30 if (path.length() >= MAXPATHLEN)
31 return false;
32 return true;
33}
34
Reid Spencerf634f462004-08-30 21:46:55 +000035Path
36Path::GetTemporaryDirectory() {
37 char pathname[MAXPATHLEN];
Misha Brukman9c02f5c2004-10-18 17:39:45 +000038 strcpy(pathname, "/tmp/llvm_XXXXXX");
39 // AIX does not have a mkdtemp(), so we emulate it as follows:
40 // mktemp() returns a valid name for a _file_, not a directory, but does not
41 // create it. We assume that it is a valid name for a directory.
42 char *TmpName = mktemp(pathname);
43 if (!mkdir(TmpName, S_IRWXU))
44 ThrowErrno(std::string(TmpName) + ": Can't create temporary directory");
Reid Spencerf634f462004-08-30 21:46:55 +000045 Path result;
Misha Brukman9c02f5c2004-10-18 17:39:45 +000046 result.set_directory(TmpName);
Reid Spencerf634f462004-08-30 21:46:55 +000047 assert(result.is_valid() && "mkdtemp didn't create a valid pathname!");
48 return result;
49}
50
Reid Spencercbad7012004-09-11 04:59:30 +000051std::string
52Path::GetDLLSuffix() {
53 return "so";
54}
55
Reid Spencer8e665952004-08-29 05:24:01 +000056}
57
58// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab