1 /* Copyright (C) 1996,1997,1998,1999,2000,2001, 2002, 2004, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /* See stime.c for comments on why _POSIX_C_SOURCE is not always defined. */
22 #define _GNU_SOURCE /* ask glibc for everything */
23 #define _LARGEFILE64_SOURCE /* ask for stat64 etc */
25 #define _POSIX_C_SOURCE 199506L /* for readdir_r */
37 #include "libguile/_scm.h"
38 #include "libguile/smob.h"
39 #include "libguile/feature.h"
40 #include "libguile/fports.h"
41 #include "libguile/private-gc.h" /* for SCM_MAX */
42 #include "libguile/iselect.h"
43 #include "libguile/strings.h"
44 #include "libguile/vectors.h"
45 #include "libguile/lang.h"
46 #include "libguile/dynwind.h"
48 #include "libguile/validate.h"
49 #include "libguile/filesys.h"
60 #ifdef TIME_WITH_SYS_TIME
61 # include <sys/time.h>
65 # include <sys/time.h>
75 #ifdef LIBC_H_WITH_UNISTD_H
79 #ifdef HAVE_SYS_SELECT_H
80 #include <sys/select.h>
87 #include <sys/types.h>
96 #if defined (__MINGW32__) || defined (_MSC_VER) || defined (__BORLANDC__)
97 # include "win32-dirent.h"
98 # define NAMLEN(dirent) strlen((dirent)->d_name)
99 /* The following bits are per AC_HEADER_DIRENT doco in the autoconf manual */
102 # define NAMLEN(dirent) strlen((dirent)->d_name)
104 # define dirent direct
105 # define NAMLEN(dirent) (dirent)->d_namlen
107 # include <sys/ndir.h>
110 # include <sys/dir.h>
117 /* Ultrix has S_IFSOCK, but no S_ISSOCK. Ipe! */
118 #if defined (S_IFSOCK) && ! defined (S_ISSOCK)
119 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
122 /* The MinGW gcc does not define the S_ISSOCK macro. Any other native Windows
123 compiler like BorlandC or MSVC has none of these macros defined. */
145 # define _S_IFIFO 0x1000 /* FIFO */
146 # define _S_IFCHR 0x2000 /* Character */
147 # define _S_IFBLK 0x3000 /* Block */
148 # define _S_IFDIR 0x4000 /* Directory */
149 # define _S_IFREG 0x8000 /* Regular */
150 # define _S_IFSOCK 0xC000 /* Socket */
171 # define S_ISBLK(mode) (((mode) & _S_IFMT) == _S_IFBLK)
172 # define S_ISFIFO(mode) (((mode) & _S_IFMT) == _S_IFIFO)
173 # define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
174 # define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR)
175 # define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG)
176 # define S_ISSOCK(mode) (((mode) & _S_IFMT) == _S_IFSOCK)
178 #endif /* __MINGW32__ */
180 /* Some more definitions for the native Windows port. */
182 # define mkdir(path, mode) mkdir (path)
183 # define fsync(fd) _commit (fd)
184 # define fchmod(fd, mode) (-1)
185 #endif /* __MINGW32__ */
187 /* dirfd() returns the file descriptor underlying a "DIR*" directory stream.
188 Found on MacOS X for instance. The following definition is for Solaris
189 10, it's probably not right elsewhere, but that's ok, it shouldn't be
190 used elsewhere. Crib note: If we need more then gnulib has a dirfd.m4
191 figuring out how to get the fd (dirfd function, dirfd macro, dd_fd field,
194 #define dirfd(dirstream) ((dirstream)->dd_fd)
199 /* Two helper macros for an often used pattern */
201 #define STRING_SYSCALL(str,cstr,code) \
204 char *cstr = scm_to_locale_string (str); \
205 SCM_SYSCALL (code); \
206 eno = errno; free (cstr); errno = eno; \
209 #define STRING2_SYSCALL(str1,cstr1,str2,cstr2,code) \
212 char *cstr1, *cstr2; \
213 scm_dynwind_begin (0); \
214 cstr1 = scm_to_locale_string (str1); \
215 scm_dynwind_free (cstr1); \
216 cstr2 = scm_to_locale_string (str2); \
217 scm_dynwind_free (cstr2); \
218 SCM_SYSCALL (code); \
219 eno = errno; scm_dynwind_end (); errno = eno; \
228 SCM_DEFINE (scm_chown
, "chown", 3, 0, 0,
229 (SCM object
, SCM owner
, SCM group
),
230 "Change the ownership and group of the file referred to by @var{object} to\n"
231 "the integer values @var{owner} and @var{group}. @var{object} can be\n"
232 "a string containing a file name or, if the platform\n"
233 "supports fchown, a port or integer file descriptor\n"
234 "which is open on the file. The return value\n"
235 "is unspecified.\n\n"
236 "If @var{object} is a symbolic link, either the\n"
237 "ownership of the link or the ownership of the referenced file will be\n"
238 "changed depending on the operating system (lchown is\n"
239 "unsupported at present). If @var{owner} or @var{group} is specified\n"
240 "as @code{-1}, then that ID is not changed.")
241 #define FUNC_NAME s_scm_chown
245 object
= SCM_COERCE_OUTPORT (object
);
248 if (scm_is_integer (object
) || (SCM_OPFPORTP (object
)))
250 int fdes
= (SCM_OPFPORTP (object
)?
251 SCM_FPORT_FDES (object
) : scm_to_int (object
));
253 SCM_SYSCALL (rv
= fchown (fdes
, scm_to_int (owner
), scm_to_int (group
)));
258 STRING_SYSCALL (object
, c_object
,
259 rv
= chown (c_object
,
260 scm_to_int (owner
), scm_to_int (group
)));
264 return SCM_UNSPECIFIED
;
267 #endif /* HAVE_CHOWN */
270 SCM_DEFINE (scm_chmod
, "chmod", 2, 0, 0,
271 (SCM object
, SCM mode
),
272 "Changes the permissions of the file referred to by @var{obj}.\n"
273 "@var{obj} can be a string containing a file name or a port or integer file\n"
274 "descriptor which is open on a file (in which case @code{fchmod} is used\n"
275 "as the underlying system call).\n"
276 "@var{mode} specifies\n"
277 "the new permissions as a decimal number, e.g., @code{(chmod \"foo\" #o755)}.\n"
278 "The return value is unspecified.")
279 #define FUNC_NAME s_scm_chmod
284 object
= SCM_COERCE_OUTPORT (object
);
286 if (scm_is_integer (object
) || SCM_OPFPORTP (object
))
288 if (scm_is_integer (object
))
289 fdes
= scm_to_int (object
);
291 fdes
= SCM_FPORT_FDES (object
);
292 SCM_SYSCALL (rv
= fchmod (fdes
, scm_to_int (mode
)));
296 STRING_SYSCALL (object
, c_object
,
297 rv
= chmod (c_object
, scm_to_int (mode
)));
301 return SCM_UNSPECIFIED
;
305 SCM_DEFINE (scm_umask
, "umask", 0, 1, 0,
307 "If @var{mode} is omitted, returns a decimal number representing the current\n"
308 "file creation mask. Otherwise the file creation mask is set to\n"
309 "@var{mode} and the previous value is returned.\n\n"
310 "E.g., @code{(umask #o022)} sets the mask to octal 22, decimal 18.")
311 #define FUNC_NAME s_scm_umask
314 if (SCM_UNBNDP (mode
))
321 mask
= umask (scm_to_uint (mode
));
323 return scm_from_uint (mask
);
329 SCM_DEFINE (scm_open_fdes
, "open-fdes", 2, 1, 0,
330 (SCM path
, SCM flags
, SCM mode
),
331 "Similar to @code{open} but return a file descriptor instead of\n"
333 #define FUNC_NAME s_scm_open_fdes
339 iflags
= SCM_NUM2INT (2, flags
);
340 imode
= SCM_NUM2INT_DEF (3, mode
, 0666);
341 STRING_SYSCALL (path
, c_path
, fd
= open_or_open64 (c_path
, iflags
, imode
));
344 return scm_from_int (fd
);
348 SCM_DEFINE (scm_open
, "open", 2, 1, 0,
349 (SCM path
, SCM flags
, SCM mode
),
350 "Open the file named by @var{path} for reading and/or writing.\n"
351 "@var{flags} is an integer specifying how the file should be opened.\n"
352 "@var{mode} is an integer specifying the permission bits of the file, if\n"
353 "it needs to be created, before the umask is applied. The default is 666\n"
354 "(Unix itself has no default).\n\n"
355 "@var{flags} can be constructed by combining variables using @code{logior}.\n"
356 "Basic flags are:\n\n"
358 "Open the file read-only.\n"
361 "Open the file write-only.\n"
364 "Open the file read/write.\n"
367 "Append to the file instead of truncating.\n"
370 "Create the file if it does not already exist.\n"
372 "See the Unix documentation of the @code{open} system call\n"
373 "for additional flags.")
374 #define FUNC_NAME s_scm_open
381 fd
= scm_to_int (scm_open_fdes (path
, flags
, mode
));
382 iflags
= SCM_NUM2INT (2, flags
);
385 if (iflags
& O_APPEND
)
387 else if (iflags
& O_CREAT
)
393 if (iflags
& O_APPEND
)
395 else if (iflags
& O_WRONLY
)
400 newpt
= scm_fdes_to_port (fd
, port_mode
, path
);
405 SCM_DEFINE (scm_close
, "close", 1, 0, 0,
407 "Similar to close-port (@pxref{Closing, close-port}),\n"
408 "but also works on file descriptors. A side\n"
409 "effect of closing a file descriptor is that any ports using that file\n"
410 "descriptor are moved to a different file descriptor and have\n"
411 "their revealed counts set to zero.")
412 #define FUNC_NAME s_scm_close
417 fd_or_port
= SCM_COERCE_OUTPORT (fd_or_port
);
419 if (SCM_PORTP (fd_or_port
))
420 return scm_close_port (fd_or_port
);
421 fd
= scm_to_int (fd_or_port
);
422 scm_evict_ports (fd
); /* see scsh manual. */
423 SCM_SYSCALL (rv
= close (fd
));
424 /* following scsh, closing an already closed file descriptor is
426 if (rv
< 0 && errno
!= EBADF
)
428 return scm_from_bool (rv
>= 0);
432 SCM_DEFINE (scm_close_fdes
, "close-fdes", 1, 0, 0,
434 "A simple wrapper for the @code{close} system call.\n"
435 "Close file descriptor @var{fd}, which must be an integer.\n"
436 "Unlike close (@pxref{Ports and File Descriptors, close}),\n"
437 "the file descriptor will be closed even if a port is using it.\n"
438 "The return value is unspecified.")
439 #define FUNC_NAME s_scm_close_fdes
444 c_fd
= scm_to_int (fd
);
445 SCM_SYSCALL (rv
= close (c_fd
));
448 return SCM_UNSPECIFIED
;
456 SCM_SYMBOL (scm_sym_regular
, "regular");
457 SCM_SYMBOL (scm_sym_directory
, "directory");
459 SCM_SYMBOL (scm_sym_symlink
, "symlink");
461 SCM_SYMBOL (scm_sym_block_special
, "block-special");
462 SCM_SYMBOL (scm_sym_char_special
, "char-special");
463 SCM_SYMBOL (scm_sym_fifo
, "fifo");
464 SCM_SYMBOL (scm_sym_sock
, "socket");
465 SCM_SYMBOL (scm_sym_unknown
, "unknown");
468 scm_stat2scm (struct stat_or_stat64
*stat_temp
)
470 SCM ans
= scm_c_make_vector (15, SCM_UNSPECIFIED
);
472 SCM_SIMPLE_VECTOR_SET(ans
, 0, scm_from_ulong (stat_temp
->st_dev
));
473 SCM_SIMPLE_VECTOR_SET(ans
, 1, scm_from_ino_t_or_ino64_t (stat_temp
->st_ino
));
474 SCM_SIMPLE_VECTOR_SET(ans
, 2, scm_from_ulong (stat_temp
->st_mode
));
475 SCM_SIMPLE_VECTOR_SET(ans
, 3, scm_from_ulong (stat_temp
->st_nlink
));
476 SCM_SIMPLE_VECTOR_SET(ans
, 4, scm_from_ulong (stat_temp
->st_uid
));
477 SCM_SIMPLE_VECTOR_SET(ans
, 5, scm_from_ulong (stat_temp
->st_gid
));
478 #ifdef HAVE_STRUCT_STAT_ST_RDEV
479 SCM_SIMPLE_VECTOR_SET(ans
, 6, scm_from_ulong (stat_temp
->st_rdev
));
481 SCM_SIMPLE_VECTOR_SET(ans
, 6, SCM_BOOL_F
);
483 SCM_SIMPLE_VECTOR_SET(ans
, 7, scm_from_off_t_or_off64_t (stat_temp
->st_size
));
484 SCM_SIMPLE_VECTOR_SET(ans
, 8, scm_from_ulong (stat_temp
->st_atime
));
485 SCM_SIMPLE_VECTOR_SET(ans
, 9, scm_from_ulong (stat_temp
->st_mtime
));
486 SCM_SIMPLE_VECTOR_SET(ans
, 10, scm_from_ulong (stat_temp
->st_ctime
));
487 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
488 SCM_SIMPLE_VECTOR_SET(ans
, 11, scm_from_ulong (stat_temp
->st_blksize
));
490 SCM_SIMPLE_VECTOR_SET(ans
, 11, scm_from_ulong (4096L));
492 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
493 SCM_SIMPLE_VECTOR_SET(ans
, 12, scm_from_blkcnt_t_or_blkcnt64_t (stat_temp
->st_blocks
));
495 SCM_SIMPLE_VECTOR_SET(ans
, 12, SCM_BOOL_F
);
498 int mode
= stat_temp
->st_mode
;
501 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_regular
);
502 else if (S_ISDIR (mode
))
503 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_directory
);
505 /* systems without symlinks probably don't have S_ISLNK */
506 else if (S_ISLNK (mode
))
507 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_symlink
);
509 else if (S_ISBLK (mode
))
510 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_block_special
);
511 else if (S_ISCHR (mode
))
512 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_char_special
);
513 else if (S_ISFIFO (mode
))
514 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_fifo
);
516 else if (S_ISSOCK (mode
))
517 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_sock
);
520 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_unknown
);
522 SCM_SIMPLE_VECTOR_SET(ans
, 14, scm_from_int ((~S_IFMT
) & mode
));
524 /* the layout of the bits in ve[14] is intended to be portable.
525 If there are systems that don't follow the usual convention,
526 the following could be used:
529 if (S_ISUID & mode) tmp += 1;
531 if (S_IRGRP & mode) tmp += 1;
533 if (S_ISVTX & mode) tmp += 1;
535 if (S_IRUSR & mode) tmp += 1;
537 if (S_IWUSR & mode) tmp += 1;
539 if (S_IXUSR & mode) tmp += 1;
541 if (S_IWGRP & mode) tmp += 1;
543 if (S_IXGRP & mode) tmp += 1;
545 if (S_IROTH & mode) tmp += 1;
547 if (S_IWOTH & mode) tmp += 1;
549 if (S_IXOTH & mode) tmp += 1;
551 SCM_SIMPLE_VECTOR_SET(ans, 14, scm_from_int (tmp));
561 * Try getting the appropiate stat buffer for a given file descriptor
562 * under Windows. It differentiates between file, pipe and socket
565 static int fstat_Win32 (int fdes
, struct stat
*buf
)
567 int error
, optlen
= sizeof (int);
569 memset (buf
, 0, sizeof (struct stat
));
571 /* Is this a socket ? */
572 if (getsockopt (fdes
, SOL_SOCKET
, SO_ERROR
, (void *) &error
, &optlen
) >= 0)
574 buf
->st_mode
= _S_IFSOCK
| _S_IREAD
| _S_IWRITE
| _S_IEXEC
;
576 buf
->st_atime
= buf
->st_ctime
= buf
->st_mtime
= time (NULL
);
579 /* Maybe a regular file or pipe ? */
580 return fstat (fdes
, buf
);
582 #endif /* __MINGW32__ */
584 SCM_DEFINE (scm_stat
, "stat", 1, 0, 0,
586 "Return an object containing various information about the file\n"
587 "determined by @var{obj}. @var{obj} can be a string containing\n"
588 "a file name or a port or integer file descriptor which is open\n"
589 "on a file (in which case @code{fstat} is used as the underlying\n"
592 "The object returned by @code{stat} can be passed as a single\n"
593 "parameter to the following procedures, all of which return\n"
598 "The device containing the file.\n"
600 "The file serial number, which distinguishes this file from all\n"
601 "other files on the same device.\n"
603 "The mode of the file. This includes file type information and\n"
604 "the file permission bits. See @code{stat:type} and\n"
605 "@code{stat:perms} below.\n"
607 "The number of hard links to the file.\n"
609 "The user ID of the file's owner.\n"
611 "The group ID of the file.\n"
613 "Device ID; this entry is defined only for character or block\n"
616 "The size of a regular file in bytes.\n"
618 "The last access time for the file.\n"
620 "The last modification time for the file.\n"
622 "The last modification time for the attributes of the file.\n"
623 "@item stat:blksize\n"
624 "The optimal block size for reading or writing the file, in\n"
626 "@item stat:blocks\n"
627 "The amount of disk space that the file occupies measured in\n"
628 "units of 512 byte blocks.\n"
631 "In addition, the following procedures return the information\n"
632 "from stat:mode in a more convenient form:\n"
636 "A symbol representing the type of file. Possible values are\n"
637 "regular, directory, symlink, block-special, char-special, fifo,\n"
638 "socket and unknown\n"
640 "An integer representing the access permission bits.\n"
642 #define FUNC_NAME s_scm_stat
646 struct stat_or_stat64 stat_temp
;
648 if (scm_is_integer (object
))
651 SCM_SYSCALL (rv
= fstat_Win32 (scm_to_int (object
), &stat_temp
));
653 SCM_SYSCALL (rv
= fstat_or_fstat64 (scm_to_int (object
), &stat_temp
));
656 else if (scm_is_string (object
))
658 char *file
= scm_to_locale_string (object
);
661 p
= file
+ strlen (file
) - 1;
662 while (p
> file
&& (*p
== '/' || *p
== '\\'))
665 SCM_SYSCALL (rv
= stat_or_stat64 (file
, &stat_temp
));
670 object
= SCM_COERCE_OUTPORT (object
);
671 SCM_VALIDATE_OPFPORT (1, object
);
672 fdes
= SCM_FPORT_FDES (object
);
674 SCM_SYSCALL (rv
= fstat_Win32 (fdes
, &stat_temp
));
676 SCM_SYSCALL (rv
= fstat_or_fstat64 (fdes
, &stat_temp
));
684 SCM_SYSERROR_MSG ("~A: ~S",
685 scm_list_2 (scm_strerror (scm_from_int (en
)),
689 return scm_stat2scm (&stat_temp
);
694 /* {Modifying Directories}
698 SCM_DEFINE (scm_link
, "link", 2, 0, 0,
699 (SCM oldpath
, SCM newpath
),
700 "Creates a new name @var{newpath} in the file system for the\n"
701 "file named by @var{oldpath}. If @var{oldpath} is a symbolic\n"
702 "link, the link may or may not be followed depending on the\n"
704 #define FUNC_NAME s_scm_link
708 STRING2_SYSCALL (oldpath
, c_oldpath
,
710 val
= link (c_oldpath
, c_newpath
));
713 return SCM_UNSPECIFIED
;
716 #endif /* HAVE_LINK */
719 #define my_rename rename
722 my_rename (const char *oldname
, const char *newname
)
726 SCM_SYSCALL (rv
= link (oldname
, newname
));
729 SCM_SYSCALL (rv
= unlink (oldname
));
731 /* unlink failed. remove new name */
732 SCM_SYSCALL (unlink (newname
));
738 SCM_DEFINE (scm_rename
, "rename-file", 2, 0, 0,
739 (SCM oldname
, SCM newname
),
740 "Renames the file specified by @var{oldname} to @var{newname}.\n"
741 "The return value is unspecified.")
742 #define FUNC_NAME s_scm_rename
746 STRING2_SYSCALL (oldname
, c_oldname
,
748 rv
= my_rename (c_oldname
, c_newname
));
751 return SCM_UNSPECIFIED
;
756 SCM_DEFINE (scm_delete_file
, "delete-file", 1, 0, 0,
758 "Deletes (or \"unlinks\") the file specified by @var{path}.")
759 #define FUNC_NAME s_scm_delete_file
762 STRING_SYSCALL (str
, c_str
, ans
= unlink (c_str
));
765 return SCM_UNSPECIFIED
;
770 SCM_DEFINE (scm_mkdir
, "mkdir", 1, 1, 0,
771 (SCM path
, SCM mode
),
772 "Create a new directory named by @var{path}. If @var{mode} is omitted\n"
773 "then the permissions of the directory file are set using the current\n"
774 "umask. Otherwise they are set to the decimal value specified with\n"
775 "@var{mode}. The return value is unspecified.")
776 #define FUNC_NAME s_scm_mkdir
781 if (SCM_UNBNDP (mode
))
785 STRING_SYSCALL (path
, c_path
, rv
= mkdir (c_path
, 0777 ^ mask
));
789 STRING_SYSCALL (path
, c_path
, rv
= mkdir (c_path
, scm_to_uint (mode
)));
793 return SCM_UNSPECIFIED
;
796 #endif /* HAVE_MKDIR */
799 SCM_DEFINE (scm_rmdir
, "rmdir", 1, 0, 0,
801 "Remove the existing directory named by @var{path}. The directory must\n"
802 "be empty for this to succeed. The return value is unspecified.")
803 #define FUNC_NAME s_scm_rmdir
807 STRING_SYSCALL (path
, c_path
, val
= rmdir (c_path
));
810 return SCM_UNSPECIFIED
;
817 /* {Examining Directories}
820 scm_t_bits scm_tc16_dir
;
823 SCM_DEFINE (scm_directory_stream_p
, "directory-stream?", 1, 0, 0,
825 "Return a boolean indicating whether @var{object} is a directory\n"
826 "stream as returned by @code{opendir}.")
827 #define FUNC_NAME s_scm_directory_stream_p
829 return scm_from_bool (SCM_DIRP (obj
));
834 SCM_DEFINE (scm_opendir
, "opendir", 1, 0, 0,
836 "Open the directory specified by @var{path} and return a directory\n"
838 #define FUNC_NAME s_scm_opendir
841 STRING_SYSCALL (dirname
, c_dirname
, ds
= opendir (c_dirname
));
844 SCM_RETURN_NEWSMOB (scm_tc16_dir
| SCM_DIR_FLAG_OPEN
, ds
);
849 /* FIXME: The glibc manual has a portability note that readdir_r may not
850 null-terminate its return string. The circumstances outlined for this
851 are not clear, nor is it clear what should be done about it. Lets use
852 NAMLEN and worry about what else should be done if/when someone can
855 SCM_DEFINE (scm_readdir
, "readdir", 1, 0, 0,
857 "Return (as a string) the next directory entry from the directory stream\n"
858 "@var{stream}. If there is no remaining entry to be read then the\n"
859 "end of file object is returned.")
860 #define FUNC_NAME s_scm_readdir
862 struct dirent_or_dirent64
*rdent
;
864 SCM_VALIDATE_DIR (1, port
);
865 if (!SCM_DIR_OPEN_P (port
))
866 SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port
));
869 /* As noted in the glibc manual, on various systems (such as Solaris) the
870 d_name[] field is only 1 char and you're expected to size the dirent
871 buffer for readdir_r based on NAME_MAX. The SCM_MAX expressions below
872 effectively give either sizeof(d_name) or NAME_MAX+1, whichever is
875 On solaris 10 there's no NAME_MAX constant, it's necessary to use
876 pathconf(). We prefer NAME_MAX though, since it should be a constant
877 and will therefore save a system call. We also prefer it since dirfd()
878 is not available everywhere.
880 An alternative to dirfd() would be to open() the directory and then use
881 fdopendir(), if the latter is available. That'd let us hold the fd
882 somewhere in the smob, or just the dirent size calculated once. */
884 struct dirent_or_dirent64 de
; /* just for sizeof */
885 DIR *ds
= (DIR *) SCM_CELL_WORD_1 (port
);
888 char buf
[SCM_MAX (sizeof (de
),
889 sizeof (de
) - sizeof (de
.d_name
) + NAME_MAX
+ 1)];
892 long name_max
= fpathconf (dirfd (ds
), _PC_NAME_MAX
);
895 buf
= alloca (SCM_MAX (sizeof (de
),
896 sizeof (de
) - sizeof (de
.d_name
) + name_max
+ 1));
900 SCM_SYSCALL (readdir_r_or_readdir64_r (ds
, (struct dirent_or_dirent64
*) buf
, &rdent
));
906 namlen
= NAMLEN (rdent
);
908 return (rdent
? scm_from_locale_stringn (rdent
->d_name
, NAMLEN (rdent
))
914 scm_dynwind_begin (0);
915 scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex
);
918 SCM_SYSCALL (rdent
= readdir_or_readdir64 ((DIR *) SCM_CELL_WORD_1 (port
)));
922 ret
= (rdent
? scm_from_locale_stringn (rdent
->d_name
, NAMLEN (rdent
))
933 SCM_DEFINE (scm_rewinddir
, "rewinddir", 1, 0, 0,
935 "Reset the directory port @var{stream} so that the next call to\n"
936 "@code{readdir} will return the first directory entry.")
937 #define FUNC_NAME s_scm_rewinddir
939 SCM_VALIDATE_DIR (1, port
);
940 if (!SCM_DIR_OPEN_P (port
))
941 SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port
));
943 rewinddir ((DIR *) SCM_CELL_WORD_1 (port
));
945 return SCM_UNSPECIFIED
;
950 SCM_DEFINE (scm_closedir
, "closedir", 1, 0, 0,
952 "Close the directory stream @var{stream}.\n"
953 "The return value is unspecified.")
954 #define FUNC_NAME s_scm_closedir
956 SCM_VALIDATE_DIR (1, port
);
958 if (SCM_DIR_OPEN_P (port
))
962 SCM_SYSCALL (sts
= closedir ((DIR *) SCM_CELL_WORD_1 (port
)));
966 SCM_SET_CELL_WORD_0 (port
, scm_tc16_dir
);
969 return SCM_UNSPECIFIED
;
975 scm_dir_print (SCM exp
, SCM port
, scm_print_state
*pstate SCM_UNUSED
)
977 scm_puts ("#<", port
);
978 if (!SCM_DIR_OPEN_P (exp
))
979 scm_puts ("closed: ", port
);
980 scm_puts ("directory stream ", port
);
981 scm_uintprint (SCM_CELL_WORD_1 (exp
), 16, port
);
982 scm_putc ('>', port
);
990 if (SCM_DIR_OPEN_P (p
))
991 closedir ((DIR *) SCM_CELL_WORD_1 (p
));
996 /* {Navigating Directories}
1000 SCM_DEFINE (scm_chdir
, "chdir", 1, 0, 0,
1002 "Change the current working directory to @var{path}.\n"
1003 "The return value is unspecified.")
1004 #define FUNC_NAME s_scm_chdir
1008 STRING_SYSCALL (str
, c_str
, ans
= chdir (c_str
));
1011 return SCM_UNSPECIFIED
;
1016 SCM_DEFINE (scm_getcwd
, "getcwd", 0, 0, 0,
1018 "Return the name of the current working directory.")
1019 #define FUNC_NAME s_scm_getcwd
1026 wd
= scm_malloc (size
);
1027 while ((rv
= getcwd (wd
, size
)) == 0 && errno
== ERANGE
)
1031 wd
= scm_malloc (size
);
1035 int save_errno
= errno
;
1040 result
= scm_from_locale_stringn (wd
, strlen (wd
));
1045 #endif /* HAVE_GETCWD */
1051 /* check that element is a port or file descriptor. if it's a port
1052 and its buffer is ready for use, add it to the ports_ready list.
1053 otherwise add its file descriptor to *set. the type of list can be
1054 determined from pos: SCM_ARG1 for reads, SCM_ARG2 for writes,
1055 SCM_ARG3 for excepts. */
1057 set_element (SELECT_TYPE
*set
, SCM
*ports_ready
, SCM element
, int pos
)
1061 if (scm_is_integer (element
))
1063 fd
= scm_to_int (element
);
1069 element
= SCM_COERCE_OUTPORT (element
);
1070 SCM_ASSERT (SCM_OPFPORTP (element
), element
, pos
, "select");
1071 if (pos
== SCM_ARG1
)
1073 /* check whether port has buffered input. */
1074 scm_t_port
*pt
= SCM_PTAB_ENTRY (element
);
1076 if (pt
->read_pos
< pt
->read_end
)
1079 else if (pos
== SCM_ARG2
)
1081 /* check whether port's output buffer has room. */
1082 scm_t_port
*pt
= SCM_PTAB_ENTRY (element
);
1084 /* > 1 since writing the last byte in the buffer causes flush. */
1085 if (pt
->write_end
- pt
->write_pos
> 1)
1088 fd
= use_buf
? -1 : SCM_FPORT_FDES (element
);
1091 *ports_ready
= scm_cons (element
, *ports_ready
);
1097 /* check list_or_vec, a list or vector of ports or file descriptors,
1098 adding each member to either the ports_ready list (if it's a port
1099 with a usable buffer) or to *set. the kind of list_or_vec can be
1100 determined from pos: SCM_ARG1 for reads, SCM_ARG2 for writes,
1101 SCM_ARG3 for excepts. */
1103 fill_select_type (SELECT_TYPE
*set
, SCM
*ports_ready
, SCM list_or_vec
, int pos
)
1107 if (scm_is_simple_vector (list_or_vec
))
1109 int i
= SCM_SIMPLE_VECTOR_LENGTH (list_or_vec
);
1113 int fd
= set_element (set
, ports_ready
,
1114 SCM_SIMPLE_VECTOR_REF (list_or_vec
, i
), pos
);
1122 while (!SCM_NULL_OR_NIL_P (list_or_vec
))
1124 int fd
= set_element (set
, ports_ready
, SCM_CAR (list_or_vec
), pos
);
1128 list_or_vec
= SCM_CDR (list_or_vec
);
1135 /* if element (a file descriptor or port) appears in *set, cons it to
1136 list. return list. */
1138 get_element (SELECT_TYPE
*set
, SCM element
, SCM list
)
1142 if (scm_is_integer (element
))
1144 fd
= scm_to_int (element
);
1148 fd
= SCM_FPORT_FDES (SCM_COERCE_OUTPORT (element
));
1150 if (FD_ISSET (fd
, set
))
1151 list
= scm_cons (element
, list
);
1155 /* construct component of scm_select return value.
1156 set: pointer to set of file descriptors found by select to be ready
1157 ports_ready: ports ready due to buffering
1158 list_or_vec: original list/vector handed to scm_select.
1159 the return value is a list/vector of ready ports/file descriptors.
1160 works by finding the objects in list which correspond to members of
1161 *set and appending them to ports_ready. result is converted to a
1162 vector if list_or_vec is a vector. */
1164 retrieve_select_type (SELECT_TYPE
*set
, SCM ports_ready
, SCM list_or_vec
)
1166 SCM answer_list
= ports_ready
;
1168 if (scm_is_simple_vector (list_or_vec
))
1170 int i
= SCM_SIMPLE_VECTOR_LENGTH (list_or_vec
);
1174 answer_list
= get_element (set
,
1175 SCM_SIMPLE_VECTOR_REF (list_or_vec
, i
),
1178 return scm_vector (answer_list
);
1182 /* list_or_vec must be a list. */
1183 while (!SCM_NULL_OR_NIL_P (list_or_vec
))
1185 answer_list
= get_element (set
, SCM_CAR (list_or_vec
), answer_list
);
1186 list_or_vec
= SCM_CDR (list_or_vec
);
1192 /* Static helper functions above refer to s_scm_select directly as s_select */
1193 SCM_DEFINE (scm_select
, "select", 3, 2, 0,
1194 (SCM reads
, SCM writes
, SCM excepts
, SCM secs
, SCM usecs
),
1195 "This procedure has a variety of uses: waiting for the ability\n"
1196 "to provide input, accept output, or the existence of\n"
1197 "exceptional conditions on a collection of ports or file\n"
1198 "descriptors, or waiting for a timeout to occur.\n"
1199 "It also returns if interrupted by a signal.\n\n"
1200 "@var{reads}, @var{writes} and @var{excepts} can be lists or\n"
1201 "vectors, with each member a port or a file descriptor.\n"
1202 "The value returned is a list of three corresponding\n"
1203 "lists or vectors containing only the members which meet the\n"
1204 "specified requirement. The ability of port buffers to\n"
1205 "provide input or accept output is taken into account.\n"
1206 "Ordering of the input lists or vectors is not preserved.\n\n"
1207 "The optional arguments @var{secs} and @var{usecs} specify the\n"
1208 "timeout. Either @var{secs} can be specified alone, as\n"
1209 "either an integer or a real number, or both @var{secs} and\n"
1210 "@var{usecs} can be specified as integers, in which case\n"
1211 "@var{usecs} is an additional timeout expressed in\n"
1212 "microseconds. If @var{secs} is omitted or is @code{#f} then\n"
1213 "select will wait for as long as it takes for one of the other\n"
1214 "conditions to be satisfied.\n\n"
1215 "The scsh version of @code{select} differs as follows:\n"
1216 "Only vectors are accepted for the first three arguments.\n"
1217 "The @var{usecs} argument is not supported.\n"
1218 "Multiple values are returned instead of a list.\n"
1219 "Duplicates in the input vectors appear only once in output.\n"
1220 "An additional @code{select!} interface is provided.")
1221 #define FUNC_NAME s_scm_select
1223 struct timeval timeout
;
1224 struct timeval
* time_ptr
;
1225 SELECT_TYPE read_set
;
1226 SELECT_TYPE write_set
;
1227 SELECT_TYPE except_set
;
1231 /* these lists accumulate ports which are ready due to buffering.
1232 their file descriptors don't need to be added to the select sets. */
1233 SCM read_ports_ready
= SCM_EOL
;
1234 SCM write_ports_ready
= SCM_EOL
;
1237 if (scm_is_simple_vector (reads
))
1239 read_count
= SCM_SIMPLE_VECTOR_LENGTH (reads
);
1243 read_count
= scm_ilength (reads
);
1244 SCM_ASSERT (read_count
>= 0, reads
, SCM_ARG1
, FUNC_NAME
);
1246 if (scm_is_simple_vector (writes
))
1248 write_count
= SCM_SIMPLE_VECTOR_LENGTH (writes
);
1252 write_count
= scm_ilength (writes
);
1253 SCM_ASSERT (write_count
>= 0, writes
, SCM_ARG2
, FUNC_NAME
);
1255 if (scm_is_simple_vector (excepts
))
1257 except_count
= SCM_SIMPLE_VECTOR_LENGTH (excepts
);
1261 except_count
= scm_ilength (excepts
);
1262 SCM_ASSERT (except_count
>= 0, excepts
, SCM_ARG3
, FUNC_NAME
);
1265 FD_ZERO (&read_set
);
1266 FD_ZERO (&write_set
);
1267 FD_ZERO (&except_set
);
1269 max_fd
= fill_select_type (&read_set
, &read_ports_ready
, reads
, SCM_ARG1
);
1272 int write_max
= fill_select_type (&write_set
, &write_ports_ready
,
1274 int except_max
= fill_select_type (&except_set
, NULL
,
1277 if (write_max
> max_fd
)
1279 if (except_max
> max_fd
)
1280 max_fd
= except_max
;
1283 /* if there's a port with a ready buffer, don't block, just
1284 check for ready file descriptors. */
1285 if (!scm_is_null (read_ports_ready
) || !scm_is_null (write_ports_ready
))
1288 timeout
.tv_usec
= 0;
1289 time_ptr
= &timeout
;
1291 else if (SCM_UNBNDP (secs
) || scm_is_false (secs
))
1295 if (scm_is_unsigned_integer (secs
, 0, ULONG_MAX
))
1297 timeout
.tv_sec
= scm_to_ulong (secs
);
1298 if (SCM_UNBNDP (usecs
))
1299 timeout
.tv_usec
= 0;
1301 timeout
.tv_usec
= scm_to_long (usecs
);
1305 double fl
= scm_to_double (secs
);
1307 if (!SCM_UNBNDP (usecs
))
1308 SCM_WRONG_TYPE_ARG (4, secs
);
1310 SCM_OUT_OF_RANGE (4, secs
);
1311 timeout
.tv_sec
= (long) fl
;
1312 timeout
.tv_usec
= (long) ((fl
- timeout
.tv_sec
) * 1000000);
1314 time_ptr
= &timeout
;
1318 int rv
= scm_std_select (max_fd
+ 1,
1319 &read_set
, &write_set
, &except_set
,
1324 return scm_list_3 (retrieve_select_type (&read_set
, read_ports_ready
, reads
),
1325 retrieve_select_type (&write_set
, write_ports_ready
, writes
),
1326 retrieve_select_type (&except_set
, SCM_EOL
, excepts
));
1329 #endif /* HAVE_SELECT */
1334 SCM_DEFINE (scm_fcntl
, "fcntl", 2, 1, 0,
1335 (SCM object
, SCM cmd
, SCM value
),
1336 "Apply @var{command} to the specified file descriptor or the underlying\n"
1337 "file descriptor of the specified port. @var{value} is an optional\n"
1338 "integer argument.\n\n"
1339 "Values for @var{command} are:\n\n"
1342 "Duplicate a file descriptor\n"
1344 "Get flags associated with the file descriptor.\n"
1346 "Set flags associated with the file descriptor to @var{value}.\n"
1348 "Get flags associated with the open file.\n"
1350 "Set flags associated with the open file to @var{value}\n"
1352 "Get the process ID of a socket's owner, for @code{SIGIO} signals.\n"
1354 "Set the process that owns a socket to @var{value}, for @code{SIGIO} signals.\n"
1355 "@item FD_CLOEXEC\n"
1356 "The value used to indicate the \"close on exec\" flag with @code{F_GETFL} or\n"
1359 #define FUNC_NAME s_scm_fcntl
1365 object
= SCM_COERCE_OUTPORT (object
);
1367 if (SCM_OPFPORTP (object
))
1368 fdes
= SCM_FPORT_FDES (object
);
1370 fdes
= scm_to_int (object
);
1372 if (SCM_UNBNDP (value
))
1375 ivalue
= scm_to_int (value
);
1377 SCM_SYSCALL (rv
= fcntl (fdes
, scm_to_int (cmd
), ivalue
));
1380 return scm_from_int (rv
);
1383 #endif /* HAVE_FCNTL */
1385 SCM_DEFINE (scm_fsync
, "fsync", 1, 0, 0,
1387 "Copies any unwritten data for the specified output file descriptor to disk.\n"
1388 "If @var{port/fd} is a port, its buffer is flushed before the underlying\n"
1389 "file descriptor is fsync'd.\n"
1390 "The return value is unspecified.")
1391 #define FUNC_NAME s_scm_fsync
1395 object
= SCM_COERCE_OUTPORT (object
);
1397 if (SCM_OPFPORTP (object
))
1400 fdes
= SCM_FPORT_FDES (object
);
1403 fdes
= scm_to_int (object
);
1405 if (fsync (fdes
) == -1)
1407 return SCM_UNSPECIFIED
;
1412 SCM_DEFINE (scm_symlink
, "symlink", 2, 0, 0,
1413 (SCM oldpath
, SCM newpath
),
1414 "Create a symbolic link named @var{path-to} with the value (i.e., pointing to)\n"
1415 "@var{path-from}. The return value is unspecified.")
1416 #define FUNC_NAME s_scm_symlink
1420 STRING2_SYSCALL (oldpath
, c_oldpath
,
1422 val
= symlink (c_oldpath
, c_newpath
));
1425 return SCM_UNSPECIFIED
;
1428 #endif /* HAVE_SYMLINK */
1430 #ifdef HAVE_READLINK
1431 SCM_DEFINE (scm_readlink
, "readlink", 1, 0, 0,
1433 "Return the value of the symbolic link named by @var{path} (a\n"
1434 "string), i.e., the file that the link points to.")
1435 #define FUNC_NAME s_scm_readlink
1443 scm_dynwind_begin (0);
1445 c_path
= scm_to_locale_string (path
);
1446 scm_dynwind_free (c_path
);
1448 buf
= scm_malloc (size
);
1450 while ((rv
= readlink (c_path
, buf
, size
)) == size
)
1454 buf
= scm_malloc (size
);
1458 int save_errno
= errno
;
1463 result
= scm_take_locale_stringn (buf
, rv
);
1469 #endif /* HAVE_READLINK */
1472 SCM_DEFINE (scm_lstat
, "lstat", 1, 0, 0,
1474 "Similar to @code{stat}, but does not follow symbolic links, i.e.,\n"
1475 "it will return information about a symbolic link itself, not the\n"
1476 "file it points to. @var{path} must be a string.")
1477 #define FUNC_NAME s_scm_lstat
1480 struct stat_or_stat64 stat_temp
;
1482 STRING_SYSCALL (str
, c_str
, rv
= lstat_or_lstat64 (c_str
, &stat_temp
));
1487 SCM_SYSERROR_MSG ("~A: ~S",
1488 scm_list_2 (scm_strerror (scm_from_int (en
)), str
),
1491 return scm_stat2scm (&stat_temp
);
1494 #endif /* HAVE_LSTAT */
1496 SCM_DEFINE (scm_copy_file
, "copy-file", 2, 0, 0,
1497 (SCM oldfile
, SCM newfile
),
1498 "Copy the file specified by @var{path-from} to @var{path-to}.\n"
1499 "The return value is unspecified.")
1500 #define FUNC_NAME s_scm_copy_file
1502 char *c_oldfile
, *c_newfile
;
1506 struct stat_or_stat64 oldstat
;
1508 scm_dynwind_begin (0);
1510 c_oldfile
= scm_to_locale_string (oldfile
);
1511 scm_dynwind_free (c_oldfile
);
1512 c_newfile
= scm_to_locale_string (newfile
);
1513 scm_dynwind_free (c_newfile
);
1515 oldfd
= open_or_open64 (c_oldfile
, O_RDONLY
);
1520 SCM_SYSCALL (rv
= fstat_Win32 (oldfd
, &oldstat
));
1522 SCM_SYSCALL (rv
= fstat_or_fstat64 (oldfd
, &oldstat
));
1525 goto err_close_oldfd
;
1527 /* use POSIX flags instead of 07777?. */
1528 newfd
= open_or_open64 (c_newfile
, O_WRONLY
| O_CREAT
| O_TRUNC
,
1529 oldstat
.st_mode
& 07777);
1537 while ((n
= read (oldfd
, buf
, sizeof buf
)) > 0)
1538 if (write (newfd
, buf
, n
) != n
)
1545 if (close (newfd
) == -1)
1549 return SCM_UNSPECIFIED
;
1554 /* Filename manipulation */
1558 SCM_DEFINE (scm_dirname
, "dirname", 1, 0, 0,
1560 "Return the directory name component of the file name\n"
1561 "@var{filename}. If @var{filename} does not contain a directory\n"
1562 "component, @code{.} is returned.")
1563 #define FUNC_NAME s_scm_dirname
1567 unsigned long int len
;
1569 SCM_VALIDATE_STRING (1, filename
);
1571 s
= scm_i_string_chars (filename
);
1572 len
= scm_i_string_length (filename
);
1576 while (i
>= 0 && (s
[i
] == '/' || s
[i
] == '\\')) --i
;
1577 while (i
>= 0 && (s
[i
] != '/' && s
[i
] != '\\')) --i
;
1578 while (i
>= 0 && (s
[i
] == '/' || s
[i
] == '\\')) --i
;
1580 while (i
>= 0 && s
[i
] == '/') --i
;
1581 while (i
>= 0 && s
[i
] != '/') --i
;
1582 while (i
>= 0 && s
[i
] == '/') --i
;
1583 #endif /* ndef __MINGW32__ */
1587 if (len
> 0 && (s
[0] == '/' || s
[0] == '\\'))
1589 if (len
> 0 && s
[0] == '/')
1590 #endif /* ndef __MINGW32__ */
1591 return scm_c_substring (filename
, 0, 1);
1593 return scm_dot_string
;
1596 return scm_c_substring (filename
, 0, i
+ 1);
1600 SCM_DEFINE (scm_basename
, "basename", 1, 1, 0,
1601 (SCM filename
, SCM suffix
),
1602 "Return the base name of the file name @var{filename}. The\n"
1603 "base name is the file name without any directory components.\n"
1604 "If @var{suffix} is provided, and is equal to the end of\n"
1605 "@var{basename}, it is removed also.")
1606 #define FUNC_NAME s_scm_basename
1608 const char *f
, *s
= 0;
1611 SCM_VALIDATE_STRING (1, filename
);
1612 f
= scm_i_string_chars (filename
);
1613 len
= scm_i_string_length (filename
);
1615 if (SCM_UNBNDP (suffix
))
1619 SCM_VALIDATE_STRING (2, suffix
);
1620 s
= scm_i_string_chars (suffix
);
1621 j
= scm_i_string_length (suffix
) - 1;
1625 while (i
>= 0 && (f
[i
] == '/' || f
[i
] == '\\')) --i
;
1627 while (i
>= 0 && f
[i
] == '/') --i
;
1628 #endif /* ndef __MINGW32__ */
1630 while (i
>= 0 && j
>= 0 && f
[i
] == s
[j
]) --i
, --j
;
1634 while (i
>= 0 && f
[i
] != '/' && f
[i
] != '\\') --i
;
1636 while (i
>= 0 && f
[i
] != '/') --i
;
1637 #endif /* ndef __MINGW32__ */
1641 if (len
> 0 && (f
[0] == '/' || f
[0] == '\\'))
1643 if (len
> 0 && f
[0] == '/')
1644 #endif /* ndef __MINGW32__ */
1645 return scm_c_substring (filename
, 0, 1);
1647 return scm_dot_string
;
1650 return scm_c_substring (filename
, i
+1, end
+1);
1661 scm_tc16_dir
= scm_make_smob_type ("directory", 0);
1662 scm_set_smob_free (scm_tc16_dir
, scm_dir_free
);
1663 scm_set_smob_print (scm_tc16_dir
, scm_dir_print
);
1665 scm_dot_string
= scm_permanent_object (scm_from_locale_string ("."));
1668 scm_c_define ("O_RDONLY", scm_from_int (O_RDONLY
));
1671 scm_c_define ("O_WRONLY", scm_from_int (O_WRONLY
));
1674 scm_c_define ("O_RDWR", scm_from_int (O_RDWR
));
1677 scm_c_define ("O_CREAT", scm_from_int (O_CREAT
));
1680 scm_c_define ("O_EXCL", scm_from_int (O_EXCL
));
1683 scm_c_define ("O_NOCTTY", scm_from_int (O_NOCTTY
));
1686 scm_c_define ("O_TRUNC", scm_from_int (O_TRUNC
));
1689 scm_c_define ("O_APPEND", scm_from_int (O_APPEND
));
1692 scm_c_define ("O_NONBLOCK", scm_from_int (O_NONBLOCK
));
1695 scm_c_define ("O_NDELAY", scm_from_int (O_NDELAY
));
1698 scm_c_define ("O_SYNC", scm_from_int (O_SYNC
));
1701 scm_c_define ("O_LARGEFILE", scm_from_int (O_LARGEFILE
));
1705 scm_c_define ("F_DUPFD", scm_from_int (F_DUPFD
));
1708 scm_c_define ("F_GETFD", scm_from_int (F_GETFD
));
1711 scm_c_define ("F_SETFD", scm_from_int (F_SETFD
));
1714 scm_c_define ("F_GETFL", scm_from_int (F_GETFL
));
1717 scm_c_define ("F_SETFL", scm_from_int (F_SETFL
));
1720 scm_c_define ("F_GETOWN", scm_from_int (F_GETOWN
));
1723 scm_c_define ("F_SETOWN", scm_from_int (F_SETOWN
));
1726 scm_c_define ("FD_CLOEXEC", scm_from_int (FD_CLOEXEC
));
1729 #include "libguile/filesys.x"