What error codes should be expected from Boost :: filesystem :: copy

I am trying to copy a file to the destination using boost :: filesystem :: copy_file with the parameter system :: error_code, since I do not want exceptions to be thrown.

This function takes a parameter whether it should crash if the file already exists with the same name, which is the behavior I want. From http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/reference.html#copy_file :

Effects: if == copy_option :: fail_if_exists && & & exists (to), an error is reported.

However, I cannot find which error codes I should expect. Does it depend on the underlying OS?

+4
source share
1 answer

Yes, it depends on the OS. The source code shows that copy_file()(and other operations) generates the following errors:

  if (ec == 0)
    BOOST_FILESYSTEM_THROW(filesystem_error(message,
      p, error_code(BOOST_ERRNO, system_category())));
  else
    ec->assign(BOOST_ERRNO, system_category());

system_category()indicates errors that occur from the operating system and BOOST_ERRNOon Posix systems errno.

In Posix, the main call open()with O_CREATand O_EXCLwill fail and set errnoto EEXISTwhen the file already exists.

+2
source

Source: https://habr.com/ru/post/1542238/


All Articles