     static let gDirectoryDoesNotExistPath = gBaseTemporaryDirectoryPath + gDirectoryDoesNotExistName
 
     static func setup_test_paths() -> Bool {
-        if creat(gFileExistsPath, S_IRWXU) < 0 && errno != EEXIST {
+        _ = FileManager.default.createFile(atPath: gFileExistsPath, contents: nil)
+
+        do {
+          try FileManager.default.removeItem(atPath: gFileDoesNotExistPath)
+        } catch let error as NSError {
+          // The error code is a CocoaError
+          if error.code != CocoaError.fileNoSuchFile.rawValue {
             return false
-        }
-        if unlink(gFileDoesNotExistPath) != 0 && errno != ENOENT {
+          }
+        }
+
+        do {
+          try FileManager.default.createDirectory(atPath: gDirectoryExistsPath, withIntermediateDirectories: false)
+        } catch let error as NSError {
+          // The error code is a CocoaError
+          if error.code != CocoaError.fileWriteFileExists.rawValue {
             return false
-        }
-        if mkdir(gDirectoryExistsPath, S_IRWXU) != 0 && errno != EEXIST {
+          }
+        }
+
+        do {
+          try FileManager.default.removeItem(atPath: gDirectoryDoesNotExistPath)
+        } catch let error as NSError {
+          // The error code is a CocoaError
+          if error.code != CocoaError.fileNoSuchFile.rawValue {
             return false
-        }
-        if rmdir(gDirectoryDoesNotExistPath) != 0 && errno != ENOENT {
-            return false
-        }
-        
+          }
+        }
+
         #if os(Android)
-        chdir("/data/local/tmp")
+        FileManager.default.changeCurrentDirectoryPath("/data/local/tmp")
         #endif
 
         let cwd = FileManager.default.currentDirectoryPath

        cwdURL.withUnsafeFileSystemRepresentation {
            gRelativeOffsetFromBaseCurrentWorkingDirectory = UInt(strlen($0!) + 1)
        }
        
        
        return true
    }
        

        #elseif os(Linux)
        let baseURL = URL(fileURLWithPath: "/usr", isDirectory: true)
        let relativePath = "include"
        #elseif os(Windows)
        let baseURL = URL(fileURLWithPath: homeDirectory, isDirectory: true)
        let relativePath = "Documents"
        #endif
        // we're telling fileURLWithPath:isDirectory:relativeTo: Documents is a directory
        let url1 = URL(fileURLWithFileSystemRepresentation: relativePath, isDirectory: true, relativeTo: baseURL)
