sync with OpenBSD -current

This commit is contained in:
purplerain 2024-08-14 02:30:10 +00:00
parent 302c0be22f
commit ee61daa776
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
105 changed files with 1609 additions and 484 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: fseek.c,v 1.14 2022/05/14 05:06:32 guenther Exp $ */
/* $OpenBSD: fseek.c,v 1.15 2024/08/12 20:53:09 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@ -116,7 +116,8 @@ fseeko(FILE *fp, off_t offset, int whence)
/*
* Can only optimise if:
* reading (and not reading-and-writing);
* not unbuffered; and
* not unbuffered;
* not immediately after an fflush(); and
* this is a `regular' Unix file (and hence seekfn==__sseek).
* We must check __NBF first, because it is possible to have __NBF
* and __SOPT both set.
@ -125,6 +126,8 @@ fseeko(FILE *fp, off_t offset, int whence)
__smakebuf(fp);
if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT))
goto dumb;
if (fp->_r == 0 && (fp->_p == NULL || fp->_p == fp->_bf._base))
goto dumb;
if ((fp->_flags & __SOPT) == 0) {
if (seekfn != __sseek ||
fp->_file < 0 || fstat(fp->_file, &st) == -1 ||
@ -228,7 +231,7 @@ fseeko(FILE *fp, off_t offset, int whence)
* do it. Allow the seek function to change fp->_bf._base.
*/
dumb:
if (__sflush(fp) ||
if (((fp->_flags & __SWR) && __sflush(fp)) ||
(*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {
FUNLOCKFILE(fp);
return (EOF);