uppdate and read files on ubuntu

hi

I'm using swift on ubuntu and my first question is if there is any easy way
to upgrade to the latest release or do I have to download from swift.org
and reinstall each time?

second, to read a file I tried fopen from Glibc but i requires
"UnsafePointer<Int8>". how do I declare that, ie var file:
UnsafePointer<Int8>?

thanks in advance

You probably wouldn’t declare a variable of that type. Instead just pass a String for that parameter — the compiler will convert to a C string for you.

For now the best documentation comes from the Using Swift With Cocoa And Objective-C book, which has a section on plain C APIs:

  Constant Pointers
  When a function is declared as taking a UnsafePointer<Type> argument, it can accept any of the following:
  ...
  * A String value, if Type is Int8 or UInt8. The string will automatically be converted to UTF8 in a buffer that lasts for the duration of the call.

Whether that’s appropriate for fopen() depends on whether the Linux filesystem APIs use UTF-8 encoding. (Sorry, I don’t know Linux well enough to say.) If they don’t, you’ll have trouble with filenames containing non-ASCII characters; in that case you’d need to write a function to encode the String into a byte array in the right encoding, and then pass that to fopen().

—Jens

···

On Dec 29, 2015, at 1:22 PM, Jonas Fredriksson via swift-users <swift-users@swift.org> wrote:

second, to read a file I tried fopen from Glibc but i requires "UnsafePointer<Int8>". how do I declare that, ie var file: UnsafePointer<Int8>?