mirror of
https://passt.top/passt
synced 2024-12-22 13:45:32 +00:00
f9e8ee0777
Functions and structures in lineread.c use plain int to record and report the length of lines we receive. This means we truncate the result from read(2) in some circumstances. Use ssize_t to avoid that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
33 lines
815 B
C
33 lines
815 B
C
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright Red Hat
|
|
* Author: David Gibson <david@gibson.dropbear.id.au>
|
|
*/
|
|
|
|
#ifndef LINEREAD_H
|
|
#define LINEREAD_H
|
|
|
|
#define LINEREAD_BUFFER_SIZE 8192
|
|
|
|
/**
|
|
* struct lineread - Line reader state
|
|
* @fd: File descriptor lines are read from
|
|
* @next_line: Offset in @buf of the start of the first line not yet
|
|
* returned by lineread_get()
|
|
* @count: Number of bytes in @buf read from the file, but not yet
|
|
* returned by lineread_get()
|
|
* @buf: Buffer storing data read from file.
|
|
*/
|
|
struct lineread {
|
|
int fd;
|
|
ssize_t next_line;
|
|
ssize_t count;
|
|
|
|
/* One extra byte for possible trailing \0 */
|
|
char buf[LINEREAD_BUFFER_SIZE+1];
|
|
};
|
|
|
|
void lineread_init(struct lineread *lr, int fd);
|
|
ssize_t lineread_get(struct lineread *lr, char **line);
|
|
|
|
#endif /* _LINEREAD_H */
|