keyring: compile and work on MinGW
Thanks for suggestion&test to Jens-Uwe Rammelt <jens-uwer@web.de>.
This commit is contained in:
		
							parent
							
								
									4cd47302b9
								
							
						
					
					
						commit
						06378a826a
					
				| 
						 | 
					@ -256,6 +256,19 @@ sencode* keyring::serialize_pubkeys (const pubkey_storage&pubs)
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * OS/disk functions
 | 
					 * OS/disk functions
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef WIN32
 | 
				
			||||||
 | 
					#define SECRETS_FILENAME "\\secrets"
 | 
				
			||||||
 | 
					#define PUBKEYS_FILENAME "\\pubkeys"
 | 
				
			||||||
 | 
					#define LOCK_FILENAME "\\lock"
 | 
				
			||||||
 | 
					#define CCR_CONFDIR "\\.ccr"
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define SECRETS_FILENAME "/secrets"
 | 
				
			||||||
 | 
					#define PUBKEYS_FILENAME "/pubkeys"
 | 
				
			||||||
 | 
					#define LOCK_FILENAME "/lock"
 | 
				
			||||||
 | 
					#define CCR_CONFDIR "/.ccr"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static std::string get_user_dir()
 | 
					static std::string get_user_dir()
 | 
				
			||||||
| 
						 | 
					@ -263,8 +276,8 @@ static std::string get_user_dir()
 | 
				
			||||||
	const char*tmp = getenv ("CCR_DIR");
 | 
						const char*tmp = getenv ("CCR_DIR");
 | 
				
			||||||
	if (tmp) return std::string (tmp);
 | 
						if (tmp) return std::string (tmp);
 | 
				
			||||||
	const char*home = getenv ("HOME");
 | 
						const char*home = getenv ("HOME");
 | 
				
			||||||
	if (home) return std::string (home) + "/.ccr";
 | 
						if (home) return std::string (home) + CCR_CONFDIR;
 | 
				
			||||||
	return "./.ccr"; //fallback for absolutely desolate systems
 | 
						return "." CCR_CONFDIR; //fallback for absolutely desolate systems
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
| 
						 | 
					@ -276,11 +289,6 @@ static std::string get_user_dir()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <fstream>
 | 
					#include <fstream>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SECRETS_FILENAME "/secrets"
 | 
					 | 
				
			||||||
#define PUBKEYS_FILENAME "/pubkeys"
 | 
					 | 
				
			||||||
#define LOCK_FILENAME "/lock"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * prepares the user directory with empty files and similar stuff.
 | 
					 * prepares the user directory with empty files and similar stuff.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -322,7 +330,11 @@ static bool ensure_empty_sencode_file (const std::string&fn,
 | 
				
			||||||
static bool prepare_user_dir (const std::string&dir)
 | 
					static bool prepare_user_dir (const std::string&dir)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	//try to create the directory, continue if it's already there
 | 
						//try to create the directory, continue if it's already there
 | 
				
			||||||
 | 
					#ifdef WIN32
 | 
				
			||||||
 | 
						if (mkdir (dir.c_str() ) ) {
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
	if (mkdir (dir.c_str(), 0777) ) {
 | 
						if (mkdir (dir.c_str(), 0777) ) {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
		if (errno != EEXIST) return false;
 | 
							if (errno != EEXIST) return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -419,11 +431,15 @@ bool keyring::open()
 | 
				
			||||||
	lockfd = creat (fn.c_str(), S_IRUSR | S_IWUSR);
 | 
						lockfd = creat (fn.c_str(), S_IRUSR | S_IWUSR);
 | 
				
			||||||
	if (lockfd < 0) return false;
 | 
						if (lockfd < 0) return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef WIN32
 | 
				
			||||||
 | 
						//no locking on windows yet
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
	if (flock (lockfd, LOCK_EX) ) {
 | 
						if (flock (lockfd, LOCK_EX) ) {
 | 
				
			||||||
		::close (lockfd);
 | 
							::close (lockfd);
 | 
				
			||||||
		lockfd = -1;
 | 
							lockfd = -1;
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//load the public keys
 | 
						//load the public keys
 | 
				
			||||||
	fn = dir + PUBKEYS_FILENAME;
 | 
						fn = dir + PUBKEYS_FILENAME;
 | 
				
			||||||
| 
						 | 
					@ -470,7 +486,12 @@ bool keyring::close()
 | 
				
			||||||
	std::string fn = get_user_dir() + LOCK_FILENAME;
 | 
						std::string fn = get_user_dir() + LOCK_FILENAME;
 | 
				
			||||||
	unlink (fn.c_str() );
 | 
						unlink (fn.c_str() );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef WIN32
 | 
				
			||||||
 | 
						//no locking on windows yet
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
	flock (lockfd, LOCK_UN);
 | 
						flock (lockfd, LOCK_UN);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	::close (lockfd);
 | 
						::close (lockfd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	lockfd = -1;
 | 
						lockfd = -1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue