gdb/contrib/expect-read1.c - gdb

Functions defined

Macros defined

Source code

  1. /* Copyright (C) 2013-2015 Free Software Foundation, Inc.

  2.    This file is part of GDB.

  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 3 of the License, or
  6.    (at your option) any later version.

  7.    This program 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
  10.    GNU General Public License for more details.

  11.    You should have received a copy of the GNU General Public License
  12.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  13. /* RTLD_NEXT requires _GNU_SOURCE.  */
  14. #define _GNU_SOURCE 1
  15. #include <dlfcn.h>
  16. #include <unistd.h>
  17. #include <fcntl.h>
  18. #include <stdlib.h>

  19. ssize_t
  20. read (int fd, void *buf, size_t count)
  21. {
  22.   static ssize_t (*read2) (int fd, void *buf, size_t count) = NULL;

  23.   if (read2 == NULL)
  24.     {
  25.       unsetenv ("LD_PRELOAD");
  26.       read2 = dlsym (RTLD_NEXT, "read");
  27.     }

  28.   if (count > 1 && isatty (fd) == 1)
  29.     count = 1;

  30.   return read2 (fd, buf, count);
  31. }