mirror of
https://github.com/swaywm/sway.git
synced 2025-10-31 22:25:26 -04:00
Address first round of review for generic blocks
This commit is contained in:
parent
51bb9d8573
commit
8bfa2def88
10 changed files with 34 additions and 32 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "readline.h"
|
||||
#include "log.h"
|
||||
#include <stdlib.h>
|
||||
|
|
@ -48,15 +49,21 @@ char *read_line(FILE *file) {
|
|||
return string;
|
||||
}
|
||||
|
||||
char *peek_line(FILE *file, int offset) {
|
||||
int pos = ftell(file);
|
||||
char *line = NULL;
|
||||
char *peek_line(FILE *file, int offset, long *position) {
|
||||
long pos = ftell(file);
|
||||
size_t length = 1;
|
||||
char *line = calloc(1, length);
|
||||
for (int i = 0; i <= offset; i++) {
|
||||
free(line);
|
||||
line = read_line(file);
|
||||
if (!line) {
|
||||
ssize_t read = getline(&line, &length, file);
|
||||
if (read < 0) {
|
||||
break;
|
||||
}
|
||||
if (line[read - 1] == '\n') {
|
||||
line[read - 1] = '\0';
|
||||
}
|
||||
}
|
||||
if (position) {
|
||||
*position = ftell(file);
|
||||
}
|
||||
fseek(file, pos, SEEK_SET);
|
||||
return line;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue