Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions inst/include/XVector_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ void filexp_putc(
int c
);

size_t filexp_fwrite(
SEXP filexp,
const void *data_ptr,
size_t size,
size_t nitems
);

int delete_trailing_LF_or_CRLF(
const char *buf,
int buf_len
Expand Down
5 changes: 5 additions & 0 deletions inst/include/_XVector_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ DEFINE_NOVALUE_CCALLABLE_STUB(filexp_putc,
( filexp, c)
)

DEFINE_CCALLABLE_STUB(size_t, filexp_fwrite,
(SEXP filexp, const void *data_ptr, size_t size, size_t nitems),
( filexp, data_ptr, size, nitems)
)

DEFINE_CCALLABLE_STUB(int, delete_trailing_LF_or_CRLF,
(const char *buf, int buf_len),
( buf, buf_len)
Expand Down
1 change: 1 addition & 0 deletions src/R_init_XVector.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ void R_init_XVector(DllInfo *info)
REGISTER_CCALLABLE(_filexp_rewind);
REGISTER_CCALLABLE(_filexp_puts);
REGISTER_CCALLABLE(_filexp_putc);
REGISTER_CCALLABLE(_filexp_fwrite);
REGISTER_CCALLABLE(_delete_trailing_LF_or_CRLF);

/* Ocopy_byteblocks.c */
Expand Down
7 changes: 7 additions & 0 deletions src/XVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ void _filexp_putc(
int c
);

size_t _filexp_fwrite(
SEXP filexp,
const void *data_ptr,
size_t size,
size_t nitems
);

SEXP new_input_filexp(SEXP filepath);

SEXP rewind_filexp(SEXP filexp);
Expand Down
30 changes: 30 additions & 0 deletions src/io_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,31 @@ static void oZFile_putc(const ZFile *zfile, int c)
error("write error");
}

static size_t oZFile_fwrite(const ZFile *zfile, const void *data_ptr,
size_t size, size_t nitems)
{
int ztype;
size_t n = 0;
void *file;

ztype = zfile->ztype;
file = zfile->file;
switch (ztype) {
case UNCOMPRESSED:
n = fwrite(data_ptr, size, nitems, (FILE *) file);
break;
case GZ_TYPE:
n = gzfwrite(data_ptr, size, nitems, (gzFile) file);
break;
default:
error(INTERNAL_ERR_IN "oZFile_puts(): "
"invalid ztype value %d", ztype);
}
if(n == nitems) return nitems;
error("write error (attempted to write %zu elements, wrote %zu)",
nitems, n);
}

/****************************************************************************
* Initialization/close.
*/
Expand Down Expand Up @@ -540,6 +565,11 @@ void _filexp_putc(SEXP filexp, int c)
return;
}

size_t _filexp_fwrite(SEXP filexp, const void *data_ptr, size_t size, size_t nitems){
CHECK_USER_INTERRUPT(2000);
return oZFile_fwrite(R_ExternalPtrAddr(filexp), data_ptr, size, nitems);
}

static SEXP new_filexp(SEXP filepath,
const char *mode, const char *compress, int level)
{
Expand Down