Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou Newsgroups: comp.lang.c Subject: Re: Running an editor from ANSI C Date: Fri, 7 Jun 2024 19:56:47 +0200 Organization: A noiseless patient Spider Lines: 44 Message-ID: References: <87o78dzw1a.fsf@nosuchdomain.example.com> <87frtpznoa.fsf@nosuchdomain.example.com> <871q59yty1.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 07 Jun 2024 19:56:49 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d0c5267e754d56cba0404b0da7ae55b5"; logging-data="2288749"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HIUs8EDlOeDBpenRrImrv" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:qLeY0uYfXG3E2Zh1CWXB4bqhv5Q= X-Enigmail-Draft-Status: N1110 In-Reply-To: Bytes: 2705 On 07.06.2024 14:57, Malcolm McLean wrote: > On 07/06/2024 10:37, Keith Thompson wrote: >> Malcolm McLean writes: >>> >>> Ah thank you. But then main has to take an extra parameter. Now will >>> the shell still be absolutely robust, and completely portable, and run >>> just anywhere? >> >> What? Why would main need an extra parameter? >> > Hre's the main function for the shell. > > int main(int argc, char **argv) > { [...] > } > > Now to get the $EDITOR variable I will have to modify this function. > > int main(int argc, char **argv, char **envp) > > Now what are the implications of doing that? [...] I'm certainly not the most qualified person to answer that, so just two comments... Declaring the extra parameter doesn't spoil the code, does it? (If you don't use it you don't need to specify it. If you have declared it you can use it or not.) Personally my first reflex would be to use a dedicated function to obtain a specific environment variable, specifically getenv(); I thought it wouldn't require the 'envp' to work? For me it works #include #include void main (int argc, char * argv[]) { printf ("%s\t%s\n", argv[1], getenv(argv[1])); } Janis