Skip to content

Commit

Permalink
Added code from oliverw#329 to resolve oliverw#325
Browse files Browse the repository at this point in the history
  • Loading branch information
BitWizJason committed Nov 23, 2021
1 parent 0ad8fc4 commit c6ffd2c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ logs/
src/Miningcore/config.json
src/Miningcore/config2.json
/src/Miningcore/coins2.json

!**/lib/**/*
Binary file modified libs/runtimes/win-x64/libethhash.dll
Binary file not shown.
11 changes: 10 additions & 1 deletion src/Native/libethhash/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
#include <stdio.h>
#include <errno.h>

int ethash_fseek(FILE* f, size_t offset, int origin)
{
#ifdef _WIN32
return _fseeki64(f, offset, origin);
#else
return fseeko(f, offset, origin);
#endif
}

enum ethash_io_rc ethash_io_prepare(
char const* dirname,
ethash_h256_t const seedhash,
Expand Down Expand Up @@ -91,7 +100,7 @@ enum ethash_io_rc ethash_io_prepare(
goto free_memo;
}
// make sure it's of the proper size
if (fseek(f, (long int)(file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1), SEEK_SET) != 0) {
if (ethash_fseek(f, file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1, SEEK_SET) != 0) {
fclose(f);
ETHASH_CRITICAL("Could not seek to the end of DAG file: \"%s\". Insufficient space?", tmpfile);
goto free_memo;
Expand Down
10 changes: 10 additions & 0 deletions src/Native/libethhash/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ enum ethash_io_rc {
#define ETHASH_CRITICAL(...)
#endif

/**
* An fseek wrapper for crossplatform 64-bit seek.
*
* @param f The file stream whose fd to get
* @param offset Number of bytes from @a origin
* @param origin Initial position
* @return Current offset or -1 to indicate an error
*/
int ethash_fseek(FILE* f, size_t offset, int origin);

/**
* Prepares io for ethash
*
Expand Down
10 changes: 10 additions & 0 deletions src/Native/libethhash/io_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,23 @@ char* ethash_io_create_filename(

bool ethash_file_size(FILE* f, size_t* ret_size)
{
#ifdef _WIN32
struct _stat64 st;
int fd;
if ((fd = _fileno(f)) == -1 || _fstat64(fd, &st) != 0) {
return false;
}
*ret_size = st.st_size;
return true;
#else
struct _stat st;
int fd;
if ((fd = _fileno(f)) == -1 || _fstat(fd, &st) != 0) {
return false;
}
*ret_size = st.st_size;
return true;
#endif
}

bool ethash_get_default_dirname(char* strbuf, size_t buffsize)
Expand Down
Binary file not shown.

0 comments on commit c6ffd2c

Please sign in to comment.