Namespaces
Variants

std::experimental::filesystem:: equivalent

From cppreference.net
헤더 파일에 정의됨 <experimental/filesystem>
bool equivalent ( const path & p1, const path & p2 ) ;
bool equivalent ( const path & p1, const path & p2, error_code & ec ) ;
(1) (filesystem TS)

경로 p1 p2 가 동일한 파일이나 디렉토리를 참조하고 status 에 의해 결정된 동일한 파일 상태를 가지는지 확인합니다 (심볼릭 링크는 따라갑니다).

만약 p1 또는 p2 가 존재하지 않거나, 파일 유형이 파일, 디렉토리 또는 심볼릭 링크가 아닌 경우( is_other 에 의해 결정됨), 오류가 보고됩니다.

비예외 오버로드는 오류 발생 시 false 를 반환합니다.

목차

매개변수

p1, p2 - 동등성을 확인할 경로
ec - non-throwing 오버로드에서 오류 보고를 위한 출력 매개변수

반환값

true 만약 p1 p2 가 동일한 파일이나 디렉토리를 참조하고 파일 상태가 동일한 경우. false 그렇지 않은 경우.

예외

The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p1 as the first argument, p2 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
noexcept 명세:
noexcept

참고 사항

두 경로는 POSIX stat 구조체 st_dev st_ino 가 동일한 경우(즉, 파일이 동일한 장치의 동일한 위치에 있는 경우) 동일한 파일 시스템 엔터티로 간주됩니다. 이 구조체는 POSIX stat 함수를 통해 얻은 것처럼 취급됩니다.

특히, 동일한 파일 또는 디렉터리에 대한 모든 하드 링크는 동등하며, 동일한 파일 시스템 상의 심볼릭 링크와 그 대상은 동등합니다.

예제

#include <cstdint>
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
    // 하드 링크 동등성
    fs::path p1 = ".";
    fs::path p2 = fs::current_path();
    if (fs::equivalent(p1, p2))
        std::cout << p1 << " is equivalent to " << p2 << '\n';
    // 심볼릭 링크 동등성
    fs::path p3 = "/lib/libc.so.6";
    fs::path p4 = p3.parent_path() / fs::read_symlink(p3);
    if (fs::equivalent(p3, p4))
        std::cout << p3 << " is equivalent to " << p4 << '\n';
}

가능한 출력:

"." is equivalent to "/var/tmp/test"
"/lib/libc.so.6" is equivalent to "/lib/libc-2.12.so"

참고 항목

파일 속성 결정
심볼릭 링크 대상 확인하며 파일 속성 결정
(function)