std::experimental::filesystem:: create_hard_link
|
헤더 파일에 정의됨
<experimental/filesystem>
|
||
|
void
create_hard_link
(
const
path
&
target,
const
path
&
link
)
;
void create_hard_link ( const path & target, const path & link, error_code & ec ) ; |
(filesystem TS) | |
하드 링크를 생성하며, 그 대상은 target 으로 설정됩니다. 이는 POSIX link() 함수와 동일하게 동작합니다: 경로명 target 이 반드시 존재해야 합니다.
생성된 이후에는, link 와 target 은 동일한 파일을 참조하는 두 개의 논리적 이름입니다(이들은 equivalent ). 원본 이름인 target 이 삭제되더라도, 파일은 계속 존재하며 link 로 접근 가능합니다.
목차 |
매개변수
| target | - | 연결할 파일 또는 디렉터리의 경로 |
| link | - | 새 하드 링크의 경로 |
| ec | - | non-throwing 오버로드에서 오류 보고를 위한 출력 매개변수 |
반환값
(없음)
예외
The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with target as the first argument, link as the second argument, and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has참고 사항
일부 운영 체제는 하드 링크를 전혀 지원하지 않거나 일반 파일에 대해서만 지원합니다.
일부 파일 시스템은 운영 체제와 관계없이 하드 링크를 지원하지 않습니다: 예를 들어 메모리 카드와 플래시 드라이브에 사용되는 FAT 파일 시스템이 그렇습니다.
일부 파일 시스템은 파일당 링크 수를 제한합니다.
디렉터리에 대한 하드 링크 생성은 일반적으로 슈퍼유저로 제한됩니다.
하드 링크는 일반적으로 파일 시스템 경계를 넘을 수 없습니다.
특수 경로명 dot ( "." )은 부모 디렉토리에 대한 하드 링크입니다. 특수 경로명 dot-dot ".." 은 부모 디렉토리의 상위 디렉토리에 대한 하드 링크입니다.
예제
#include <experimental/filesystem> #include <fstream> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::create_directories("sandbox/subdir"); std::ofstream("sandbox/a").put('a'); // 일반 파일 생성 fs::create_hard_link("sandbox/a", "sandbox/b"); fs::remove("sandbox/a"); // 생존한 하드 링크를 통해 원본 파일에서 읽기 char c = std::ifstream("sandbox/b").get(); std::cout << c << '\n'; fs::remove_all("sandbox"); }
출력:
a
참고 항목
|
심볼릭 링크 생성
(함수) |
|
|
특정 파일을 참조하는 하드 링크의 수를 반환
(함수) |