4 ms·
That's incomplete in that it doesn't automatically chdir back. A proper block-scope "with-" macro will wrap the body in something like: char *olddir = get
by qewrffewqwfqew 12y ago
That's incomplete in that it doesn't automatically chdir back. A proper block-scope "with-" macro will wrap the body in something like:
char *olddir = getcwd();
chdir(newdir);
try {
do_stuff();
} finally {
chdir(olddir);
}
- jacquesm 12y ago'try' and 'finally' are in C now? Someone should warn the GCC guys they're behind the times. Also, getcwd has a size parameter these days, and of course you want to check if the getcwd actually worked.
- xxs 12y agoThe OP said: wrap in a macro having similar properties (ala pseudo code).
- jacquesm 12y agoGood luck writing a macro in C to express language functionality for which you don't have the primitives. It's not exactly lisp. Think of C macros as a way to save you some typing and lisp macros as a way to extend the language.
- xxs 12y agoyou can definitely save the chdir and restore it macro.
- tedunangst 12y agosetjmp and longjmp are sufficient building blocks for this.
- xxs 12y agoAny multithreaded code will be destroyed if relying on chdir. chdir should be deprecated, as resolving relative to is just trivial in an application.