Skip to content

Commit

Permalink
fgkc
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonKercher committed Oct 12, 2021
1 parent 79a1fdc commit 3a1f162
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
25 changes: 8 additions & 17 deletions lib/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,13 @@ struct csv_reader* csv_reader_construct(struct csv_reader* reader)
{
init_sig();
*reader = (struct csv_reader) {
._in = NULL,
.offset = 0,
.quotes = QUOTE_RFC4180,
.normal = 0,
.failsafe_mode = false,
.trim = false,
};

reader->_in = malloc_(sizeof(*reader->_in));
*reader->_in = (struct csv_read_internal) {
.file = stdin,
.delim = {0},
.weak_delim = {0},
.embedded_break = {0},
.mmap_ptr = NULL,
.offset = 0,
.file_size = 0,
.fd = 0,
.rows = 0,
.embedded_breaks = 0,
.normorg = 0,
.is_mmap = false,
.fd = -1,
};

string_construct(&reader->_in->delim);
Expand Down Expand Up @@ -733,8 +718,14 @@ int csv_reader_close(struct csv_reader* self)
if (self->_in->mmap_ptr != NULL) {
csvfail_if_(munmap(self->_in->mmap_ptr, self->_in->file_size),
"munmap");
self->_in->mmap_ptr = NULL;
}
csvfail_if_(close(self->_in->fd), "close");
/* how this could be false? I don't know... */
if (self->_in->fd != -1) {
csvfail_if_(close(self->_in->fd), "close");
self->_in->fd = -1;
}

} else if (self->_in->file && self->_in->file != stdin) {
csvfail_if_(fclose(self->_in->file), "fclose");
}
Expand Down
13 changes: 1 addition & 12 deletions lib/writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@ struct csv_writer* csv_writer_construct(struct csv_writer* self)
{
init_sig();

*self = (struct csv_writer) {
._in = NULL,
QUOTE_RFC4180 /* quotes */
};
*self = (struct csv_writer) {.quotes = QUOTE_RFC4180};

self->_in = malloc_(sizeof(*self->_in));
*self->_in = (struct csv_write_internal) {
.file = stdout,
.tmp_node = NULL,
.tempname = {0},
.filename = {0},
.buffer = {0},
.delim = {0},
.rec_terminator = {0},
.reclen = 0,
.is_detached = false,
};

string_construct(&self->_in->tempname);
Expand Down

0 comments on commit 3a1f162

Please sign in to comment.