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 */
32 /* AIX requires this to be the first thing in the file. The #pragma
33 directive is indented so pre-ANSI compilers will ignore it, rather
42 # ifndef alloca /* predefined by HP cc +Olibcalls */
49 #include <malloc.h> /* alloca on mingw, though its not used on that system */
55 #include "libguile/_scm.h"
56 #include "libguile/smob.h"
57 #include "libguile/feature.h"
58 #include "libguile/fports.h"
59 #include "libguile/private-gc.h" /* for SCM_MAX */
60 #include "libguile/iselect.h"
61 #include "libguile/strings.h"
62 #include "libguile/vectors.h"
63 #include "libguile/lang.h"
64 #include "libguile/dynwind.h"
66 #include "libguile/validate.h"
67 #include "libguile/filesys.h"
78 #ifdef TIME_WITH_SYS_TIME
79 # include <sys/time.h>
83 # include <sys/time.h>
93 #ifdef LIBC_H_WITH_UNISTD_H
97 #ifdef HAVE_SYS_SELECT_H
98 #include <sys/select.h>
105 #include <sys/types.h>
106 #include <sys/stat.h>
114 #if defined (__MINGW32__) || defined (_MSC_VER) || defined (__BORLANDC__)
115 # include "win32-dirent.h"
116 # define NAMLEN(dirent) strlen((dirent)->d_name)
117 /* The following bits are per AC_HEADER_DIRENT doco in the autoconf manual */
120 # define NAMLEN(dirent) strlen((dirent)->d_name)
122 # define dirent direct
123 # define NAMLEN(dirent) (dirent)->d_namlen
125 # include <sys/ndir.h>
128 # include <sys/dir.h>
135 /* Ultrix has S_IFSOCK, but no S_ISSOCK. Ipe! */
136 #if defined (S_IFSOCK) && ! defined (S_ISSOCK)
137 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
140 /* The MinGW gcc does not define the S_ISSOCK macro. Any other native Windows
141 compiler like BorlandC or MSVC has none of these macros defined. */
163 # define _S_IFIFO 0x1000 /* FIFO */
164 # define _S_IFCHR 0x2000 /* Character */
165 # define _S_IFBLK 0x3000 /* Block */
166 # define _S_IFDIR 0x4000 /* Directory */
167 # define _S_IFREG 0x8000 /* Regular */
168 # define _S_IFSOCK 0xC000 /* Socket */
189 # define S_ISBLK(mode) (((mode) & _S_IFMT) == _S_IFBLK)
190 # define S_ISFIFO(mode) (((mode) & _S_IFMT) == _S_IFIFO)
191 # define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
192 # define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR)
193 # define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG)
194 # define S_ISSOCK(mode) (((mode) & _S_IFMT) == _S_IFSOCK)
196 #endif /* __MINGW32__ */
198 /* Some more definitions for the native Windows port. */
200 # define mkdir(path, mode) mkdir (path)
201 # define fsync(fd) _commit (fd)
202 # define fchmod(fd, mode) (-1)
203 #endif /* __MINGW32__ */
205 /* This definition is for Solaris 10, it's probably not right elsewhere, but
206 that's ok, it shouldn't be used elsewhere. */
208 #define dirfd(dirstream) (dirstream->dd_fd)
213 /* Two helper macros for an often used pattern */
215 #define STRING_SYSCALL(str,cstr,code) \
218 char *cstr = scm_to_locale_string (str); \
219 SCM_SYSCALL (code); \
220 eno = errno; free (cstr); errno = eno; \
223 #define STRING2_SYSCALL(str1,cstr1,str2,cstr2,code) \
226 char *cstr1, *cstr2; \
227 scm_dynwind_begin (0); \
228 cstr1 = scm_to_locale_string (str1); \
229 scm_dynwind_free (cstr1); \
230 cstr2 = scm_to_locale_string (str2); \
231 scm_dynwind_free (cstr2); \
232 SCM_SYSCALL (code); \
233 eno = errno; scm_dynwind_end (); errno = eno; \
242 SCM_DEFINE (scm_chown
, "chown", 3, 0, 0,
243 (SCM object
, SCM owner
, SCM group
),
244 "Change the ownership and group of the file referred to by @var{object} to\n"
245 "the integer values @var{owner} and @var{group}. @var{object} can be\n"
246 "a string containing a file name or, if the platform\n"
247 "supports fchown, a port or integer file descriptor\n"
248 "which is open on the file. The return value\n"
249 "is unspecified.\n\n"
250 "If @var{object} is a symbolic link, either the\n"
251 "ownership of the link or the ownership of the referenced file will be\n"
252 "changed depending on the operating system (lchown is\n"
253 "unsupported at present). If @var{owner} or @var{group} is specified\n"
254 "as @code{-1}, then that ID is not changed.")
255 #define FUNC_NAME s_scm_chown
259 object
= SCM_COERCE_OUTPORT (object
);
262 if (scm_is_integer (object
) || (SCM_OPFPORTP (object
)))
264 int fdes
= (SCM_OPFPORTP (object
)?
265 SCM_FPORT_FDES (object
) : scm_to_int (object
));
267 SCM_SYSCALL (rv
= fchown (fdes
, scm_to_int (owner
), scm_to_int (group
)));
272 STRING_SYSCALL (object
, c_object
,
273 rv
= chown (c_object
,
274 scm_to_int (owner
), scm_to_int (group
)));
278 return SCM_UNSPECIFIED
;
281 #endif /* HAVE_CHOWN */
284 SCM_DEFINE (scm_chmod
, "chmod", 2, 0, 0,
285 (SCM object
, SCM mode
),
286 "Changes the permissions of the file referred to by @var{obj}.\n"
287 "@var{obj} can be a string containing a file name or a port or integer file\n"
288 "descriptor which is open on a file (in which case @code{fchmod} is used\n"
289 "as the underlying system call).\n"
290 "@var{mode} specifies\n"
291 "the new permissions as a decimal number, e.g., @code{(chmod \"foo\" #o755)}.\n"
292 "The return value is unspecified.")
293 #define FUNC_NAME s_scm_chmod
298 object
= SCM_COERCE_OUTPORT (object
);
300 if (scm_is_integer (object
) || SCM_OPFPORTP (object
))
302 if (scm_is_integer (object
))
303 fdes
= scm_to_int (object
);
305 fdes
= SCM_FPORT_FDES (object
);
306 SCM_SYSCALL (rv
= fchmod (fdes
, scm_to_int (mode
)));
310 STRING_SYSCALL (object
, c_object
,
311 rv
= chmod (c_object
, scm_to_int (mode
)));
315 return SCM_UNSPECIFIED
;
319 SCM_DEFINE (scm_umask
, "umask", 0, 1, 0,
321 "If @var{mode} is omitted, returns a decimal number representing the current\n"
322 "file creation mask. Otherwise the file creation mask is set to\n"
323 "@var{mode} and the previous value is returned.\n\n"
324 "E.g., @code{(umask #o022)} sets the mask to octal 22, decimal 18.")
325 #define FUNC_NAME s_scm_umask
328 if (SCM_UNBNDP (mode
))
335 mask
= umask (scm_to_uint (mode
));
337 return scm_from_uint (mask
);
343 SCM_DEFINE (scm_open_fdes
, "open-fdes", 2, 1, 0,
344 (SCM path
, SCM flags
, SCM mode
),
345 "Similar to @code{open} but return a file descriptor instead of\n"
347 #define FUNC_NAME s_scm_open_fdes
353 iflags
= SCM_NUM2INT (2, flags
);
354 imode
= SCM_NUM2INT_DEF (3, mode
, 0666);
355 STRING_SYSCALL (path
, c_path
, fd
= open_or_open64 (c_path
, iflags
, imode
));
358 return scm_from_int (fd
);
362 SCM_DEFINE (scm_open
, "open", 2, 1, 0,
363 (SCM path
, SCM flags
, SCM mode
),
364 "Open the file named by @var{path} for reading and/or writing.\n"
365 "@var{flags} is an integer specifying how the file should be opened.\n"
366 "@var{mode} is an integer specifying the permission bits of the file, if\n"
367 "it needs to be created, before the umask is applied. The default is 666\n"
368 "(Unix itself has no default).\n\n"
369 "@var{flags} can be constructed by combining variables using @code{logior}.\n"
370 "Basic flags are:\n\n"
372 "Open the file read-only.\n"
375 "Open the file write-only.\n"
378 "Open the file read/write.\n"
381 "Append to the file instead of truncating.\n"
384 "Create the file if it does not already exist.\n"
386 "See the Unix documentation of the @code{open} system call\n"
387 "for additional flags.")
388 #define FUNC_NAME s_scm_open
395 fd
= scm_to_int (scm_open_fdes (path
, flags
, mode
));
396 iflags
= SCM_NUM2INT (2, flags
);
399 if (iflags
& O_APPEND
)
401 else if (iflags
& O_CREAT
)
407 if (iflags
& O_APPEND
)
409 else if (iflags
& O_WRONLY
)
414 newpt
= scm_fdes_to_port (fd
, port_mode
, path
);
419 SCM_DEFINE (scm_close
, "close", 1, 0, 0,
421 "Similar to close-port (@pxref{Closing, close-port}),\n"
422 "but also works on file descriptors. A side\n"
423 "effect of closing a file descriptor is that any ports using that file\n"
424 "descriptor are moved to a different file descriptor and have\n"
425 "their revealed counts set to zero.")
426 #define FUNC_NAME s_scm_close
431 fd_or_port
= SCM_COERCE_OUTPORT (fd_or_port
);
433 if (SCM_PORTP (fd_or_port
))
434 return scm_close_port (fd_or_port
);
435 fd
= scm_to_int (fd_or_port
);
436 scm_evict_ports (fd
); /* see scsh manual. */
437 SCM_SYSCALL (rv
= close (fd
));
438 /* following scsh, closing an already closed file descriptor is
440 if (rv
< 0 && errno
!= EBADF
)
442 return scm_from_bool (rv
>= 0);
446 SCM_DEFINE (scm_close_fdes
, "close-fdes", 1, 0, 0,
448 "A simple wrapper for the @code{close} system call.\n"
449 "Close file descriptor @var{fd}, which must be an integer.\n"
450 "Unlike close (@pxref{Ports and File Descriptors, close}),\n"
451 "the file descriptor will be closed even if a port is using it.\n"
452 "The return value is unspecified.")
453 #define FUNC_NAME s_scm_close_fdes
458 c_fd
= scm_to_int (fd
);
459 SCM_SYSCALL (rv
= close (c_fd
));
462 return SCM_UNSPECIFIED
;
470 SCM_SYMBOL (scm_sym_regular
, "regular");
471 SCM_SYMBOL (scm_sym_directory
, "directory");
473 SCM_SYMBOL (scm_sym_symlink
, "symlink");
475 SCM_SYMBOL (scm_sym_block_special
, "block-special");
476 SCM_SYMBOL (scm_sym_char_special
, "char-special");
477 SCM_SYMBOL (scm_sym_fifo
, "fifo");
478 SCM_SYMBOL (scm_sym_sock
, "socket");
479 SCM_SYMBOL (scm_sym_unknown
, "unknown");
482 scm_stat2scm (struct stat_or_stat64
*stat_temp
)
484 SCM ans
= scm_c_make_vector (15, SCM_UNSPECIFIED
);
486 SCM_SIMPLE_VECTOR_SET(ans
, 0, scm_from_ulong (stat_temp
->st_dev
));
487 SCM_SIMPLE_VECTOR_SET(ans
, 1, scm_from_ino_t_or_ino64_t (stat_temp
->st_ino
));
488 SCM_SIMPLE_VECTOR_SET(ans
, 2, scm_from_ulong (stat_temp
->st_mode
));
489 SCM_SIMPLE_VECTOR_SET(ans
, 3, scm_from_ulong (stat_temp
->st_nlink
));
490 SCM_SIMPLE_VECTOR_SET(ans
, 4, scm_from_ulong (stat_temp
->st_uid
));
491 SCM_SIMPLE_VECTOR_SET(ans
, 5, scm_from_ulong (stat_temp
->st_gid
));
492 #ifdef HAVE_STRUCT_STAT_ST_RDEV
493 SCM_SIMPLE_VECTOR_SET(ans
, 6, scm_from_ulong (stat_temp
->st_rdev
));
495 SCM_SIMPLE_VECTOR_SET(ans
, 6, SCM_BOOL_F
);
497 SCM_SIMPLE_VECTOR_SET(ans
, 7, scm_from_off_t_or_off64_t (stat_temp
->st_size
));
498 SCM_SIMPLE_VECTOR_SET(ans
, 8, scm_from_ulong (stat_temp
->st_atime
));
499 SCM_SIMPLE_VECTOR_SET(ans
, 9, scm_from_ulong (stat_temp
->st_mtime
));
500 SCM_SIMPLE_VECTOR_SET(ans
, 10, scm_from_ulong (stat_temp
->st_ctime
));
501 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
502 SCM_SIMPLE_VECTOR_SET(ans
, 11, scm_from_ulong (stat_temp
->st_blksize
));
504 SCM_SIMPLE_VECTOR_SET(ans
, 11, scm_from_ulong (4096L));
506 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
507 SCM_SIMPLE_VECTOR_SET(ans
, 12, scm_from_blkcnt_t_or_blkcnt64_t (stat_temp
->st_blocks
));
509 SCM_SIMPLE_VECTOR_SET(ans
, 12, SCM_BOOL_F
);
512 int mode
= stat_temp
->st_mode
;
515 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_regular
);
516 else if (S_ISDIR (mode
))
517 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_directory
);
519 /* systems without symlinks probably don't have S_ISLNK */
520 else if (S_ISLNK (mode
))
521 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_symlink
);
523 else if (S_ISBLK (mode
))
524 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_block_special
);
525 else if (S_ISCHR (mode
))
526 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_char_special
);
527 else if (S_ISFIFO (mode
))
528 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_fifo
);
530 else if (S_ISSOCK (mode
))
531 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_sock
);
534 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_unknown
);
536 SCM_SIMPLE_VECTOR_SET(ans
, 14, scm_from_int ((~S_IFMT
) & mode
));
538 /* the layout of the bits in ve[14] is intended to be portable.
539 If there are systems that don't follow the usual convention,
540 the following could be used:
543 if (S_ISUID & mode) tmp += 1;
545 if (S_IRGRP & mode) tmp += 1;
547 if (S_ISVTX & mode) tmp += 1;
549 if (S_IRUSR & mode) tmp += 1;
551 if (S_IWUSR & mode) tmp += 1;
553 if (S_IXUSR & mode) tmp += 1;
555 if (S_IWGRP & mode) tmp += 1;
557 if (S_IXGRP & mode) tmp += 1;
559 if (S_IROTH & mode) tmp += 1;
561 if (S_IWOTH & mode) tmp += 1;
563 if (S_IXOTH & mode) tmp += 1;
565 SCM_SIMPLE_VECTOR_SET(ans, 14, scm_from_int (tmp));
575 * Try getting the appropiate stat buffer for a given file descriptor
576 * under Windows. It differentiates between file, pipe and socket
579 static int fstat_Win32 (int fdes
, struct stat
*buf
)
581 int error
, optlen
= sizeof (int);
583 memset (buf
, 0, sizeof (struct stat
));
585 /* Is this a socket ? */
586 if (getsockopt (fdes
, SOL_SOCKET
, SO_ERROR
, (void *) &error
, &optlen
) >= 0)
588 buf
->st_mode
= _S_IFSOCK
| _S_IREAD
| _S_IWRITE
| _S_IEXEC
;
590 buf
->st_atime
= buf
->st_ctime
= buf
->st_mtime
= time (NULL
);
593 /* Maybe a regular file or pipe ? */
594 return fstat (fdes
, buf
);
596 #endif /* __MINGW32__ */
598 SCM_DEFINE (scm_stat
, "stat", 1, 0, 0,
600 "Return an object containing various information about the file\n"
601 "determined by @var{obj}. @var{obj} can be a string containing\n"
602 "a file name or a port or integer file descriptor which is open\n"
603 "on a file (in which case @code{fstat} is used as the underlying\n"
606 "The object returned by @code{stat} can be passed as a single\n"
607 "parameter to the following procedures, all of which return\n"
612 "The device containing the file.\n"
614 "The file serial number, which distinguishes this file from all\n"
615 "other files on the same device.\n"
617 "The mode of the file. This includes file type information and\n"
618 "the file permission bits. See @code{stat:type} and\n"
619 "@code{stat:perms} below.\n"
621 "The number of hard links to the file.\n"
623 "The user ID of the file's owner.\n"
625 "The group ID of the file.\n"
627 "Device ID; this entry is defined only for character or block\n"
630 "The size of a regular file in bytes.\n"
632 "The last access time for the file.\n"
634 "The last modification time for the file.\n"
636 "The last modification time for the attributes of the file.\n"
637 "@item stat:blksize\n"
638 "The optimal block size for reading or writing the file, in\n"
640 "@item stat:blocks\n"
641 "The amount of disk space that the file occupies measured in\n"
642 "units of 512 byte blocks.\n"
645 "In addition, the following procedures return the information\n"
646 "from stat:mode in a more convenient form:\n"
650 "A symbol representing the type of file. Possible values are\n"
651 "regular, directory, symlink, block-special, char-special, fifo,\n"
652 "socket and unknown\n"
654 "An integer representing the access permission bits.\n"
656 #define FUNC_NAME s_scm_stat
660 struct stat_or_stat64 stat_temp
;
662 if (scm_is_integer (object
))
665 SCM_SYSCALL (rv
= fstat_Win32 (scm_to_int (object
), &stat_temp
));
667 SCM_SYSCALL (rv
= fstat_or_fstat64 (scm_to_int (object
), &stat_temp
));
670 else if (scm_is_string (object
))
672 char *file
= scm_to_locale_string (object
);
675 p
= file
+ strlen (file
) - 1;
676 while (p
> file
&& (*p
== '/' || *p
== '\\'))
679 SCM_SYSCALL (rv
= stat_or_stat64 (file
, &stat_temp
));
684 object
= SCM_COERCE_OUTPORT (object
);
685 SCM_VALIDATE_OPFPORT (1, object
);
686 fdes
= SCM_FPORT_FDES (object
);
688 SCM_SYSCALL (rv
= fstat_Win32 (fdes
, &stat_temp
));
690 SCM_SYSCALL (rv
= fstat_or_fstat64 (fdes
, &stat_temp
));
698 SCM_SYSERROR_MSG ("~A: ~S",
699 scm_list_2 (scm_strerror (scm_from_int (en
)),
703 return scm_stat2scm (&stat_temp
);
708 /* {Modifying Directories}
712 SCM_DEFINE (scm_link
, "link", 2, 0, 0,
713 (SCM oldpath
, SCM newpath
),
714 "Creates a new name @var{newpath} in the file system for the\n"
715 "file named by @var{oldpath}. If @var{oldpath} is a symbolic\n"
716 "link, the link may or may not be followed depending on the\n"
718 #define FUNC_NAME s_scm_link
722 STRING2_SYSCALL (oldpath
, c_oldpath
,
724 val
= link (c_oldpath
, c_newpath
));
727 return SCM_UNSPECIFIED
;
730 #endif /* HAVE_LINK */
733 #define my_rename rename
736 my_rename (const char *oldname
, const char *newname
)
740 SCM_SYSCALL (rv
= link (oldname
, newname
));
743 SCM_SYSCALL (rv
= unlink (oldname
));
745 /* unlink failed. remove new name */
746 SCM_SYSCALL (unlink (newname
));
752 SCM_DEFINE (scm_rename
, "rename-file", 2, 0, 0,
753 (SCM oldname
, SCM newname
),
754 "Renames the file specified by @var{oldname} to @var{newname}.\n"
755 "The return value is unspecified.")
756 #define FUNC_NAME s_scm_rename
760 STRING2_SYSCALL (oldname
, c_oldname
,
762 rv
= my_rename (c_oldname
, c_newname
));
765 return SCM_UNSPECIFIED
;
770 SCM_DEFINE (scm_delete_file
, "delete-file", 1, 0, 0,
772 "Deletes (or \"unlinks\") the file specified by @var{path}.")
773 #define FUNC_NAME s_scm_delete_file
776 STRING_SYSCALL (str
, c_str
, ans
= unlink (c_str
));
779 return SCM_UNSPECIFIED
;
784 SCM_DEFINE (scm_mkdir
, "mkdir", 1, 1, 0,
785 (SCM path
, SCM mode
),
786 "Create a new directory named by @var{path}. If @var{mode} is omitted\n"
787 "then the permissions of the directory file are set using the current\n"
788 "umask. Otherwise they are set to the decimal value specified with\n"
789 "@var{mode}. The return value is unspecified.")
790 #define FUNC_NAME s_scm_mkdir
795 if (SCM_UNBNDP (mode
))
799 STRING_SYSCALL (path
, c_path
, rv
= mkdir (c_path
, 0777 ^ mask
));
803 STRING_SYSCALL (path
, c_path
, rv
= mkdir (c_path
, scm_to_uint (mode
)));
807 return SCM_UNSPECIFIED
;
810 #endif /* HAVE_MKDIR */
813 SCM_DEFINE (scm_rmdir
, "rmdir", 1, 0, 0,
815 "Remove the existing directory named by @var{path}. The directory must\n"
816 "be empty for this to succeed. The return value is unspecified.")
817 #define FUNC_NAME s_scm_rmdir
821 STRING_SYSCALL (path
, c_path
, val
= rmdir (c_path
));
824 return SCM_UNSPECIFIED
;
831 /* {Examining Directories}
834 scm_t_bits scm_tc16_dir
;
837 SCM_DEFINE (scm_directory_stream_p
, "directory-stream?", 1, 0, 0,
839 "Return a boolean indicating whether @var{object} is a directory\n"
840 "stream as returned by @code{opendir}.")
841 #define FUNC_NAME s_scm_directory_stream_p
843 return scm_from_bool (SCM_DIRP (obj
));
848 SCM_DEFINE (scm_opendir
, "opendir", 1, 0, 0,
850 "Open the directory specified by @var{path} and return a directory\n"
852 #define FUNC_NAME s_scm_opendir
855 STRING_SYSCALL (dirname
, c_dirname
, ds
= opendir (c_dirname
));
858 SCM_RETURN_NEWSMOB (scm_tc16_dir
| SCM_DIR_FLAG_OPEN
, ds
);
863 /* FIXME: The glibc manual has a portability note that readdir_r may not
864 null-terminate its return string. The circumstances outlined for this
865 are not clear, nor is it clear what should be done about it. Lets use
866 NAMLEN and worry about what else should be done if/when someone can
869 SCM_DEFINE (scm_readdir
, "readdir", 1, 0, 0,
871 "Return (as a string) the next directory entry from the directory stream\n"
872 "@var{stream}. If there is no remaining entry to be read then the\n"
873 "end of file object is returned.")
874 #define FUNC_NAME s_scm_readdir
876 struct dirent_or_dirent64
*rdent
;
878 SCM_VALIDATE_DIR (1, port
);
879 if (!SCM_DIR_OPEN_P (port
))
880 SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port
));
883 /* As noted in the glibc manual, on various systems (such as Solaris) the
884 d_name[] field is only 1 char and you're expected to size the dirent
885 buffer for readdir_r based on NAME_MAX. The SCM_MAX expressions below
886 effectively give either sizeof(d_name) or NAME_MAX+1, whichever is
889 On solaris 10 there's no NAME_MAX constant, it's necessary to use
890 pathconf(). We prefer NAME_MAX though, since it should be a constant
891 and will therefore save a system call. We also prefer it since dirfd()
892 is not available everywhere.
894 An alternative to dirfd() would be to open() the directory and then use
895 fdopendir(), if the latter is available. That'd let us hold the fd
896 somewhere in the smob, or just the dirent size calculated once. */
898 struct dirent_or_dirent64 de
; /* just for sizeof */
899 DIR *ds
= (DIR *) SCM_CELL_WORD_1 (port
);
902 char buf
[SCM_MAX (sizeof (de
),
903 sizeof (de
) - sizeof (de
.d_name
) + NAME_MAX
+ 1)];
906 long name_max
= fpathconf (dirfd (ds
), _PC_NAME_MAX
);
909 buf
= alloca (SCM_MAX (sizeof (de
),
910 sizeof (de
) - sizeof (de
.d_name
) + name_max
+ 1));
914 SCM_SYSCALL (readdir_r_or_readdir64_r (ds
, (struct dirent_or_dirent64
*) buf
, &rdent
));
920 namlen
= NAMLEN (rdent
);
922 return (rdent
? scm_from_locale_stringn (rdent
->d_name
, NAMLEN (rdent
))
928 scm_dynwind_begin (0);
929 scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex
);
932 SCM_SYSCALL (rdent
= readdir_or_readdir64 ((DIR *) SCM_CELL_WORD_1 (port
)));
936 ret
= (rdent
? scm_from_locale_stringn (rdent
->d_name
, NAMLEN (rdent
))
947 SCM_DEFINE (scm_rewinddir
, "rewinddir", 1, 0, 0,
949 "Reset the directory port @var{stream} so that the next call to\n"
950 "@code{readdir} will return the first directory entry.")
951 #define FUNC_NAME s_scm_rewinddir
953 SCM_VALIDATE_DIR (1, port
);
954 if (!SCM_DIR_OPEN_P (port
))
955 SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port
));
957 rewinddir ((DIR *) SCM_CELL_WORD_1 (port
));
959 return SCM_UNSPECIFIED
;
964 SCM_DEFINE (scm_closedir
, "closedir", 1, 0, 0,
966 "Close the directory stream @var{stream}.\n"
967 "The return value is unspecified.")
968 #define FUNC_NAME s_scm_closedir
970 SCM_VALIDATE_DIR (1, port
);
972 if (SCM_DIR_OPEN_P (port
))
976 SCM_SYSCALL (sts
= closedir ((DIR *) SCM_CELL_WORD_1 (port
)));
980 SCM_SET_CELL_WORD_0 (port
, scm_tc16_dir
);
983 return SCM_UNSPECIFIED
;
989 scm_dir_print (SCM exp
, SCM port
, scm_print_state
*pstate SCM_UNUSED
)
991 scm_puts ("#<", port
);
992 if (!SCM_DIR_OPEN_P (exp
))
993 scm_puts ("closed: ", port
);
994 scm_puts ("directory stream ", port
);
995 scm_uintprint (SCM_CELL_WORD_1 (exp
), 16, port
);
996 scm_putc ('>', port
);
1002 scm_dir_free (SCM p
)
1004 if (SCM_DIR_OPEN_P (p
))
1005 closedir ((DIR *) SCM_CELL_WORD_1 (p
));
1010 /* {Navigating Directories}
1014 SCM_DEFINE (scm_chdir
, "chdir", 1, 0, 0,
1016 "Change the current working directory to @var{path}.\n"
1017 "The return value is unspecified.")
1018 #define FUNC_NAME s_scm_chdir
1022 STRING_SYSCALL (str
, c_str
, ans
= chdir (c_str
));
1025 return SCM_UNSPECIFIED
;
1030 SCM_DEFINE (scm_getcwd
, "getcwd", 0, 0, 0,
1032 "Return the name of the current working directory.")
1033 #define FUNC_NAME s_scm_getcwd
1040 wd
= scm_malloc (size
);
1041 while ((rv
= getcwd (wd
, size
)) == 0 && errno
== ERANGE
)
1045 wd
= scm_malloc (size
);
1049 int save_errno
= errno
;
1054 result
= scm_from_locale_stringn (wd
, strlen (wd
));
1059 #endif /* HAVE_GETCWD */
1065 /* check that element is a port or file descriptor. if it's a port
1066 and its buffer is ready for use, add it to the ports_ready list.
1067 otherwise add its file descriptor to *set. the type of list can be
1068 determined from pos: SCM_ARG1 for reads, SCM_ARG2 for writes,
1069 SCM_ARG3 for excepts. */
1071 set_element (SELECT_TYPE
*set
, SCM
*ports_ready
, SCM element
, int pos
)
1075 if (scm_is_integer (element
))
1077 fd
= scm_to_int (element
);
1083 element
= SCM_COERCE_OUTPORT (element
);
1084 SCM_ASSERT (SCM_OPFPORTP (element
), element
, pos
, "select");
1085 if (pos
== SCM_ARG1
)
1087 /* check whether port has buffered input. */
1088 scm_t_port
*pt
= SCM_PTAB_ENTRY (element
);
1090 if (pt
->read_pos
< pt
->read_end
)
1093 else if (pos
== SCM_ARG2
)
1095 /* check whether port's output buffer has room. */
1096 scm_t_port
*pt
= SCM_PTAB_ENTRY (element
);
1098 /* > 1 since writing the last byte in the buffer causes flush. */
1099 if (pt
->write_end
- pt
->write_pos
> 1)
1102 fd
= use_buf
? -1 : SCM_FPORT_FDES (element
);
1105 *ports_ready
= scm_cons (element
, *ports_ready
);
1111 /* check list_or_vec, a list or vector of ports or file descriptors,
1112 adding each member to either the ports_ready list (if it's a port
1113 with a usable buffer) or to *set. the kind of list_or_vec can be
1114 determined from pos: SCM_ARG1 for reads, SCM_ARG2 for writes,
1115 SCM_ARG3 for excepts. */
1117 fill_select_type (SELECT_TYPE
*set
, SCM
*ports_ready
, SCM list_or_vec
, int pos
)
1121 if (scm_is_simple_vector (list_or_vec
))
1123 int i
= SCM_SIMPLE_VECTOR_LENGTH (list_or_vec
);
1127 int fd
= set_element (set
, ports_ready
,
1128 SCM_SIMPLE_VECTOR_REF (list_or_vec
, i
), pos
);
1136 while (!SCM_NULL_OR_NIL_P (list_or_vec
))
1138 int fd
= set_element (set
, ports_ready
, SCM_CAR (list_or_vec
), pos
);
1142 list_or_vec
= SCM_CDR (list_or_vec
);
1149 /* if element (a file descriptor or port) appears in *set, cons it to
1150 list. return list. */
1152 get_element (SELECT_TYPE
*set
, SCM element
, SCM list
)
1156 if (scm_is_integer (element
))
1158 fd
= scm_to_int (element
);
1162 fd
= SCM_FPORT_FDES (SCM_COERCE_OUTPORT (element
));
1164 if (FD_ISSET (fd
, set
))
1165 list
= scm_cons (element
, list
);
1169 /* construct component of scm_select return value.
1170 set: pointer to set of file descriptors found by select to be ready
1171 ports_ready: ports ready due to buffering
1172 list_or_vec: original list/vector handed to scm_select.
1173 the return value is a list/vector of ready ports/file descriptors.
1174 works by finding the objects in list which correspond to members of
1175 *set and appending them to ports_ready. result is converted to a
1176 vector if list_or_vec is a vector. */
1178 retrieve_select_type (SELECT_TYPE
*set
, SCM ports_ready
, SCM list_or_vec
)
1180 SCM answer_list
= ports_ready
;
1182 if (scm_is_simple_vector (list_or_vec
))
1184 int i
= SCM_SIMPLE_VECTOR_LENGTH (list_or_vec
);
1188 answer_list
= get_element (set
,
1189 SCM_SIMPLE_VECTOR_REF (list_or_vec
, i
),
1192 return scm_vector (answer_list
);
1196 /* list_or_vec must be a list. */
1197 while (!SCM_NULL_OR_NIL_P (list_or_vec
))
1199 answer_list
= get_element (set
, SCM_CAR (list_or_vec
), answer_list
);
1200 list_or_vec
= SCM_CDR (list_or_vec
);
1206 /* Static helper functions above refer to s_scm_select directly as s_select */
1207 SCM_DEFINE (scm_select
, "select", 3, 2, 0,
1208 (SCM reads
, SCM writes
, SCM excepts
, SCM secs
, SCM usecs
),
1209 "This procedure has a variety of uses: waiting for the ability\n"
1210 "to provide input, accept output, or the existence of\n"
1211 "exceptional conditions on a collection of ports or file\n"
1212 "descriptors, or waiting for a timeout to occur.\n"
1213 "It also returns if interrupted by a signal.\n\n"
1214 "@var{reads}, @var{writes} and @var{excepts} can be lists or\n"
1215 "vectors, with each member a port or a file descriptor.\n"
1216 "The value returned is a list of three corresponding\n"
1217 "lists or vectors containing only the members which meet the\n"
1218 "specified requirement. The ability of port buffers to\n"
1219 "provide input or accept output is taken into account.\n"
1220 "Ordering of the input lists or vectors is not preserved.\n\n"
1221 "The optional arguments @var{secs} and @var{usecs} specify the\n"
1222 "timeout. Either @var{secs} can be specified alone, as\n"
1223 "either an integer or a real number, or both @var{secs} and\n"
1224 "@var{usecs} can be specified as integers, in which case\n"
1225 "@var{usecs} is an additional timeout expressed in\n"
1226 "microseconds. If @var{secs} is omitted or is @code{#f} then\n"
1227 "select will wait for as long as it takes for one of the other\n"
1228 "conditions to be satisfied.\n\n"
1229 "The scsh version of @code{select} differs as follows:\n"
1230 "Only vectors are accepted for the first three arguments.\n"
1231 "The @var{usecs} argument is not supported.\n"
1232 "Multiple values are returned instead of a list.\n"
1233 "Duplicates in the input vectors appear only once in output.\n"
1234 "An additional @code{select!} interface is provided.")
1235 #define FUNC_NAME s_scm_select
1237 struct timeval timeout
;
1238 struct timeval
* time_ptr
;
1239 SELECT_TYPE read_set
;
1240 SELECT_TYPE write_set
;
1241 SELECT_TYPE except_set
;
1245 /* these lists accumulate ports which are ready due to buffering.
1246 their file descriptors don't need to be added to the select sets. */
1247 SCM read_ports_ready
= SCM_EOL
;
1248 SCM write_ports_ready
= SCM_EOL
;
1251 if (scm_is_simple_vector (reads
))
1253 read_count
= SCM_SIMPLE_VECTOR_LENGTH (reads
);
1257 read_count
= scm_ilength (reads
);
1258 SCM_ASSERT (read_count
>= 0, reads
, SCM_ARG1
, FUNC_NAME
);
1260 if (scm_is_simple_vector (writes
))
1262 write_count
= SCM_SIMPLE_VECTOR_LENGTH (writes
);
1266 write_count
= scm_ilength (writes
);
1267 SCM_ASSERT (write_count
>= 0, writes
, SCM_ARG2
, FUNC_NAME
);
1269 if (scm_is_simple_vector (excepts
))
1271 except_count
= SCM_SIMPLE_VECTOR_LENGTH (excepts
);
1275 except_count
= scm_ilength (excepts
);
1276 SCM_ASSERT (except_count
>= 0, excepts
, SCM_ARG3
, FUNC_NAME
);
1279 FD_ZERO (&read_set
);
1280 FD_ZERO (&write_set
);
1281 FD_ZERO (&except_set
);
1283 max_fd
= fill_select_type (&read_set
, &read_ports_ready
, reads
, SCM_ARG1
);
1286 int write_max
= fill_select_type (&write_set
, &write_ports_ready
,
1288 int except_max
= fill_select_type (&except_set
, NULL
,
1291 if (write_max
> max_fd
)
1293 if (except_max
> max_fd
)
1294 max_fd
= except_max
;
1297 /* if there's a port with a ready buffer, don't block, just
1298 check for ready file descriptors. */
1299 if (!scm_is_null (read_ports_ready
) || !scm_is_null (write_ports_ready
))
1302 timeout
.tv_usec
= 0;
1303 time_ptr
= &timeout
;
1305 else if (SCM_UNBNDP (secs
) || scm_is_false (secs
))
1309 if (scm_is_unsigned_integer (secs
, 0, ULONG_MAX
))
1311 timeout
.tv_sec
= scm_to_ulong (secs
);
1312 if (SCM_UNBNDP (usecs
))
1313 timeout
.tv_usec
= 0;
1315 timeout
.tv_usec
= scm_to_long (usecs
);
1319 double fl
= scm_to_double (secs
);
1321 if (!SCM_UNBNDP (usecs
))
1322 SCM_WRONG_TYPE_ARG (4, secs
);
1324 SCM_OUT_OF_RANGE (4, secs
);
1325 timeout
.tv_sec
= (long) fl
;
1326 timeout
.tv_usec
= (long) ((fl
- timeout
.tv_sec
) * 1000000);
1328 time_ptr
= &timeout
;
1332 int rv
= scm_std_select (max_fd
+ 1,
1333 &read_set
, &write_set
, &except_set
,
1338 return scm_list_3 (retrieve_select_type (&read_set
, read_ports_ready
, reads
),
1339 retrieve_select_type (&write_set
, write_ports_ready
, writes
),
1340 retrieve_select_type (&except_set
, SCM_EOL
, excepts
));
1343 #endif /* HAVE_SELECT */
1348 SCM_DEFINE (scm_fcntl
, "fcntl", 2, 1, 0,
1349 (SCM object
, SCM cmd
, SCM value
),
1350 "Apply @var{command} to the specified file descriptor or the underlying\n"
1351 "file descriptor of the specified port. @var{value} is an optional\n"
1352 "integer argument.\n\n"
1353 "Values for @var{command} are:\n\n"
1356 "Duplicate a file descriptor\n"
1358 "Get flags associated with the file descriptor.\n"
1360 "Set flags associated with the file descriptor to @var{value}.\n"
1362 "Get flags associated with the open file.\n"
1364 "Set flags associated with the open file to @var{value}\n"
1366 "Get the process ID of a socket's owner, for @code{SIGIO} signals.\n"
1368 "Set the process that owns a socket to @var{value}, for @code{SIGIO} signals.\n"
1369 "@item FD_CLOEXEC\n"
1370 "The value used to indicate the \"close on exec\" flag with @code{F_GETFL} or\n"
1373 #define FUNC_NAME s_scm_fcntl
1379 object
= SCM_COERCE_OUTPORT (object
);
1381 if (SCM_OPFPORTP (object
))
1382 fdes
= SCM_FPORT_FDES (object
);
1384 fdes
= scm_to_int (object
);
1386 if (SCM_UNBNDP (value
))
1389 ivalue
= scm_to_int (value
);
1391 SCM_SYSCALL (rv
= fcntl (fdes
, scm_to_int (cmd
), ivalue
));
1394 return scm_from_int (rv
);
1397 #endif /* HAVE_FCNTL */
1399 SCM_DEFINE (scm_fsync
, "fsync", 1, 0, 0,
1401 "Copies any unwritten data for the specified output file descriptor to disk.\n"
1402 "If @var{port/fd} is a port, its buffer is flushed before the underlying\n"
1403 "file descriptor is fsync'd.\n"
1404 "The return value is unspecified.")
1405 #define FUNC_NAME s_scm_fsync
1409 object
= SCM_COERCE_OUTPORT (object
);
1411 if (SCM_OPFPORTP (object
))
1414 fdes
= SCM_FPORT_FDES (object
);
1417 fdes
= scm_to_int (object
);
1419 if (fsync (fdes
) == -1)
1421 return SCM_UNSPECIFIED
;
1426 SCM_DEFINE (scm_symlink
, "symlink", 2, 0, 0,
1427 (SCM oldpath
, SCM newpath
),
1428 "Create a symbolic link named @var{path-to} with the value (i.e., pointing to)\n"
1429 "@var{path-from}. The return value is unspecified.")
1430 #define FUNC_NAME s_scm_symlink
1434 STRING2_SYSCALL (oldpath
, c_oldpath
,
1436 val
= symlink (c_oldpath
, c_newpath
));
1439 return SCM_UNSPECIFIED
;
1442 #endif /* HAVE_SYMLINK */
1444 #ifdef HAVE_READLINK
1445 SCM_DEFINE (scm_readlink
, "readlink", 1, 0, 0,
1447 "Return the value of the symbolic link named by @var{path} (a\n"
1448 "string), i.e., the file that the link points to.")
1449 #define FUNC_NAME s_scm_readlink
1457 scm_dynwind_begin (0);
1459 c_path
= scm_to_locale_string (path
);
1460 scm_dynwind_free (c_path
);
1462 buf
= scm_malloc (size
);
1464 while ((rv
= readlink (c_path
, buf
, size
)) == size
)
1468 buf
= scm_malloc (size
);
1472 int save_errno
= errno
;
1477 result
= scm_take_locale_stringn (buf
, rv
);
1483 #endif /* HAVE_READLINK */
1486 SCM_DEFINE (scm_lstat
, "lstat", 1, 0, 0,
1488 "Similar to @code{stat}, but does not follow symbolic links, i.e.,\n"
1489 "it will return information about a symbolic link itself, not the\n"
1490 "file it points to. @var{path} must be a string.")
1491 #define FUNC_NAME s_scm_lstat
1494 struct stat_or_stat64 stat_temp
;
1496 STRING_SYSCALL (str
, c_str
, rv
= lstat_or_lstat64 (c_str
, &stat_temp
));
1501 SCM_SYSERROR_MSG ("~A: ~S",
1502 scm_list_2 (scm_strerror (scm_from_int (en
)), str
),
1505 return scm_stat2scm (&stat_temp
);
1508 #endif /* HAVE_LSTAT */
1510 SCM_DEFINE (scm_copy_file
, "copy-file", 2, 0, 0,
1511 (SCM oldfile
, SCM newfile
),
1512 "Copy the file specified by @var{path-from} to @var{path-to}.\n"
1513 "The return value is unspecified.")
1514 #define FUNC_NAME s_scm_copy_file
1516 char *c_oldfile
, *c_newfile
;
1520 struct stat_or_stat64 oldstat
;
1522 scm_dynwind_begin (0);
1524 c_oldfile
= scm_to_locale_string (oldfile
);
1525 scm_dynwind_free (c_oldfile
);
1526 c_newfile
= scm_to_locale_string (newfile
);
1527 scm_dynwind_free (c_newfile
);
1529 oldfd
= open_or_open64 (c_oldfile
, O_RDONLY
);
1534 SCM_SYSCALL (rv
= fstat_Win32 (oldfd
, &oldstat
));
1536 SCM_SYSCALL (rv
= fstat_or_fstat64 (oldfd
, &oldstat
));
1539 goto err_close_oldfd
;
1541 /* use POSIX flags instead of 07777?. */
1542 newfd
= open_or_open64 (c_newfile
, O_WRONLY
| O_CREAT
| O_TRUNC
,
1543 oldstat
.st_mode
& 07777);
1551 while ((n
= read (oldfd
, buf
, sizeof buf
)) > 0)
1552 if (write (newfd
, buf
, n
) != n
)
1559 if (close (newfd
) == -1)
1563 return SCM_UNSPECIFIED
;
1568 /* Filename manipulation */
1572 SCM_DEFINE (scm_dirname
, "dirname", 1, 0, 0,
1574 "Return the directory name component of the file name\n"
1575 "@var{filename}. If @var{filename} does not contain a directory\n"
1576 "component, @code{.} is returned.")
1577 #define FUNC_NAME s_scm_dirname
1581 unsigned long int len
;
1583 SCM_VALIDATE_STRING (1, filename
);
1585 s
= scm_i_string_chars (filename
);
1586 len
= scm_i_string_length (filename
);
1590 while (i
>= 0 && (s
[i
] == '/' || s
[i
] == '\\')) --i
;
1591 while (i
>= 0 && (s
[i
] != '/' && s
[i
] != '\\')) --i
;
1592 while (i
>= 0 && (s
[i
] == '/' || s
[i
] == '\\')) --i
;
1594 while (i
>= 0 && s
[i
] == '/') --i
;
1595 while (i
>= 0 && s
[i
] != '/') --i
;
1596 while (i
>= 0 && s
[i
] == '/') --i
;
1597 #endif /* ndef __MINGW32__ */
1601 if (len
> 0 && (s
[0] == '/' || s
[0] == '\\'))
1603 if (len
> 0 && s
[0] == '/')
1604 #endif /* ndef __MINGW32__ */
1605 return scm_c_substring (filename
, 0, 1);
1607 return scm_dot_string
;
1610 return scm_c_substring (filename
, 0, i
+ 1);
1614 SCM_DEFINE (scm_basename
, "basename", 1, 1, 0,
1615 (SCM filename
, SCM suffix
),
1616 "Return the base name of the file name @var{filename}. The\n"
1617 "base name is the file name without any directory components.\n"
1618 "If @var{suffix} is provided, and is equal to the end of\n"
1619 "@var{basename}, it is removed also.")
1620 #define FUNC_NAME s_scm_basename
1622 const char *f
, *s
= 0;
1625 SCM_VALIDATE_STRING (1, filename
);
1626 f
= scm_i_string_chars (filename
);
1627 len
= scm_i_string_length (filename
);
1629 if (SCM_UNBNDP (suffix
))
1633 SCM_VALIDATE_STRING (2, suffix
);
1634 s
= scm_i_string_chars (suffix
);
1635 j
= scm_i_string_length (suffix
) - 1;
1639 while (i
>= 0 && (f
[i
] == '/' || f
[i
] == '\\')) --i
;
1641 while (i
>= 0 && f
[i
] == '/') --i
;
1642 #endif /* ndef __MINGW32__ */
1644 while (i
>= 0 && j
>= 0 && f
[i
] == s
[j
]) --i
, --j
;
1648 while (i
>= 0 && f
[i
] != '/' && f
[i
] != '\\') --i
;
1650 while (i
>= 0 && f
[i
] != '/') --i
;
1651 #endif /* ndef __MINGW32__ */
1655 if (len
> 0 && (f
[0] == '/' || f
[0] == '\\'))
1657 if (len
> 0 && f
[0] == '/')
1658 #endif /* ndef __MINGW32__ */
1659 return scm_c_substring (filename
, 0, 1);
1661 return scm_dot_string
;
1664 return scm_c_substring (filename
, i
+1, end
+1);
1675 scm_tc16_dir
= scm_make_smob_type ("directory", 0);
1676 scm_set_smob_free (scm_tc16_dir
, scm_dir_free
);
1677 scm_set_smob_print (scm_tc16_dir
, scm_dir_print
);
1679 scm_dot_string
= scm_permanent_object (scm_from_locale_string ("."));
1682 scm_c_define ("O_RDONLY", scm_from_long (O_RDONLY
));
1685 scm_c_define ("O_WRONLY", scm_from_long (O_WRONLY
));
1688 scm_c_define ("O_RDWR", scm_from_long (O_RDWR
));
1691 scm_c_define ("O_CREAT", scm_from_long (O_CREAT
));
1694 scm_c_define ("O_EXCL", scm_from_long (O_EXCL
));
1697 scm_c_define ("O_NOCTTY", scm_from_long (O_NOCTTY
));
1700 scm_c_define ("O_TRUNC", scm_from_long (O_TRUNC
));
1703 scm_c_define ("O_APPEND", scm_from_long (O_APPEND
));
1706 scm_c_define ("O_NONBLOCK", scm_from_long (O_NONBLOCK
));
1709 scm_c_define ("O_NDELAY", scm_from_long (O_NDELAY
));
1712 scm_c_define ("O_SYNC", scm_from_long (O_SYNC
));
1715 scm_c_define ("O_LARGEFILE", scm_from_long (O_LARGEFILE
));
1719 scm_c_define ("F_DUPFD", scm_from_long (F_DUPFD
));
1722 scm_c_define ("F_GETFD", scm_from_long (F_GETFD
));
1725 scm_c_define ("F_SETFD", scm_from_long (F_SETFD
));
1728 scm_c_define ("F_GETFL", scm_from_long (F_GETFL
));
1731 scm_c_define ("F_SETFL", scm_from_long (F_SETFL
));
1734 scm_c_define ("F_GETOWN", scm_from_long (F_GETOWN
));
1737 scm_c_define ("F_SETOWN", scm_from_long (F_SETOWN
));
1740 scm_c_define ("FD_CLOEXEC", scm_from_long (FD_CLOEXEC
));
1743 #include "libguile/filesys.x"