mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 12:35:05 +02:00
Issue #216 - read-line remove trailing newlines
This commit is contained in:
parent
59d98aeb8c
commit
eac30107d3
2 changed files with 14 additions and 3 deletions
|
@ -7,6 +7,10 @@ Features
|
||||||
- Allow the compiler to optimize calls to `+`, `-`, `*`, and `/` that accept more than 2 arguments.
|
- Allow the compiler to optimize calls to `+`, `-`, `*`, and `/` that accept more than 2 arguments.
|
||||||
- Added support for bignums to `bitwise-if` from SRFI 60.
|
- Added support for bignums to `bitwise-if` from SRFI 60.
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
|
||||||
|
- Fix `read-line` to remove trailing newlines. Thanks to wasamasa for the bug report!
|
||||||
|
|
||||||
## 0.6.2 - August 25, 2017
|
## 0.6.2 - August 25, 2017
|
||||||
|
|
||||||
Features
|
Features
|
||||||
|
|
13
runtime.c
13
runtime.c
|
@ -6174,7 +6174,7 @@ object Cyc_io_read_line(void *data, object cont, object port)
|
||||||
{
|
{
|
||||||
FILE *stream = ((port_type *) port)->fp;
|
FILE *stream = ((port_type *) port)->fp;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
//int i = 0, c;
|
int len;
|
||||||
|
|
||||||
Cyc_check_port(data, port);
|
Cyc_check_port(data, port);
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
|
@ -6183,8 +6183,15 @@ object Cyc_io_read_line(void *data, object cont, object port)
|
||||||
set_thread_blocked(data, cont);
|
set_thread_blocked(data, cont);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (fgets(buf, 1023, stream) != NULL) {
|
if (fgets(buf, 1023, stream) != NULL) {
|
||||||
make_string(s, buf);
|
len = strlen(buf);
|
||||||
return_thread_runnable(data, &s);
|
{
|
||||||
|
// Remove trailing newline
|
||||||
|
if (len > 0 && buf[len - 1] == '\n') {
|
||||||
|
buf[len - 1] = '\0';
|
||||||
|
}
|
||||||
|
make_string_noalloc(s, buf, len);
|
||||||
|
return_thread_runnable(data, &s);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (feof(stream)) {
|
if (feof(stream)) {
|
||||||
return_thread_runnable(data, Cyc_EOF);
|
return_thread_runnable(data, Cyc_EOF);
|
||||||
|
|
Loading…
Add table
Reference in a new issue