Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!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: <1990Aug2.143551.7104@specialix.co.uk> Date: 2 Aug 90 14:35:51 GMT References: <9220003@hpldsla.sid.hp.com> <3802@auspex.auspex.com> Organization: Specialix International, London Lines: 52 Someone writes: >Also, I do not think I want to use a global and initialize it to >argv[0] in body of main(), because I do not use globals! Try this sort of thing: #include /* for NULL and printf */ char *ProgName(); main( argc, argv ) char **argv; { ProgName( argv[0] ); /* ** Code of your choice entered here */ Funky1(); } Funky1() { printf("My name is '%s'\n",ProgName(NULL)); } /* ** ProgName - if passed a name will save a (private) handle to the name passed. ** Regardless, it will return a pointer to the current name stored. */ char *ProgName( pname ) char *pname; { static char *myname = NULL; if ( pname ) myname = pname; return myname; } No guarantees - no liability accepted. Have fun! --- 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'' -- 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