home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,671 of 243,242   
   Keith Thompson to bart   
   Re: srand(0)   
   31 Dec 25 16:00:45   
   
   From: Keith.S.Thompson+u@gmail.com   
      
   bart  writes:   
   [...]   
   > argv[0] merely returns what was typed on the command line to invoke the   
   application.   
   >   
   > So if someone types:   
   >   
   >    C:\abc> prog   
   >   
   > it may run a prog.exe found in, say, c:\programs\myapp, and return the full   
   path as   
   > "c:\programs\myapp\prog.exe".   
   >   
   > args[0] will give you only "prog"; good luck with that!   
   [...]   
      
   That's typically how it works, but it's not guaranteed.   
      
   If a program is invoked from a shell on a Unix-like system, the   
   shell will use something like fork() and one of the exec() functions,   
   and will typically (perhaps always?) arrange for the new process's   
   argv[0] to point to a copy of the program name given on the shell   
   command line.  (Programs that behave differently depending on the   
   string pointed to by argv[0] are typically invoked via symbolic   
   links, so for example vi and view might be names for the same   
   executable.)   
      
   But there are a number of other ways to invoke programs.  In the   
   example I posted, a C program calls execve() directly, and sets up   
   argc and argv in a way that a shell would never do.   
      
   For safety, any program should safely handle being invoked   
   with unusual arguments -- especially any program with extra   
   privileges.  For simplicity, it could simply abort if argc==0   
   and/or argv[0]==NULL.   
      
   Similar considerations probably apply on Windows, though it seems that   
   Windows tries to guarantee argc>1 and argv[0]!=NULL.   
      
   --   
   Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com   
   void Void(void) { Void(); } /* The recursive call of the void */   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca