mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-15 02:36:30 +08:00
Update to FreeBSD head 2017-08-01
Git mirror commit f5002f5e5f78cae9f0269d812dc0aedb0339312c. Update #3472.
This commit is contained in:
@@ -87,22 +87,25 @@ char *
|
||||
fgetln(FILE *fp, size_t *lenp)
|
||||
{
|
||||
unsigned char *p;
|
||||
char *ret;
|
||||
size_t len;
|
||||
size_t off;
|
||||
|
||||
#ifndef __rtems__
|
||||
FLOCKFILE_CANCELSAFE(fp);
|
||||
#else /* __rtems__ */
|
||||
FLOCKFILE(fp);
|
||||
#endif /* __rtems__ */
|
||||
ORIENT(fp, -1);
|
||||
/* make sure there is input */
|
||||
if (fp->_r <= 0 && __srefill(fp)) {
|
||||
*lenp = 0;
|
||||
FUNLOCKFILE(fp);
|
||||
return (NULL);
|
||||
ret = NULL;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* look for a newline in the input */
|
||||
if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) {
|
||||
char *ret;
|
||||
|
||||
/*
|
||||
* Found one. Flag buffer as modified to keep fseek from
|
||||
* `optimising' a backward seek, in case the user stomps on
|
||||
@@ -116,8 +119,7 @@ fgetln(FILE *fp, size_t *lenp)
|
||||
#endif /* __rtems__ */
|
||||
fp->_r -= len;
|
||||
fp->_p = p;
|
||||
FUNLOCKFILE(fp);
|
||||
return (ret);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -167,12 +169,18 @@ fgetln(FILE *fp, size_t *lenp)
|
||||
#ifdef notdef
|
||||
fp->_lb._base[len] = '\0';
|
||||
#endif
|
||||
ret = (char *)fp->_lb._base;
|
||||
end:
|
||||
#ifndef __rtems__
|
||||
FUNLOCKFILE_CANCELSAFE();
|
||||
#else /* __rtems__ */
|
||||
FUNLOCKFILE(fp);
|
||||
return ((char *)fp->_lb._base);
|
||||
#endif /* __rtems__ */
|
||||
return (ret);
|
||||
|
||||
error:
|
||||
*lenp = 0; /* ??? */
|
||||
fp->_flags |= __SERR;
|
||||
FUNLOCKFILE(fp);
|
||||
return (NULL); /* ??? */
|
||||
ret = NULL;
|
||||
goto end;
|
||||
}
|
||||
|
@@ -38,6 +38,9 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _STDIO_LOCAL_H
|
||||
#define _STDIO_LOCAL_H
|
||||
|
||||
#include <sys/types.h> /* for off_t */
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
@@ -65,7 +68,7 @@ extern FILE *__sfp(void);
|
||||
extern int __slbexpand(FILE *, size_t);
|
||||
#ifndef __rtems__
|
||||
extern int __srefill(FILE *);
|
||||
#else
|
||||
#else /* __rtems__ */
|
||||
/*
|
||||
* __srefill is used by fgetln(). The method is in newlib but the
|
||||
* prototype is in a private .h which is not installed.
|
||||
@@ -74,7 +77,7 @@ extern int __srefill(FILE *);
|
||||
extern int __srefill_r(struct _reent *,FILE *);
|
||||
|
||||
#define __srefill(_x) __srefill_r(__getreent(), _x)
|
||||
#endif
|
||||
#endif /* __rtems__ */
|
||||
extern int __sread(void *, char *, int);
|
||||
extern int __swrite(void *, char const *, int);
|
||||
extern fpos_t __sseek(void *, fpos_t, int);
|
||||
@@ -155,9 +158,32 @@ __fgetwc(FILE *fp, locale_t locale)
|
||||
*/
|
||||
#ifdef __rtems__
|
||||
#define ORIENT(fp, o)
|
||||
#else
|
||||
#else /* __rtems__ */
|
||||
#define ORIENT(fp, o) do { \
|
||||
if ((fp)->_orientation == 0) \
|
||||
(fp)->_orientation = (o); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
void __stdio_cancel_cleanup(void *);
|
||||
#define FLOCKFILE_CANCELSAFE(fp) \
|
||||
{ \
|
||||
struct _pthread_cleanup_info __cleanup_info__; \
|
||||
if (__isthreaded) { \
|
||||
_FLOCKFILE(fp); \
|
||||
___pthread_cleanup_push_imp( \
|
||||
__stdio_cancel_cleanup, (fp), \
|
||||
&__cleanup_info__); \
|
||||
} else { \
|
||||
___pthread_cleanup_push_imp( \
|
||||
__stdio_cancel_cleanup, NULL, \
|
||||
&__cleanup_info__); \
|
||||
} \
|
||||
{
|
||||
#define FUNLOCKFILE_CANCELSAFE() \
|
||||
(void)0; \
|
||||
} \
|
||||
___pthread_cleanup_pop_imp(1); \
|
||||
}
|
||||
|
||||
#endif /* __rtems__ */
|
||||
#endif /* _STDIO_LOCAL_H */
|
||||
|
Reference in New Issue
Block a user