Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!asuvax!mcdphx!mcdchg!ddsw1!tronsbox!dsoft!sauron From: sauron@dsoft.UUCP (Ron Stanions) Newsgroups: comp.sys.amiga Subject: Re: File sources Keywords: C, file manipulation, lock Message-ID: <405@dsoft.UUCP> Date: 27 Dec 89 23:00:19 GMT References: <[25985311:3493.1]com Lines: 55 In article <[25985311:3493.1]comp.sys.amiga;1@tronsbox.UUCP> tron1@tronsbox.UUCP (HIM) writes: >>I'm looking for example sources for performing basic file manipulation >>on the Amiga. I'd like the "correct" way to do things such as create, >>open, read, and write files. I also need examples of how to implement >>a lock. If anyone could mail me sources, or point me to an FTP archive >>I'd much appreciate it. If you're programming in C, you can stick with the standard C calls to do 99% of this type of work. There are the actual system calls Open(), Close(), Read(), Write() also, but by using them you get away from portability, and C's calls are pretty much at least as powerful. Locking files is a problem. Ados 1.3 and below don't support file locking. I had a need for this and researched it myself. The end results that I can suggest are: All methods of locking that I have worked with on the amiga require 'friendly' locks. That is, all programs must agree to look for the lock before using the file. 1) Do something unix-like. Create a lockfile. if it exists, you can't gain access to the file, someone else owns it for now. Disadvantages are: if the task crashes the file is owned forever by the dead task (here you check for the file's age. if it's older than X minutes, you can assume the lock is dead and delete the lock.) It's also maliciously slow, unless you use a RAM: lockfile, which would be safest since a reboot wouldn't leave dead locks lying around. 2) Use semaphores. It might take longer to learn how, but they're more efficient than method 1, and a bit more reliable I think. This was the approache I chose to use, but to my dismay I was never able to get them to work, even following the instructions in the documentation I had on how to do it. The semaphore never even opened. 3) Since I couldn't get semaphores to work, I ended up writing my own mini-semaphore handler. (Basically a simple message port that held the locked file name in it.) If I had a working amiga (It's a Loooong story!) I'd upload the code for this one. It was pretty reliable I think, but it still required the 'friendly' lock. 4) There is a function call in Ados that lets you obtain a lock on a directory. I've never worked with this function, but I beleive it may also allow you to obtain a lock on a file as well. This MAY be the most efficient way, if it works, and it would not require 'friendly' locking if it did. I simply never played with it to find out. That's the best I can do for suggestions. I fried my Amiga some time ago and am stuck without one for now, otherwise I'd upload the source to my locking routines. Anyway, that's the best I have to offer for ideas. -- Ron Stanions -- sauron@dsoft \_/\--/\_/ All things posted by me are dsoft system administrator < \ / > by-products of a deranged mind Dragonsoft Development \ / from spending too many hours ...!uunet!tronsbox!dsoft!sauron `\oo/' trying to make uucp work!