mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-10-31 11:07:44 +00:00
added fgetln.c to build
This commit is contained in:
parent
c6828d9ec1
commit
da9cc85bc1
@ -6,7 +6,7 @@
|
||||
# directories:
|
||||
# gen, gno, locale, stdio, stdlib, string, sys
|
||||
#
|
||||
# $Id: Makefile,v 1.1 1997/02/28 05:12:39 gdr Exp $
|
||||
# $Id: Makefile,v 1.2 1997/05/03 19:40:37 gdr Exp $
|
||||
#
|
||||
|
||||
.INCLUDE: ../const.mk
|
||||
@ -45,6 +45,7 @@ LIBC_OBJ = \
|
||||
gen/tty.o \
|
||||
gen/utime.o \
|
||||
locale/table.o \
|
||||
stdio/fgetln.o \
|
||||
stdio/mktemp.o \
|
||||
stdio/perror.o \
|
||||
stdio/tempnam.o \
|
||||
|
@ -1,10 +1,10 @@
|
||||
#
|
||||
# $Id: Makefile,v 1.1 1997/02/28 05:12:49 gdr Exp $
|
||||
# $Id: Makefile,v 1.2 1997/05/03 19:40:45 gdr Exp $
|
||||
#
|
||||
|
||||
.INCLUDE: ../../const.mk
|
||||
|
||||
OBJS = mktemp.o perror.o tempnam.o
|
||||
OBJS = fgetln.o mktemp.o perror.o tempnam.o
|
||||
|
||||
default: $(OBJS)
|
||||
|
||||
|
72
lib/libc/stdio/fgetln.c
Normal file
72
lib/libc/stdio/fgetln.c
Normal file
@ -0,0 +1,72 @@
|
||||
#ifdef __ORCAC__
|
||||
segment "libc_stdio";
|
||||
#endif
|
||||
|
||||
#pragma databank 1
|
||||
#pragma optimize 0
|
||||
#pragma debug 0
|
||||
#pragma memorymodel 0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINESIZE 20
|
||||
|
||||
char *
|
||||
fgetln (FILE *stream, size_t *len)
|
||||
{
|
||||
static char *buffer = NULL;
|
||||
static size_t currentBufferSize = 0;
|
||||
char *p, *q;
|
||||
|
||||
if (buffer == NULL) {
|
||||
currentBufferSize = LINESIZE;
|
||||
if ((buffer = malloc (currentBufferSize)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
p = fgets(buffer, currentBufferSize, stream);
|
||||
if (p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if ((p = strchr(buffer, '\n')) != NULL) {
|
||||
break;
|
||||
}
|
||||
p = buffer + strlen(buffer);
|
||||
if ((q = realloc(buffer, currentBufferSize + LINESIZE)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
buffer = q;
|
||||
currentBufferSize += LINESIZE;
|
||||
if (fgets(p, LINESIZE, stream) == NULL) {
|
||||
if (ferror(stream)) {
|
||||
return NULL;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*len = strlen(buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
#if 0 /* for testing fgetln */
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
char *p;
|
||||
size_t len;
|
||||
|
||||
while ((p = fgetln(stdin, &len)) != NULL) {
|
||||
printf("%d:%s", len, p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user