Path: utzoo!attcan!uunet!mcsun!ukc!slxsys!jonb From: jonb@specialix.co.uk (Jon Brawn) Newsgroups: comp.unix.questions Subject: Re: Get process name w/o using argv[0] in C function? Message-ID: <1990Aug6.115204.20113@specialix.co.uk> Date: 6 Aug 90 11:52:04 GMT References: <9220003@hpldsla.sid.hp.com> <3802@auspex.auspex.com> <1990Aug2.143551.7104@specialix.co.uk> <13476@yunexus.YorkU.CA> Organization: Specialix International, London Lines: 57 davecb@yunexus.YorkU.CA (David Collier-Brown) writes: >jonb@specialix.co.uk (Jon Brawn) writes: >>Try this sort of thing: >[function that saves argv[0] in a static] > Er, that substitutes a globally callable function for a globally >referable variable. Net gain? more code to do the same thing, value >is read-only. ^^^^^^^^^^ Course its read only! When was the last time you wanted to change the name that you where invoked as? Shouldn't be allowed! There are often occasions when I would like to be able to label something as read only (yeah, I could grock the MMU on my machine, create a page entry, set the appropriate flags and stuff, but its a hell of a chore!). Hiding data in statics within functions is a relatively easy way of achieving the same net effect. You can also use the same approach for controlling access to objects. Keep the actual data storage within one .c file as a static, and have functions within that file that can be callable from outside the file which do error checking on their arguments (wow! what a concept - error checking!) before asigning to the object in question. It also means that you can change the algorithm within the module at any time, change the shape of the data, and still maintain the same interface to the rest of the code. It would be perfectly possible to re-write the routine I posted so that it did scan the proc table for the program name, and still not have to change a single line of the main program. Or perhaps a line could be added to the function which only saved the last part of the programs name, stripping of any leading path. (e.g. store "myprog" rather than "/usr/jonb/ace_progs/myprog"). Or perhaps it could store the name in EBCDIC rather than ASCII (perhaps for efficiancy reasons?) > Looks like a bad tradeoff unless you have an imposed religious >requirement to avoid global variables... Hmm. I remember getting 0% for a piece of course work at college for using a GOTO statement in Pascal, because it wasn't the sort of thing one did in Pascal. Religious convictions? Possibly a more open outlook on future trends....maybe the global will go the same way as the goto (I can but hope). What if the original question had been about something somewhat larger than the program name? where would you stand then? Look at the streams routines - compare them with the routines for clists. Whereas the cblock manipulation was left mainly to the programmer (forming linked lists and all that) the streams interface has lots of little functions to do it for you. Nuff said? >--dave --Jon. -- Jon Brawn, Specialix, 3 Wintersells Road, Byfleet, Surrey, KT14 7LF, UK. Tel: +44(0)9323-54254, Fax:+44(0)9323-52781, jonb@specialix.co.uk or: {backbone}!mcsun!ukc!slxsys!jonb ``Once upon a time, not so very long ago, in a land, not so very far away''