23 #include <sys/types.h> 34 return fopen(file_name, mode);
39 return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL;
44 int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
45 return rc != -1 || errno == EEXIST;
56 size_t filename_length
59 size_t dirlen = strlen(dirname);
60 size_t dest_size = dirlen + filename_length + 1;
61 if (dirname[dirlen] !=
'/') {
64 char*
name = malloc(dest_size);
71 if (dirname[dirlen] !=
'/') {
82 if ((fd = fileno(f)) == -1 || fstat(fd, &st) != 0) {
85 *ret_size = st.st_size;
91 static const char dir_suffix[] =
".ethash/";
93 char* home_dir = getenv(
"HOME");
94 if (!home_dir || strlen(home_dir) == 0)
96 struct passwd* pwd = getpwuid(getuid());
98 home_dir = pwd->pw_dir;
103 size_t len = strlen(home_dir);
107 if (home_dir[len] !=
'/') {
112 return ethash_strncat(strbuf, buffsize, dir_suffix,
sizeof(dir_suffix));
FILE * fopen(const fs::path &p, const char *mode)
char * ethash_strncat(char *dest, size_t dest_size, char const *src, size_t count)
An strncat wrapper for no-warnings crossplatform strncat.
FILE * ethash_fopen(char const *file_name, char const *mode)
An fopen wrapper for no-warnings crossplatform fopen.
bool ethash_mkdir(char const *dirname)
A cross-platform mkdir wrapper to create a directory or assert it's there.
bool ethash_file_size(FILE *f, size_t *ret_size)
Get a file's size.
int ethash_fileno(FILE *f)
Get a file descriptor number from a FILE stream.
char * ethash_io_create_filename(char const *dirname, char const *filename, size_t filename_length)
Create the filename for the DAG.
bool ethash_get_default_dirname(char *strbuf, size_t buffsize)
Gets the default directory name for the DAG depending on the system.