1 /* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004 Free Software Foundation, Inc.
3 * This 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.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "libguile/_scm.h"
30 #include "libguile/eval.h"
31 #include "libguile/objects.h"
32 #include "libguile/smob.h"
33 #include "libguile/chars.h"
34 #include "libguile/dynwind.h"
36 #include "libguile/keywords.h"
37 #include "libguile/root.h"
38 #include "libguile/strings.h"
39 #include "libguile/mallocs.h"
40 #include "libguile/validate.h"
41 #include "libguile/ports.h"
59 #ifdef HAVE_SYS_IOCTL_H
60 #include <sys/ioctl.h>
65 #define ftruncate(fd, size) chsize (fd, size)
69 /* The port kind table --- a dynamically resized array of port types. */
72 /* scm_ptobs scm_numptob
73 * implement a dynamicly resized array of ptob records.
74 * Indexes into this table are used when generating type
75 * tags for smobjects (if you know a tag you can get an index and conversely).
77 scm_t_ptob_descriptor
*scm_ptobs
;
80 /* GC marker for a port with stream of SCM type. */
82 scm_markstream (SCM ptr
)
85 openp
= SCM_CELL_WORD_0 (ptr
) & SCM_OPN
;
87 return SCM_PACK (SCM_STREAM (ptr
));
93 * We choose to use an interface similar to the smob interface with
94 * fill_input and write as standard fields, passed to the port
95 * type constructor, and optional fields set by setters.
99 flush_port_default (SCM port SCM_UNUSED
)
104 end_input_default (SCM port SCM_UNUSED
, int offset SCM_UNUSED
)
109 scm_port_free0 (SCM port
)
115 scm_make_port_type (char *name
,
116 int (*fill_input
) (SCM port
),
117 void (*write
) (SCM port
, const void *data
, size_t size
))
120 if (255 <= scm_numptob
)
123 SCM_SYSCALL (tmp
= (char *) realloc ((char *) scm_ptobs
,
125 * sizeof (scm_t_ptob_descriptor
)));
128 scm_ptobs
= (scm_t_ptob_descriptor
*) tmp
;
130 scm_ptobs
[scm_numptob
].name
= name
;
131 scm_ptobs
[scm_numptob
].mark
= 0;
132 scm_ptobs
[scm_numptob
].free
= scm_port_free0
;
133 scm_ptobs
[scm_numptob
].print
= scm_port_print
;
134 scm_ptobs
[scm_numptob
].equalp
= 0;
135 scm_ptobs
[scm_numptob
].close
= 0;
137 scm_ptobs
[scm_numptob
].write
= write
;
138 scm_ptobs
[scm_numptob
].flush
= flush_port_default
;
140 scm_ptobs
[scm_numptob
].end_input
= end_input_default
;
141 scm_ptobs
[scm_numptob
].fill_input
= fill_input
;
142 scm_ptobs
[scm_numptob
].input_waiting
= 0;
144 scm_ptobs
[scm_numptob
].seek
= 0;
145 scm_ptobs
[scm_numptob
].truncate
= 0;
153 scm_memory_error ("scm_make_port_type");
155 /* Make a class object if Goops is present */
157 scm_make_port_classes (scm_numptob
- 1, SCM_PTOBNAME (scm_numptob
- 1));
158 return scm_tc7_port
+ (scm_numptob
- 1) * 256;
162 scm_set_port_mark (long tc
, SCM (*mark
) (SCM
))
164 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].mark
= mark
;
168 scm_set_port_free (long tc
, size_t (*free
) (SCM
))
170 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].free
= free
;
174 scm_set_port_print (long tc
, int (*print
) (SCM exp
, SCM port
,
175 scm_print_state
*pstate
))
177 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].print
= print
;
181 scm_set_port_equalp (long tc
, SCM (*equalp
) (SCM
, SCM
))
183 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].equalp
= equalp
;
187 scm_set_port_flush (long tc
, void (*flush
) (SCM port
))
189 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].flush
= flush
;
193 scm_set_port_end_input (long tc
, void (*end_input
) (SCM port
, int offset
))
195 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].end_input
= end_input
;
199 scm_set_port_close (long tc
, int (*close
) (SCM
))
201 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].close
= close
;
205 scm_set_port_seek (long tc
, off_t (*seek
) (SCM port
,
209 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].seek
= seek
;
213 scm_set_port_truncate (long tc
, void (*truncate
) (SCM port
, off_t length
))
215 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].truncate
= truncate
;
219 scm_set_port_input_waiting (long tc
, int (*input_waiting
) (SCM
))
221 scm_ptobs
[SCM_TC2PTOBNUM (tc
)].input_waiting
= input_waiting
;
226 SCM_DEFINE (scm_char_ready_p
, "char-ready?", 0, 1, 0,
228 "Return @code{#t} if a character is ready on input @var{port}\n"
229 "and return @code{#f} otherwise. If @code{char-ready?} returns\n"
230 "@code{#t} then the next @code{read-char} operation on\n"
231 "@var{port} is guaranteed not to hang. If @var{port} is a file\n"
232 "port at end of file then @code{char-ready?} returns @code{#t}.\n"
234 "@code{char-ready?} exists to make it possible for a\n"
235 "program to accept characters from interactive ports without\n"
236 "getting stuck waiting for input. Any input editors associated\n"
237 "with such ports must make sure that characters whose existence\n"
238 "has been asserted by @code{char-ready?} cannot be rubbed out.\n"
239 "If @code{char-ready?} were to return @code{#f} at end of file,\n"
240 "a port at end of file would be indistinguishable from an\n"
241 "interactive port that has no ready characters.")
242 #define FUNC_NAME s_scm_char_ready_p
246 if (SCM_UNBNDP (port
))
249 SCM_VALIDATE_OPINPORT (1, port
);
251 pt
= SCM_PTAB_ENTRY (port
);
253 /* if the current read buffer is filled, or the
254 last pushed-back char has been read and the saved buffer is
255 filled, result is true. */
256 if (pt
->read_pos
< pt
->read_end
257 || (pt
->read_buf
== pt
->putback_buf
258 && pt
->saved_read_pos
< pt
->saved_read_end
))
262 scm_t_ptob_descriptor
*ptob
= &scm_ptobs
[SCM_PTOBNUM (port
)];
264 if (ptob
->input_waiting
)
265 return scm_from_bool(ptob
->input_waiting (port
));
272 /* move up to read_len chars from port's putback and/or read buffers
273 into memory starting at dest. returns the number of chars moved. */
274 size_t scm_take_from_input_buffers (SCM port
, char *dest
, size_t read_len
)
276 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
277 size_t chars_read
= 0;
278 size_t from_buf
= min (pt
->read_end
- pt
->read_pos
, read_len
);
282 memcpy (dest
, pt
->read_pos
, from_buf
);
283 pt
->read_pos
+= from_buf
;
284 chars_read
+= from_buf
;
285 read_len
-= from_buf
;
289 /* if putback was active, try the real input buffer too. */
290 if (pt
->read_buf
== pt
->putback_buf
)
292 from_buf
= min (pt
->saved_read_end
- pt
->saved_read_pos
, read_len
);
295 memcpy (dest
, pt
->saved_read_pos
, from_buf
);
296 pt
->saved_read_pos
+= from_buf
;
297 chars_read
+= from_buf
;
303 /* Clear a port's read buffers, returning the contents. */
304 SCM_DEFINE (scm_drain_input
, "drain-input", 1, 0, 0,
306 "This procedure clears a port's input buffers, similar\n"
307 "to the way that force-output clears the output buffer. The\n"
308 "contents of the buffers are returned as a single string, e.g.,\n"
311 "(define p (open-input-file ...))\n"
312 "(drain-input p) => empty string, nothing buffered yet.\n"
313 "(unread-char (read-char p) p)\n"
314 "(drain-input p) => initial chars from p, up to the buffer size.\n"
316 "Draining the buffers may be useful for cleanly finishing\n"
317 "buffered I/O so that the file descriptor can be used directly\n"
318 "for further input.")
319 #define FUNC_NAME s_scm_drain_input
325 SCM_VALIDATE_OPINPORT (1, port
);
326 pt
= SCM_PTAB_ENTRY (port
);
328 count
= pt
->read_end
- pt
->read_pos
;
329 if (pt
->read_buf
== pt
->putback_buf
)
330 count
+= pt
->saved_read_end
- pt
->saved_read_pos
;
332 result
= scm_allocate_string (count
);
333 scm_take_from_input_buffers (port
, SCM_I_STRING_CHARS (result
), count
);
340 /* Standard ports --- current input, output, error, and more(!). */
342 SCM_DEFINE (scm_current_input_port
, "current-input-port", 0, 0, 0,
344 "Return the current input port. This is the default port used\n"
345 "by many input procedures. Initially, @code{current-input-port}\n"
346 "returns the @dfn{standard input} in Unix and C terminology.")
347 #define FUNC_NAME s_scm_current_input_port
353 SCM_DEFINE (scm_current_output_port
, "current-output-port", 0, 0, 0,
355 "Return the current output port. This is the default port used\n"
356 "by many output procedures. Initially,\n"
357 "@code{current-output-port} returns the @dfn{standard output} in\n"
358 "Unix and C terminology.")
359 #define FUNC_NAME s_scm_current_output_port
365 SCM_DEFINE (scm_current_error_port
, "current-error-port", 0, 0, 0,
367 "Return the port to which errors and warnings should be sent (the\n"
368 "@dfn{standard error} in Unix and C terminology).")
369 #define FUNC_NAME s_scm_current_error_port
375 SCM_DEFINE (scm_current_load_port
, "current-load-port", 0, 0, 0,
377 "Return the current-load-port.\n"
378 "The load port is used internally by @code{primitive-load}.")
379 #define FUNC_NAME s_scm_current_load_port
381 return scm_cur_loadp
;
385 SCM_DEFINE (scm_set_current_input_port
, "set-current-input-port", 1, 0, 0,
387 "@deffnx {Scheme Procedure} set-current-output-port port\n"
388 "@deffnx {Scheme Procedure} set-current-error-port port\n"
389 "Change the ports returned by @code{current-input-port},\n"
390 "@code{current-output-port} and @code{current-error-port}, respectively,\n"
391 "so that they use the supplied @var{port} for input or output.")
392 #define FUNC_NAME s_scm_set_current_input_port
394 SCM oinp
= scm_cur_inp
;
395 SCM_VALIDATE_OPINPORT (1, port
);
402 SCM_DEFINE (scm_set_current_output_port
, "set-current-output-port", 1, 0, 0,
404 "Set the current default output port to @var{port}.")
405 #define FUNC_NAME s_scm_set_current_output_port
407 SCM ooutp
= scm_cur_outp
;
408 port
= SCM_COERCE_OUTPORT (port
);
409 SCM_VALIDATE_OPOUTPORT (1, port
);
416 SCM_DEFINE (scm_set_current_error_port
, "set-current-error-port", 1, 0, 0,
418 "Set the current default error port to @var{port}.")
419 #define FUNC_NAME s_scm_set_current_error_port
421 SCM oerrp
= scm_cur_errp
;
422 port
= SCM_COERCE_OUTPORT (port
);
423 SCM_VALIDATE_OPOUTPORT (1, port
);
431 SCM (*getter
) (void);
436 swap_port (SCM scm_data
)
438 swap_data
*d
= (swap_data
*)SCM_MALLOCDATA (scm_data
);
442 d
->setter (d
->value
);
447 scm_frame_current_foo_port (SCM port
,
448 SCM (*getter
) (void), SCM (*setter
) (SCM
))
450 SCM scm_data
= scm_malloc_obj (sizeof (swap_data
));
451 swap_data
*data
= (swap_data
*)SCM_MALLOCDATA (scm_data
);
453 data
->getter
= getter
;
454 data
->setter
= setter
;
456 scm_frame_rewind_handler_with_scm (swap_port
, scm_data
,
457 SCM_F_WIND_EXPLICITLY
);
458 scm_frame_unwind_handler_with_scm (swap_port
, scm_data
,
459 SCM_F_WIND_EXPLICITLY
);
463 scm_frame_current_input_port (SCM port
)
465 scm_frame_current_foo_port (port
,
466 scm_current_input_port
,
467 scm_set_current_input_port
);
471 scm_frame_current_output_port (SCM port
)
473 scm_frame_current_foo_port (port
,
474 scm_current_output_port
,
475 scm_set_current_output_port
);
479 scm_frame_current_error_port (SCM port
)
481 scm_frame_current_foo_port (port
,
482 scm_current_error_port
,
483 scm_set_current_error_port
);
487 /* The port table --- an array of pointers to ports. */
489 scm_t_port
**scm_i_port_table
;
491 long scm_i_port_table_size
= 0; /* Number of ports in scm_i_port_table. */
492 long scm_i_port_table_room
= 20; /* Size of the array. */
494 SCM_GLOBAL_MUTEX (scm_i_port_table_mutex
);
496 /* This function is not and should not be thread safe. */
499 scm_new_port_table_entry (scm_t_bits tag
)
500 #define FUNC_NAME "scm_new_port_table_entry"
503 We initialize the cell to empty, this is in case scm_gc_calloc
504 triggers GC ; we don't want the GC to scan a half-finished Z.
507 SCM z
= scm_cons (SCM_EOL
, SCM_EOL
);
508 scm_t_port
*entry
= (scm_t_port
*) scm_gc_calloc (sizeof (scm_t_port
), "port");
509 if (scm_i_port_table_size
== scm_i_port_table_room
)
511 /* initial malloc is in gc.c. this doesn't use scm_gc_malloc etc.,
512 since it can never be freed during gc. */
513 void *newt
= scm_realloc ((char *) scm_i_port_table
,
514 (size_t) (sizeof (scm_t_port
*)
515 * scm_i_port_table_room
* 2));
516 scm_i_port_table
= (scm_t_port
**) newt
;
517 scm_i_port_table_room
*= 2;
520 entry
->entry
= scm_i_port_table_size
;
522 entry
->file_name
= SCM_BOOL_F
;
523 entry
->rw_active
= SCM_PORT_NEITHER
;
525 scm_i_port_table
[scm_i_port_table_size
] = entry
;
526 scm_i_port_table_size
++;
529 SCM_SET_CELL_TYPE(z
, tag
);
530 SCM_SETPTAB_ENTRY(z
, entry
);
536 #if SCM_ENABLE_DEPRECATED==1
538 scm_add_to_port_table (SCM port
)
540 SCM z
= scm_new_port_table_entry (scm_tc7_port
);
541 scm_t_port
* pt
= SCM_PTAB_ENTRY(z
);
544 SCM_SETCAR(z
, SCM_EOL
);
545 SCM_SETCDR(z
, SCM_EOL
);
546 SCM_SETPTAB_ENTRY (port
, pt
);
552 /* Remove a port from the table and destroy it. */
554 /* This function is not and should not be thread safe. */
557 scm_remove_from_port_table (SCM port
)
558 #define FUNC_NAME "scm_remove_from_port_table"
560 scm_t_port
*p
= SCM_PTAB_ENTRY (port
);
563 if (i
>= scm_i_port_table_size
)
564 SCM_MISC_ERROR ("Port not in table: ~S", scm_list_1 (port
));
566 scm_gc_free (p
->putback_buf
, p
->putback_buf_size
, "putback buffer");
567 scm_gc_free (p
, sizeof (scm_t_port
), "port");
568 /* Since we have just freed slot i we can shrink the table by moving
569 the last entry to that slot... */
570 if (i
< scm_i_port_table_size
- 1)
572 scm_i_port_table
[i
] = scm_i_port_table
[scm_i_port_table_size
- 1];
573 scm_i_port_table
[i
]->entry
= i
;
575 SCM_SETPTAB_ENTRY (port
, 0);
576 scm_i_port_table_size
--;
582 /* Functions for debugging. */
584 SCM_DEFINE (scm_pt_size
, "pt-size", 0, 0, 0,
586 "Return the number of ports in the port table. @code{pt-size}\n"
587 "is only included in @code{--enable-guile-debug} builds.")
588 #define FUNC_NAME s_scm_pt_size
590 return scm_from_int (scm_i_port_table_size
);
594 SCM_DEFINE (scm_pt_member
, "pt-member", 1, 0, 0,
596 "Return the port at @var{index} in the port table.\n"
597 "@code{pt-member} is only included in\n"
598 "@code{--enable-guile-debug} builds.")
599 #define FUNC_NAME s_scm_pt_member
601 size_t i
= scm_to_size_t (index
);
602 if (i
>= scm_i_port_table_size
)
605 return scm_i_port_table
[i
]->port
;
611 scm_port_non_buffer (scm_t_port
*pt
)
613 pt
->read_pos
= pt
->read_buf
= pt
->read_end
= &pt
->shortbuf
;
614 pt
->write_buf
= pt
->write_pos
= &pt
->shortbuf
;
615 pt
->read_buf_size
= pt
->write_buf_size
= 1;
616 pt
->write_end
= pt
->write_buf
+ pt
->write_buf_size
;
620 /* Revealed counts --- an oddity inherited from SCSH. */
622 /* Find a port in the table and return its revealed count.
623 Also used by the garbage collector.
627 scm_revealed_count (SCM port
)
629 return SCM_REVEALED(port
);
634 /* Return the revealed count for a port. */
636 SCM_DEFINE (scm_port_revealed
, "port-revealed", 1, 0, 0,
638 "Return the revealed count for @var{port}.")
639 #define FUNC_NAME s_scm_port_revealed
641 port
= SCM_COERCE_OUTPORT (port
);
642 SCM_VALIDATE_OPENPORT (1, port
);
643 return scm_from_int (scm_revealed_count (port
));
647 /* Set the revealed count for a port. */
648 SCM_DEFINE (scm_set_port_revealed_x
, "set-port-revealed!", 2, 0, 0,
649 (SCM port
, SCM rcount
),
650 "Sets the revealed count for a port to a given value.\n"
651 "The return value is unspecified.")
652 #define FUNC_NAME s_scm_set_port_revealed_x
654 port
= SCM_COERCE_OUTPORT (port
);
655 SCM_VALIDATE_OPENPORT (1, port
);
656 SCM_REVEALED (port
) = scm_to_int (rcount
);
657 return SCM_UNSPECIFIED
;
663 /* Retrieving a port's mode. */
665 /* Return the flags that characterize a port based on the mode
666 * string used to open a file for that port.
668 * See PORT FLAGS in scm.h
672 scm_mode_bits (char *modes
)
675 | (strchr (modes
, 'r') || strchr (modes
, '+') ? SCM_RDNG
: 0)
676 | ( strchr (modes
, 'w')
677 || strchr (modes
, 'a')
678 || strchr (modes
, '+') ? SCM_WRTNG
: 0)
679 | (strchr (modes
, '0') ? SCM_BUF0
: 0)
680 | (strchr (modes
, 'l') ? SCM_BUFLINE
: 0));
684 scm_i_mode_bits (SCM modes
)
688 if (!scm_is_string (modes
))
689 scm_wrong_type_arg_msg (NULL
, 0, modes
, "string");
691 bits
= scm_mode_bits (SCM_I_STRING_CHARS (modes
));
692 scm_remember_upto_here_1 (modes
);
696 /* Return the mode flags from an open port.
697 * Some modes such as "append" are only used when opening
698 * a file and are not returned here. */
700 SCM_DEFINE (scm_port_mode
, "port-mode", 1, 0, 0,
702 "Return the port modes associated with the open port @var{port}.\n"
703 "These will not necessarily be identical to the modes used when\n"
704 "the port was opened, since modes such as \"append\" which are\n"
705 "used only during port creation are not retained.")
706 #define FUNC_NAME s_scm_port_mode
711 port
= SCM_COERCE_OUTPORT (port
);
712 SCM_VALIDATE_OPPORT (1, port
);
713 if (SCM_CELL_WORD_0 (port
) & SCM_RDNG
) {
714 if (SCM_CELL_WORD_0 (port
) & SCM_WRTNG
)
715 strcpy (modes
, "r+");
719 else if (SCM_CELL_WORD_0 (port
) & SCM_WRTNG
)
721 if (SCM_CELL_WORD_0 (port
) & SCM_BUF0
)
723 return scm_mem2string (modes
, strlen (modes
));
732 * Call the close operation on a port object.
733 * see also scm_close.
735 SCM_DEFINE (scm_close_port
, "close-port", 1, 0, 0,
737 "Close the specified port object. Return @code{#t} if it\n"
738 "successfully closes a port or @code{#f} if it was already\n"
739 "closed. An exception may be raised if an error occurs, for\n"
740 "example when flushing buffered output. See also @ref{Ports and\n"
741 "File Descriptors, close}, for a procedure which can close file\n"
743 #define FUNC_NAME s_scm_close_port
748 port
= SCM_COERCE_OUTPORT (port
);
750 SCM_VALIDATE_PORT (1, port
);
751 if (SCM_CLOSEDP (port
))
753 i
= SCM_PTOBNUM (port
);
754 if (scm_ptobs
[i
].close
)
755 rv
= (scm_ptobs
[i
].close
) (port
);
758 scm_mutex_lock (&scm_i_port_table_mutex
);
759 scm_remove_from_port_table (port
);
760 scm_mutex_unlock (&scm_i_port_table_mutex
);
761 SCM_CLR_PORT_OPEN_FLAG (port
);
762 return scm_from_bool (rv
>= 0);
766 SCM_DEFINE (scm_close_input_port
, "close-input-port", 1, 0, 0,
768 "Close the specified input port object. The routine has no effect if\n"
769 "the file has already been closed. An exception may be raised if an\n"
770 "error occurs. The value returned is unspecified.\n\n"
771 "See also @ref{Ports and File Descriptors, close}, for a procedure\n"
772 "which can close file descriptors.")
773 #define FUNC_NAME s_scm_close_input_port
775 SCM_VALIDATE_INPUT_PORT (1, port
);
776 scm_close_port (port
);
777 return SCM_UNSPECIFIED
;
781 SCM_DEFINE (scm_close_output_port
, "close-output-port", 1, 0, 0,
783 "Close the specified output port object. The routine has no effect if\n"
784 "the file has already been closed. An exception may be raised if an\n"
785 "error occurs. The value returned is unspecified.\n\n"
786 "See also @ref{Ports and File Descriptors, close}, for a procedure\n"
787 "which can close file descriptors.")
788 #define FUNC_NAME s_scm_close_output_port
790 port
= SCM_COERCE_OUTPORT (port
);
791 SCM_VALIDATE_OUTPUT_PORT (1, port
);
792 scm_close_port (port
);
793 return SCM_UNSPECIFIED
;
798 scm_c_port_for_each (void (*proc
)(void *data
, SCM p
), void *data
)
803 /* Even without pre-emptive multithreading, running arbitrary code
804 while scanning the port table is unsafe because the port table
805 can change arbitrarily (from a GC, for example). So we build a
806 list in advance while blocking the GC. -mvo */
808 scm_mutex_lock (&scm_i_port_table_mutex
);
811 for (i
= 0; i
< scm_i_port_table_size
; i
++)
812 ports
= scm_cons (scm_i_port_table
[i
]->port
, ports
);
814 scm_mutex_unlock (&scm_i_port_table_mutex
);
816 while (ports
!= SCM_EOL
)
818 proc (data
, SCM_CAR (ports
));
819 ports
= SCM_CDR (ports
);
823 SCM_DEFINE (scm_port_for_each
, "port-for-each", 1, 0, 0,
825 "Apply @var{proc} to each port in the Guile port table\n"
826 "in turn. The return value is unspecified. More specifically,\n"
827 "@var{proc} is applied exactly once to every port that exists\n"
828 "in the system at the time @var{port-for-each} is invoked.\n"
829 "Changes to the port table while @var{port-for-each} is running\n"
830 "have no effect as far as @var{port-for-each} is concerned.")
831 #define FUNC_NAME s_scm_port_for_each
833 SCM_VALIDATE_PROC (1, proc
);
835 scm_c_port_for_each ((void (*)(void*,SCM
))scm_call_1
, proc
);
836 return SCM_UNSPECIFIED
;
842 /* Utter miscellany. Gosh, we should clean this up some time. */
844 SCM_DEFINE (scm_input_port_p
, "input-port?", 1, 0, 0,
846 "Return @code{#t} if @var{x} is an input port, otherwise return\n"
847 "@code{#f}. Any object satisfying this predicate also satisfies\n"
849 #define FUNC_NAME s_scm_input_port_p
851 return scm_from_bool (SCM_INPUT_PORT_P (x
));
855 SCM_DEFINE (scm_output_port_p
, "output-port?", 1, 0, 0,
857 "Return @code{#t} if @var{x} is an output port, otherwise return\n"
858 "@code{#f}. Any object satisfying this predicate also satisfies\n"
860 #define FUNC_NAME s_scm_output_port_p
862 x
= SCM_COERCE_OUTPORT (x
);
863 return scm_from_bool (SCM_OUTPUT_PORT_P (x
));
867 SCM_DEFINE (scm_port_p
, "port?", 1, 0, 0,
869 "Return a boolean indicating whether @var{x} is a port.\n"
870 "Equivalent to @code{(or (input-port? @var{x}) (output-port?\n"
872 #define FUNC_NAME s_scm_port_p
874 return scm_from_bool (SCM_PORTP (x
));
878 SCM_DEFINE (scm_port_closed_p
, "port-closed?", 1, 0, 0,
880 "Return @code{#t} if @var{port} is closed or @code{#f} if it is\n"
882 #define FUNC_NAME s_scm_port_closed_p
884 SCM_VALIDATE_PORT (1, port
);
885 return scm_from_bool (!SCM_OPPORTP (port
));
889 SCM_DEFINE (scm_eof_object_p
, "eof-object?", 1, 0, 0,
891 "Return @code{#t} if @var{x} is an end-of-file object; otherwise\n"
893 #define FUNC_NAME s_scm_eof_object_p
895 return scm_from_bool(SCM_EOF_OBJECT_P (x
));
899 SCM_DEFINE (scm_force_output
, "force-output", 0, 1, 0,
901 "Flush the specified output port, or the current output port if @var{port}\n"
902 "is omitted. The current output buffer contents are passed to the\n"
903 "underlying port implementation (e.g., in the case of fports, the\n"
904 "data will be written to the file and the output buffer will be cleared.)\n"
905 "It has no effect on an unbuffered port.\n\n"
906 "The return value is unspecified.")
907 #define FUNC_NAME s_scm_force_output
909 if (SCM_UNBNDP (port
))
913 port
= SCM_COERCE_OUTPORT (port
);
914 SCM_VALIDATE_OPOUTPORT (1, port
);
917 return SCM_UNSPECIFIED
;
921 SCM_DEFINE (scm_flush_all_ports
, "flush-all-ports", 0, 0, 0,
923 "Equivalent to calling @code{force-output} on\n"
924 "all open output ports. The return value is unspecified.")
925 #define FUNC_NAME s_scm_flush_all_ports
929 scm_mutex_lock (&scm_i_port_table_mutex
);
930 for (i
= 0; i
< scm_i_port_table_size
; i
++)
932 if (SCM_OPOUTPORTP (scm_i_port_table
[i
]->port
))
933 scm_flush (scm_i_port_table
[i
]->port
);
935 scm_mutex_unlock (&scm_i_port_table_mutex
);
936 return SCM_UNSPECIFIED
;
940 SCM_DEFINE (scm_read_char
, "read-char", 0, 1, 0,
942 "Return the next character available from @var{port}, updating\n"
943 "@var{port} to point to the following character. If no more\n"
944 "characters are available, the end-of-file object is returned.")
945 #define FUNC_NAME s_scm_read_char
948 if (SCM_UNBNDP (port
))
950 SCM_VALIDATE_OPINPORT (1, port
);
954 return SCM_MAKE_CHAR (c
);
958 /* this should only be called when the read buffer is empty. it
959 tries to refill the read buffer. it returns the first char from
960 the port, which is either EOF or *(pt->read_pos). */
962 scm_fill_input (SCM port
)
964 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
966 if (pt
->read_buf
== pt
->putback_buf
)
968 /* finished reading put-back chars. */
969 pt
->read_buf
= pt
->saved_read_buf
;
970 pt
->read_pos
= pt
->saved_read_pos
;
971 pt
->read_end
= pt
->saved_read_end
;
972 pt
->read_buf_size
= pt
->saved_read_buf_size
;
973 if (pt
->read_pos
< pt
->read_end
)
974 return *(pt
->read_pos
);
976 return scm_ptobs
[SCM_PTOBNUM (port
)].fill_input (port
);
983 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
985 if (pt
->rw_active
== SCM_PORT_WRITE
)
986 /* may be marginally faster than calling scm_flush. */
987 scm_ptobs
[SCM_PTOBNUM (port
)].flush (port
);
990 pt
->rw_active
= SCM_PORT_READ
;
992 if (pt
->read_pos
>= pt
->read_end
)
994 if (scm_fill_input (port
) == EOF
)
998 c
= *(pt
->read_pos
++);
1017 scm_putc (char c
, SCM port
)
1019 scm_lfwrite (&c
, 1, port
);
1023 scm_puts (const char *s
, SCM port
)
1025 scm_lfwrite (s
, strlen (s
), port
);
1030 * This function differs from scm_c_write; it updates port line and
1034 scm_lfwrite (const char *ptr
, size_t size
, SCM port
)
1036 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
1037 scm_t_ptob_descriptor
*ptob
= &scm_ptobs
[SCM_PTOBNUM (port
)];
1039 if (pt
->rw_active
== SCM_PORT_READ
)
1040 scm_end_input (port
);
1042 ptob
->write (port
, ptr
, size
);
1044 for (; size
; ptr
++, size
--) {
1048 else if (*ptr
== '\t') {
1057 pt
->rw_active
= SCM_PORT_WRITE
;
1062 * Used by an application to read arbitrary number of bytes from an
1063 * SCM port. Same semantics as libc read, except that scm_c_read only
1064 * returns less than SIZE bytes if at end-of-file.
1066 * Warning: Doesn't update port line and column counts! */
1069 scm_c_read (SCM port
, void *buffer
, size_t size
)
1071 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
1072 size_t n_read
= 0, n_available
;
1074 if (pt
->rw_active
== SCM_PORT_WRITE
)
1075 scm_ptobs
[SCM_PTOBNUM (port
)].flush (port
);
1078 pt
->rw_active
= SCM_PORT_READ
;
1080 if (SCM_READ_BUFFER_EMPTY_P (pt
))
1082 if (scm_fill_input (port
) == EOF
)
1086 n_available
= pt
->read_end
- pt
->read_pos
;
1088 while (n_available
< size
)
1090 memcpy (buffer
, pt
->read_pos
, n_available
);
1091 buffer
= (char *) buffer
+ n_available
;
1092 pt
->read_pos
+= n_available
;
1093 n_read
+= n_available
;
1095 if (SCM_READ_BUFFER_EMPTY_P (pt
))
1097 if (scm_fill_input (port
) == EOF
)
1101 size
-= n_available
;
1102 n_available
= pt
->read_end
- pt
->read_pos
;
1105 memcpy (buffer
, pt
->read_pos
, size
);
1106 pt
->read_pos
+= size
;
1108 return n_read
+ size
;
1113 * Used by an application to write arbitrary number of bytes to an SCM
1114 * port. Similar semantics as libc write. However, unlike libc
1115 * write, scm_c_write writes the requested number of bytes and has no
1118 * Warning: Doesn't update port line and column counts!
1122 scm_c_write (SCM port
, const void *ptr
, size_t size
)
1124 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
1125 scm_t_ptob_descriptor
*ptob
= &scm_ptobs
[SCM_PTOBNUM (port
)];
1127 if (pt
->rw_active
== SCM_PORT_READ
)
1128 scm_end_input (port
);
1130 ptob
->write (port
, ptr
, size
);
1133 pt
->rw_active
= SCM_PORT_WRITE
;
1137 scm_flush (SCM port
)
1139 long i
= SCM_PTOBNUM (port
);
1140 (scm_ptobs
[i
].flush
) (port
);
1144 scm_end_input (SCM port
)
1147 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
1149 if (pt
->read_buf
== pt
->putback_buf
)
1151 offset
= pt
->read_end
- pt
->read_pos
;
1152 pt
->read_buf
= pt
->saved_read_buf
;
1153 pt
->read_pos
= pt
->saved_read_pos
;
1154 pt
->read_end
= pt
->saved_read_end
;
1155 pt
->read_buf_size
= pt
->saved_read_buf_size
;
1160 scm_ptobs
[SCM_PTOBNUM (port
)].end_input (port
, offset
);
1167 scm_ungetc (int c
, SCM port
)
1168 #define FUNC_NAME "scm_ungetc"
1170 scm_t_port
*pt
= SCM_PTAB_ENTRY (port
);
1172 if (pt
->read_buf
== pt
->putback_buf
)
1173 /* already using the put-back buffer. */
1175 /* enlarge putback_buf if necessary. */
1176 if (pt
->read_end
== pt
->read_buf
+ pt
->read_buf_size
1177 && pt
->read_buf
== pt
->read_pos
)
1179 size_t new_size
= pt
->read_buf_size
* 2;
1180 unsigned char *tmp
= (unsigned char *)
1181 scm_gc_realloc (pt
->putback_buf
, pt
->read_buf_size
, new_size
,
1184 pt
->read_pos
= pt
->read_buf
= pt
->putback_buf
= tmp
;
1185 pt
->read_end
= pt
->read_buf
+ pt
->read_buf_size
;
1186 pt
->read_buf_size
= pt
->putback_buf_size
= new_size
;
1189 /* shift any existing bytes to buffer + 1. */
1190 if (pt
->read_pos
== pt
->read_end
)
1191 pt
->read_end
= pt
->read_buf
+ 1;
1192 else if (pt
->read_pos
!= pt
->read_buf
+ 1)
1194 int count
= pt
->read_end
- pt
->read_pos
;
1196 memmove (pt
->read_buf
+ 1, pt
->read_pos
, count
);
1197 pt
->read_end
= pt
->read_buf
+ 1 + count
;
1200 pt
->read_pos
= pt
->read_buf
;
1203 /* switch to the put-back buffer. */
1205 if (pt
->putback_buf
== NULL
)
1208 = (unsigned char *) scm_gc_malloc (SCM_INITIAL_PUTBACK_BUF_SIZE
,
1210 pt
->putback_buf_size
= SCM_INITIAL_PUTBACK_BUF_SIZE
;
1213 pt
->saved_read_buf
= pt
->read_buf
;
1214 pt
->saved_read_pos
= pt
->read_pos
;
1215 pt
->saved_read_end
= pt
->read_end
;
1216 pt
->saved_read_buf_size
= pt
->read_buf_size
;
1218 pt
->read_pos
= pt
->read_buf
= pt
->putback_buf
;
1219 pt
->read_end
= pt
->read_buf
+ 1;
1220 pt
->read_buf_size
= pt
->putback_buf_size
;
1226 pt
->rw_active
= SCM_PORT_READ
;
1230 /* What should col be in this case?
1231 * We'll leave it at -1.
1233 SCM_LINUM (port
) -= 1;
1242 scm_ungets (const char *s
, int n
, SCM port
)
1244 /* This is simple minded and inefficient, but unreading strings is
1245 * probably not a common operation, and remember that line and
1246 * column numbers have to be handled...
1248 * Please feel free to write an optimized version!
1251 scm_ungetc (s
[n
], port
);
1255 SCM_DEFINE (scm_peek_char
, "peek-char", 0, 1, 0,
1257 "Return the next character available from @var{port},\n"
1258 "@emph{without} updating @var{port} to point to the following\n"
1259 "character. If no more characters are available, the\n"
1260 "end-of-file object is returned.\n"
1262 "The value returned by\n"
1263 "a call to @code{peek-char} is the same as the value that would\n"
1264 "have been returned by a call to @code{read-char} on the same\n"
1265 "port. The only difference is that the very next call to\n"
1266 "@code{read-char} or @code{peek-char} on that @var{port} will\n"
1267 "return the value returned by the preceding call to\n"
1268 "@code{peek-char}. In particular, a call to @code{peek-char} on\n"
1269 "an interactive port will hang waiting for input whenever a call\n"
1270 "to @code{read-char} would have hung.")
1271 #define FUNC_NAME s_scm_peek_char
1274 if (SCM_UNBNDP (port
))
1277 SCM_VALIDATE_OPINPORT (1, port
);
1278 column
= SCM_COL(port
);
1279 c
= scm_getc (port
);
1282 scm_ungetc (c
, port
);
1283 SCM_COL(port
) = column
;
1284 return SCM_MAKE_CHAR (c
);
1288 SCM_DEFINE (scm_unread_char
, "unread-char", 1, 1, 0,
1289 (SCM cobj
, SCM port
),
1290 "Place @var{char} in @var{port} so that it will be read by the\n"
1291 "next read operation. If called multiple times, the unread characters\n"
1292 "will be read again in last-in first-out order. If @var{port} is\n"
1293 "not supplied, the current input port is used.")
1294 #define FUNC_NAME s_scm_unread_char
1298 SCM_VALIDATE_CHAR (1, cobj
);
1299 if (SCM_UNBNDP (port
))
1302 SCM_VALIDATE_OPINPORT (2, port
);
1304 c
= SCM_CHAR (cobj
);
1306 scm_ungetc (c
, port
);
1311 SCM_DEFINE (scm_unread_string
, "unread-string", 2, 0, 0,
1312 (SCM str
, SCM port
),
1313 "Place the string @var{str} in @var{port} so that its characters will be\n"
1314 "read in subsequent read operations. If called multiple times, the\n"
1315 "unread characters will be read again in last-in first-out order. If\n"
1316 "@var{port} is not supplied, the current-input-port is used.")
1317 #define FUNC_NAME s_scm_unread_string
1319 SCM_VALIDATE_STRING (1, str
);
1320 if (SCM_UNBNDP (port
))
1323 SCM_VALIDATE_OPINPORT (2, port
);
1325 scm_ungets (SCM_I_STRING_CHARS (str
), SCM_I_STRING_LENGTH (str
), port
);
1331 SCM_DEFINE (scm_seek
, "seek", 3, 0, 0,
1332 (SCM fd_port
, SCM offset
, SCM whence
),
1333 "Sets the current position of @var{fd/port} to the integer\n"
1334 "@var{offset}, which is interpreted according to the value of\n"
1337 "One of the following variables should be supplied for\n"
1339 "@defvar SEEK_SET\n"
1340 "Seek from the beginning of the file.\n"
1342 "@defvar SEEK_CUR\n"
1343 "Seek from the current position.\n"
1345 "@defvar SEEK_END\n"
1346 "Seek from the end of the file.\n"
1348 "If @var{fd/port} is a file descriptor, the underlying system\n"
1349 "call is @code{lseek}. @var{port} may be a string port.\n"
1351 "The value returned is the new position in the file. This means\n"
1352 "that the current position of a port can be obtained using:\n"
1354 "(seek port 0 SEEK_CUR)\n"
1356 #define FUNC_NAME s_scm_seek
1362 fd_port
= SCM_COERCE_OUTPORT (fd_port
);
1364 if (sizeof (off_t
) == sizeof (scm_t_intmax
))
1365 off
= scm_to_intmax (offset
);
1367 off
= scm_to_long (offset
);
1368 how
= scm_to_int (whence
);
1370 if (how
!= SEEK_SET
&& how
!= SEEK_CUR
&& how
!= SEEK_END
)
1371 SCM_OUT_OF_RANGE (3, whence
);
1372 if (SCM_OPPORTP (fd_port
))
1374 scm_t_ptob_descriptor
*ptob
= scm_ptobs
+ SCM_PTOBNUM (fd_port
);
1377 SCM_MISC_ERROR ("port is not seekable",
1378 scm_cons (fd_port
, SCM_EOL
));
1380 rv
= ptob
->seek (fd_port
, off
, how
);
1382 else /* file descriptor?. */
1384 rv
= lseek (scm_to_int (fd_port
), off
, how
);
1388 return scm_from_intmax (rv
);
1393 /* Define this function since it is not supported under Windows. */
1394 static int truncate (char *file
, int length
)
1397 if ((fdes
= open (file
, O_BINARY
| O_WRONLY
)) != -1)
1399 ret
= chsize (fdes
, length
);
1404 #endif /* __MINGW32__ */
1406 SCM_DEFINE (scm_truncate_file
, "truncate-file", 1, 1, 0,
1407 (SCM object
, SCM length
),
1408 "Truncates the object referred to by @var{object} to at most\n"
1409 "@var{length} bytes. @var{object} can be a string containing a\n"
1410 "file name or an integer file descriptor or a port.\n"
1411 "@var{length} may be omitted if @var{object} is not a file name,\n"
1412 "in which case the truncation occurs at the current port\n"
1413 "position. The return value is unspecified.")
1414 #define FUNC_NAME s_scm_truncate_file
1419 /* object can be a port, fdes or filename. */
1421 if (SCM_UNBNDP (length
))
1423 /* must supply length if object is a filename. */
1424 if (scm_is_string (object
))
1425 SCM_MISC_ERROR("must supply length if OBJECT is a filename", SCM_EOL
);
1427 length
= scm_seek (object
, SCM_INUM0
, scm_from_int (SEEK_CUR
));
1429 c_length
= scm_to_size_t (length
);
1431 object
= SCM_COERCE_OUTPORT (object
);
1432 if (scm_is_integer (object
))
1434 SCM_SYSCALL (rv
= ftruncate (scm_to_int (object
), c_length
));
1436 else if (SCM_OPOUTPORTP (object
))
1438 scm_t_port
*pt
= SCM_PTAB_ENTRY (object
);
1439 scm_t_ptob_descriptor
*ptob
= scm_ptobs
+ SCM_PTOBNUM (object
);
1441 if (!ptob
->truncate
)
1442 SCM_MISC_ERROR ("port is not truncatable", SCM_EOL
);
1443 if (pt
->rw_active
== SCM_PORT_READ
)
1444 scm_end_input (object
);
1445 else if (pt
->rw_active
== SCM_PORT_WRITE
)
1446 ptob
->flush (object
);
1448 ptob
->truncate (object
, c_length
);
1453 char *str
= scm_to_locale_string (object
);
1455 SCM_SYSCALL (rv
= truncate (str
, c_length
));
1462 return SCM_UNSPECIFIED
;
1466 SCM_DEFINE (scm_port_line
, "port-line", 1, 0, 0,
1468 "Return the current line number for @var{port}.\n"
1470 "The first line of a file is 0. But you might want to add 1\n"
1471 "when printing line numbers, since starting from 1 is\n"
1472 "traditional in error messages, and likely to be more natural to\n"
1474 #define FUNC_NAME s_scm_port_line
1476 port
= SCM_COERCE_OUTPORT (port
);
1477 SCM_VALIDATE_OPENPORT (1, port
);
1478 return scm_from_int (SCM_LINUM (port
));
1482 SCM_DEFINE (scm_set_port_line_x
, "set-port-line!", 2, 0, 0,
1483 (SCM port
, SCM line
),
1484 "Set the current line number for @var{port} to @var{line}. The\n"
1485 "first line of a file is 0.")
1486 #define FUNC_NAME s_scm_set_port_line_x
1488 port
= SCM_COERCE_OUTPORT (port
);
1489 SCM_VALIDATE_OPENPORT (1, port
);
1490 SCM_PTAB_ENTRY (port
)->line_number
= scm_to_int (line
);
1491 return SCM_UNSPECIFIED
;
1495 SCM_DEFINE (scm_port_column
, "port-column", 1, 0, 0,
1497 "Return the current column number of @var{port}.\n"
1498 "If the number is\n"
1499 "unknown, the result is #f. Otherwise, the result is a 0-origin integer\n"
1500 "- i.e. the first character of the first line is line 0, column 0.\n"
1501 "(However, when you display a file position, for example in an error\n"
1502 "message, we recommend you add 1 to get 1-origin integers. This is\n"
1503 "because lines and column numbers traditionally start with 1, and that is\n"
1504 "what non-programmers will find most natural.)")
1505 #define FUNC_NAME s_scm_port_column
1507 port
= SCM_COERCE_OUTPORT (port
);
1508 SCM_VALIDATE_OPENPORT (1, port
);
1509 return scm_from_int (SCM_COL (port
));
1513 SCM_DEFINE (scm_set_port_column_x
, "set-port-column!", 2, 0, 0,
1514 (SCM port
, SCM column
),
1515 "Set the current column of @var{port}. Before reading the first\n"
1516 "character on a line the column should be 0.")
1517 #define FUNC_NAME s_scm_set_port_column_x
1519 port
= SCM_COERCE_OUTPORT (port
);
1520 SCM_VALIDATE_OPENPORT (1, port
);
1521 SCM_PTAB_ENTRY (port
)->column_number
= scm_to_int (column
);
1522 return SCM_UNSPECIFIED
;
1526 SCM_DEFINE (scm_port_filename
, "port-filename", 1, 0, 0,
1528 "Return the filename associated with @var{port}. This function returns\n"
1529 "the strings \"standard input\", \"standard output\" and \"standard error\"\n"
1530 "when called on the current input, output and error ports respectively.")
1531 #define FUNC_NAME s_scm_port_filename
1533 port
= SCM_COERCE_OUTPORT (port
);
1534 SCM_VALIDATE_OPENPORT (1, port
);
1535 return SCM_FILENAME (port
);
1539 SCM_DEFINE (scm_set_port_filename_x
, "set-port-filename!", 2, 0, 0,
1540 (SCM port
, SCM filename
),
1541 "Change the filename associated with @var{port}, using the current input\n"
1542 "port if none is specified. Note that this does not change the port's\n"
1543 "source of data, but only the value that is returned by\n"
1544 "@code{port-filename} and reported in diagnostic output.")
1545 #define FUNC_NAME s_scm_set_port_filename_x
1547 port
= SCM_COERCE_OUTPORT (port
);
1548 SCM_VALIDATE_OPENPORT (1, port
);
1549 /* We allow the user to set the filename to whatever he likes. */
1550 SCM_SET_FILENAME (port
, filename
);
1551 return SCM_UNSPECIFIED
;
1556 scm_print_port_mode (SCM exp
, SCM port
)
1558 scm_puts (SCM_CLOSEDP (exp
)
1560 : (SCM_RDNG
& SCM_CELL_WORD_0 (exp
)
1561 ? (SCM_WRTNG
& SCM_CELL_WORD_0 (exp
)
1564 : (SCM_WRTNG
& SCM_CELL_WORD_0 (exp
)
1571 scm_port_print (SCM exp
, SCM port
, scm_print_state
*pstate SCM_UNUSED
)
1573 char *type
= SCM_PTOBNAME (SCM_PTOBNUM (exp
));
1576 scm_puts ("#<", port
);
1577 scm_print_port_mode (exp
, port
);
1578 scm_puts (type
, port
);
1579 scm_putc (' ', port
);
1580 scm_intprint (SCM_CELL_WORD_1 (exp
), 16, port
);
1581 scm_putc ('>', port
);
1586 scm_ports_prehistory ()
1589 scm_ptobs
= (scm_t_ptob_descriptor
*) scm_malloc (sizeof (scm_t_ptob_descriptor
));
1596 scm_t_bits scm_tc16_void_port
= 0;
1598 static int fill_input_void_port (SCM port SCM_UNUSED
)
1604 write_void_port (SCM port SCM_UNUSED
,
1605 const void *data SCM_UNUSED
,
1606 size_t size SCM_UNUSED
)
1611 scm_i_void_port (long mode_bits
)
1613 scm_mutex_lock (&scm_i_port_table_mutex
);
1615 SCM answer
= scm_new_port_table_entry (scm_tc16_void_port
);
1616 scm_t_port
* pt
= SCM_PTAB_ENTRY(answer
);
1618 scm_port_non_buffer (pt
);
1620 SCM_SETSTREAM (answer
, 0);
1621 SCM_SET_CELL_TYPE (answer
, scm_tc16_void_port
| mode_bits
);
1622 scm_mutex_unlock (&scm_i_port_table_mutex
);
1628 scm_void_port (char *mode_str
)
1630 return scm_i_void_port (scm_mode_bits (mode_str
));
1633 SCM_DEFINE (scm_sys_make_void_port
, "%make-void-port", 1, 0, 0,
1635 "Create and return a new void port. A void port acts like\n"
1636 "@file{/dev/null}. The @var{mode} argument\n"
1637 "specifies the input/output modes for this port: see the\n"
1638 "documentation for @code{open-file} in @ref{File Ports}.")
1639 #define FUNC_NAME s_scm_sys_make_void_port
1641 return scm_i_void_port (scm_i_mode_bits (mode
));
1646 /* Initialization. */
1651 /* lseek() symbols. */
1652 scm_c_define ("SEEK_SET", scm_from_int (SEEK_SET
));
1653 scm_c_define ("SEEK_CUR", scm_from_int (SEEK_CUR
));
1654 scm_c_define ("SEEK_END", scm_from_int (SEEK_END
));
1656 scm_tc16_void_port
= scm_make_port_type ("void", fill_input_void_port
,
1658 #include "libguile/ports.x"