libroot/glibc: Add missing stdio_ext methods needed by gnulib.

Otherwise it needs to use libio internals to implement these,
which we don't want. musl also exports all these methods for
the same reason.

Implementations taken from glibc 2.15, current gnulib (5077f67), and
in a few cases tweaked for better Haiku support.

Should fix #19479.
This commit is contained in:
Augustin Cavalier
2025-03-18 22:03:10 -04:00
parent 0796aaabfc
commit a5854d713e
14 changed files with 291 additions and 109 deletions
+13 -11
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2008-2012 Haiku, Inc. All Rights Reserved. * Copyright 2008-2025, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _STDIO_EXT_H_ #ifndef _STDIO_EXT_H_
@@ -16,19 +16,21 @@ extern "C" {
#define FSETLOCKING_INTERNAL 1 #define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_BYCALLER 2 #define FSETLOCKING_BYCALLER 2
/* The following stdio extensions are not implemented yet */
/* extern size_t __fufsize(FILE* stream); */
extern int __freading(FILE* stream);
/* extern int __fwriting(FILE* stream); */
/* extern int __freadable(FILE* stream); */
/* extern int __fwritable(FILE* stream); */
/* extern int __flbf(FILE* stream); */
extern void __fpurge(FILE* stream);
/* extern size_t __fpending(FILE* stream); */
extern void _flushlbf(void); extern void _flushlbf(void);
extern int __fsetlocking(FILE* stream, int type); extern int __fsetlocking(FILE* stream, int type);
extern int __freading(FILE* stream);
extern int __fwriting(FILE* stream);
extern int __freadable(FILE* stream);
extern int __fwritable(FILE* stream);
extern size_t __freadahead(FILE* stream);
extern const char* __freadptr(FILE* stream, size_t* size);
extern void __freadptrinc(FILE* stream, size_t inc);
extern int __flbf(FILE* stream);
extern size_t __fbufsize(FILE* stream);
extern size_t __fpending(FILE* stream);
extern void __fpurge(FILE* stream);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@@ -1,11 +0,0 @@
#ifndef _STDIO_EXT_H
# include <stdio-common/stdio_ext.h>
extern int __fsetlocking_internal (FILE *__fp, int __type) attribute_hidden;
#ifndef NOT_IN_libc
# define __fsetlocking(fp, type) INTUSE(__fsetlocking) (fp, type)
#endif
#endif
@@ -25,9 +25,19 @@ for architectureObject in [ MultiArchSubDirSetup ] {
UsePrivateHeaders libroot ; UsePrivateHeaders libroot ;
MergeObject <$(architecture)>posix_gnu_libio.o : MergeObject <$(architecture)>posix_gnu_libio.o :
__fbufsize.c
__flbf.c
__fpending.c
__fpurge.c __fpurge.c
__freadable.c
__freadahead.c
__freading.c __freading.c
__freadptr.c
__freadptrinc.c
__fseterr.c
__fsetlocking.c __fsetlocking.c
__fwritable.c
__fwriting.c
clearerr.c clearerr.c
clearerr_u.c clearerr_u.c
fcloseall.c fcloseall.c
@@ -0,0 +1,33 @@
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdio_ext.h>
size_t
__fbufsize (FILE *fp)
{
#ifdef __HAIKU__
if (fp->_flags & _IO_UNBUFFERED)
return 0;
#endif
if (fp->_mode > 0)
return fp->_wide_data->_IO_buf_end - fp->_wide_data->_IO_buf_base;
else
return fp->_IO_buf_end - fp->_IO_buf_base;
}
@@ -0,0 +1,25 @@
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdio_ext.h>
int
__flbf (FILE *fp)
{
return fp->_flags & _IO_LINE_BUF;
}
@@ -0,0 +1,28 @@
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdio_ext.h>
size_t
__fpending (FILE *fp)
{
if (fp->_mode > 0)
return fp->_wide_data->_IO_write_ptr - fp->_wide_data->_IO_write_base;
else
return fp->_IO_write_ptr - fp->_IO_write_base;
}
@@ -0,0 +1,25 @@
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdio_ext.h>
int
__freadable (FILE *fp)
{
return (fp->_flags & _IO_NO_READS) == 0;
}
@@ -0,0 +1,28 @@
/* Retrieve information about a FILE stream.
Copyright (C) 2007-2025 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <stdio_ext.h>
#include "libioP.h"
size_t
__freadahead (FILE *fp)
{
if (fp->_IO_write_ptr > fp->_IO_write_base)
return 0;
return (fp->_IO_read_end - fp->_IO_read_ptr)
+ (fp->_flags & _IO_IN_BACKUP ? fp->_IO_save_end - fp->_IO_save_base :
0);
}
@@ -0,0 +1,31 @@
/* Retrieve information about a FILE stream.
Copyright (C) 2007-2025 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <stdio_ext.h>
#include "libioP.h"
const char *
__freadptr (FILE *fp, size_t *sizep)
{
size_t size;
if (fp->_IO_write_ptr > fp->_IO_write_base)
return NULL;
size = fp->_IO_read_end - fp->_IO_read_ptr;
if (size == 0)
return NULL;
*sizep = size;
return (const char *) fp->_IO_read_ptr;
}
@@ -0,0 +1,24 @@
/* Skipping input from a FILE stream.
Copyright (C) 2007-2025 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <stdio_ext.h>
#include "libioP.h"
void
__freadptrinc (FILE *fp, size_t increment)
{
fp->_IO_read_ptr += increment;
}
@@ -0,0 +1,24 @@
/* Set the error indicator of a stream.
Copyright (C) 2007-2025 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <stdio_ext.h>
#include "libioP.h"
void
__fseterr (FILE *fp)
{
fp->_flags |= _IO_ERR_SEEN;
}
@@ -0,0 +1,25 @@
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdio_ext.h>
int
__fwritable (FILE *fp)
{
return (fp->_flags & _IO_NO_WRITES) == 0;
}
@@ -0,0 +1,25 @@
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdio_ext.h>
int
__fwriting (FILE *fp)
{
return fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING);
}
@@ -1,87 +0,0 @@
/* Functions to access FILE structure internals.
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
/* This header contains the same definitions as the header of the same name
on Sun's Solaris OS. */
#ifndef _STDIO_EXT_H
#define _STDIO_EXT_H 1
#include <stdio.h>
enum
{
/* Query current state of the locking status. */
FSETLOCKING_QUERY = 0,
#define FSETLOCKING_QUERY FSETLOCKING_QUERY
/* The library protects all uses of the stream functions, except for
uses of the *_unlocked functions, by calls equivalent to flockfile(). */
FSETLOCKING_INTERNAL,
#define FSETLOCKING_INTERNAL FSETLOCKING_INTERNAL
/* The user will take care of locking. */
FSETLOCKING_BYCALLER
#define FSETLOCKING_BYCALLER FSETLOCKING_BYCALLER
};
__BEGIN_DECLS
/* Return the size of the buffer of FP in bytes currently in use by
the given stream. */
extern size_t __fbufsize (FILE *__fp);
/* Return non-zero value iff the stream FP is opened readonly, or if the
last operation on the stream was a read operation. */
extern int __freading (FILE *__fp);
/* Return non-zero value iff the stream FP is opened write-only or
append-only, or if the last operation on the stream was a write
operation. */
extern int __fwriting (FILE *__fp);
/* Return non-zero value iff stream FP is not opened write-only or
append-only. */
extern int __freadable (FILE *__fp);
/* Return non-zero value iff stream FP is not opened read-only. */
extern int __fwritable (FILE *__fp);
/* Return non-zero value iff the stream FP is line-buffered. */
extern int __flbf (FILE *__fp);
/* Discard all pending buffered I/O on the stream FP. */
extern void __fpurge (FILE *__fp);
/* Return amount of output in bytes pending on a stream FP. */
extern size_t __fpending (FILE *__fp);
/* Flush all line-buffered files. */
extern void _flushlbf (void);
/* Set locking status of stream FP to TYPE. */
extern int __fsetlocking (FILE *__fp, int __type);
__END_DECLS
#endif /* stdio_ext.h */