You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
60 lines
1.5 KiB
/*
|
|
This file is part of ethash.
|
|
|
|
ethash is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
ethash is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with ethash. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
/** @file io_posix.c
|
|
* @author Lefteris Karapetsas <lefteris@ethdev.com>
|
|
* @date 2015
|
|
*/
|
|
|
|
#include "io.h"
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <errno.h>
|
|
#include <libgen.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
FILE* ethash_fopen(char const* file_name, char const* mode)
|
|
{
|
|
return fopen(file_name, mode);
|
|
}
|
|
|
|
char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count)
|
|
{
|
|
return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL;
|
|
}
|
|
|
|
bool ethash_mkdir(char const* dirname)
|
|
{
|
|
int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
|
return rc != -1 || errno == EEXIST;
|
|
}
|
|
|
|
int ethash_fileno(FILE *f)
|
|
{
|
|
return fileno(f);
|
|
}
|
|
|
|
bool ethash_file_size(FILE* f, size_t* ret_size)
|
|
{
|
|
struct stat st;
|
|
int fd;
|
|
if ((fd = fileno(f)) == -1 || fstat(fd, &st) != 0) {
|
|
return false;
|
|
}
|
|
*ret_size = st.st_size;
|
|
return true;
|
|
}
|
|
|