public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Michael Eager <eager@mvista.com>
To: ciaran <pcxmac@yahoo.com>
Cc: gcc@gcc.gnu.org
Subject: Re: using linux environment variables such as $USER in c++ applications
Date: Thu, 09 Aug 2001 16:21:00 -0000	[thread overview]
Message-ID: <3B731B13.AA54E917@mvista.com> (raw)
In-Reply-To: <3B71F618.8070500@yahoo.com>

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

  reply	other threads:[~2001-08-09 16:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-08 19:30 ciaran
2001-08-09 16:21 ` Michael Eager [this message]
2001-09-15 15:00 Paolo Carlini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B731B13.AA54E917@mvista.com \
    --to=eager@mvista.com \
    --cc=gcc@gcc.gnu.org \
    --cc=pcxmac@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).