Example: getcwd

This example uses getcwd to save the current directory, before moving to a new directory. It then moves back to the first directory.

    #include <direct.h>
    #define DIR_LEN 512
    char original_dir[DIR_LEN];
    #ifdef unix
        char new_dir[] = "/tmp";
    #else
        char new_dir[] = "C:\\";
    #endif
    if (!getcwd(original_dir, DIR_LEN)) {
        lr_output_message ("getcwd error");
        return -1;
    }
    // Change the current working directory to new_dir 
    if (chdir(new_dir)) {
        lr_output_message ("Unable to locate directory: %s", new_dir);
        return -1;
    }
    else
        lr_output_message ("Changed dir to %s", new_dir);
    // Move back to original directory 
    if (chdir(original_dir)) {
        lr_output_message ("Cannot move back to %s", original_dir);
        return -1;
    }
    else
        lr_output_message ("Moved back to %s", original_dir);
Example: Output:
Action.c(25): Changed dir to C:\
Action.c(35): Moved back to D:\TEMP\noname13