file system question

Member
Posts: 105
Joined: 2007.03
Post: #1
How should read and write game data using carbon since all the fs stuff is now depricated?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
the FSSpec stuff is deprecated, the FSRef stuff isn't.

Still, the standard C library functions (fopen/fclose/fread/fwrite/fseek/ftell/etc) are usually the best way.

The POSIX functions (open/close/read/write/lseek/etc) are also pretty simple if you want to go that way.
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #3
Thanks alot. Also, would you happen to know where I could find some sample code or a decent reference for using FSRef stuff, because I couldn't find anything useful on adc.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
On your hard disk

I'd really recommend using one of the other two APIs though Rasp
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #5
OneSadCookie Wrote:I'd really recommend using one of the other two APIs though Rasp

Really? I was under the impression that the c library stuff had too many compatability issues to be practical. Do you know if this is still the case? Also, i'm curious, why would you reccomend posix and c library against fsref?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
"compatibility issues"? Never heard of any. fopen is fopen is fopen.

The libc/POSIX APIs are easier to use, better documented, and more portable. Unless you need something only Carbon can do (eg. alias resolution) there's little reason to go there.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #7
The C library is almost available on every platform that I've used (linux, Windows, Mac OS X, PSP, NDS).
Quote this message in a reply
Member
Posts: 105
Joined: 2007.03
Post: #8
bronxbomber92 Wrote:The C library is almost available on every platform that I've used (linux, Windows, Mac OS X, PSP, NDS).

Well I looked into it and here's what I found concerning the c lib:

"the data file layout is a one-to-one map of the individual in-memory data structures that were written, the file layout ends up depending on all kinds of platform-specific details. The number of bytes written for objects of types int, and float can vary from machine to machine."


This quote was taken from a C reference book published in 2000. If this no longer holds true, would someone please let me know.
Quote this message in a reply
Hog
Member
Posts: 151
Joined: 2002.09
Post: #9
Leroy Wrote:The number of bytes written for objects of types int, and float can vary from machine to machine.

On those machines FSRef isn't available in the first place. sizeof(int) or sizeof(float) should be 4 usually. You could explicitly also pass 4 instead of sizeof(float) to fread, but that wouldn't really be a workaround if floats had size other than 4 bytes. What you do need to do however is take care of endianness.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
It's still perfectly true today (the one you'll most often hit is sizeof(long) varying between 4 and 8). You shouldn't be writing those basic types directly in binary to files anyway, and using FSRefs wouldn't help you if you did. <stdint.h> has guaranteed-size integer types, like uint32_t, that you can use for this purpose. And as Hog says, you need to watch out for endianness.
Quote this message in a reply
Post Reply