diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-10-17 12:51:13 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-10-17 14:15:31 +0200 |
| commit | bd354843c2751ec6c7b5b85ef08f9145f6232e6e (patch) | |
| tree | 384528ba3c384160b5a07159f7e49fe6efdd0f01 /text.c | |
| parent | 9c4999fc9ee4a071bba068e68d690ba637ec28f5 (diff) | |
| download | vis-bd354843c2751ec6c7b5b85ef08f9145f6232e6e.tar.gz vis-bd354843c2751ec6c7b5b85ef08f9145f6232e6e.tar.xz | |
Read stdin when given - as filename
Diffstat (limited to 'text.c')
| -rw-r--r-- | text.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -692,6 +692,18 @@ out: return NULL; } +Text *text_load_fd(int fd) { + Text *txt = text_load(NULL); + if (!txt) + return NULL; + char buf[1024]; + for (ssize_t len = 0; (len = read(fd, buf, sizeof buf)) > 0;) + text_insert(txt, text_size(txt), buf, len); + text_snapshot(txt); + txt->fd = fd; + return txt; +} + static void print_piece(Piece *p) { fprintf(stderr, "index: %d\tnext: %d\tprev: %d\t len: %d\t data: %p\n", p->index, p->next ? p->next->index : -1, |
