80-columns.
[oota-llvm.git] / lib / Support / Path.cpp
index 1bd94a76faf7934bc1047140c1960c9ba969b06c..76bee479847b2d149ccdf5b75423a5c7ee46d604 100644 (file)
@@ -209,7 +209,7 @@ retry_random_path:
       return EC;
     }
 
-    return error_code::success();
+    return error_code();
   }
 
   case FS_Name: {
@@ -219,7 +219,7 @@ retry_random_path:
       return EC;
     if (Exists)
       goto retry_random_path;
-    return error_code::success();
+    return error_code();
   }
 
   case FS_Dir: {
@@ -228,7 +228,7 @@ retry_random_path:
         goto retry_random_path;
       return EC;
     }
-    return error_code::success();
+    return error_code();
   }
   }
   llvm_unreachable("Invalid Type");
@@ -307,21 +307,18 @@ const_iterator &const_iterator::operator++() {
 }
 
 const_iterator &const_iterator::operator--() {
-  // If we're at the end and the previous char was a '/', return '.'.
+  // If we're at the end and the previous char was a '/', return '.' unless
+  // we are the root path.
+  size_t root_dir_pos = root_dir_start(Path);
   if (Position == Path.size() &&
-      Path.size() > 1 &&
-      is_separator(Path[Position - 1])
-#ifdef LLVM_ON_WIN32
-      && Path[Position - 2] != ':'
-#endif
-      ) {
+      Path.size() > root_dir_pos + 1 &&
+      is_separator(Path[Position - 1])) {
     --Position;
     Component = ".";
     return *this;
   }
 
   // Skip separators unless it's the root directory.
-  size_t root_dir_pos = root_dir_start(Path);
   size_t end_pos = Position;
 
   while(end_pos > 0 &&
@@ -572,6 +569,12 @@ bool is_separator(char value) {
   }
 }
 
+static const char preferred_separator_string[] = { preferred_separator, '\0' };
+
+const StringRef get_separator() {
+  return preferred_separator_string;
+}
+
 void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result) {
   result.clear();
 
@@ -580,7 +583,7 @@ void system_temp_directory(bool erasedOnReboot, SmallVectorImpl<char> &result) {
   // macros defined in <unistd.h> on darwin >= 9
   int ConfName = erasedOnReboot? _CS_DARWIN_USER_TEMP_DIR
                                : _CS_DARWIN_USER_CACHE_DIR;
-  size_t ConfLen = confstr(ConfName, 0, 0);
+  size_t ConfLen = confstr(ConfName, nullptr, 0);
   if (ConfLen > 0) {
     do {
       result.resize(ConfLen);
@@ -708,7 +711,7 @@ error_code getUniqueID(const Twine Path, UniqueID &Result) {
   if (EC)
     return EC;
   Result = Status.getUniqueID();
-  return error_code::success();
+  return error_code();
 }
 
 error_code createUniqueFile(const Twine &Model, int &ResultFd,
@@ -778,7 +781,7 @@ error_code make_absolute(SmallVectorImpl<char> &path) {
 
   // Already absolute.
   if (rootName && rootDirectory)
-    return error_code::success();
+    return error_code();
 
   // All of the following conditions will need the current directory.
   SmallString<128> current_dir;
@@ -790,7 +793,7 @@ error_code make_absolute(SmallVectorImpl<char> &path) {
     path::append(current_dir, p);
     // Set path to the result.
     path.swap(current_dir);
-    return error_code::success();
+    return error_code();
   }
 
   if (!rootName && rootDirectory) {
@@ -799,7 +802,7 @@ error_code make_absolute(SmallVectorImpl<char> &path) {
     path::append(curDirRootName, p);
     // Set path to the result.
     path.swap(curDirRootName);
-    return error_code::success();
+    return error_code();
   }
 
   if (rootName && !rootDirectory) {
@@ -811,7 +814,7 @@ error_code make_absolute(SmallVectorImpl<char> &path) {
     SmallString<128> res;
     path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
     path.swap(res);
-    return error_code::success();
+    return error_code();
   }
 
   llvm_unreachable("All rootName and rootDirectory combinations should have "
@@ -858,7 +861,7 @@ error_code is_directory(const Twine &path, bool &result) {
   if (error_code ec = status(path, st))
     return ec;
   result = is_directory(st);
-  return error_code::success();
+  return error_code();
 }
 
 bool is_regular_file(file_status status) {
@@ -870,26 +873,13 @@ error_code is_regular_file(const Twine &path, bool &result) {
   if (error_code ec = status(path, st))
     return ec;
   result = is_regular_file(st);
-  return error_code::success();
-}
-
-bool is_symlink(file_status status) {
-  return status.type() == file_type::symlink_file;
-}
-
-error_code is_symlink(const Twine &path, bool &result) {
-  file_status st;
-  if (error_code ec = status(path, st))
-    return ec;
-  result = is_symlink(st);
-  return error_code::success();
+  return error_code();
 }
 
 bool is_other(file_status status) {
   return exists(status) &&
          !is_regular_file(status) &&
-         !is_directory(status) &&
-         !is_symlink(status);
+         !is_directory(status);
 }
 
 void directory_entry::replace_filename(const Twine &filename, file_status st) {
@@ -909,13 +899,13 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) {
     if (ec == errc::value_too_large) {
       // Magic.size() > file_size(Path).
       result = false;
-      return error_code::success();
+      return error_code();
     }
     return ec;
   }
 
   result = Magic == Buffer;
-  return error_code::success();
+  return error_code();
 }
 
 /// @brief Identify the magic in magic.
@@ -1019,6 +1009,7 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) {
     case 0x66: // MPS R4000 Windows
     case 0x50: // mc68K
     case 0x4c: // 80386 Windows
+    case 0xc4: // ARMNT Windows
       if (Magic[1] == 0x01)
         return file_magic::coff_object;
 
@@ -1056,7 +1047,7 @@ error_code identify_magic(const Twine &path, file_magic &result) {
     return ec;
 
   result = identify_magic(Magic);
-  return error_code::success();
+  return error_code();
 }
 
 error_code directory_entry::status(file_status &result) const {