-#include "gdb_select.h"
-#include "filestuff.h"
-
-static ui_file_isatty_ftype null_file_isatty;
-static ui_file_write_ftype null_file_write;
-static ui_file_write_ftype null_file_write_async_safe;
-static ui_file_fputs_ftype null_file_fputs;
-static ui_file_read_ftype null_file_read;
-static ui_file_flush_ftype null_file_flush;
-static ui_file_delete_ftype null_file_delete;
-static ui_file_rewind_ftype null_file_rewind;
-static ui_file_put_ftype null_file_put;
-static ui_file_fseek_ftype null_file_fseek;
-
-struct ui_file
- {
- int *magic;
- ui_file_flush_ftype *to_flush;
- ui_file_write_ftype *to_write;
- ui_file_write_async_safe_ftype *to_write_async_safe;
- ui_file_fputs_ftype *to_fputs;
- ui_file_read_ftype *to_read;
- ui_file_delete_ftype *to_delete;
- ui_file_isatty_ftype *to_isatty;
- ui_file_rewind_ftype *to_rewind;
- ui_file_put_ftype *to_put;
- ui_file_fseek_ftype *to_fseek;
- void *to_data;
- };
-int ui_file_magic;
-
-struct ui_file *
-ui_file_new (void)
-{
- struct ui_file *file = XNEW (struct ui_file);
-
- file->magic = &ui_file_magic;
- set_ui_file_data (file, NULL, null_file_delete);
- set_ui_file_flush (file, null_file_flush);
- set_ui_file_write (file, null_file_write);
- set_ui_file_write_async_safe (file, null_file_write_async_safe);
- set_ui_file_fputs (file, null_file_fputs);
- set_ui_file_read (file, null_file_read);
- set_ui_file_isatty (file, null_file_isatty);
- set_ui_file_rewind (file, null_file_rewind);
- set_ui_file_put (file, null_file_put);
- set_ui_file_fseek (file, null_file_fseek);
- return file;
-}
-
-void
-ui_file_delete (struct ui_file *file)
-{
- file->to_delete (file);
- xfree (file);
-}
-
-static int
-null_file_isatty (struct ui_file *file)
-{
- return 0;
-}
-
-static void
-null_file_rewind (struct ui_file *file)
-{
- return;
-}
-
-static void
-null_file_put (struct ui_file *file,
- ui_file_put_method_ftype *write,
- void *dest)
-{
- return;
-}
-
-static void
-null_file_flush (struct ui_file *file)
-{
- return;
-}
-
-static void
-null_file_write (struct ui_file *file,
- const char *buf,
- long sizeof_buf)
-{
- if (file->to_fputs == null_file_fputs)
- /* Both the write and fputs methods are null. Discard the
- request. */
- return;
- else
- {
- /* The fputs method isn't null, slowly pass the write request
- onto that. FYI, this isn't as bad as it may look - the
- current (as of 1999-11-07) printf_* function calls fputc and
- fputc does exactly the below. By having a write function it
- is possible to clean up that code. */
- int i;
- char b[2];
-
- b[1] = '\0';
- for (i = 0; i < sizeof_buf; i++)
- {
- b[0] = buf[i];
- file->to_fputs (b, file);
- }
- return;
- }
-}
-
-static long
-null_file_read (struct ui_file *file,
- char *buf,
- long sizeof_buf)
-{
- errno = EBADF;
- return 0;
-}
-
-static void
-null_file_fputs (const char *buf, struct ui_file *file)
-{
- if (file->to_write == null_file_write)
- /* Both the write and fputs methods are null. Discard the
- request. */
- return;
- else
- {
- /* The write method was implemented, use that. */
- file->to_write (file, buf, strlen (buf));
- }
-}