Path: utzoo!attcan!utgpu!watmath!watdragon!rose!ccplumb From: ccplumb@rose.waterloo.edu (Colin Plumb) Newsgroups: comp.sys.amiga.tech Subject: Re: File name of current task Message-ID: <16659@watdragon.waterloo.edu> Date: 25 Sep 89 16:11:28 GMT References: <2045@leah.Albany.Edu> <623@tardis.Tymnet.COM> Sender: daemon@watdragon.waterloo.edu Reply-To: ccplumb@rose.waterloo.edu (Colin Plumb) Organization: U. of Waterloo, Ontario Lines: 22 In article <623@tardis.Tymnet.COM> jms@tardis.Tymnet.COM (Joe Smith) writes: >AmigaDOS needs this, for the same reasons. Not as a kludge by mangling >argv[0], but as a fully supported and official way. An example function >name would be GetTaskFileName(). Of course, it should return NULL if the >task was created on the fly and not loaded straight from disk. > >I'm surprised this wasn't part of AmigaDOS 1.0. Quick race-condition quiz: why is the filename useless to know? Answer: because someone might have moved the file in the meantime! Yes, unlikely, but it's possible. You need to use locks, not filenames, to get around this. 1.4 has a call which returns a lock on the directory the current program was loaded from (watch for NULL meaning from the resident list or otherwise not associated with a file), but I'd rather have a lock on the file proper. It seems simpler (the OS needs a lock to open and load the code) and the ParentDir() call exists. It also lets you tell which copy was run if there are (for some reason) multiple copies. -- -Colin