armhold@topaz.rutgers.edu (George Armhold) (12/23/89)
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. Thanks, -George --------------------------------------------------------------------------- AMIGA software coordinator, armhold@topaz.rutgers.edu Rutgers University Faculty/Staff armhold@zodiac.rutgers.edu Development Center ---------------------------------------------------------------------------
tron1@tronsbox.UUCP (HIM) (12/27/89)
>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. here here !! -- One could also use this! Send duplicates to me please (grin).. **************************************************************************** "Perfume and leather baby , you and me together baby, what good is living in paradise, if you don't let yourself once or twice." -Tiffany Kenneth J. Jamieson ---- THE BOSS at Xanadu Enterprises Inc. UUCP: tron1@tronsbox.UUCP BEST PATH ---> uunet!tronsbox!tron1 Sysop, Romantic Encounters BBS - (201)759-8450 / (201)759-8568 ****************************************************************************
sauron@dsoft.UUCP (Ron Stanions) (12/28/89)
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!
lphillips@lpami.wimsey.bc.ca (Larry Phillips) (01/01/90)
In <2629@jolnet.ORPK.IL.US>, caw@jolnet.ORPK.IL.US (Chris Wichura) writes: > >Also, always remember to UnLock() locks you have obtained or you could >keep the system from fully accessing a file and the only way to get >access back is to reboot the system (unless someone has written a utility >to UnLock specific locks [I forget if XOper has a function to do this]). Khalid Aldoseri wrote a 'locks' program, based loosely on one that was posted to the net some time ago. Khalid's version allows you to both view and remove locks left lying around by errant programs. I don't think it's been posted to Usenet, though I know it's on Compuserve (AmigaTech, LIB 13 or 14). It's a little dangerous if you aren't careful or don't know what you're doing, but is incredibly handy when you need it. -larry -- " All I ask of my body is that it carry around my head." - Thomas Alva Edison - +-----------------------------------------------------------------------+ | // Larry Phillips | | \X/ lphillips@lpami.wimsey.bc.ca -or- uunet!van-bc!lpami!lphillips | | COMPUSERVE: 76703,4322 -or- 76703.4322@compuserve.com | +-----------------------------------------------------------------------+
caw@jolnet.ORPK.IL.US (Chris Wichura) (01/01/90)
The Ados Lock() command in dos.library is really all you should need to get a lock on a file (it is not just for directories). If you go "lock = Lock("filename", ACCESS_READ)" you will get a shared lock on the file. Others can read it but no one else can write to it. If you go "lock = Lock("filename", ACCESS_WRITE)" you get an exclusive lock. You can read and write it, but no one else in the system can access it until you UnLock() it. Also, always remember to UnLock() locks you have obtained or you could keep the system from fully accessing a file and the only way to get access back is to reboot the system (unless someone has written a utility to UnLock specific locks [I forget if XOper has a function to do this]). -- Christopher A. Wichura u12401 @ uicvm.uic.edu (my home account) caw @ jolnet.UUCP (my Usenet feed)