Skip to content

Commit

Permalink
consolidate file errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jul 1, 2024
1 parent 2d1630a commit 8cbe4f8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ knitr::opts_chunk$set(

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/secretbase?color=17411d)](https://CRAN.R-project.org/package=secretbase)
[![R-multiverse status](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcommunity.r-multiverse.org%2Fapi%2Fpackages%2Fsecretbase&query=%24.Version&label=r-multiverse)](https://community.r-multiverse.org/secretbase)
[![secretbase status badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=e67f53)](https://shikokuchuo.r-universe.dev/secretbase)
[![R-multiverse status](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcommunity.r-multiverse.org%2Fapi%2Fpackages%2Fsecretbase&query=%24.Version&label=r-multiverse&color=17411d)](https://community.r-multiverse.org/secretbase)
[![secretbase status badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=ff803d)](https://shikokuchuo.r-universe.dev/secretbase)
[![R-CMD-check](https://github.com/shikokuchuo/secretbase/workflows/R-CMD-check/badge.svg)](https://github.com/shikokuchuo/secretbase/actions)
[![codecov](https://codecov.io/gh/shikokuchuo/secretbase/graph/badge.svg)](https://app.codecov.io/gh/shikokuchuo/secretbase)
[![DOI](https://zenodo.org/badge/745691432.svg)](https://zenodo.org/doi/10.5281/zenodo.10553139)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[![CRAN
status](https://www.r-pkg.org/badges/version/secretbase?color=17411d)](https://CRAN.R-project.org/package=secretbase)
[![R-multiverse
status](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcommunity.r-multiverse.org%2Fapi%2Fpackages%2Fsecretbase&query=%24.Version&label=r-multiverse)](https://community.r-multiverse.org/secretbase)
status](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fcommunity.r-multiverse.org%2Fapi%2Fpackages%2Fsecretbase&query=%24.Version&label=r-multiverse&color=17411d)](https://community.r-multiverse.org/secretbase)
[![secretbase status
badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=e67f53)](https://shikokuchuo.r-universe.dev/secretbase)
badge](https://shikokuchuo.r-universe.dev/badges/secretbase?color=ff803d)](https://shikokuchuo.r-universe.dev/secretbase)
[![R-CMD-check](https://github.com/shikokuchuo/secretbase/workflows/R-CMD-check/badge.svg)](https://github.com/shikokuchuo/secretbase/actions)
[![codecov](https://codecov.io/gh/shikokuchuo/secretbase/graph/badge.svg)](https://app.codecov.io/gh/shikokuchuo/secretbase)
[![DOI](https://zenodo.org/badge/745691432.svg)](https://zenodo.org/doi/10.5281/zenodo.10553139)
Expand Down
4 changes: 2 additions & 2 deletions src/secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static void hash_file(mbedtls_sha3_context *ctx, const SEXP x) {
size_t cur;

if ((f = fopen(file, "rb")) == NULL)
Rf_error("file not found or no read permission at '%s'", file);
ERROR_FOPEN(file);

setbuf(f, NULL);

Expand All @@ -266,7 +266,7 @@ static void hash_file(mbedtls_sha3_context *ctx, const SEXP x) {

if (ferror(f)) {
fclose(f);
Rf_error("file read error at '%s'", file);
ERROR_FREAD(file);
}
fclose(f);

Expand Down
2 changes: 2 additions & 0 deletions src/secret.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ typedef struct nano_buf_s {
Rf_error("write buffer insufficient"); }
#define ERROR_OUT(x) if (x->len) R_Free(x->buf); \
Rf_error("serialization exceeds max length of raw vector")
#define ERROR_FOPEN(x) Rf_error("file not found or no read permission at '%s'", x)
#define ERROR_FREAD(x) Rf_error("file read error at '%s'", x)

void clear_buffer(void *, size_t);
SEXP hash_to_sexp(unsigned char *, size_t, int);
Expand Down
4 changes: 2 additions & 2 deletions src/secret2.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static void hash_file(mbedtls_sha256_context *ctx, const SEXP x) {
size_t cur;

if ((f = fopen(file, "rb")) == NULL)
Rf_error("file not found or no read permission at '%s'", file);
ERROR_FOPEN(file);

setbuf(f, NULL);

Expand All @@ -401,7 +401,7 @@ static void hash_file(mbedtls_sha256_context *ctx, const SEXP x) {

if (ferror(f)) {
fclose(f);
Rf_error("file read error at '%s'", file);
ERROR_FREAD(file);
}
fclose(f);

Expand Down
4 changes: 2 additions & 2 deletions src/secret3.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ static void hash_file(CSipHash *ctx, const SEXP x) {
size_t cur;

if ((f = fopen(file, "rb")) == NULL)
Rf_error("file not found or no read permission at '%s'", file);
ERROR_FOPEN(file);

while ((cur = fread(buf, sizeof(char), SB_BUF_SIZE, f))) {
c_siphash_append(ctx, buf, cur);
}

if (ferror(f)) {
fclose(f);
Rf_error("file read error at '%s'", file);
ERROR_FREAD(file);
}
fclose(f);

Expand Down

0 comments on commit 8cbe4f8

Please sign in to comment.