Add libString.
This commit is contained in:
parent
57ccfb9e8f
commit
7f11104a57
20 changed files with 1315 additions and 0 deletions
31
src/libString/s_read_line.c
Normal file
31
src/libString/s_read_line.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <bio.h>
|
||||
#include "libString.h"
|
||||
|
||||
/* Append an input line to a String.
|
||||
*
|
||||
* Returns a pointer to the character string (or 0).
|
||||
* Trailing newline is left on.
|
||||
*/
|
||||
extern char *
|
||||
s_read_line(Biobuf *fp, String *to)
|
||||
{
|
||||
char *cp;
|
||||
int llen;
|
||||
|
||||
if(to->ref > 1)
|
||||
sysfatal("can't s_read_line a shared string");
|
||||
s_terminate(to);
|
||||
cp = Brdline(fp, '\n');
|
||||
if(cp == 0)
|
||||
return 0;
|
||||
llen = Blinelen(fp);
|
||||
if(to->end - to->ptr < llen)
|
||||
s_grow(to, llen);
|
||||
memmove(to->ptr, cp, llen);
|
||||
cp = to->ptr;
|
||||
to->ptr += llen;
|
||||
s_terminate(to);
|
||||
return cp;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue