oldstdfiles.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Copyright (C) 1993-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>.
  14. As a special exception, if you link the code in this file with
  15. files compiled with a GNU compiler to produce an executable,
  16. that does not cause the resulting executable to be covered by
  17. the GNU Lesser General Public License. This exception does not
  18. however invalidate any other reasons why the executable file
  19. might be covered by the GNU Lesser General Public License.
  20. This exception applies to code released by its copyright holders
  21. in files containing the exception. */
  22. #include <shlib-compat.h>
  23. #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
  24. /* This file provides legacy definitions of _IO_stdin_, _IO_stdout_,
  25. and _IO_stderr_. See stdfiles.c for the current definitions. */
  26. #define _IO_USE_OLD_IO_FILE
  27. #include "libioP.h"
  28. #ifdef _IO_MTSAFE_IO
  29. #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
  30. static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
  31. struct _IO_FILE_plus NAME \
  32. = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
  33. #else
  34. #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
  35. struct _IO_FILE_plus NAME \
  36. = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
  37. #endif
  38. DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
  39. DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_, _IO_NO_READS);
  40. DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_, _IO_NO_READS+_IO_UNBUFFERED);
  41. compat_symbol (libc, _IO_stdin_, _IO_stdin_, GLIBC_2_0);
  42. compat_symbol (libc, _IO_stdout_, _IO_stdout_, GLIBC_2_0);
  43. compat_symbol (libc, _IO_stderr_, _IO_stderr_, GLIBC_2_0);
  44. #if defined __GNUC__ && __GNUC__ >= 2
  45. #include <stdio.h>
  46. extern const int _IO_stdin_used;
  47. weak_extern (_IO_stdin_used);
  48. #undef stdin
  49. #undef stdout
  50. #undef stderr
  51. extern FILE *stdin;
  52. extern FILE *stdout;
  53. extern FILE *stderr;
  54. static void _IO_check_libio (void) __THROW __attribute__ ((constructor));
  55. /* This function determines which shared C library the application
  56. was linked against. We then set up the stdin/stdout/stderr and
  57. _IO_list_all accordingly. */
  58. static void
  59. _IO_check_libio (void)
  60. {
  61. if (&_IO_stdin_used == NULL)
  62. {
  63. /* We are using the old one. */
  64. stdin = (FILE *) &_IO_stdin_;
  65. stdout = (FILE *) &_IO_stdout_;
  66. stderr = (FILE *) &_IO_stderr_;
  67. _IO_list_all = &_IO_stderr_;
  68. stdin->_vtable_offset = stdout->_vtable_offset
  69. = stderr->_vtable_offset =
  70. ((int) sizeof (struct _IO_FILE)
  71. - (int) sizeof (struct _IO_FILE_complete));
  72. if (_IO_stdin_.vtable != &_IO_old_file_jumps
  73. || _IO_stdout_.vtable != &_IO_old_file_jumps
  74. || _IO_stderr_.vtable != &_IO_old_file_jumps)
  75. IO_set_accept_foreign_vtables (&_IO_vtable_check);
  76. }
  77. }
  78. #endif
  79. #endif