diff options
| author | emersion <contact@emersion.fr> | 2019-01-08 10:05:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-08 10:05:37 +0100 |
| commit | 140bc2dd5b81205df58bf06e695788e689fae397 (patch) | |
| tree | 6a88913630734736763b12ec0b10da68ef413256 /common/readline.c | |
| parent | 353d9ed74f3560e12500c08920cf8a1ca3344cc2 (diff) | |
| parent | 5bef06adfdac4ce9940dcaf2d90a4bdffae7bba9 (diff) | |
Merge pull request #3275 from ianyfan/remove-readline
Rewrite strip_whitespace and remove readline.c
Diffstat (limited to 'common/readline.c')
| -rw-r--r-- | common/readline.c | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/common/readline.c b/common/readline.c deleted file mode 100644 index 58652429..00000000 --- a/common/readline.c +++ /dev/null @@ -1,72 +0,0 @@ -#define _POSIX_C_SOURCE 200809L -#include "readline.h" -#include "log.h" -#include <stdlib.h> -#include <stdio.h> - -char *read_line(FILE *file) { - size_t length = 0, size = 128; - char *string = malloc(size); - char lastChar = '\0'; - if (!string) { - wlr_log(WLR_ERROR, "Unable to allocate memory for read_line"); - return NULL; - } - while (1) { - int c = getc(file); - if (c == '\n' && lastChar == '\\'){ - --length; // Ignore last character. - lastChar = '\0'; - continue; - } - if (c == EOF || c == '\n' || c == '\0') { - break; - } - if (c == '\r') { - continue; - } - lastChar = c; - if (length == size) { - char *new_string = realloc(string, size *= 2); - if (!new_string) { - free(string); - wlr_log(WLR_ERROR, "Unable to allocate memory for read_line"); - return NULL; - } - string = new_string; - } - string[length++] = c; - } - if (length + 1 == size) { - char *new_string = realloc(string, length + 1); - if (!new_string) { - free(string); - return NULL; - } - string = new_string; - } - string[length] = '\0'; - return string; -} - -char *peek_line(FILE *file, int line_offset, long *position) { - long pos = ftell(file); - size_t length = 0; - char *line = NULL; - for (int i = 0; i <= line_offset; i++) { - ssize_t read = getline(&line, &length, file); - if (read < 0) { - free(line); - line = NULL; - break; - } - if (read > 0 && line[read - 1] == '\n') { - line[read - 1] = '\0'; - } - } - if (position) { - *position = ftell(file); - } - fseek(file, pos, SEEK_SET); - return line; -} |
