- SCM_SYSCALL ( fd = open (SCM_ROCHARS (path), SCM_INUM (flags), SCM_INUM (mode)) );
- if (fd == -1)
- scm_syserror (s_sys_open);
- sfd = scm_intern_fd (fd, scm_fd_is_open | scm_close_fd_on_gc);
- SCM_ALLOW_INTS;
-
- return scm_return_first (sfd, path);
-}
-
-
-SCM_PROC (s_sys_create, "create", 2, 0, 0, scm_sys_create);
-
-SCM
-scm_sys_create (path, mode)
- SCM path;
- SCM mode;
-{
- int fd;
- SCM sfd;
-
- SCM_ASSERT (SCM_NIMP (path) && SCM_ROSTRINGP (path), path, SCM_ARG1, s_sys_create);
- SCM_ASSERT (SCM_INUMP (mode), mode, SCM_ARG2, s_sys_create);
-
- if (SCM_SUBSTRP (path))
- path = scm_makfromstr (SCM_ROCHARS (path), SCM_ROLENGTH (path), 0);
-
- SCM_DEFER_INTS;
- SCM_SYSCALL ( fd = creat (SCM_ROCHARS (path), SCM_INUM (mode)) );
- if (fd == -1)
- scm_syserror (s_sys_create);
- sfd = scm_intern_fd (fd, scm_fd_is_open | scm_close_fd_on_gc);
- SCM_ALLOW_INTS;
-
- return scm_return_first (sfd, path);
-}
-
-
-SCM_PROC (s_sys_close, "close", 1, 0, 0, scm_sys_close);
-
-SCM
-scm_sys_close (sfd)
- SCM sfd;
-{
- int fd;
- int got;
- SCM_ASSERT (SCM_NIMP (sfd) && SCM_FD_P (sfd), sfd, SCM_ARG1, s_sys_close);
- fd = SCM_FD (sfd);
-
- SCM_DEFER_INTS;
- got = close (fd);
- SCM_SETCAR (sfd, scm_tc16_fd);
- SCM_ALLOW_INTS;
- if (got == -1)
- scm_syserror (s_sys_close);
- return SCM_UNSPECIFIED;
-}
-
-
-SCM_PROC (s_sys_write_fd, "write-fd", 2, 0, 0, scm_sys_write_fd);
-
-SCM
-scm_sys_write_fd (sfd, buf)
- SCM sfd;
- SCM buf;
-{
- SCM answer;
- int fd;
- size_t written;
- SCM_ASSERT (SCM_NIMP (sfd) && SCM_FD_P (sfd), sfd, SCM_ARG1, s_sys_write_fd);
- SCM_ASSERT (SCM_NIMP (buf) && SCM_ROSTRINGP (buf), buf, SCM_ARG2, s_sys_write_fd);
- fd = SCM_FD (sfd);
- SCM_DEFER_INTS;
- written = write (fd, SCM_ROCHARS (buf), SCM_ROLENGTH (buf));
- if (written == -1)
- scm_syserror (s_sys_write_fd);
- answer = scm_long2num (written);
- SCM_ALLOW_INTS;
- return scm_return_first (answer, buf);
-}
-
-
-SCM_PROC (s_sys_read_fd, "read-fd", 2, 2, 0, scm_sys_read_fd);
-
-SCM
-scm_sys_read_fd (sfd, buf, offset, length)
- SCM sfd;
- SCM buf;
- SCM offset;
- SCM length;
-{
- SCM answer;
- int fd;
- char * bytes;
- int off;
- int len;
- size_t got;
-
- SCM_ASSERT (SCM_NIMP (sfd) && SCM_FD_P (sfd), sfd, SCM_ARG1, s_sys_read_fd);
- fd = SCM_FD (sfd);
-
- SCM_ASSERT (SCM_NIMP (buf) && SCM_STRINGP (buf), buf, SCM_ARG2, s_sys_read_fd);
- bytes = SCM_CHARS (buf);
-
- if (SCM_UNBNDP (offset))
- off = 0;
- else
- {
- SCM_ASSERT (SCM_INUMP (offset), offset, SCM_ARG3, s_sys_read_fd);
- off = SCM_INUM (offset);
- }
-
- if (SCM_UNBNDP (length))
- len = SCM_LENGTH (buf);