简体   繁体   中英

How do I read and write binary data in OS-X?

I need to write a DLL (dynalib, whatever) for OS X 10.6 (Snow Leopard) or later The DLL reads and writes a binary file. (It's the company's proprietary format.) It'll be used by an app that's all Cocoa (AFIK). Everything 64 bit only.

From reading Apple's docs, books, and asking questions here, I still don't have a clear and confident idea as to the good, proper way to deal with binary files. I have the impression I can't use the standard unix/C fopen(), fread() or open(), read() etc. Or I can but I'd be asking for trouble. Is this true? Should I be using something else, and just what?

I have the impression I can't use the standard unix/C fopen(), fread() or open(), read() etc.

The POSIX/BSD personality is fully supported by the operating system. Feel free to write standards compliant C.

Foundation Kit has Objective-C classes and messages you can use ( NSData , NSFile , etc), however they are often more of a pain to use especially when you are maintaining portable code amongst platforms. There is also the side-effect of Objective-C being somewhat easier to reverse engineer than straight C (a trait shared by all higher-level languages).

Depending on the needs of your library, you can consider wrapping it into a Framework as opposed to a naked dylib .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM