sapling/eden/fs/utils/SystemError.h
Andres Suarez fbdb46f5cb Tidy up license headers
Reviewed By: chadaustin

Differential Revision: D17872966

fbshipit-source-id: cd60a364a2146f0dadbeca693b1d4a5d7c97ff63
2019-10-11 05:28:23 -07:00

36 lines
943 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <system_error>
namespace facebook {
namespace eden {
/**
* Return true if this exception contains an errno value in ex.code().value()
*/
inline bool isErrnoError(const std::system_error& ex) {
// std::generic_category is the correct category to represent errno values.
// However folly/Exception.h unfortunately throws errno values as
// std::system_category for now.
return (
ex.code().category() == std::generic_category() ||
ex.code().category() == std::system_category());
}
/**
* Return true if this exception is equivalent to an ENOENT error code.
*/
inline bool isEnoent(const std::system_error& ex) {
return isErrnoError(ex) && ex.code().value() == ENOENT;
}
} // namespace eden
} // namespace facebook