From: Ramon F Herrera on

The closest I have is this:

getenv("PWD");

But that only tells the value of such environment variable at the time
the program was started.

I need to know (for debugging purposes) the current working directory,
dynamically.

TIA,

-Ramon

From: Ramon F Herrera on
On Dec 27, 12:10 am, Ramon F Herrera <ra...(a)conexus.net> wrote:
> The closest I have is this:
>
> getenv("PWD");
>
> But that only tells the value of such environment variable at the time
> the program was started.
>
> I need to know (for debugging purposes) the current working directory,
> dynamically.
>
> TIA,
>
> -Ramon

Bonus question:

Are the commands 'pushd' and 'popd' implemented programmatically?

From: Gordon Burditt on
>The closest I have is this:
>
>getenv("PWD");

That can lie if the invoker of your program is malicious.
The invoker of your program might not be a shell, and it might
not know to update $PWD or even provide it.

>But that only tells the value of such environment variable at the time
>the program was started.

Look at getcwd() (POSIX). This can fail due to permissions problems
(having x but not r permission on directories, for example.)

>I need to know (for debugging purposes) the current working directory,
>dynamically.

From: Ramon F Herrera on
On Dec 27, 1:06 am, gordonb.pr...(a)burditt.org (Gordon Burditt) wrote:
> >The closest I have is this:
>
> >getenv("PWD");
>
> That can lie if the invoker of your program is malicious.
> The invoker of your program might not be a shell, and it might
> not know to update $PWD or even provide it.
>
> >But that only tells the value of such environment variable at the time
> >the program was started.
>


> Look at getcwd() (POSIX).

My program works great now, thanks Gordon!

-Ramon


From: Ramon F Herrera on
On Dec 27, 12:12 am, Ramon F Herrera <ra...(a)conexus.net> wrote:
> On Dec 27, 12:10 am, Ramon F Herrera <ra...(a)conexus.net> wrote:
>
> > The closest I have is this:
>
> > getenv("PWD");
>
> > But that only tells the value of such environment variable at the time
> > the program was started.
>
> > I need to know (for debugging purposes) the current working directory,
> > dynamically.
>
> > TIA,
>
> > -Ramon
>

> Bonus question:
>
> Are the commands 'pushd' and 'popd' implemented programmatically?

I guess a good way to achieve the above is through a combination of
`getcwd()' and a std::vector which behaves like a stack. That should
be simple enough, at least for those of the C++ persuasion.

Thx,

-Ramon