Hi all,
I am trying to understand how Swift 3 File I/O works in a linux
environment. I put together a trivial test program using what I
can glean from the few examples I can find. See below.
===============================
import Glibc
import Foundation
let filename = Process.arguments[1]
let file_handle = fopen (filename, "r")
let BUFSIZE = 1024
var buf = [CChar](repeating:CChar(0), count:BUFSIZE)
while fgets(&buf, Int32(BUFSIZE), file_handle) != nil
{
print(buf)
}
exit(0)
===============================
The program runs, but produces a stream of integer arrays, each of 1024
bytes. I can see what appears to be ASCII character values in the
sample text, plus a lot of trailing zeros. I suspect I haven't mapped
the bytes in buf to Strings, so how should that be done?
--
Ken Burgett
Principal Software Engineer
Email: k...@iotone.io
Office: 530.693.4449
Mobile: 831.332.6846
URL: www.iotone.co
import Glibc
import Foundation
//
// 'main program'
//
// command: "blake2b filename [key]",
//
guard Process.arguments.count == 2 else
{
print("Usage: blake2b FILENAME")
exit(-1)
}
let filename = Process.arguments[1]
let file_handle = fopen (filename, "r")
let BUFSIZE = 1024
var buf = [CChar](repeating:CChar(0), count:BUFSIZE)
while fgets(&buf, Int32(BUFSIZE), file_handle) != nil {
print(buf)
}
exit(0)
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users