Rcpp std::chdir
0
0
Entering edit mode
ullrich ▴ 20
@ullrich-23697
Last seen 2.5 years ago
Germany

Hi,

I am porting existing C++ code into Rcpp.

So far everything is working, but R CMD check fais with the following warnings, which is related to the std::chdir and std::getcwd function.

 Found the following significant warnings:
  mcscanxr.cpp:1041:14: warning: ignoring return value of ‘int chdir(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
  mcscanxr.cpp:1103:11: warning: ignoring return value of ‘char* getcwd(char*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
  mcscanxr.cpp:1141:18: warning: ignoring return value of ‘int chdir(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
  mcscanxr.cpp:1162:14: warning: ignoring return value of ‘int chdir(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
  mcscanxr.cpp:1178:10: warning: ignoring return value of ‘int chdir(const char*)’, declared with attribute warn_unused_result [-Wunused-result]

The problem is that the orginal C++ code uses std::chdir to first check if a directory exists and than changes into it to write some files.

    if (outdir!=""){
        const char *outdir_fn = outdir.c_str();
        if (chdir(outdir_fn)<0){
            mkdir(outdir_fn,S_IRWXU|S_IRGRP|S_IXGRP);
            chdir(outdir_fn);
        }
    }

After the process I need to change back into the original working directory from R.

My initial fix, first using std::getcwd to get back into the original working directory now seems to be part of the same problem.

    char curwd[256];
    getcwd(curwd, 256);

Any ideas how to circumvent these warnings?

Any suggestion to overcome this problem are welcome.

Thank you in anticipation

Best regards

Kristian

Rcpp • 634 views
ADD COMMENT

Login before adding your answer.

Traffic: 815 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6