Data(contentsOf:) doesn't work properly on Linux

Number:rdar://39621032 Date Originated:21-kwi-2018 02:53 PM
Status:Open Resolved:
Product:macOS + SDK Product Version:4.1
Classification:Other Bug Reproducible:Always
Fetching data from the remote server using Data(contentsOf:) on Ubuntu does not work in comparison to macOS, where the same line of code works as expected.

Steps to Reproduce:
1. Install Swift 4.1-RELEASE snapshot on Linux (in my case it was Ubuntu 17.10)
2. Open Swift REPL (in my case I needed a correct path for linker as well, `swift -I /usr/include/clang/4.0.1/include`)
3. Type in the REPL 
import Foundation
4. Type in the REPL 
Data(contentsOf: URL(string: "")!, options: .alwaysMapped)

Expected Results:
Expected the function to fetch the data and return it to me. If there is a problem on Linux, I’d expect it to throw an error as the function is already marked as `throwing`.

Actual Results:
It just returns an empty Data with length=0. On macOS it works as expected.


After further investigation the problem is also in `NSData(contentsOfFile:)` and a family, on which `Data(contentsOf:)` relies (based on the open-sourced core-libs-foundation). The line below:

NSData(contentsOfFile: "", options: .alwaysMapped)

returns an error that doesn’t really say much to me:
$E0: Foundation.NSError = {
  Foundation.NSObject = {}
  _domain = "NSPOSIXErrorDomain"
  _code = 2
  _userInfo = nil


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!