Boost logo

Boost :

From: Lars Gullik Bjønnes (larsbj_at_[hidden])
Date: 2002-03-20 18:00:20


"Jeff Garland" <jeff_at_[hidden]> writes:

>> >int main()
>> >{
>> > std::string initial = getcwd();
>> >// rest unchanged
>> >}
>>
>> There would be no difference at all at that point in the code. But if
>> initial_directory() is called again later by some library routine, it still
>> will give the correct answer. Eventually initial_directory() might become
>> part of the standard, and then would be set by the runtime library before
>> main() runs.
>>
>> If anyone comes up with a killer argument for get/set cwd, we can include
>> them. But that hasn't happened so far.

Probably not a killer argument, but in LyX we call external programs
in a lot of cases as well as work with and handle files in a lot of
different directories. To be able to set the external programs cwd by
changing cwd inside LyX is nice, also to change the cwd inside lyx is
nice when working on several files in different dirs. We use a class
like this a lot of places:

class Path : boost::noncopyable {
public:
        ///
        explicit
        Path(string const & path)
                : popped_(false)
        {
                if (!path.empty()) {
                        pushedDir_ = lyx::getcwd(); // GetCWD();
                        lyx::chdir(path);
                } else {
                        popped_ = true;
                }
        }
        ///
        ~Path()
        {
                if (!popped_) pop();
        }
        ///
        int pop();
private:
        ///
        bool popped_;
        ///
        string pushedDir_;
};

If it is spawn, fork/exec or system does not really make a difference.

-- 
	Lgb

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk