aboutsummaryrefslogtreecommitdiff
path: root/libio/iosetvbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'libio/iosetvbuf.c')
-rw-r--r--libio/iosetvbuf.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/libio/iosetvbuf.c b/libio/iosetvbuf.c
index 396ef2fb14..6d4bcff2bc 100644
--- a/libio/iosetvbuf.c
+++ b/libio/iosetvbuf.c
@@ -35,7 +35,9 @@ _IO_setvbuf (fp, buf, mode, size)
int mode;
_IO_size_t size;
{
+ int result;
CHECK_FILE (fp, EOF);
+ _IO_flockfile (fp);
switch (mode)
{
case _IOFBF:
@@ -58,25 +60,36 @@ _IO_setvbuf (fp, buf, mode, size)
A possibly cleaner alternative would be to add an
extra flag, but then flags are a finite resource. */
if (_IO_DOALLOCATE (fp) < 0)
- return EOF;
+ {
+ result = EOF;
+ goto unlock_return;
+ }
fp->_IO_file_flags &= ~_IO_LINE_BUF;
}
- return 0;
+ result = 0;
+ goto unlock_return;
}
break;
case _IOLBF:
fp->_IO_file_flags |= _IO_LINE_BUF;
if (buf == NULL)
- return 0;
+ {
+ result = 0;
+ goto unlock_return;
+ }
break;
case _IONBF:
buf = NULL;
size = 0;
break;
default:
- return EOF;
+ result = EOF;
+ goto unlock_return;
}
- return _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
+ result = _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
+unlock_return:
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_setvbuf, setvbuf)