mirror of
https://github.com/AGWA/git-crypt.git
synced 2025-12-05 20:40:05 -08:00
Addresses -Wdeprecated-declarations warnings
changing all references of std::auto_ptr to std::unique_ptr and changing the implementation of get_directory_contents() to use readdir, which is now reentrant, instead of readdir_r. Signed-off-by: Andrew Ayer <agwa@andrewayer.name> Note: old implementations or readdir might not be re-entrant, but that's OK because git-crypt is not multi-threaded.
This commit is contained in:
committed by
Andrew Ayer
parent
edfa3dcb5f
commit
d3bb5aba46
@@ -63,8 +63,8 @@ Aes_ecb_encryptor::Aes_ecb_encryptor (const unsigned char* raw_key)
|
|||||||
|
|
||||||
Aes_ecb_encryptor::~Aes_ecb_encryptor ()
|
Aes_ecb_encryptor::~Aes_ecb_encryptor ()
|
||||||
{
|
{
|
||||||
// Note: Explicit destructor necessary because class contains an auto_ptr
|
// Note: Explicit destructor necessary because class contains an unique_ptr
|
||||||
// which contains an incomplete type when the auto_ptr is declared.
|
// which contains an incomplete type when the unique_ptr is declared.
|
||||||
|
|
||||||
explicit_memset(&impl->key, '\0', sizeof(impl->key));
|
explicit_memset(&impl->key, '\0', sizeof(impl->key));
|
||||||
}
|
}
|
||||||
@@ -86,8 +86,8 @@ Hmac_sha1_state::Hmac_sha1_state (const unsigned char* key, size_t key_len)
|
|||||||
|
|
||||||
Hmac_sha1_state::~Hmac_sha1_state ()
|
Hmac_sha1_state::~Hmac_sha1_state ()
|
||||||
{
|
{
|
||||||
// Note: Explicit destructor necessary because class contains an auto_ptr
|
// Note: Explicit destructor necessary because class contains an unique_ptr
|
||||||
// which contains an incomplete type when the auto_ptr is declared.
|
// which contains an incomplete type when the unique_ptr is declared.
|
||||||
|
|
||||||
HMAC_cleanup(&(impl->ctx));
|
HMAC_cleanup(&(impl->ctx));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
struct Aes_impl;
|
struct Aes_impl;
|
||||||
|
|
||||||
std::auto_ptr<Aes_impl> impl;
|
std::unique_ptr<Aes_impl> impl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Aes_ecb_encryptor (const unsigned char* key);
|
Aes_ecb_encryptor (const unsigned char* key);
|
||||||
@@ -102,7 +102,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
struct Hmac_impl;
|
struct Hmac_impl;
|
||||||
|
|
||||||
std::auto_ptr<Hmac_impl> impl;
|
std::unique_ptr<Hmac_impl> impl;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Hmac_sha1_state (const unsigned char* key, size_t key_len);
|
Hmac_sha1_state (const unsigned char* key, size_t key_len);
|
||||||
|
|||||||
@@ -179,19 +179,6 @@ int util_rename (const char* from, const char* to)
|
|||||||
return rename(from, to);
|
return rename(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t sizeof_dirent_for (DIR* p)
|
|
||||||
{
|
|
||||||
long name_max = fpathconf(dirfd(p), _PC_NAME_MAX);
|
|
||||||
if (name_max == -1) {
|
|
||||||
#ifdef NAME_MAX
|
|
||||||
name_max = NAME_MAX;
|
|
||||||
#else
|
|
||||||
name_max = 255;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return offsetof(struct dirent, d_name) + name_max + 1; // final +1 is for d_name's null terminator
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> get_directory_contents (const char* path)
|
std::vector<std::string> get_directory_contents (const char* path)
|
||||||
{
|
{
|
||||||
std::vector<std::string> contents;
|
std::vector<std::string> contents;
|
||||||
@@ -201,19 +188,18 @@ std::vector<std::string> get_directory_contents (const char* path)
|
|||||||
throw System_error("opendir", path, errno);
|
throw System_error("opendir", path, errno);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
std::vector<unsigned char> buffer(sizeof_dirent_for(dir));
|
|
||||||
struct dirent* dirent_buffer = reinterpret_cast<struct dirent*>(&buffer[0]);
|
|
||||||
struct dirent* ent = NULL;
|
struct dirent* ent = NULL;
|
||||||
int err = 0;
|
|
||||||
while ((err = readdir_r(dir, dirent_buffer, &ent)) == 0 && ent != NULL) {
|
errno = 0;
|
||||||
if (std::strcmp(ent->d_name, ".") == 0 || std::strcmp(ent->d_name, "..") == 0) {
|
|
||||||
continue;
|
while((ent = readdir(dir)) != NULL && errno == 0) {
|
||||||
}
|
if (std::strcmp(ent->d_name, ".") && std::strcmp(ent->d_name, ".."))
|
||||||
contents.push_back(ent->d_name);
|
contents.push_back(ent->d_name);
|
||||||
}
|
|
||||||
if (err != 0) {
|
|
||||||
throw System_error("readdir_r", path, errno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(errno)
|
||||||
|
throw System_error("readdir", path, errno);
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
throw;
|
throw;
|
||||||
|
|||||||
Reference in New Issue
Block a user