public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: using linux environment variables such as $USER in c++ applications
@ 2001-09-15 15:00 Paolo Carlini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Carlini @ 2001-09-15 15:00 UTC (permalink / raw)
  To: pcxmac; +Cc: gcc

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 359 bytes --]

Hi,

in case you have'nt already solved your problem, you will find a very
nice introduction to those issues in §2.1.6 of "Advanced Linux
Programming" by Mark Mitchell et al. The book is published under the
Open Publication License and its full text may be downloaded from the
site:

    http://www.advancedlinuxprogramming.com/


Cheers,
Paolo Carlini.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using linux environment variables such as $USER in c++ applications
  2001-08-08 19:30 ciaran
@ 2001-08-09 16:21 ` Michael Eager
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Eager @ 2001-08-09 16:21 UTC (permalink / raw)
  To: ciaran; +Cc: gcc

ciaran wrote:
> 
> how do i get the compiler to recognize variables like $PATH or $USER? i
> wanna use them like how i would in a shell script

This is probably off topic for the GCC mailing list.

I presume you want to have a string which contains an environment variable
which you want to expand to it's contents.  For example:

	char * filename = "$USER/myfile";

You need to scan the string for occurances of environment variables:

	char * env = strchr (filename, '$');

Find the end of the environment variable (look at strspn()).  Remove
the environment variable from the string, save it somewhere, say in "env".
Call getenv(env) to get the value of the environment variable, remembering
to remove the '$'.  Insert the value into the string where you removed 
the environment variable.

There are similar functions in the C++ string class which you can use.

--
Michael Eager     eager@mvista.com	408-328-8426	
MontaVista Software, Inc. 1237 E. Arques Ave., Sunnyvale, CA  94085

^ permalink raw reply	[flat|nested] 3+ messages in thread

* using linux environment variables such as $USER in c++ applications
@ 2001-08-08 19:30 ciaran
  2001-08-09 16:21 ` Michael Eager
  0 siblings, 1 reply; 3+ messages in thread
From: ciaran @ 2001-08-08 19:30 UTC (permalink / raw)
  To: gcc

how do i get the compiler to recognize variables like $PATH or $USER? i 
wanna use them like how i would in a shell script


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-09-15 15:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-15 15:00 using linux environment variables such as $USER in c++ applications Paolo Carlini
  -- strict thread matches above, loose matches on Subject: below --
2001-08-08 19:30 ciaran
2001-08-09 16:21 ` Michael Eager

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).