1 /* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program 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
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this software; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
17 * As a special exception, the Free Software Foundation gives permission
18 * for additional uses of the text contained in its release of GUILE.
20 * The exception is that, if you link the GUILE library with other files
21 * to produce an executable, this does not by itself cause the
22 * resulting executable to be covered by the GNU General Public License.
23 * Your use of that executable is in no way restricted on account of
24 * linking the GUILE library code into it.
26 * This exception does not however invalidate any other reasons why
27 * the executable file might be covered by the GNU General Public License.
29 * This exception applies only to the code released by the
30 * Free Software Foundation under the name GUILE. If you copy
31 * code from other Free Software Foundation releases into a copy of
32 * GUILE, as the General Public License permits, the exception does
33 * not apply to the code that you add in this way. To avoid misleading
34 * anyone as to the status of such modified files, you must delete
35 * this exception notice from them.
37 * If you write modifications of your own for GUILE, it is your choice
38 * whether to permit this exception to apply to your modifications.
39 * If you do not wish that, delete this exception notice.
51 #ifdef TIME_WITH_SYS_TIME
52 # include <sys/time.h>
56 # include <sys/time.h>
66 #ifdef LIBC_H_WITH_UNISTD_H
70 #ifdef HAVE_SYS_SELECT_H
71 #include <sys/select.h>
78 #include <sys/types.h>
87 #define SELECT_TYPE fd_set
88 #define SELECT_SET_SIZE FD_SETSIZE
92 /* Define the macros to access a single-int bitmap of descriptors. */
93 #define SELECT_SET_SIZE 32
94 #define SELECT_TYPE int
95 #define FD_SET(n, p) (*(p) |= (1 << (n)))
96 #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
97 #define FD_ISSET(n, p) (*(p) & (1 << (n)))
98 #define FD_ZERO(p) (*(p) = 0)
100 #endif /* no FD_SET */
104 # define NAMLEN(dirent) strlen((dirent)->d_name)
106 # define dirent direct
107 # define NAMLEN(dirent) (dirent)->d_namlen
109 # include <sys/ndir.h>
112 # include <sys/dir.h>
127 SCM_PROC (s_chown
, "chown", 3, 0, 0, scm_chown
);
130 scm_chown (path
, owner
, group
)
137 SCM_ASSERT (SCM_NIMP (path
) && SCM_ROSTRINGP (path
), path
, SCM_ARG1
, s_chown
);
138 if (SCM_SUBSTRP (path
))
139 path
= scm_makfromstr (SCM_ROCHARS (path
), SCM_ROLENGTH (path
), 0);
140 SCM_ASSERT (SCM_INUMP (owner
), owner
, SCM_ARG2
, s_chown
);
141 SCM_ASSERT (SCM_INUMP (group
), group
, SCM_ARG3
, s_chown
);
142 SCM_SYSCALL (val
= chown (SCM_ROCHARS (path
),
143 SCM_INUM (owner
), SCM_INUM (group
)));
145 scm_syserror (s_chown
);
146 return SCM_UNSPECIFIED
;
150 SCM_PROC (s_chmod
, "chmod", 2, 0, 0, scm_chmod
);
153 scm_chmod (port_or_path
, mode
)
158 SCM_ASSERT (SCM_INUMP (mode
), mode
, SCM_ARG2
, s_chmod
);
159 SCM_ASSERT (SCM_NIMP (port_or_path
), port_or_path
, SCM_ARG1
, s_chmod
);
160 if (SCM_STRINGP (port_or_path
))
161 SCM_SYSCALL (rv
= chmod (SCM_CHARS (port_or_path
), SCM_INUM (mode
)));
164 SCM_ASSERT (SCM_OPFPORTP (port_or_path
), port_or_path
, SCM_ARG1
, s_chmod
);
165 rv
= fileno ((FILE *)SCM_STREAM (port_or_path
));
167 SCM_SYSCALL (rv
= fchmod (rv
, SCM_INUM (mode
)));
170 scm_syserror (s_chmod
);
171 return SCM_UNSPECIFIED
;
174 SCM_PROC (s_umask
, "umask", 0, 1, 0, scm_umask
);
181 if (SCM_UNBNDP (mode
))
188 SCM_ASSERT (SCM_INUMP (mode
), mode
, SCM_ARG1
, s_umask
);
189 mask
= umask (SCM_INUM (mode
));
191 return SCM_MAKINUM (mask
);
196 SCM_PROC (s_open
, "open", 2, 1, 0, scm_open
);
199 scm_open (path
, flags
, mode
)
210 SCM_ASSERT (SCM_NIMP (path
) && SCM_ROSTRINGP (path
), path
, SCM_ARG1
, s_open
);
211 iflags
= scm_num2long (flags
, (char *) SCM_ARG2
, s_open
);
213 if (SCM_SUBSTRP (path
))
214 path
= scm_makfromstr (SCM_ROCHARS (path
), SCM_ROLENGTH (path
), 0);
217 if (SCM_UNBNDP (mode
))
218 SCM_SYSCALL (fd
= open (SCM_ROCHARS (path
), iflags
));
221 SCM_ASSERT (SCM_INUMP (mode
), mode
, SCM_ARG3
, s_open
);
222 SCM_SYSCALL (fd
= open (SCM_ROCHARS (path
), iflags
, SCM_INUM (mode
)));
225 scm_syserror (s_open
);
230 if (iflags
& O_WRONLY
)
235 f
= fdopen (fd
, port_mode
);
238 SCM_SYSCALL (close (fd
));
239 scm_syserror (s_open
);
242 struct scm_port_table
* pt
;
244 pt
= scm_add_to_port_table (newpt
);
245 SCM_SETPTAB_ENTRY (newpt
, pt
);
246 SCM_SETCAR (newpt
, scm_tc16_fport
| scm_mode_bits (port_mode
));
247 /* if (SCM_BUF0 & SCM_CAR (newpt))
248 scm_setbuf0 (newpt); */
249 SCM_SETSTREAM (newpt
, (SCM
)f
);
250 SCM_PTAB_ENTRY (newpt
)->file_name
= path
;
261 SCM_SYMBOL (scm_sym_regular
, "regular");
262 SCM_SYMBOL (scm_sym_directory
, "directory");
263 SCM_SYMBOL (scm_sym_symlink
, "symlink");
264 SCM_SYMBOL (scm_sym_block_special
, "block-special");
265 SCM_SYMBOL (scm_sym_char_special
, "char-special");
266 SCM_SYMBOL (scm_sym_fifo
, "fifo");
267 SCM_SYMBOL (scm_sym_sock
, "socket");
268 SCM_SYMBOL (scm_sym_unknown
, "unknown");
270 static SCM scm_stat2scm
SCM_P ((struct stat
*stat_temp
));
273 scm_stat2scm (stat_temp
)
274 struct stat
*stat_temp
;
276 SCM ans
= scm_make_vector (SCM_MAKINUM (15), SCM_UNSPECIFIED
, SCM_BOOL_F
);
277 SCM
*ve
= SCM_VELTS (ans
);
279 ve
[0] = scm_ulong2num ((unsigned long) stat_temp
->st_dev
);
280 ve
[1] = scm_ulong2num ((unsigned long) stat_temp
->st_ino
);
281 ve
[2] = scm_ulong2num ((unsigned long) stat_temp
->st_mode
);
282 ve
[3] = scm_ulong2num ((unsigned long) stat_temp
->st_nlink
);
283 ve
[4] = scm_ulong2num ((unsigned long) stat_temp
->st_uid
);
284 ve
[5] = scm_ulong2num ((unsigned long) stat_temp
->st_gid
);
286 ve
[6] = scm_ulong2num ((unsigned long) stat_temp
->st_rdev
);
290 ve
[7] = scm_ulong2num ((unsigned long) stat_temp
->st_size
);
291 ve
[8] = scm_ulong2num ((unsigned long) stat_temp
->st_atime
);
292 ve
[9] = scm_ulong2num ((unsigned long) stat_temp
->st_mtime
);
293 ve
[10] = scm_ulong2num ((unsigned long) stat_temp
->st_ctime
);
294 #ifdef HAVE_ST_BLKSIZE
295 ve
[11] = scm_ulong2num ((unsigned long) stat_temp
->st_blksize
);
297 ve
[11] = scm_ulong2num (4096L);
299 #ifdef HAVE_ST_BLOCKS
300 ve
[12] = scm_ulong2num ((unsigned long) stat_temp
->st_blocks
);
305 int mode
= stat_temp
->st_mode
;
308 ve
[13] = scm_sym_regular
;
309 else if (S_ISDIR (mode
))
310 ve
[13] = scm_sym_directory
;
311 else if (S_ISLNK (mode
))
312 ve
[13] = scm_sym_symlink
;
313 else if (S_ISBLK (mode
))
314 ve
[13] = scm_sym_block_special
;
315 else if (S_ISCHR (mode
))
316 ve
[13] = scm_sym_char_special
;
317 else if (S_ISFIFO (mode
))
318 ve
[13] = scm_sym_fifo
;
319 else if (S_ISSOCK (mode
))
320 ve
[13] = scm_sym_sock
;
322 ve
[13] = scm_sym_unknown
;
324 ve
[14] = SCM_MAKINUM ((~S_IFMT
) & mode
);
326 /* the layout of the bits in ve[14] is intended to be portable.
327 If there are systems that don't follow the usual convention,
328 the following could be used:
331 if (S_ISUID & mode) tmp += 1;
333 if (S_IRGRP & mode) tmp += 1;
335 if (S_ISVTX & mode) tmp += 1;
337 if (S_IRUSR & mode) tmp += 1;
339 if (S_IWUSR & mode) tmp += 1;
341 if (S_IXUSR & mode) tmp += 1;
343 if (S_IWGRP & mode) tmp += 1;
345 if (S_IXGRP & mode) tmp += 1;
347 if (S_IROTH & mode) tmp += 1;
349 if (S_IWOTH & mode) tmp += 1;
351 if (S_IXOTH & mode) tmp += 1;
353 ve[14] = SCM_MAKINUM (tmp);
361 SCM_PROC (s_stat
, "stat", 1, 0, 0, scm_stat
);
364 scm_stat (fd_or_path
)
368 struct stat stat_temp
;
370 if (SCM_INUMP (fd_or_path
))
372 rv
= SCM_INUM (fd_or_path
);
373 SCM_SYSCALL (rv
= fstat (rv
, &stat_temp
));
377 SCM_ASSERT (SCM_NIMP (fd_or_path
), fd_or_path
, SCM_ARG1
, s_stat
);
378 SCM_ASSERT (SCM_ROSTRINGP (fd_or_path
), fd_or_path
, SCM_ARG1
, s_stat
);
379 if (SCM_ROSTRINGP (fd_or_path
))
381 if (SCM_SUBSTRP (fd_or_path
))
382 fd_or_path
= scm_makfromstr (SCM_ROCHARS (fd_or_path
), SCM_ROLENGTH (fd_or_path
), 0);
383 SCM_SYSCALL (rv
= stat (SCM_CHARS (fd_or_path
), &stat_temp
));
391 scm_syserror_msg (s_stat
, "%s: %S",
392 scm_listify (scm_makfrom0str (strerror (errno
)),
397 return scm_stat2scm (&stat_temp
);
402 /* {Modifying Directories}
405 SCM_PROC (s_link
, "link", 2, 0, 0, scm_link
);
408 scm_link (oldpath
, newpath
)
414 SCM_ASSERT (SCM_NIMP (oldpath
) && SCM_ROSTRINGP (oldpath
), oldpath
, SCM_ARG1
, s_link
);
415 if (SCM_SUBSTRP (oldpath
))
416 oldpath
= scm_makfromstr (SCM_ROCHARS (oldpath
), SCM_ROLENGTH (oldpath
), 0);
417 SCM_ASSERT (SCM_NIMP (newpath
) && SCM_ROSTRINGP (newpath
), newpath
, SCM_ARG2
, s_link
);
418 if (SCM_SUBSTRP (newpath
))
419 newpath
= scm_makfromstr (SCM_ROCHARS (newpath
), SCM_ROLENGTH (newpath
), 0);
420 SCM_SYSCALL (val
= link (SCM_ROCHARS (oldpath
), SCM_ROCHARS (newpath
)));
422 scm_syserror (s_link
);
423 return SCM_UNSPECIFIED
;
428 SCM_PROC (s_rename
, "rename-file", 2, 0, 0, scm_rename
);
431 scm_rename (oldname
, newname
)
436 SCM_ASSERT (SCM_NIMP (oldname
) && SCM_STRINGP (oldname
), oldname
, SCM_ARG1
, s_rename
);
437 SCM_ASSERT (SCM_NIMP (newname
) && SCM_STRINGP (newname
), newname
, SCM_ARG2
, s_rename
);
439 SCM_SYSCALL (rv
= rename (SCM_CHARS (oldname
), SCM_CHARS (newname
)));
441 scm_syserror (s_rename
);
442 return SCM_UNSPECIFIED
;
445 SCM_SYSCALL (rv
= link (SCM_CHARS (oldname
), SCM_CHARS (newname
)));
448 SCM_SYSCALL (rv
= unlink (SCM_CHARS (oldname
)));;
450 /* unlink failed. remove new name */
451 SCM_SYSCALL (unlink (SCM_CHARS (newname
)));
455 scm_syserror (s_rename
);
456 return SCM_UNSPECIFIED
;
461 SCM_PROC(s_delete_file
, "delete-file", 1, 0, 0, scm_delete_file
);
464 scm_delete_file (str
)
468 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_delete_file
);
469 SCM_SYSCALL (ans
= unlink (SCM_CHARS (str
)));
471 scm_syserror (s_delete_file
);
472 return SCM_UNSPECIFIED
;
476 SCM_PROC (s_mkdir
, "mkdir", 1, 1, 0, scm_mkdir
);
479 scm_mkdir (path
, mode
)
486 SCM_ASSERT (SCM_NIMP (path
) && SCM_STRINGP (path
), path
, SCM_ARG1
, s_mkdir
);
487 if (SCM_UNBNDP (mode
))
491 SCM_SYSCALL (rv
= mkdir (SCM_CHARS (path
), 0777 ^ mask
));
495 SCM_ASSERT (SCM_INUMP (mode
), mode
, SCM_ARG2
, s_mkdir
);
496 SCM_SYSCALL (rv
= mkdir (SCM_CHARS (path
), SCM_INUM (mode
)));
499 scm_syserror (s_mkdir
);
500 return SCM_UNSPECIFIED
;
502 scm_sysmissing (s_mkdir
);
509 SCM_PROC (s_rmdir
, "rmdir", 1, 0, 0, scm_rmdir
);
518 SCM_ASSERT (SCM_NIMP (path
) && SCM_STRINGP (path
), path
, SCM_ARG1
, s_rmdir
);
519 SCM_SYSCALL (val
= rmdir (SCM_CHARS (path
)));
521 scm_syserror (s_rmdir
);
522 return SCM_UNSPECIFIED
;
524 scm_sysmissing (s_rmdir
);
531 /* {Examining Directories}
536 SCM_PROC (s_opendir
, "opendir", 1, 0, 0, scm_opendir
);
539 scm_opendir (dirname
)
544 SCM_ASSERT (SCM_NIMP (dirname
) && SCM_STRINGP (dirname
), dirname
, SCM_ARG1
, s_opendir
);
547 SCM_SYSCALL (ds
= opendir (SCM_CHARS (dirname
)));
549 scm_syserror (s_opendir
);
550 SCM_SETCAR (dir
, scm_tc16_dir
| SCM_OPN
);
551 SCM_SETCDR (dir
, ds
);
557 SCM_PROC (s_readdir
, "readdir", 1, 0, 0, scm_readdir
);
563 struct dirent
*rdent
;
565 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPDIRP (port
), port
, SCM_ARG1
, s_readdir
);
567 SCM_SYSCALL (rdent
= readdir ((DIR *) SCM_CDR (port
)));
570 scm_syserror (s_readdir
);
571 return (rdent
? scm_makfromstr (rdent
->d_name
, NAMLEN (rdent
), 0)
577 SCM_PROC (s_rewinddir
, "rewinddir", 1, 0, 0, scm_rewinddir
);
583 SCM_ASSERT (SCM_NIMP (port
) && SCM_OPDIRP (port
), port
, SCM_ARG1
, s_rewinddir
);
584 rewinddir ((DIR *) SCM_CDR (port
));
585 return SCM_UNSPECIFIED
;
590 SCM_PROC (s_closedir
, "closedir", 1, 0, 0, scm_closedir
);
598 SCM_ASSERT (SCM_NIMP (port
) && SCM_DIRP (port
), port
, SCM_ARG1
, s_closedir
);
600 if (SCM_CLOSEDP (port
))
603 return SCM_UNSPECIFIED
;
605 SCM_SYSCALL (sts
= closedir ((DIR *) SCM_CDR (port
)));
607 scm_syserror (s_closedir
);
608 SCM_SETCAR (port
, scm_tc16_dir
);
610 return SCM_UNSPECIFIED
;
616 static int scm_dir_print
SCM_P ((SCM sexp
, SCM port
, scm_print_state
*pstate
));
619 scm_dir_print (sexp
, port
, pstate
)
622 scm_print_state
*pstate
;
624 scm_prinport (sexp
, port
, "directory");
629 static scm_sizet scm_dir_free
SCM_P ((SCM p
));
636 closedir ((DIR *) SCM_CDR (p
));
640 static scm_smobfuns dir_smob
= {scm_mark0
, scm_dir_free
, scm_dir_print
, 0};
643 /* {Navigating Directories}
647 SCM_PROC (s_chdir
, "chdir", 1, 0, 0, scm_chdir
);
655 SCM_ASSERT (SCM_NIMP (str
) && SCM_STRINGP (str
), str
, SCM_ARG1
, s_chdir
);
656 SCM_SYSCALL (ans
= chdir (SCM_CHARS (str
)));
658 scm_syserror (s_chdir
);
659 return SCM_UNSPECIFIED
;
664 SCM_PROC (s_getcwd
, "getcwd", 0, 0, 0, scm_getcwd
);
672 scm_sizet size
= 100;
677 wd
= scm_must_malloc (size
, s_getcwd
);
678 while ((rv
= getcwd (wd
, size
)) == 0 && errno
== ERANGE
)
682 wd
= scm_must_malloc (size
, s_getcwd
);
685 scm_syserror (s_getcwd
);
686 result
= scm_makfromstr (wd
, strlen (wd
), 0);
691 scm_sysmissing (s_getcwd
);
700 static void fill_select_type
SCM_P ((SELECT_TYPE
* set
, SCM list
));
703 fill_select_type (set
, list
)
707 while (list
!= SCM_EOL
)
709 if ( SCM_NIMP (SCM_CAR (list
))
710 && (scm_tc16_fport
== SCM_TYP16 (SCM_CAR (list
)))
711 && SCM_OPPORTP (SCM_CAR (list
)))
712 FD_SET (fileno ((FILE *)SCM_STREAM (SCM_CAR (list
))), set
);
713 else if (SCM_INUMP (SCM_CAR (list
)))
714 FD_SET (SCM_INUM (SCM_CAR (list
)), set
);
715 list
= SCM_CDR (list
);
720 static SCM retrieve_select_type
SCM_P ((SELECT_TYPE
* set
, SCM list
));
723 retrieve_select_type (set
, list
)
729 while (list
!= SCM_EOL
)
731 if ( SCM_NIMP (SCM_CAR (list
))
732 && (scm_tc16_fport
== SCM_TYP16 (SCM_CAR (list
)))
733 && SCM_OPPORTP (SCM_CAR (list
)))
735 if (FD_ISSET (fileno ((FILE *)SCM_STREAM (SCM_CAR (list
))), set
))
736 answer
= scm_cons (SCM_CAR (list
), answer
);
738 else if (SCM_INUMP (SCM_CAR (list
)))
740 if (FD_ISSET (SCM_INUM (SCM_CAR (list
)), set
))
741 answer
= scm_cons (SCM_CAR (list
), answer
);
743 list
= SCM_CDR (list
);
749 /* {Checking for events}
752 SCM_PROC (s_select
, "select", 3, 2, 0, scm_select
);
755 scm_select (reads
, writes
, excepts
, secs
, msecs
)
763 struct timeval timeout
;
764 struct timeval
* time_p
;
765 SELECT_TYPE read_set
;
766 SELECT_TYPE write_set
;
767 SELECT_TYPE except_set
;
770 SCM_ASSERT (-1 < scm_ilength (reads
), reads
, SCM_ARG1
, s_select
);
771 SCM_ASSERT (-1 < scm_ilength (writes
), reads
, SCM_ARG1
, s_select
);
772 SCM_ASSERT (-1 < scm_ilength (excepts
), reads
, SCM_ARG1
, s_select
);
775 FD_ZERO (&write_set
);
776 FD_ZERO (&except_set
);
778 fill_select_type (&read_set
, reads
);
779 fill_select_type (&write_set
, writes
);
780 fill_select_type (&except_set
, excepts
);
782 if (SCM_UNBNDP (secs
))
786 SCM_ASSERT (SCM_INUMP (secs
), secs
, SCM_ARG4
, s_select
);
787 if (SCM_UNBNDP (msecs
))
790 SCM_ASSERT (SCM_INUMP (msecs
), msecs
, SCM_ARG5
, s_select
);
792 timeout
.tv_sec
= SCM_INUM (secs
);
793 timeout
.tv_usec
= 1000 * SCM_INUM (msecs
);
798 sreturn
= select (SELECT_SET_SIZE
,
799 &read_set
, &write_set
, &except_set
, time_p
);
801 scm_syserror (s_select
);
803 return scm_listify (retrieve_select_type (&read_set
, reads
),
804 retrieve_select_type (&write_set
, writes
),
805 retrieve_select_type (&except_set
, excepts
),
808 scm_sysmissing (s_select
);
814 /* Check if FILE has characters waiting to be read. */
825 scm_input_waiting_p (f
, caller
)
831 if (fileno (f
) == fileno (stdin
) && (isatty (fileno (stdin
))))
848 # include <sys/ioctl.h>
857 scm_input_waiting_p (f
, caller
)
861 /* Can we return an end-of-file character? */
865 /* Do we have characters in the stdio buffer? */
866 # ifdef FILE_CNT_FIELD
867 if (f
->FILE_CNT_FIELD
> 0)
870 # ifdef FILE_CNT_GPTR
871 if (f
->_gptr
!= f
->_egptr
)
874 # ifdef FILE_CNT_READPTR
875 if (f
->_IO_read_end
!= f
->_IO_read_ptr
)
878 Configure
.in could
not guess the name of the correct field in a
FILE *.
879 This function needs to be ported to your system
.
880 It should
return zero iff no characters are waiting to be read
.;
885 /* Is the file prepared to deliver input? */
888 struct timeval timeout
;
889 SELECT_TYPE read_set
;
890 SELECT_TYPE write_set
;
891 SELECT_TYPE except_set
;
892 int fno
= fileno ((FILE *)f
);
895 FD_ZERO (&write_set
);
896 FD_ZERO (&except_set
);
898 FD_SET (fno
, &read_set
);
904 if (select (SELECT_SET_SIZE
,
905 &read_set
, &write_set
, &except_set
, &timeout
)
907 scm_syserror (caller
);
909 return FD_ISSET (fno
, &read_set
);
915 ioctl(fileno(f
), FIONREAD
, &remir
);
919 scm_misc_error ("char-ready?", "Not fully implemented\n");
929 SCM_PROC (s_symlink
, "symlink", 2, 0, 0, scm_symlink
);
932 scm_symlink(oldpath
, newpath
)
939 SCM_ASSERT(SCM_NIMP(oldpath
) && SCM_STRINGP(oldpath
), oldpath
, SCM_ARG1
, s_symlink
);
940 SCM_ASSERT(SCM_NIMP(newpath
) && SCM_STRINGP(newpath
), newpath
, SCM_ARG2
, s_symlink
);
941 SCM_SYSCALL (val
= symlink(SCM_CHARS(oldpath
), SCM_CHARS(newpath
)));
943 scm_syserror (s_symlink
);
944 return SCM_UNSPECIFIED
;
946 scm_sysmissing (s_symlink
);
953 SCM_PROC (s_readlink
, "readlink", 1, 0, 0, scm_readlink
);
961 scm_sizet size
= 100;
964 SCM_ASSERT (SCM_NIMP (path
) && SCM_STRINGP (path
), path
, (char *) SCM_ARG1
, s_readlink
);
966 buf
= scm_must_malloc (size
, s_readlink
);
967 while ((rv
= readlink (SCM_CHARS (path
), buf
, (scm_sizet
) size
)) == size
)
971 buf
= scm_must_malloc (size
, s_readlink
);
974 scm_syserror (s_readlink
);
975 result
= scm_makfromstr (buf
, rv
, 0);
980 scm_sysmissing (s_readlink
);
987 SCM_PROC (s_lstat
, "lstat", 1, 0, 0, scm_lstat
);
995 struct stat stat_temp
;
997 SCM_ASSERT(SCM_NIMP(str
) && SCM_STRINGP(str
), str
, (char *)SCM_ARG1
, s_lstat
);
998 SCM_SYSCALL(rv
= lstat(SCM_CHARS(str
), &stat_temp
));
1003 scm_syserror_msg (s_lstat
, "%s: %S",
1004 scm_listify (scm_makfrom0str (strerror (errno
)),
1009 return scm_stat2scm(&stat_temp
);
1011 scm_sysmissing (s_lstat
);
1018 SCM_PROC (s_copy_file
, "copy-file", 2, 0, 0, scm_copy_file
);
1021 scm_copy_file (oldfile
, newfile
)
1027 char buf
[BUFSIZ
]; /* this space could be shared. */
1028 struct stat oldstat
;
1030 SCM_ASSERT (SCM_NIMP (oldfile
) && SCM_ROSTRINGP (oldfile
), oldfile
, SCM_ARG1
, s_copy_file
);
1031 if (SCM_SUBSTRP (oldfile
))
1032 oldfile
= scm_makfromstr (SCM_ROCHARS (oldfile
), SCM_ROLENGTH (oldfile
), 0);
1033 SCM_ASSERT (SCM_NIMP (newfile
) && SCM_ROSTRINGP (newfile
), newfile
, SCM_ARG2
, s_copy_file
);
1034 if (SCM_SUBSTRP (newfile
))
1035 newfile
= scm_makfromstr (SCM_ROCHARS (newfile
), SCM_ROLENGTH (newfile
), 0);
1036 if (stat (SCM_ROCHARS (oldfile
), &oldstat
) == -1)
1037 scm_syserror (s_copy_file
);
1039 oldfd
= open (SCM_ROCHARS (oldfile
), O_RDONLY
);
1041 scm_syserror (s_copy_file
);
1043 /* use POSIX flags instead of 07777?. */
1044 newfd
= open (SCM_ROCHARS (newfile
), O_WRONLY
| O_CREAT
| O_TRUNC
,
1045 oldstat
.st_mode
& 07777);
1047 scm_syserror (s_copy_file
);
1049 while ((n
= read (oldfd
, buf
, sizeof buf
)) > 0)
1050 if (write (newfd
, buf
, n
) != n
)
1054 scm_syserror (s_copy_file
);
1057 if (close (newfd
) == -1)
1058 scm_syserror (s_copy_file
);
1060 return SCM_UNSPECIFIED
;
1068 scm_add_feature ("i/o-extensions");
1070 scm_tc16_dir
= scm_newsmob (&dir_smob
);
1073 scm_sysintern ("O_RDONLY", scm_long2num (O_RDONLY
));
1076 scm_sysintern ("O_WRONLY", scm_long2num (O_WRONLY
));
1079 scm_sysintern ("O_RDWR", scm_long2num (O_RDWR
));
1082 scm_sysintern ("O_CREAT", scm_long2num (O_CREAT
));
1085 scm_sysintern ("O_EXCL", scm_long2num (O_EXCL
));
1088 scm_sysintern ("O_NOCTTY", scm_long2num (O_NOCTTY
));
1091 scm_sysintern ("O_TRUNC", scm_long2num (O_TRUNC
));
1094 scm_sysintern ("O_APPEND", scm_long2num (O_APPEND
));
1097 scm_sysintern ("O_NONBLOCK", scm_long2num (O_NONBLOCK
));
1100 scm_sysintern ("O_NDELAY", scm_long2num (O_NDELAY
));
1103 scm_sysintern ("O_SYNC", scm_long2num (O_SYNC
));
1108 #include "filesys.x"