Next: , Previous: , Up: Input and Output   [Contents][Index]


6.14.12 Using Ports from C

Guile’s C interfaces provides some niceties for sending and receiving bytes and characters in a way that works better with C.

C Function: size_t scm_c_read (SCM port, void *buffer, size_t size)

Read up to size bytes from port and store them in buffer. The return value is the number of bytes actually read, which can be less than size if end-of-file has been reached.

Note that as this is a binary input procedure, this function does not update port-line and port-column (see Textual I/O).

C Function: void scm_c_write (SCM port, const void *buffer, size_t size)

Write size bytes at buffer to port.

Note that as this is a binary output procedure, this function does not update port-line and port-column (see Textual I/O).

C Function: size_t scm_c_read_bytes (SCM port, SCM bv, size_t start, size_t count)
C Function: void scm_c_write_bytes (SCM port, SCM bv, size_t start, size_t count)

Like scm_c_read and scm_c_write, but reading into or writing from the bytevector bv. count indicates the byte index at which to start in the bytevector, and the read or write will continue for count bytes.

C Function: void scm_unget_bytes (const unsigned char *buf, size_t len, SCM port)
C Function: void scm_unget_byte (int c, SCM port)
C Function: void scm_ungetc (scm_t_wchar c, SCM port)

Like unget-bytevector, unget-byte, and unget-char, respectively. See Textual I/O.

C Function: void scm_c_put_latin1_chars (SCM port, const scm_t_uint8 *buf, size_t len)
C Function: void scm_c_put_utf32_chars (SCM port, const scm_t_uint32 *buf, size_t len);

Write a string to port. In the first case, the scm_t_uint8* buffer is a string in the latin-1 encoding. In the second, the scm_t_uint32* buffer is a string in the UTF-32 encoding. These routines will update the port’s line and column.


Next: , Previous: , Up: Input and Output   [Contents][Index]