Path: utzoo!utgpu!water!watmath!clyde!bellcore!decvax!ucbvax!pasteur!ames!ll-xn!mit-eddie!husc6!cmcl2!brl-adm!umd5!uvaarpa!mcnc!rti!sas!toebes From: toebes@sas.UUCP (John Toebes) Newsgroups: comp.sys.amiga Subject: Re: getenv() -- Lattice 4.0 Summary: Of course it is ANSI compatible :-) Keywords: getenv, stdlib.h, Lattice Message-ID: <334@sas.UUCP> Date: 17 Feb 88 12:35:38 GMT References: <6893@agate.BERKELEY.EDU> Organization: SAS Institute Inc.,Cary NC,25712 Lines: 47 In article <6893@agate.BERKELEY.EDU>, pete@violet.berkeley.edu writes: > In a recent posting, David Roch [roch@b.uiuc.edu] asked: > > While looking through the include files for Lattice 4.0, I noticed > > that getenv is defined in stdlib.h. Curious, I tried accessing > > the environment variables set by assign, both with and without > > the colon, but in each case the null string was returned. > OK -- you got me curious, so I did some code disassembly... > You're right [strangely...!] in that getenv searches the Device List for > names. However, what's returned is NOT another character string (despite > the prototype in stdlib.h!), but the ADDRESS of the relevant DevInfo block. > (It can be any device -- not just assigned ones.) > > I wonder what Lattice intends this for? You can of course use it just > to test if a device is "mounted" (just like Bryce and others have done). > Why use the name "getenv" though? ...Not exactly ANSI compatible! Actually it is quite ANSI compatible (in a sense). To quote the standard: Description the getenv function searches an environment list, provided by the host environment, for a string that matches the string pointed to by name. The set of environment names and the method for altering the environment list are implementation-defined. Returns The getenv function returns a pointer to a string associated with the matched list member. The array pointed to shall not be modified by the program, but may be overwritten by a subsequent call to the getenv function. If the specified name cannot be fount, a null pointer is returned. Since the description requires the environment list to be provided by the host environment and we wish to follow the Amiga standards, the appropriate place to get the information is from the list of assigns. When an alternative to this is provided by Commodore as a standard defined interface we would certainly look toward that. However since this is what is to be done, we must return an indicator of whether or not the item exists. Note that ANSI imposes no restrictions on the format of the information returned. You have the ability to cast the pointer to a DevInfo structure and get additional information out of the return value. It's best use is for testing whether something is mounted, but there are other possibilities. (Testing for the presence of a configuration file by name). /*---------------------All standard Disclaimers apply---------------------*/ /*----Working for but not officially representing SAS or Lattice Inc.-----*/ /*----John A. Toebes, VIII usenet:...!mcnc!rti!sas!toebes-----*/ /*------------------------------------------------------------------------*/