From 9769edfa33abe2c4bd1352d7121aa2fadc17199a Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 13 Mar 2025 15:56:23 -0400 Subject: [PATCH] headers: Get glibc out of the default include path. It's needed by GCC2 stdc++, but we shouldn't be including it for all consumers of , which we were. Drop it, and adjust all the things that were relying on 's definition of __PRINTFLIKE to use the _PRINTFLIKE defined in BeBuild.h instead. Hopefully should not cause any breakage; the libroot implementation of __freading depended on this, but I didn't see anything else which did. --- headers/compatibility/bsd/stdio.h | 2 +- headers/{posix => cpp}/libio.h | 0 headers/posix/stdio.h | 12 ++++----- headers/posix/stdio_pre.h | 20 -------------- headers/private/kernel/console.h | 5 ++-- src/system/libroot/posix/glibc/libio/Jamfile | 1 + .../libroot/posix/glibc/libio/__freading.c | 26 +++++++++++++++++++ src/system/libroot/posix/stdio/Jamfile | 1 - src/system/libroot/posix/stdio/__freading.cpp | 17 ------------ 9 files changed, 36 insertions(+), 48 deletions(-) rename headers/{posix => cpp}/libio.h (100%) delete mode 100644 headers/posix/stdio_pre.h create mode 100644 src/system/libroot/posix/glibc/libio/__freading.c delete mode 100644 src/system/libroot/posix/stdio/__freading.cpp diff --git a/headers/compatibility/bsd/stdio.h b/headers/compatibility/bsd/stdio.h index f926978ed3..9f5f690095 100644 --- a/headers/compatibility/bsd/stdio.h +++ b/headers/compatibility/bsd/stdio.h @@ -19,7 +19,7 @@ extern "C" { char *fgetln(FILE *stream, size_t *_length); -int asprintf(char **ret, char const *format, ...) __PRINTFLIKE(2,3); +int asprintf(char **ret, char const *format, ...) _PRINTFLIKE(2,3); int vasprintf(char **ret, char const *format, va_list ap); diff --git a/headers/posix/libio.h b/headers/cpp/libio.h similarity index 100% rename from headers/posix/libio.h rename to headers/cpp/libio.h diff --git a/headers/posix/stdio.h b/headers/posix/stdio.h index 63125aa381..bde8ab4645 100644 --- a/headers/posix/stdio.h +++ b/headers/posix/stdio.h @@ -53,8 +53,8 @@ typedef off_t fpos_t; +typedef struct _IO_FILE FILE; -#include extern FILE *stdin; extern FILE *stdout; @@ -169,13 +169,13 @@ extern ssize_t getdelim(char **_line, size_t *_length, int delimiter, extern ssize_t getline(char **_line, size_t *_length, FILE *stream); /* formatted I/O */ -extern int printf(char const *format, ...) __PRINTFLIKE(1,2); +extern int printf(char const *format, ...) _PRINTFLIKE(1,2); #if !defined(_KERNEL_MODE) && !defined(_BOOT_MODE) && !defined(_LOADER_MODE) -extern int dprintf(int fd, char const *format, ...) __PRINTFLIKE(2,3); +extern int dprintf(int fd, char const *format, ...) _PRINTFLIKE(2,3); #endif -extern int fprintf(FILE *stream, char const *format, ...) __PRINTFLIKE(2,3); -extern int sprintf(char *string, char const *format, ...) __PRINTFLIKE(2,3); -extern int snprintf(char *string, size_t size, char const *format, ...) __PRINTFLIKE(3,4); +extern int fprintf(FILE *stream, char const *format, ...) _PRINTFLIKE(2,3); +extern int sprintf(char *string, char const *format, ...) _PRINTFLIKE(2,3); +extern int snprintf(char *string, size_t size, char const *format, ...) _PRINTFLIKE(3,4); extern int vprintf(char const *format, va_list ap); extern int vfprintf(FILE *stream, char const *format, va_list ap); extern int vsprintf(char *string, char const *format, va_list ap); diff --git a/headers/posix/stdio_pre.h b/headers/posix/stdio_pre.h deleted file mode 100644 index 3d37b86e4d..0000000000 --- a/headers/posix/stdio_pre.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2003-2012 Haiku, Inc. All Rights Reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef _STDIO_PRE_H_ -#define _STDIO_PRE_H_ - - -#ifndef _STDIO_H_ -# error "This file must be included from stdio.h!" -#endif - -#include - -typedef struct _IO_FILE FILE; - -#define __PRINTFLIKE(format, varargs) __attribute__ ((__format__ (__printf__, format, varargs))) -#define __SCANFLIKE(format, varargs) __attribute__((__format__ (__scanf__, format, varargs))) - -#endif /* _STDIO_PRE_H_ */ diff --git a/headers/private/kernel/console.h b/headers/private/kernel/console.h index b3cad2b9a6..b74ba160f4 100644 --- a/headers/private/kernel/console.h +++ b/headers/private/kernel/console.h @@ -10,7 +10,6 @@ #include -#include struct kernel_args; @@ -32,8 +31,8 @@ extern "C" { #endif int con_init(struct kernel_args *args); -void kprintf(const char *fmt, ...) __PRINTFLIKE(1,2); -void kprintf_xy(int x, int y, const char *fmt, ...) __PRINTFLIKE(3,4); +void kprintf(const char *fmt, ...) _PRINTFLIKE(1,2); +void kprintf_xy(int x, int y, const char *fmt, ...) _PRINTFLIKE(3,4); #ifdef __cplusplus } diff --git a/src/system/libroot/posix/glibc/libio/Jamfile b/src/system/libroot/posix/glibc/libio/Jamfile index 0b41ea12a3..0c1601d7e7 100644 --- a/src/system/libroot/posix/glibc/libio/Jamfile +++ b/src/system/libroot/posix/glibc/libio/Jamfile @@ -26,6 +26,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { MergeObject <$(architecture)>posix_gnu_libio.o : __fpurge.c + __freading.c __fsetlocking.c clearerr.c clearerr_u.c diff --git a/src/system/libroot/posix/glibc/libio/__freading.c b/src/system/libroot/posix/glibc/libio/__freading.c new file mode 100644 index 0000000000..c5fa659e7e --- /dev/null +++ b/src/system/libroot/posix/glibc/libio/__freading.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2000-2025 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, see + . */ + +#include + +int +__freading (FILE *fp) +{ + return ((fp->_flags & _IO_NO_WRITES) + || ((fp->_flags & (_IO_CURRENTLY_PUTTING | _IO_NO_READS)) == 0 + && fp->_IO_read_base != NULL)); +} diff --git a/src/system/libroot/posix/stdio/Jamfile b/src/system/libroot/posix/stdio/Jamfile index c271f8b9d9..9ec78b5de2 100644 --- a/src/system/libroot/posix/stdio/Jamfile +++ b/src/system/libroot/posix/stdio/Jamfile @@ -10,7 +10,6 @@ for architectureObject in [ MultiArchSubDirSetup ] { UsePrivateSystemHeaders ; MergeObject <$(architecture)>posix_stdio.o : - __freading.cpp _fseek.c remove.c rename.c diff --git a/src/system/libroot/posix/stdio/__freading.cpp b/src/system/libroot/posix/stdio/__freading.cpp deleted file mode 100644 index ece7bc922c..0000000000 --- a/src/system/libroot/posix/stdio/__freading.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. - * Distributed under the terms of the MIT License. - */ - -#include -#include - - -int -__freading(FILE* stream) -{ - // Return true, if writing is not allowed or the last operation was a read. - return (stream->_flags & _IO_NO_WRITES) != 0 - || ((stream->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING)) == 0 - && stream->_IO_read_base != NULL); -}