Replace copyreloc-main.c with copyreloc-main.S
[platform/upstream/binutils.git] / gdb / ui-file.c
1 /* UI_FILE - a generic STDIO like output stream.
2
3    Copyright (C) 1999-2014 Free Software Foundation, Inc.
4
5    This file is part of GDB.
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* Implement the ``struct ui_file'' object.  */
21
22 #include "defs.h"
23 #include "ui-file.h"
24 #include "gdb_obstack.h"
25 #include "gdb_select.h"
26 #include "filestuff.h"
27
28 static ui_file_isatty_ftype null_file_isatty;
29 static ui_file_write_ftype null_file_write;
30 static ui_file_write_ftype null_file_write_async_safe;
31 static ui_file_fputs_ftype null_file_fputs;
32 static ui_file_read_ftype null_file_read;
33 static ui_file_flush_ftype null_file_flush;
34 static ui_file_delete_ftype null_file_delete;
35 static ui_file_rewind_ftype null_file_rewind;
36 static ui_file_put_ftype null_file_put;
37 static ui_file_fseek_ftype null_file_fseek;
38
39 struct ui_file
40   {
41     int *magic;
42     ui_file_flush_ftype *to_flush;
43     ui_file_write_ftype *to_write;
44     ui_file_write_async_safe_ftype *to_write_async_safe;
45     ui_file_fputs_ftype *to_fputs;
46     ui_file_read_ftype *to_read;
47     ui_file_delete_ftype *to_delete;
48     ui_file_isatty_ftype *to_isatty;
49     ui_file_rewind_ftype *to_rewind;
50     ui_file_put_ftype *to_put;
51     ui_file_fseek_ftype *to_fseek;
52     void *to_data;
53   };
54 int ui_file_magic;
55
56 struct ui_file *
57 ui_file_new (void)
58 {
59   struct ui_file *file = xmalloc (sizeof (struct ui_file));
60
61   file->magic = &ui_file_magic;
62   set_ui_file_data (file, NULL, null_file_delete);
63   set_ui_file_flush (file, null_file_flush);
64   set_ui_file_write (file, null_file_write);
65   set_ui_file_write_async_safe (file, null_file_write_async_safe);
66   set_ui_file_fputs (file, null_file_fputs);
67   set_ui_file_read (file, null_file_read);
68   set_ui_file_isatty (file, null_file_isatty);
69   set_ui_file_rewind (file, null_file_rewind);
70   set_ui_file_put (file, null_file_put);
71   set_ui_file_fseek (file, null_file_fseek);
72   return file;
73 }
74
75 void
76 ui_file_delete (struct ui_file *file)
77 {
78   file->to_delete (file);
79   xfree (file);
80 }
81
82 static int
83 null_file_isatty (struct ui_file *file)
84 {
85   return 0;
86 }
87
88 static void
89 null_file_rewind (struct ui_file *file)
90 {
91   return;
92 }
93
94 static void
95 null_file_put (struct ui_file *file,
96                ui_file_put_method_ftype *write,
97                void *dest)
98 {
99   return;
100 }
101
102 static void
103 null_file_flush (struct ui_file *file)
104 {
105   return;
106 }
107
108 static void
109 null_file_write (struct ui_file *file,
110                  const char *buf,
111                  long sizeof_buf)
112 {
113   if (file->to_fputs == null_file_fputs)
114     /* Both the write and fputs methods are null.  Discard the
115        request.  */
116     return;
117   else
118     {
119       /* The fputs method isn't null, slowly pass the write request
120          onto that.  FYI, this isn't as bad as it may look - the
121          current (as of 1999-11-07) printf_* function calls fputc and
122          fputc does exactly the below.  By having a write function it
123          is possible to clean up that code.  */
124       int i;
125       char b[2];
126
127       b[1] = '\0';
128       for (i = 0; i < sizeof_buf; i++)
129         {
130           b[0] = buf[i];
131           file->to_fputs (b, file);
132         }
133       return;
134     }
135 }
136
137 static long
138 null_file_read (struct ui_file *file,
139                 char *buf,
140                 long sizeof_buf)
141 {
142   errno = EBADF;
143   return 0;
144 }
145
146 static void
147 null_file_fputs (const char *buf, struct ui_file *file)
148 {
149   if (file->to_write == null_file_write)
150     /* Both the write and fputs methods are null.  Discard the
151        request.  */
152     return;
153   else
154     {
155       /* The write method was implemented, use that.  */
156       file->to_write (file, buf, strlen (buf));
157     }
158 }
159
160 static void
161 null_file_write_async_safe (struct ui_file *file,
162                             const char *buf,
163                             long sizeof_buf)
164 {
165   return;
166 }
167
168 static void
169 null_file_delete (struct ui_file *file)
170 {
171   return;
172 }
173
174 static int
175 null_file_fseek (struct ui_file *stream, long offset, int whence)
176 {
177   errno = EBADF;
178
179   return -1;
180 }
181
182 void *
183 ui_file_data (struct ui_file *file)
184 {
185   if (file->magic != &ui_file_magic)
186     internal_error (__FILE__, __LINE__,
187                     _("ui_file_data: bad magic number"));
188   return file->to_data;
189 }
190
191 void
192 gdb_flush (struct ui_file *file)
193 {
194   file->to_flush (file);
195 }
196
197 int
198 ui_file_isatty (struct ui_file *file)
199 {
200   return file->to_isatty (file);
201 }
202
203 void
204 ui_file_rewind (struct ui_file *file)
205 {
206   file->to_rewind (file);
207 }
208
209 void
210 ui_file_put (struct ui_file *file,
211               ui_file_put_method_ftype *write,
212               void *dest)
213 {
214   file->to_put (file, write, dest);
215 }
216
217 void
218 ui_file_write (struct ui_file *file,
219                 const char *buf,
220                 long length_buf)
221 {
222   file->to_write (file, buf, length_buf);
223 }
224
225 void
226 ui_file_write_async_safe (struct ui_file *file,
227                           const char *buf,
228                           long length_buf)
229 {
230   file->to_write_async_safe (file, buf, length_buf);
231 }
232
233 long
234 ui_file_read (struct ui_file *file, char *buf, long length_buf)
235 {
236   return file->to_read (file, buf, length_buf); 
237 }
238
239 int
240 ui_file_fseek (struct ui_file *file, long offset, int whence)
241 {
242   return file->to_fseek (file, offset, whence);
243 }
244
245 void
246 fputs_unfiltered (const char *buf, struct ui_file *file)
247 {
248   file->to_fputs (buf, file);
249 }
250
251 void
252 set_ui_file_flush (struct ui_file *file, ui_file_flush_ftype *flush_ptr)
253 {
254   file->to_flush = flush_ptr;
255 }
256
257 void
258 set_ui_file_isatty (struct ui_file *file, ui_file_isatty_ftype *isatty_ptr)
259 {
260   file->to_isatty = isatty_ptr;
261 }
262
263 void
264 set_ui_file_rewind (struct ui_file *file, ui_file_rewind_ftype *rewind_ptr)
265 {
266   file->to_rewind = rewind_ptr;
267 }
268
269 void
270 set_ui_file_put (struct ui_file *file, ui_file_put_ftype *put_ptr)
271 {
272   file->to_put = put_ptr;
273 }
274
275 void
276 set_ui_file_write (struct ui_file *file,
277                     ui_file_write_ftype *write_ptr)
278 {
279   file->to_write = write_ptr;
280 }
281
282 void
283 set_ui_file_write_async_safe (struct ui_file *file,
284                               ui_file_write_async_safe_ftype *write_async_safe_ptr)
285 {
286   file->to_write_async_safe = write_async_safe_ptr;
287 }
288
289 void
290 set_ui_file_read (struct ui_file *file, ui_file_read_ftype *read_ptr)
291 {
292   file->to_read = read_ptr;
293 }
294
295 void
296 set_ui_file_fputs (struct ui_file *file, ui_file_fputs_ftype *fputs_ptr)
297 {
298   file->to_fputs = fputs_ptr;
299 }
300
301 void
302 set_ui_file_fseek (struct ui_file *file, ui_file_fseek_ftype *fseek_ptr)
303 {
304   file->to_fseek = fseek_ptr;
305 }
306
307 void
308 set_ui_file_data (struct ui_file *file, void *data,
309                   ui_file_delete_ftype *delete_ptr)
310 {
311   file->to_data = data;
312   file->to_delete = delete_ptr;
313 }
314
315 /* ui_file utility function for converting a ``struct ui_file'' into
316    a memory buffer.  */
317
318 struct accumulated_ui_file
319 {
320   char *buffer;
321   long length;
322 };
323
324 static void
325 do_ui_file_xstrdup (void *context, const char *buffer, long length)
326 {
327   struct accumulated_ui_file *acc = context;
328
329   if (acc->buffer == NULL)
330     acc->buffer = xmalloc (length + 1);
331   else
332     acc->buffer = xrealloc (acc->buffer, acc->length + length + 1);
333   memcpy (acc->buffer + acc->length, buffer, length);
334   acc->length += length;
335   acc->buffer[acc->length] = '\0';
336 }
337
338 char *
339 ui_file_xstrdup (struct ui_file *file, long *length)
340 {
341   struct accumulated_ui_file acc;
342
343   acc.buffer = NULL;
344   acc.length = 0;
345   ui_file_put (file, do_ui_file_xstrdup, &acc);
346   if (acc.buffer == NULL)
347     acc.buffer = xstrdup ("");
348   if (length != NULL)
349     *length = acc.length;
350   return acc.buffer;
351 }
352
353 static void
354 do_ui_file_obsavestring (void *context, const char *buffer, long length)
355 {
356   struct obstack *obstack = (struct obstack *) context;
357
358   obstack_grow (obstack, buffer, length);
359 }
360
361 char *
362 ui_file_obsavestring (struct ui_file *file, struct obstack *obstack,
363                       long *length)
364 {
365   ui_file_put (file, do_ui_file_obsavestring, obstack);
366   *length = obstack_object_size (obstack);
367   obstack_1grow (obstack, '\0');
368   return obstack_finish (obstack);
369 }
370 \f
371 /* A pure memory based ``struct ui_file'' that can be used an output
372    buffer.  The buffers accumulated contents are available via
373    ui_file_put().  */
374
375 struct mem_file
376   {
377     int *magic;
378     char *buffer;
379     int sizeof_buffer;
380     int length_buffer;
381   };
382
383 static ui_file_rewind_ftype mem_file_rewind;
384 static ui_file_put_ftype mem_file_put;
385 static ui_file_write_ftype mem_file_write;
386 static ui_file_delete_ftype mem_file_delete;
387 static struct ui_file *mem_file_new (void);
388 static int mem_file_magic;
389
390 static struct ui_file *
391 mem_file_new (void)
392 {
393   struct mem_file *stream = XNEW (struct mem_file);
394   struct ui_file *file = ui_file_new ();
395
396   set_ui_file_data (file, stream, mem_file_delete);
397   set_ui_file_rewind (file, mem_file_rewind);
398   set_ui_file_put (file, mem_file_put);
399   set_ui_file_write (file, mem_file_write);
400   stream->magic = &mem_file_magic;
401   stream->buffer = NULL;
402   stream->sizeof_buffer = 0;
403   stream->length_buffer = 0;
404   return file;
405 }
406
407 static void
408 mem_file_delete (struct ui_file *file)
409 {
410   struct mem_file *stream = ui_file_data (file);
411
412   if (stream->magic != &mem_file_magic)
413     internal_error (__FILE__, __LINE__,
414                     _("mem_file_delete: bad magic number"));
415   if (stream->buffer != NULL)
416     xfree (stream->buffer);
417   xfree (stream);
418 }
419
420 struct ui_file *
421 mem_fileopen (void)
422 {
423   return mem_file_new ();
424 }
425
426 static void
427 mem_file_rewind (struct ui_file *file)
428 {
429   struct mem_file *stream = ui_file_data (file);
430
431   if (stream->magic != &mem_file_magic)
432     internal_error (__FILE__, __LINE__,
433                     _("mem_file_rewind: bad magic number"));
434   stream->length_buffer = 0;
435 }
436
437 static void
438 mem_file_put (struct ui_file *file,
439               ui_file_put_method_ftype *write,
440               void *dest)
441 {
442   struct mem_file *stream = ui_file_data (file);
443
444   if (stream->magic != &mem_file_magic)
445     internal_error (__FILE__, __LINE__,
446                     _("mem_file_put: bad magic number"));
447   if (stream->length_buffer > 0)
448     write (dest, stream->buffer, stream->length_buffer);
449 }
450
451 void
452 mem_file_write (struct ui_file *file,
453                 const char *buffer,
454                 long length_buffer)
455 {
456   struct mem_file *stream = ui_file_data (file);
457
458   if (stream->magic != &mem_file_magic)
459     internal_error (__FILE__, __LINE__,
460                     _("mem_file_write: bad magic number"));
461   if (stream->buffer == NULL)
462     {
463       stream->length_buffer = length_buffer;
464       stream->sizeof_buffer = length_buffer;
465       stream->buffer = xmalloc (stream->sizeof_buffer);
466       memcpy (stream->buffer, buffer, length_buffer);
467     }
468   else
469     {
470       int new_length = stream->length_buffer + length_buffer;
471
472       if (new_length >= stream->sizeof_buffer)
473         {
474           stream->sizeof_buffer = new_length;
475           stream->buffer = xrealloc (stream->buffer, stream->sizeof_buffer);
476         }
477       memcpy (stream->buffer + stream->length_buffer, buffer, length_buffer);
478       stream->length_buffer = new_length;
479     }
480 }
481 \f
482 /* ``struct ui_file'' implementation that maps directly onto
483    <stdio.h>'s FILE.  */
484
485 static ui_file_write_ftype stdio_file_write;
486 static ui_file_write_async_safe_ftype stdio_file_write_async_safe;
487 static ui_file_fputs_ftype stdio_file_fputs;
488 static ui_file_read_ftype stdio_file_read;
489 static ui_file_isatty_ftype stdio_file_isatty;
490 static ui_file_delete_ftype stdio_file_delete;
491 static struct ui_file *stdio_file_new (FILE *file, int close_p);
492 static ui_file_flush_ftype stdio_file_flush;
493 static ui_file_fseek_ftype stdio_file_fseek;
494
495 static int stdio_file_magic;
496
497 struct stdio_file
498   {
499     int *magic;
500     FILE *file;
501     /* The associated file descriptor is extracted ahead of time for
502        stdio_file_write_async_safe's benefit, in case fileno isn't async-safe.  */
503     int fd;
504     int close_p;
505   };
506
507 static struct ui_file *
508 stdio_file_new (FILE *file, int close_p)
509 {
510   struct ui_file *ui_file = ui_file_new ();
511   struct stdio_file *stdio = xmalloc (sizeof (struct stdio_file));
512
513   stdio->magic = &stdio_file_magic;
514   stdio->file = file;
515   stdio->fd = fileno (file);
516   stdio->close_p = close_p;
517   set_ui_file_data (ui_file, stdio, stdio_file_delete);
518   set_ui_file_flush (ui_file, stdio_file_flush);
519   set_ui_file_write (ui_file, stdio_file_write);
520   set_ui_file_write_async_safe (ui_file, stdio_file_write_async_safe);
521   set_ui_file_fputs (ui_file, stdio_file_fputs);
522   set_ui_file_read (ui_file, stdio_file_read);
523   set_ui_file_isatty (ui_file, stdio_file_isatty);
524   set_ui_file_fseek (ui_file, stdio_file_fseek);
525   return ui_file;
526 }
527
528 static void
529 stdio_file_delete (struct ui_file *file)
530 {
531   struct stdio_file *stdio = ui_file_data (file);
532
533   if (stdio->magic != &stdio_file_magic)
534     internal_error (__FILE__, __LINE__,
535                     _("stdio_file_delete: bad magic number"));
536   if (stdio->close_p)
537     {
538       fclose (stdio->file);
539     }
540   xfree (stdio);
541 }
542
543 static void
544 stdio_file_flush (struct ui_file *file)
545 {
546   struct stdio_file *stdio = ui_file_data (file);
547
548   if (stdio->magic != &stdio_file_magic)
549     internal_error (__FILE__, __LINE__,
550                     _("stdio_file_flush: bad magic number"));
551   fflush (stdio->file);
552 }
553
554 static long
555 stdio_file_read (struct ui_file *file, char *buf, long length_buf)
556 {
557   struct stdio_file *stdio = ui_file_data (file);
558
559   if (stdio->magic != &stdio_file_magic)
560     internal_error (__FILE__, __LINE__,
561                     _("stdio_file_read: bad magic number"));
562
563   /* For the benefit of Windows, call gdb_select before reading from
564      the file.  Wait until at least one byte of data is available.
565      Control-C can interrupt gdb_select, but not read.  */
566   {
567     fd_set readfds;
568     FD_ZERO (&readfds);
569     FD_SET (stdio->fd, &readfds);
570     if (gdb_select (stdio->fd + 1, &readfds, NULL, NULL, NULL) == -1)
571       return -1;
572   }
573
574   return read (stdio->fd, buf, length_buf);
575 }
576
577 static void
578 stdio_file_write (struct ui_file *file, const char *buf, long length_buf)
579 {
580   struct stdio_file *stdio = ui_file_data (file);
581
582   if (stdio->magic != &stdio_file_magic)
583     internal_error (__FILE__, __LINE__,
584                     _("stdio_file_write: bad magic number"));
585   /* Calling error crashes when we are called from the exception framework.  */
586   if (fwrite (buf, length_buf, 1, stdio->file))
587     {
588       /* Nothing.  */
589     }
590 }
591
592 static void
593 stdio_file_write_async_safe (struct ui_file *file,
594                              const char *buf, long length_buf)
595 {
596   struct stdio_file *stdio = ui_file_data (file);
597
598   if (stdio->magic != &stdio_file_magic)
599     {
600       /* gettext isn't necessarily async safe, so we can't use _("error message") here.
601          We could extract the correct translation ahead of time, but this is an extremely
602          rare event, and one of the other stdio_file_* routines will presumably catch
603          the problem anyway.  For now keep it simple and ignore the error here.  */
604       return;
605     }
606
607   /* This is written the way it is to avoid a warning from gcc about not using the
608      result of write (since it can be declared with attribute warn_unused_result).
609      Alas casting to void doesn't work for this.  */
610   if (write (stdio->fd, buf, length_buf))
611     {
612       /* Nothing.  */
613     }
614 }
615
616 static void
617 stdio_file_fputs (const char *linebuffer, struct ui_file *file)
618 {
619   struct stdio_file *stdio = ui_file_data (file);
620
621   if (stdio->magic != &stdio_file_magic)
622     internal_error (__FILE__, __LINE__,
623                     _("stdio_file_fputs: bad magic number"));
624   /* Calling error crashes when we are called from the exception framework.  */
625   if (fputs (linebuffer, stdio->file))
626     {
627       /* Nothing.  */
628     }
629 }
630
631 static int
632 stdio_file_isatty (struct ui_file *file)
633 {
634   struct stdio_file *stdio = ui_file_data (file);
635
636   if (stdio->magic != &stdio_file_magic)
637     internal_error (__FILE__, __LINE__,
638                     _("stdio_file_isatty: bad magic number"));
639   return (isatty (stdio->fd));
640 }
641
642 static int
643 stdio_file_fseek (struct ui_file *file, long offset, int whence)
644 {
645   struct stdio_file *stdio = ui_file_data (file);
646
647   if (stdio->magic != &stdio_file_magic)
648     internal_error (__FILE__, __LINE__,
649                     _("stdio_file_fseek: bad magic number"));
650
651   return fseek (stdio->file, offset, whence);
652 }
653
654 #ifdef __MINGW32__
655 /* This is the implementation of ui_file method to_write for stderr.
656    gdb_stdout is flushed before writing to gdb_stderr.  */
657
658 static void
659 stderr_file_write (struct ui_file *file, const char *buf, long length_buf)
660 {
661   gdb_flush (gdb_stdout);
662   stdio_file_write (file, buf, length_buf);
663 }
664
665 /* This is the implementation of ui_file method to_fputs for stderr.
666    gdb_stdout is flushed before writing to gdb_stderr.  */
667
668 static void
669 stderr_file_fputs (const char *linebuffer, struct ui_file *file)
670 {
671   gdb_flush (gdb_stdout);
672   stdio_file_fputs (linebuffer, file);
673 }
674 #endif
675
676 struct ui_file *
677 stderr_fileopen (void)
678 {
679   struct ui_file *ui_file = stdio_fileopen (stderr);
680
681 #ifdef __MINGW32__
682   /* There is no real line-buffering on Windows, see
683      http://msdn.microsoft.com/en-us/library/86cebhfs%28v=vs.71%29.aspx
684      so the stdout is either fully-buffered or non-buffered.  We can't
685      make stdout non-buffered, because of two concerns,
686      1.  non-buffering hurts performance,
687      2.  non-buffering may change GDB's behavior when it is interacting
688      with front-end, such as Emacs.
689
690      We decided to leave stdout as fully buffered, but flush it first
691      when something is written to stderr.  */
692
693   /* Method 'to_write_async_safe' is not overwritten, because there's
694      no way to flush a stream in an async-safe manner.  Fortunately,
695      it doesn't really matter, because:
696      - that method is only used for printing internal debug output
697        from signal handlers.
698      - Windows hosts don't have a concept of async-safeness.  Signal
699        handlers run in a separate thread, so they can call
700        the regular non-async-safe output routines freely.  */
701   set_ui_file_write (ui_file, stderr_file_write);
702   set_ui_file_fputs (ui_file, stderr_file_fputs);
703 #endif
704
705   return ui_file;
706 }
707
708 /* Like fdopen().  Create a ui_file from a previously opened FILE.  */
709
710 struct ui_file *
711 stdio_fileopen (FILE *file)
712 {
713   return stdio_file_new (file, 0);
714 }
715
716 struct ui_file *
717 gdb_fopen (const char *name, const char *mode)
718 {
719   FILE *f = gdb_fopen_cloexec (name, mode);
720
721   if (f == NULL)
722     return NULL;
723   return stdio_file_new (f, 1);
724 }
725
726 /* ``struct ui_file'' implementation that maps onto two ui-file objects.  */
727
728 static ui_file_write_ftype tee_file_write;
729 static ui_file_fputs_ftype tee_file_fputs;
730 static ui_file_isatty_ftype tee_file_isatty;
731 static ui_file_delete_ftype tee_file_delete;
732 static ui_file_flush_ftype tee_file_flush;
733
734 static int tee_file_magic;
735
736 struct tee_file
737   {
738     int *magic;
739     struct ui_file *one, *two;
740     int close_one, close_two;
741   };
742
743 struct ui_file *
744 tee_file_new (struct ui_file *one, int close_one,
745               struct ui_file *two, int close_two)
746 {
747   struct ui_file *ui_file = ui_file_new ();
748   struct tee_file *tee = xmalloc (sizeof (struct tee_file));
749
750   tee->magic = &tee_file_magic;
751   tee->one = one;
752   tee->two = two;
753   tee->close_one = close_one;
754   tee->close_two = close_two;
755   set_ui_file_data (ui_file, tee, tee_file_delete);
756   set_ui_file_flush (ui_file, tee_file_flush);
757   set_ui_file_write (ui_file, tee_file_write);
758   set_ui_file_fputs (ui_file, tee_file_fputs);
759   set_ui_file_isatty (ui_file, tee_file_isatty);
760   return ui_file;
761 }
762
763 static void
764 tee_file_delete (struct ui_file *file)
765 {
766   struct tee_file *tee = ui_file_data (file);
767
768   if (tee->magic != &tee_file_magic)
769     internal_error (__FILE__, __LINE__,
770                     _("tee_file_delete: bad magic number"));
771   if (tee->close_one)
772     ui_file_delete (tee->one);
773   if (tee->close_two)
774     ui_file_delete (tee->two);
775
776   xfree (tee);
777 }
778
779 static void
780 tee_file_flush (struct ui_file *file)
781 {
782   struct tee_file *tee = ui_file_data (file);
783
784   if (tee->magic != &tee_file_magic)
785     internal_error (__FILE__, __LINE__,
786                     _("tee_file_flush: bad magic number"));
787   tee->one->to_flush (tee->one);
788   tee->two->to_flush (tee->two);
789 }
790
791 static void
792 tee_file_write (struct ui_file *file, const char *buf, long length_buf)
793 {
794   struct tee_file *tee = ui_file_data (file);
795
796   if (tee->magic != &tee_file_magic)
797     internal_error (__FILE__, __LINE__,
798                     _("tee_file_write: bad magic number"));
799   ui_file_write (tee->one, buf, length_buf);
800   ui_file_write (tee->two, buf, length_buf);
801 }
802
803 static void
804 tee_file_fputs (const char *linebuffer, struct ui_file *file)
805 {
806   struct tee_file *tee = ui_file_data (file);
807
808   if (tee->magic != &tee_file_magic)
809     internal_error (__FILE__, __LINE__,
810                     _("tee_file_fputs: bad magic number"));
811   tee->one->to_fputs (linebuffer, tee->one);
812   tee->two->to_fputs (linebuffer, tee->two);
813 }
814
815 static int
816 tee_file_isatty (struct ui_file *file)
817 {
818   struct tee_file *tee = ui_file_data (file);
819
820   if (tee->magic != &tee_file_magic)
821     internal_error (__FILE__, __LINE__,
822                     _("tee_file_isatty: bad magic number"));
823
824   return ui_file_isatty (tee->one);
825 }