std::filesystem::create_symlink

target을 가리키는 심볼릭 링크 link를 만드는 함수예요. C++17부터 있어요.

출처: cppreference

본문

<filesystem> 헤더에 정의돼 있어요.

void create_symlink( const std::filesystem::path& target,
                     const std::filesystem::path& link );          // (1) C++17
void create_symlink( const std::filesystem::path& target,
                     const std::filesystem::path& link,
                     std::error_code& ec ) noexcept;               // (2) C++17
void create_directory_symlink( const std::filesystem::path& target,
                               const std::filesystem::path& link ); // (3) C++17
void create_directory_symlink( const std::filesystem::path& target,
                               const std::filesystem::path& link,
                               std::error_code& ec ) noexcept;      // (4) C++17

POSIX symlink()처럼 target을 목표로 하는 심볼릭 링크 link를 만들어요. 경로 이름 target은 유효하지 않거나 존재하지 않아도 돼요. 일부 운영체제는 심볼릭 링크가 디렉터리를 가리키는지 알려줘야 한다고 요구해요. 이식 가능한 코드는 POSIX에서 차이가 없더라도 (1,2)보다 (3,4)로 디렉터리 심볼릭 링크를 만드는 걸 권장해요.

매개변수

  • target — 심볼릭 링크가 가리킬 경로. 존재하지 않아도 됨.
  • link — 새 심볼릭 링크의 경로.
  • ec — 예외 없는 버전에서 오류 보고용 출력 매개변수.

반환값

(없음)

예외

noexcept로 표시되지 않은 오버로드는 메모리 할당이 실패하면 std::bad_alloc을 던질 수 있어요.

  • 1,3) OS API 오류가 있으면 target을 첫 경로 인자, link를 두 번째 경로 인자로 삼아 std::filesystem::filesystem_error를 던져요.
  • 2,4) OS API 호출이 실패하면 ec에 OS 오류 코드를 설정하고, 오류가 없다면 ec.clear()를 실행해요.

더 알아보기 (Learn more)

cppreference