Browse Source

Update paths so macos is consistent with linux and windows isn't using wchar.

cl-refactor
subtly 10 years ago
parent
commit
6879c04393
  1. 13
      io_posix.c
  2. 4
      io_win32.c

13
io_posix.c

@ -26,6 +26,10 @@
#include <libgen.h> #include <libgen.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#if defined(__APPLE__)
#include <stdlib.h>
#include <pwd.h>
#endif
FILE* ethash_fopen(char const* file_name, char const* mode) FILE* ethash_fopen(char const* file_name, char const* mode)
{ {
@ -89,6 +93,15 @@ bool ethash_get_default_dirname(char* strbuf, size_t buffsize)
static const char dir_suffix[] = ".ethash/"; static const char dir_suffix[] = ".ethash/";
strbuf[0] = '\0'; strbuf[0] = '\0';
char* home_dir = getenv("HOME"); char* home_dir = getenv("HOME");
#if defined(__APPLE__)
if (!home_dir || strlen(home_dir) == 0)
{
struct passwd* pwd = getpwuid(getuid());
if (pwd)
home_dir = pwd->pw_dir;
}
#endif
size_t len = strlen(home_dir); size_t len = strlen(home_dir);
if (!ethash_strncat(strbuf, buffsize, home_dir, len)) { if (!ethash_strncat(strbuf, buffsize, home_dir, len)) {
return false; return false;

4
io_win32.c

@ -87,9 +87,9 @@ bool ethash_file_size(FILE* f, size_t* ret_size)
bool ethash_get_default_dirname(char* strbuf, size_t buffsize) bool ethash_get_default_dirname(char* strbuf, size_t buffsize)
{ {
static const char dir_suffix[] = "Appdata\\Ethash\\"; static const char dir_suffix[] = "Ethash\\";
strbuf[0] = '\0'; strbuf[0] = '\0';
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, (WCHAR*)strbuf))) { if (!SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, (CHAR*)strbuf))) {
return false; return false;
} }
if (!ethash_strncat(strbuf, buffsize, "\\", 1)) { if (!ethash_strncat(strbuf, buffsize, "\\", 1)) {

Loading…
Cancel
Save