| 4066 | ); |
| 4067 | |
| 4068 | BOOST_FILESYSTEM_DECL |
| 4069 | bool is_empty(path const& p, system::error_code* ec) |
| 4070 | { |
| 4071 | if (ec) |
| 4072 | ec->clear(); |
| 4073 | |
| 4074 | #if defined(BOOST_FILESYSTEM_POSIX_API) |
| 4075 | |
| 4076 | boost::scope::unique_fd file; |
| 4077 | int err = 0; |
| 4078 | while (true) |
| 4079 | { |
| 4080 | file.reset(::open(p.c_str(), O_RDONLY | O_CLOEXEC)); |
| 4081 | if (BOOST_UNLIKELY(!file)) |
| 4082 | { |
| 4083 | err = errno; |
| 4084 | if (err == EINTR) |
| 4085 | continue; |
| 4086 | |
| 4087 | fail: |
| 4088 | emit_error(err, p, ec, "boost::filesystem::is_empty"); |
| 4089 | return false; |
| 4090 | } |
| 4091 | |
| 4092 | break; |
| 4093 | } |
| 4094 | |
| 4095 | #if defined(BOOST_FILESYSTEM_NO_O_CLOEXEC) && defined(FD_CLOEXEC) |
| 4096 | if (BOOST_UNLIKELY(::fcntl(file.get(), F_SETFD, FD_CLOEXEC) < 0)) |
| 4097 | { |
| 4098 | err = errno; |
| 4099 | goto fail; |
| 4100 | } |
| 4101 | #endif |
| 4102 | |
| 4103 | #if defined(BOOST_FILESYSTEM_USE_STATX) |
| 4104 | struct ::statx path_stat; |
| 4105 | if (BOOST_UNLIKELY(invoke_statx(file.get(), "", AT_EMPTY_PATH | AT_NO_AUTOMOUNT, STATX_TYPE | STATX_SIZE, &path_stat) < 0)) |
| 4106 | { |
| 4107 | err = errno; |
| 4108 | goto fail; |
| 4109 | } |
| 4110 | |
| 4111 | if (BOOST_UNLIKELY((path_stat.stx_mask & (STATX_TYPE | STATX_SIZE)) != (STATX_TYPE | STATX_SIZE))) |
| 4112 | { |
| 4113 | err = BOOST_ERROR_NOT_SUPPORTED; |
| 4114 | goto fail; |
| 4115 | } |
| 4116 | #else |
| 4117 | struct ::stat path_stat; |
| 4118 | if (BOOST_UNLIKELY(::fstat(file.get(), &path_stat) < 0)) |
| 4119 | { |
| 4120 | err = errno; |
| 4121 | goto fail; |
| 4122 | } |
| 4123 | #endif |
| 4124 | |
| 4125 | const mode_t mode = get_mode(path_stat); |