summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/_flock_stub.c3
-rw-r--r--lib/libc/stdio/fdopen.c5
-rw-r--r--lib/libc/stdio/fgetwln.c2
-rw-r--r--lib/libc/stdio/findfp.c7
-rw-r--r--lib/libc/stdio/fmemopen.c3
-rw-r--r--lib/libc/stdio/fopen.c5
-rw-r--r--lib/libc/stdio/freopen.c5
-rw-r--r--lib/libc/stdio/ftell.c32
-rw-r--r--lib/libc/stdio/getchar.c2
-rw-r--r--lib/libc/stdio/stdio.c3
-rw-r--r--lib/libc/stdio/tmpfile.c7
-rw-r--r--lib/libc/stdio/vfscanf.c4
12 files changed, 49 insertions, 29 deletions
diff --git a/lib/libc/stdio/_flock_stub.c b/lib/libc/stdio/_flock_stub.c
index 0b61315..f53df35 100644
--- a/lib/libc/stdio/_flock_stub.c
+++ b/lib/libc/stdio/_flock_stub.c
@@ -55,6 +55,9 @@ __weak_reference(_flockfile_debug_stub, _flockfile_debug);
__weak_reference(_ftrylockfile, ftrylockfile);
__weak_reference(_funlockfile, funlockfile);
+void _flockfile_debug_stub(FILE *, char *, int);
+int _ftrylockfile(FILE *);
+
void
_flockfile(FILE *fp)
{
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c
index b936998..8bd9c2d 100644
--- a/lib/libc/stdio/fdopen.c
+++ b/lib/libc/stdio/fdopen.c
@@ -91,7 +91,10 @@ fdopen(int fd, const char *mode)
* O_APPEND bit set, assert __SAPP so that __swrite() caller
* will _sseek() to the end before write.
*/
- if ((oflags & O_APPEND) && !(fdflags & O_APPEND))
+ /* XXX: Reuse __SALC for O_APPEND. */
+ if (fdflags & O_APPEND)
+ fp->_flags |= __SALC;
+ else if (oflags & O_APPEND)
fp->_flags |= __SAPP;
fp->_file = fd;
fp->_cookie = fp;
diff --git a/lib/libc/stdio/fgetwln.c b/lib/libc/stdio/fgetwln.c
index 6d9087b..8439496 100644
--- a/lib/libc/stdio/fgetwln.c
+++ b/lib/libc/stdio/fgetwln.c
@@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$");
#include "local.h"
#include "xlocale_private.h"
+wchar_t *fgetwln_l(FILE * __restrict, size_t *, locale_t);
+
wchar_t *
fgetwln_l(FILE * __restrict fp, size_t *lenp, locale_t locale)
{
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c
index be196b7..0eabe82 100644
--- a/lib/libc/stdio/findfp.c
+++ b/lib/libc/stdio/findfp.c
@@ -113,7 +113,7 @@ moreglue(int n)
* Find a free FILE for fopen et al.
*/
FILE *
-__sfp()
+__sfp(void)
{
FILE *fp;
int n;
@@ -164,6 +164,7 @@ found:
*/
__warn_references(f_prealloc,
"warning: this program uses f_prealloc(), which is not recommended.");
+void f_prealloc(void);
void
f_prealloc(void)
@@ -195,7 +196,7 @@ f_prealloc(void)
* The name `_cleanup' is, alas, fairly well known outside stdio.
*/
void
-_cleanup()
+_cleanup(void)
{
/* (void) _fwalk(fclose); */
(void) _fwalk(__sflush); /* `cheating' */
@@ -205,7 +206,7 @@ _cleanup()
* __sinit() is called whenever stdio's internal variables must be set up.
*/
void
-__sinit()
+__sinit(void)
{
/* Make sure we clean up on exit. */
diff --git a/lib/libc/stdio/fmemopen.c b/lib/libc/stdio/fmemopen.c
index ebd3596..bcf187d 100644
--- a/lib/libc/stdio/fmemopen.c
+++ b/lib/libc/stdio/fmemopen.c
@@ -149,6 +149,9 @@ fmemopen(void * __restrict buf, size_t size, const char * __restrict mode)
return (NULL);
}
+ if (mode[0] == 'a')
+ f->_flags |= __SAPP;
+
/*
* Turn off buffering, so a write past the end of the buffer
* correctly returns a short object count.
diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c
index b08e336..b26f637 100644
--- a/lib/libc/stdio/fopen.c
+++ b/lib/libc/stdio/fopen.c
@@ -91,7 +91,10 @@ fopen(const char * __restrict file, const char * __restrict mode)
* we can do about this. (We could set __SAPP and check in
* fseek and ftell.)
*/
- if (oflags & O_APPEND)
+ if (oflags & O_APPEND) {
+ /* XXX: Reuse __SALC for O_APPEND. */
+ fp->_flags |= __SALC;
(void)_sseek(fp, (fpos_t)0, SEEK_END);
+ }
return (fp);
}
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index 4dcd50f..8b68bac 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -240,8 +240,11 @@ finish:
* we can do about this. (We could set __SAPP and check in
* fseek and ftell.)
*/
- if (oflags & O_APPEND)
+ if (oflags & O_APPEND) {
+ /* XXX: Reuse __SALC for O_APPEND. */
+ fp->_flags |= __SALC;
(void) _sseek(fp, (fpos_t)0, SEEK_END);
+ }
FUNLOCKFILE(fp);
return (fp);
}
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 745d500..0d2222b 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -88,7 +88,6 @@ _ftello(FILE *fp, fpos_t *offset)
{
fpos_t pos;
size_t n;
- int dflags;
if (fp->_seek == NULL) {
errno = ESPIPE; /* historic practice */
@@ -120,21 +119,24 @@ _ftello(FILE *fp, fpos_t *offset)
if (HASUB(fp))
pos -= fp->_r; /* Can be negative at this point. */
} else if ((fp->_flags & __SWR) && fp->_p != NULL) {
- dflags = 0;
- if (fp->_flags & __SAPP)
- dflags = O_APPEND;
- else if (fp->_file != -1 &&
- (dflags = _fcntl(fp->_file, F_GETFL)) < 0)
- return (1);
- if ((dflags & O_APPEND) &&
- (pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
- if ((fp->_flags & __SOPT) || __sflush(fp) ||
- (pos = _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
- return (1);
- else {
- *offset = pos;
- return (0);
+ /* XXX: Reuse __SALC for O_APPEND. */
+ if (fp->_flags & (__SAPP|__SALC)) {
+ int serrno = errno;
+
+ errno = 0;
+ if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
+ if (errno == ESPIPE ||
+ (fp->_flags & __SOPT) || __sflush(fp) ||
+ (pos =
+ _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
+ return (1);
+ else {
+ errno = serrno;
+ *offset = pos;
+ return (0);
+ }
}
+ errno = serrno;
}
/*
* Writing. Any buffered characters cause the
diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c
index 21040bc..2815072 100644
--- a/lib/libc/stdio/getchar.c
+++ b/lib/libc/stdio/getchar.c
@@ -49,7 +49,7 @@ __FBSDID("$FreeBSD$");
#undef getchar_unlocked
int
-getchar()
+getchar(void)
{
int retval;
FLOCKFILE(stdin);
diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c
index 44ee0ab..fc2e74b 100644
--- a/lib/libc/stdio/stdio.c
+++ b/lib/libc/stdio/stdio.c
@@ -117,7 +117,8 @@ _swrite(FILE *fp, char const *buf, int n)
ret = (*fp->_write)(fp->_cookie, buf, n);
/* __SOFF removed even on success in case O_APPEND mode is set. */
if (ret >= 0) {
- if ((fp->_flags & (__SAPP|__SOFF)) == (__SAPP|__SOFF) &&
+ /* XXX: Reuse __SALC for O_APPEND. */
+ if ((fp->_flags & __SOFF) && !(fp->_flags & __SALC) &&
fp->_offset <= OFF_MAX - ret)
fp->_offset += ret;
else
diff --git a/lib/libc/stdio/tmpfile.c b/lib/libc/stdio/tmpfile.c
index c67d1e4..e5a2be1 100644
--- a/lib/libc/stdio/tmpfile.c
+++ b/lib/libc/stdio/tmpfile.c
@@ -46,9 +46,10 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <paths.h>
#include "un-namespace.h"
+#include "libc_private.h"
FILE *
-tmpfile()
+tmpfile(void)
{
sigset_t set, oset;
FILE *fp;
@@ -69,7 +70,7 @@ tmpfile()
return (NULL);
sigfillset(&set);
- (void)_sigprocmask(SIG_BLOCK, &set, &oset);
+ (void)__libc_sigprocmask(SIG_BLOCK, &set, &oset);
fd = mkstemp(buf);
if (fd != -1)
@@ -77,7 +78,7 @@ tmpfile()
free(buf);
- (void)_sigprocmask(SIG_SETMASK, &oset, NULL);
+ (void)__libc_sigprocmask(SIG_SETMASK, &oset, NULL);
if (fd == -1)
return (NULL);
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index 50f0690..b537263 100644
--- a/lib/libc/stdio/vfscanf.c
+++ b/lib/libc/stdio/vfscanf.c
@@ -814,9 +814,7 @@ match_failure:
* considered part of the scanset.
*/
static const u_char *
-__sccl(tab, fmt)
- char *tab;
- const u_char *fmt;
+__sccl(char *tab, const u_char *fmt)
{
int c, n, v, i;
struct xlocale_collate *table =
OpenPOWER on IntegriCloud