Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ptsfa!hoptoad!academ!killer!jfh From: jfh@killer.UUCP (John Haugh) Newsgroups: comp.lang.c Subject: Re: Destroying arguments Message-ID: <908@killer.UUCP> Date: Tue, 19-May-87 12:46:34 EDT Article-I.D.: killer.908 Posted: Tue May 19 12:46:34 1987 Date-Received: Sun, 24-May-87 02:02:22 EDT References: <292@osupyr.UUCP> <239@polyof.UUCP> <485@bene.UUCP> Distribution: comp.unix.questions Organization: The Unix(tm) Connection, Dallas, Texas Lines: 39 Summary: Some ps(1)'s look at the stack for the strings, not the pointers ... In article <485@bene.UUCP>, itkin@bene.UUCP (Steven List) writes: > In article <239@polyof.UUCP> john@polyof.UUCP ( John Buck ) writes: > >In article <292@osupyr.UUCP>, dusan@osupyr.UUCP (Dusan Nedeljkovic) writes: > >> I'm looking for a way to modify/destroy agruments passed to a C program > >> on the command line. > >For each argv[] element you wish to destroy, simply copy another (any) > >string (or string of characters) over it using strncpy() or a pointer > >assignment loop: Yes, this is a more correct way. Some versions (all of the few ones that I have seen) of PS(1) print out the arguments by looking in the stack segment for the strings themselves. Destroying the strings requires that you modify the strings themselves. This removes the possibility that the PS(1) you are using does look at the stack. However - some options of PS(1) look in the U-page (u_command?) for the name of the command, and that can't be (easily) changed. > Without commenting in detail on John's reply, I would note that since > argv is an array of POINTERS to strings, the simple thing to do is to > set up your own string and then store the address/pointer in argv[n]. > This avoids the potential pitfalls that John's method involves and gives > you the option to store ANYTHING YOU WANT in the argument list. The problem with this is that ps may not look at the pointers. If the pointers are looked at this fragment if (*argv[1] == '-') for (argv[1]++;*argv[1];argv[1]++) /* option processing here */ would trash the second argument. You might want to try writing a program that handles its flags this way and see what ps shows. Please don't post your results. I will summarize if the is enough response. - John. Disclaimer - No disclaimer. Whatcha donna do, sue me?