2002-06-21 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/stdio.h (__getline, __getdelim): New prototypes. * libc/include/time.h [HAVE_GETDATE](getdate, getdate_r): Ditto. [HAVE_GETDATE](getdate_err): New error code. * libc/stdio/Makefile.am: Add support for getline.c and getdelim.c. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/getdelim.c: New file. * libc/stdio/getline.c: Ditto. * libc/sys/linux/Makefile.am: Add support for getdate.c, getdate_err.c and ntp_gettime.c. Also add AM_CFLAGS to point to libc/stdio. * libc/sys/linux/Makefile.in: Regenerated. * libc/sys/linux/getdate.c: New file. * libc/sys/linux/getdate_err.c: Ditto. * libc/sys/linux/ntp_gettime.c: Ditto. * libc/sys/linux/time.c (adjtimex, ntp_adjtime): New functions. * libc/sys/linux/sys/stdio.h (getline, getdelim): New macros.
This commit is contained in:
@ -35,6 +35,8 @@ LIB_SOURCES = \
|
||||
getchar.c \
|
||||
getc_u.c \
|
||||
getchar_u.c \
|
||||
getdelim.c \
|
||||
getline.c \
|
||||
gets.c \
|
||||
getw.c \
|
||||
iprintf.c \
|
||||
@ -129,6 +131,8 @@ CHEWOUT_FILES = \
|
||||
getchar.def \
|
||||
getc_u.def \
|
||||
getchar_u.def \
|
||||
getdelim.def \
|
||||
getline.def \
|
||||
gets.def \
|
||||
getw.def \
|
||||
iprintf.def \
|
||||
|
@ -139,6 +139,8 @@ LIB_SOURCES = \
|
||||
getchar.c \
|
||||
getc_u.c \
|
||||
getchar_u.c \
|
||||
getdelim.c \
|
||||
getline.c \
|
||||
gets.c \
|
||||
getw.c \
|
||||
iprintf.c \
|
||||
@ -220,6 +222,8 @@ CHEWOUT_FILES = \
|
||||
getchar.def \
|
||||
getc_u.def \
|
||||
getchar_u.def \
|
||||
getdelim.def \
|
||||
getline.def \
|
||||
gets.def \
|
||||
getw.def \
|
||||
iprintf.def \
|
||||
@ -274,7 +278,8 @@ LIBS = @LIBS@
|
||||
@USE_LIBTOOL_FALSE@fseek.$(OBJEXT) fsetpos.$(OBJEXT) ftell.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@fvwrite.$(OBJEXT) fwalk.$(OBJEXT) fwrite.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@getc.$(OBJEXT) getchar.$(OBJEXT) getc_u.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@getchar_u.$(OBJEXT) gets.$(OBJEXT) getw.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@getchar_u.$(OBJEXT) getdelim.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@getline.$(OBJEXT) gets.$(OBJEXT) getw.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@iprintf.$(OBJEXT) makebuf.$(OBJEXT) mktemp.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@perror.$(OBJEXT) printf.$(OBJEXT) putc.$(OBJEXT) \
|
||||
@USE_LIBTOOL_FALSE@putchar.$(OBJEXT) putc_u.$(OBJEXT) \
|
||||
@ -299,15 +304,15 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
|
||||
@USE_LIBTOOL_TRUE@fopen.lo fprintf.lo fputc.lo fputs.lo fread.lo \
|
||||
@USE_LIBTOOL_TRUE@freopen.lo fscanf.lo fseek.lo fsetpos.lo ftell.lo \
|
||||
@USE_LIBTOOL_TRUE@fvwrite.lo fwalk.lo fwrite.lo getc.lo getchar.lo \
|
||||
@USE_LIBTOOL_TRUE@getc_u.lo getchar_u.lo gets.lo getw.lo iprintf.lo \
|
||||
@USE_LIBTOOL_TRUE@makebuf.lo mktemp.lo perror.lo printf.lo putc.lo \
|
||||
@USE_LIBTOOL_TRUE@putchar.lo putc_u.lo putchar_u.lo puts.lo putw.lo \
|
||||
@USE_LIBTOOL_TRUE@refill.lo remove.lo rename.lo rewind.lo rget.lo \
|
||||
@USE_LIBTOOL_TRUE@scanf.lo setbuf.lo setbuffer.lo setlinebuf.lo \
|
||||
@USE_LIBTOOL_TRUE@setvbuf.lo siprintf.lo snprintf.lo sprintf.lo \
|
||||
@USE_LIBTOOL_TRUE@sscanf.lo stdio.lo tmpfile.lo tmpnam.lo ungetc.lo \
|
||||
@USE_LIBTOOL_TRUE@vfscanf.lo vprintf.lo vscanf.lo vsnprintf.lo \
|
||||
@USE_LIBTOOL_TRUE@vsprintf.lo vsscanf.lo wbuf.lo wsetup.lo
|
||||
@USE_LIBTOOL_TRUE@getc_u.lo getchar_u.lo getdelim.lo getline.lo gets.lo \
|
||||
@USE_LIBTOOL_TRUE@getw.lo iprintf.lo makebuf.lo mktemp.lo perror.lo \
|
||||
@USE_LIBTOOL_TRUE@printf.lo putc.lo putchar.lo putc_u.lo putchar_u.lo \
|
||||
@USE_LIBTOOL_TRUE@puts.lo putw.lo refill.lo remove.lo rename.lo \
|
||||
@USE_LIBTOOL_TRUE@rewind.lo rget.lo scanf.lo setbuf.lo setbuffer.lo \
|
||||
@USE_LIBTOOL_TRUE@setlinebuf.lo setvbuf.lo siprintf.lo snprintf.lo \
|
||||
@USE_LIBTOOL_TRUE@sprintf.lo sscanf.lo stdio.lo tmpfile.lo tmpnam.lo \
|
||||
@USE_LIBTOOL_TRUE@ungetc.lo vfscanf.lo vprintf.lo vscanf.lo \
|
||||
@USE_LIBTOOL_TRUE@vsnprintf.lo vsprintf.lo vsscanf.lo wbuf.lo wsetup.lo
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
|
139
newlib/libc/stdio/getdelim.c
Normal file
139
newlib/libc/stdio/getdelim.c
Normal file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<getdelim>>---read a line up to a specified line delimeter
|
||||
|
||||
INDEX
|
||||
getdelim
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
int getdelim(char **<[bufptr]>, size_t *<[n]>,
|
||||
int <[delim]>, FILE *<[fp]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
int getdelim(<[bufptr]>, <[n]>, <[delim]>, <[fp]>)
|
||||
char **<[bufptr]>;
|
||||
size_t *<[n]>;
|
||||
int <[delim]>;
|
||||
FILE *<[fp]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<getdelim>> reads a file <[fp]> up to and possibly including a specified
|
||||
delimeter <[delim]>. The line is read into a buffer pointed to
|
||||
by <[bufptr]> and designated with size *<[n]>. If the buffer is
|
||||
not large enough, it will be dynamically grown by <<getdelim>>.
|
||||
As the buffer is grown, the pointer to the size <[n]> will be
|
||||
updated.
|
||||
|
||||
RETURNS
|
||||
<<getdelim>> returns <<-1>> if no characters were successfully read,
|
||||
otherwise, it returns the number of bytes successfully read.
|
||||
at end of file, the result is nonzero.
|
||||
|
||||
PORTABILITY
|
||||
<<getdelim>> is a glibc extension.
|
||||
|
||||
No supporting OS subroutines are directly required.
|
||||
*/
|
||||
|
||||
/* Copyright 2002, Red Hat Inc. - all rights reserved */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "local.h"
|
||||
|
||||
#define MIN_LINE_SIZE 4
|
||||
#define DEFAULT_LINE_SIZE 128
|
||||
|
||||
ssize_t
|
||||
__getdelim (bufptr, n, delim, fp)
|
||||
char **bufptr;
|
||||
size_t *n;
|
||||
int delim;
|
||||
FILE *fp;
|
||||
{
|
||||
char *buf;
|
||||
char *ptr;
|
||||
size_t newsize, numbytes;
|
||||
int pos;
|
||||
int ch;
|
||||
int cont;
|
||||
|
||||
if (fp == NULL || bufptr == NULL || n == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf = *bufptr;
|
||||
if (buf == NULL || *n < MIN_LINE_SIZE)
|
||||
{
|
||||
buf = (char *)realloc (*bufptr, DEFAULT_LINE_SIZE);
|
||||
if (buf == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*bufptr = buf;
|
||||
*n = DEFAULT_LINE_SIZE;
|
||||
}
|
||||
|
||||
_flockfile(fp);
|
||||
|
||||
CHECK_INIT(fp);
|
||||
|
||||
numbytes = *n;
|
||||
ptr = buf;
|
||||
|
||||
cont = 1;
|
||||
|
||||
while (cont)
|
||||
{
|
||||
/* fill buffer - leaving room for nul-terminator */
|
||||
while (--numbytes > 0)
|
||||
{
|
||||
if ((ch = getc_unlocked (fp)) == EOF)
|
||||
{
|
||||
cont = 0;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr++ = ch;
|
||||
if (ch == delim)
|
||||
{
|
||||
cont = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Buffer is too small so reallocate a larger buffer. */
|
||||
pos = ptr - buf;
|
||||
newsize = (*n << 1);
|
||||
buf = realloc (buf, newsize);
|
||||
if (buf == NULL)
|
||||
{
|
||||
cont = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
/* After reallocating, continue in new buffer */
|
||||
*bufptr = buf;
|
||||
*n = newsize;
|
||||
ptr = buf + pos;
|
||||
numbytes = newsize - pos;
|
||||
}
|
||||
|
||||
_funlockfile (fp);
|
||||
|
||||
/* if no input data, return failure */
|
||||
if (ptr == buf)
|
||||
return -1;
|
||||
|
||||
/* otherwise, nul-terminate and return number of bytes read */
|
||||
*ptr = '\0';
|
||||
return (ssize_t)(ptr - buf);
|
||||
}
|
||||
|
54
newlib/libc/stdio/getline.c
Normal file
54
newlib/libc/stdio/getline.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<getline>>---read a line from a file
|
||||
|
||||
INDEX
|
||||
getline
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
ssize_t getline(char **<[bufptr]>, size_t *<[n]>, FILE *<[fp]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdio.h>
|
||||
ssize_t getline(<[bufptr]>, <[n]>, <[fp]>)
|
||||
char **<[bufptr]>;
|
||||
size_t *<[n]>;
|
||||
FILE *<[fp]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<getline>> reads a file <[fp]> up to and possibly including the
|
||||
newline character. The line is read into a buffer pointed to
|
||||
by <[bufptr]> and designated with size *<[n]>. If the buffer is
|
||||
not large enough, it will be dynamically grown by <<getdelim>>.
|
||||
As the buffer is grown, the pointer to the size <[n]> will be
|
||||
updated.
|
||||
|
||||
<<getline>> is equivalent to getdelim(bufptr, n, '\n', fp);
|
||||
|
||||
RETURNS
|
||||
<<getline>> returns <<-1>> if no characters were successfully read,
|
||||
otherwise, it returns the number of bytes successfully read.
|
||||
at end of file, the result is nonzero.
|
||||
|
||||
PORTABILITY
|
||||
<<getline>> is a glibc extension.
|
||||
|
||||
No supporting OS subroutines are directly required.
|
||||
*/
|
||||
|
||||
/* Copyright 2002, Red Hat Inc. - all rights reserved */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern ssize_t __getdelim (char **, size_t *, int, FILE *);
|
||||
|
||||
ssize_t
|
||||
__getline (lptr, n, fp)
|
||||
char **lptr;
|
||||
size_t *n;
|
||||
FILE *fp;
|
||||
{
|
||||
return __getdelim (lptr, n, '\n', fp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user