1 /* Copyright (C) 1996,1997,1998,1999,2000,2001, 2002, 2004, 2006, 2009, 2010 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 License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * 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
22 /* See stime.c for comments on why _POSIX_C_SOURCE is not always defined. */
23 #define _LARGEFILE64_SOURCE /* ask for stat64 etc */
25 #define _POSIX_C_SOURCE 199506L /* for readdir_r */
38 #include "libguile/_scm.h"
39 #include "libguile/smob.h"
40 #include "libguile/feature.h"
41 #include "libguile/fports.h"
42 #include "libguile/private-gc.h" /* for SCM_MAX */
43 #include "libguile/iselect.h"
44 #include "libguile/strings.h"
45 #include "libguile/vectors.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 /* Some more definitions for the native Windows port. */
119 # define mkdir(path, mode) mkdir (path)
120 # define fsync(fd) _commit (fd)
121 # define fchmod(fd, mode) (-1)
122 #endif /* __MINGW32__ */
124 /* dirfd() returns the file descriptor underlying a "DIR*" directory stream.
125 Found on MacOS X for instance. The following definition is for Solaris
126 10, it's probably not right elsewhere, but that's ok, it shouldn't be
127 used elsewhere. Crib note: If we need more then gnulib has a dirfd.m4
128 figuring out how to get the fd (dirfd function, dirfd macro, dd_fd field,
131 #define dirfd(dirstream) ((dirstream)->dd_fd)
136 /* Two helper macros for an often used pattern */
138 #define STRING_SYSCALL(str,cstr,code) \
141 char *cstr = scm_to_locale_string (str); \
142 SCM_SYSCALL (code); \
143 eno = errno; free (cstr); errno = eno; \
146 #define STRING2_SYSCALL(str1,cstr1,str2,cstr2,code) \
149 char *cstr1, *cstr2; \
150 scm_dynwind_begin (0); \
151 cstr1 = scm_to_locale_string (str1); \
152 scm_dynwind_free (cstr1); \
153 cstr2 = scm_to_locale_string (str2); \
154 scm_dynwind_free (cstr2); \
155 SCM_SYSCALL (code); \
156 eno = errno; scm_dynwind_end (); errno = eno; \
165 SCM_DEFINE (scm_chown
, "chown", 3, 0, 0,
166 (SCM object
, SCM owner
, SCM group
),
167 "Change the ownership and group of the file referred to by @var{object} to\n"
168 "the integer values @var{owner} and @var{group}. @var{object} can be\n"
169 "a string containing a file name or, if the platform\n"
170 "supports fchown, a port or integer file descriptor\n"
171 "which is open on the file. The return value\n"
172 "is unspecified.\n\n"
173 "If @var{object} is a symbolic link, either the\n"
174 "ownership of the link or the ownership of the referenced file will be\n"
175 "changed depending on the operating system (lchown is\n"
176 "unsupported at present). If @var{owner} or @var{group} is specified\n"
177 "as @code{-1}, then that ID is not changed.")
178 #define FUNC_NAME s_scm_chown
182 object
= SCM_COERCE_OUTPORT (object
);
185 if (scm_is_integer (object
) || (SCM_OPFPORTP (object
)))
187 int fdes
= (SCM_OPFPORTP (object
)?
188 SCM_FPORT_FDES (object
) : scm_to_int (object
));
190 SCM_SYSCALL (rv
= fchown (fdes
, scm_to_int (owner
), scm_to_int (group
)));
195 STRING_SYSCALL (object
, c_object
,
196 rv
= chown (c_object
,
197 scm_to_int (owner
), scm_to_int (group
)));
201 return SCM_UNSPECIFIED
;
204 #endif /* HAVE_CHOWN */
207 SCM_DEFINE (scm_chmod
, "chmod", 2, 0, 0,
208 (SCM object
, SCM mode
),
209 "Changes the permissions of the file referred to by @var{obj}.\n"
210 "@var{obj} can be a string containing a file name or a port or integer file\n"
211 "descriptor which is open on a file (in which case @code{fchmod} is used\n"
212 "as the underlying system call).\n"
213 "@var{mode} specifies\n"
214 "the new permissions as a decimal number, e.g., @code{(chmod \"foo\" #o755)}.\n"
215 "The return value is unspecified.")
216 #define FUNC_NAME s_scm_chmod
221 object
= SCM_COERCE_OUTPORT (object
);
223 if (scm_is_integer (object
) || SCM_OPFPORTP (object
))
225 if (scm_is_integer (object
))
226 fdes
= scm_to_int (object
);
228 fdes
= SCM_FPORT_FDES (object
);
229 SCM_SYSCALL (rv
= fchmod (fdes
, scm_to_int (mode
)));
233 STRING_SYSCALL (object
, c_object
,
234 rv
= chmod (c_object
, scm_to_int (mode
)));
238 return SCM_UNSPECIFIED
;
242 SCM_DEFINE (scm_umask
, "umask", 0, 1, 0,
244 "If @var{mode} is omitted, returns a decimal number representing the current\n"
245 "file creation mask. Otherwise the file creation mask is set to\n"
246 "@var{mode} and the previous value is returned.\n\n"
247 "E.g., @code{(umask #o022)} sets the mask to octal 22, decimal 18.")
248 #define FUNC_NAME s_scm_umask
251 if (SCM_UNBNDP (mode
))
258 mask
= umask (scm_to_uint (mode
));
260 return scm_from_uint (mask
);
266 SCM_DEFINE (scm_open_fdes
, "open-fdes", 2, 1, 0,
267 (SCM path
, SCM flags
, SCM mode
),
268 "Similar to @code{open} but return a file descriptor instead of\n"
270 #define FUNC_NAME s_scm_open_fdes
276 iflags
= SCM_NUM2INT (2, flags
);
277 imode
= SCM_NUM2INT_DEF (3, mode
, 0666);
278 STRING_SYSCALL (path
, c_path
, fd
= open_or_open64 (c_path
, iflags
, imode
));
281 return scm_from_int (fd
);
285 SCM_DEFINE (scm_open
, "open", 2, 1, 0,
286 (SCM path
, SCM flags
, SCM mode
),
287 "Open the file named by @var{path} for reading and/or writing.\n"
288 "@var{flags} is an integer specifying how the file should be opened.\n"
289 "@var{mode} is an integer specifying the permission bits of the file, if\n"
290 "it needs to be created, before the umask is applied. The default is 666\n"
291 "(Unix itself has no default).\n\n"
292 "@var{flags} can be constructed by combining variables using @code{logior}.\n"
293 "Basic flags are:\n\n"
295 "Open the file read-only.\n"
298 "Open the file write-only.\n"
301 "Open the file read/write.\n"
304 "Append to the file instead of truncating.\n"
307 "Create the file if it does not already exist.\n"
309 "See the Unix documentation of the @code{open} system call\n"
310 "for additional flags.")
311 #define FUNC_NAME s_scm_open
318 fd
= scm_to_int (scm_open_fdes (path
, flags
, mode
));
319 iflags
= SCM_NUM2INT (2, flags
);
322 if (iflags
& O_APPEND
)
324 else if (iflags
& O_CREAT
)
330 if (iflags
& O_APPEND
)
332 else if (iflags
& O_WRONLY
)
337 newpt
= scm_fdes_to_port (fd
, port_mode
, path
);
342 SCM_DEFINE (scm_close
, "close", 1, 0, 0,
344 "Similar to close-port (@pxref{Closing, close-port}),\n"
345 "but also works on file descriptors. A side\n"
346 "effect of closing a file descriptor is that any ports using that file\n"
347 "descriptor are moved to a different file descriptor and have\n"
348 "their revealed counts set to zero.")
349 #define FUNC_NAME s_scm_close
354 fd_or_port
= SCM_COERCE_OUTPORT (fd_or_port
);
356 if (SCM_PORTP (fd_or_port
))
357 return scm_close_port (fd_or_port
);
358 fd
= scm_to_int (fd_or_port
);
359 scm_evict_ports (fd
); /* see scsh manual. */
360 SCM_SYSCALL (rv
= close (fd
));
361 /* following scsh, closing an already closed file descriptor is
363 if (rv
< 0 && errno
!= EBADF
)
365 return scm_from_bool (rv
>= 0);
369 SCM_DEFINE (scm_close_fdes
, "close-fdes", 1, 0, 0,
371 "A simple wrapper for the @code{close} system call.\n"
372 "Close file descriptor @var{fd}, which must be an integer.\n"
373 "Unlike close (@pxref{Ports and File Descriptors, close}),\n"
374 "the file descriptor will be closed even if a port is using it.\n"
375 "The return value is unspecified.")
376 #define FUNC_NAME s_scm_close_fdes
381 c_fd
= scm_to_int (fd
);
382 SCM_SYSCALL (rv
= close (c_fd
));
385 return SCM_UNSPECIFIED
;
393 SCM_SYMBOL (scm_sym_regular
, "regular");
394 SCM_SYMBOL (scm_sym_directory
, "directory");
396 SCM_SYMBOL (scm_sym_symlink
, "symlink");
398 SCM_SYMBOL (scm_sym_block_special
, "block-special");
399 SCM_SYMBOL (scm_sym_char_special
, "char-special");
400 SCM_SYMBOL (scm_sym_fifo
, "fifo");
401 SCM_SYMBOL (scm_sym_sock
, "socket");
402 SCM_SYMBOL (scm_sym_unknown
, "unknown");
405 scm_stat2scm (struct stat_or_stat64
*stat_temp
)
407 SCM ans
= scm_c_make_vector (18, SCM_UNSPECIFIED
);
409 SCM_SIMPLE_VECTOR_SET(ans
, 0, scm_from_ulong (stat_temp
->st_dev
));
410 SCM_SIMPLE_VECTOR_SET(ans
, 1, scm_from_ino_t_or_ino64_t (stat_temp
->st_ino
));
411 SCM_SIMPLE_VECTOR_SET(ans
, 2, scm_from_ulong (stat_temp
->st_mode
));
412 SCM_SIMPLE_VECTOR_SET(ans
, 3, scm_from_ulong (stat_temp
->st_nlink
));
413 SCM_SIMPLE_VECTOR_SET(ans
, 4, scm_from_ulong (stat_temp
->st_uid
));
414 SCM_SIMPLE_VECTOR_SET(ans
, 5, scm_from_ulong (stat_temp
->st_gid
));
415 #ifdef HAVE_STRUCT_STAT_ST_RDEV
416 SCM_SIMPLE_VECTOR_SET(ans
, 6, scm_from_ulong (stat_temp
->st_rdev
));
418 SCM_SIMPLE_VECTOR_SET(ans
, 6, SCM_BOOL_F
);
420 SCM_SIMPLE_VECTOR_SET(ans
, 7, scm_from_off_t_or_off64_t (stat_temp
->st_size
));
421 SCM_SIMPLE_VECTOR_SET(ans
, 8, scm_from_ulong (stat_temp
->st_atime
));
422 SCM_SIMPLE_VECTOR_SET(ans
, 9, scm_from_ulong (stat_temp
->st_mtime
));
423 SCM_SIMPLE_VECTOR_SET(ans
, 10, scm_from_ulong (stat_temp
->st_ctime
));
424 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
425 SCM_SIMPLE_VECTOR_SET(ans
, 11, scm_from_ulong (stat_temp
->st_blksize
));
427 SCM_SIMPLE_VECTOR_SET(ans
, 11, scm_from_ulong (4096L));
429 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
430 SCM_SIMPLE_VECTOR_SET(ans
, 12, scm_from_blkcnt_t_or_blkcnt64_t (stat_temp
->st_blocks
));
432 SCM_SIMPLE_VECTOR_SET(ans
, 12, SCM_BOOL_F
);
435 int mode
= stat_temp
->st_mode
;
438 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_regular
);
439 else if (S_ISDIR (mode
))
440 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_directory
);
442 /* systems without symlinks probably don't have S_ISLNK */
443 else if (S_ISLNK (mode
))
444 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_symlink
);
446 else if (S_ISBLK (mode
))
447 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_block_special
);
448 else if (S_ISCHR (mode
))
449 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_char_special
);
450 else if (S_ISFIFO (mode
))
451 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_fifo
);
453 else if (S_ISSOCK (mode
))
454 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_sock
);
457 SCM_SIMPLE_VECTOR_SET(ans
, 13, scm_sym_unknown
);
459 SCM_SIMPLE_VECTOR_SET(ans
, 14, scm_from_int ((~S_IFMT
) & mode
));
461 /* the layout of the bits in ve[14] is intended to be portable.
462 If there are systems that don't follow the usual convention,
463 the following could be used:
466 if (S_ISUID & mode) tmp += 1;
468 if (S_IRGRP & mode) tmp += 1;
470 if (S_ISVTX & mode) tmp += 1;
472 if (S_IRUSR & mode) tmp += 1;
474 if (S_IWUSR & mode) tmp += 1;
476 if (S_IXUSR & mode) tmp += 1;
478 if (S_IWGRP & mode) tmp += 1;
480 if (S_IXGRP & mode) tmp += 1;
482 if (S_IROTH & mode) tmp += 1;
484 if (S_IWOTH & mode) tmp += 1;
486 if (S_IXOTH & mode) tmp += 1;
488 SCM_SIMPLE_VECTOR_SET(ans, 14, scm_from_int (tmp));
492 #ifdef HAVE_STRUCT_STAT_ST_ATIM
493 SCM_SIMPLE_VECTOR_SET(ans
, 15, scm_from_long (stat_temp
->st_atim
.tv_nsec
));
495 SCM_SIMPLE_VECTOR_SET(ans
, 15, SCM_I_MAKINUM (0));
497 #ifdef HAVE_STRUCT_STAT_ST_MTIM
498 SCM_SIMPLE_VECTOR_SET(ans
, 16, scm_from_long (stat_temp
->st_mtim
.tv_nsec
));
500 SCM_SIMPLE_VECTOR_SET(ans
, 16, SCM_I_MAKINUM (0));
502 #ifdef HAVE_STRUCT_STAT_ST_CTIM
503 SCM_SIMPLE_VECTOR_SET(ans
, 17, scm_from_ulong (stat_temp
->st_ctim
.tv_sec
));
505 SCM_SIMPLE_VECTOR_SET(ans
, 17, SCM_I_MAKINUM (0));
513 * Try getting the appropiate stat buffer for a given file descriptor
514 * under Windows. It differentiates between file, pipe and socket
517 static int fstat_Win32 (int fdes
, struct stat
*buf
)
519 int error
, optlen
= sizeof (int);
521 memset (buf
, 0, sizeof (struct stat
));
523 /* Is this a socket ? */
524 if (getsockopt (fdes
, SOL_SOCKET
, SO_ERROR
, (void *) &error
, &optlen
) >= 0)
526 buf
->st_mode
= _S_IFSOCK
| _S_IREAD
| _S_IWRITE
| _S_IEXEC
;
528 buf
->st_atime
= buf
->st_ctime
= buf
->st_mtime
= time (NULL
);
531 /* Maybe a regular file or pipe ? */
532 return fstat (fdes
, buf
);
534 #endif /* __MINGW32__ */
536 SCM_DEFINE (scm_stat
, "stat", 1, 1, 0,
537 (SCM object
, SCM exception_on_error
),
538 "Return an object containing various information about the file\n"
539 "determined by @var{obj}. @var{obj} can be a string containing\n"
540 "a file name or a port or integer file descriptor which is open\n"
541 "on a file (in which case @code{fstat} is used as the underlying\n"
544 "If the optional @var{exception_on_error} argument is true, which\n"
545 "is the default, an exception will be raised if the underlying\n"
546 "system call returns an error, for example if the file is not\n"
547 "found or is not readable. Otherwise, an error will cause\n"
548 "@code{stat} to return @code{#f}."
550 "The object returned by a successful call to @code{stat} can be\n"
551 "passed as a single parameter to the following procedures, all of\n"
552 "which return integers:\n"
556 "The device containing the file.\n"
558 "The file serial number, which distinguishes this file from all\n"
559 "other files on the same device.\n"
561 "The mode of the file. This includes file type information and\n"
562 "the file permission bits. See @code{stat:type} and\n"
563 "@code{stat:perms} below.\n"
565 "The number of hard links to the file.\n"
567 "The user ID of the file's owner.\n"
569 "The group ID of the file.\n"
571 "Device ID; this entry is defined only for character or block\n"
574 "The size of a regular file in bytes.\n"
576 "The last access time for the file.\n"
578 "The last modification time for the file.\n"
580 "The last modification time for the attributes of the file.\n"
581 "@item stat:blksize\n"
582 "The optimal block size for reading or writing the file, in\n"
584 "@item stat:blocks\n"
585 "The amount of disk space that the file occupies measured in\n"
586 "units of 512 byte blocks.\n"
589 "In addition, the following procedures return the information\n"
590 "from stat:mode in a more convenient form:\n"
594 "A symbol representing the type of file. Possible values are\n"
595 "regular, directory, symlink, block-special, char-special, fifo,\n"
596 "socket and unknown\n"
598 "An integer representing the access permission bits.\n"
600 #define FUNC_NAME s_scm_stat
604 struct stat_or_stat64 stat_temp
;
606 if (scm_is_integer (object
))
609 SCM_SYSCALL (rv
= fstat_Win32 (scm_to_int (object
), &stat_temp
));
611 SCM_SYSCALL (rv
= fstat_or_fstat64 (scm_to_int (object
), &stat_temp
));
614 else if (scm_is_string (object
))
616 char *file
= scm_to_locale_string (object
);
619 p
= file
+ strlen (file
) - 1;
620 while (p
> file
&& (*p
== '/' || *p
== '\\'))
623 SCM_SYSCALL (rv
= stat_or_stat64 (file
, &stat_temp
));
628 object
= SCM_COERCE_OUTPORT (object
);
629 SCM_VALIDATE_OPFPORT (1, object
);
630 fdes
= SCM_FPORT_FDES (object
);
632 SCM_SYSCALL (rv
= fstat_Win32 (fdes
, &stat_temp
));
634 SCM_SYSCALL (rv
= fstat_or_fstat64 (fdes
, &stat_temp
));
640 if (SCM_UNBNDP (exception_on_error
) || scm_is_true (exception_on_error
))
643 SCM_SYSERROR_MSG ("~A: ~S",
644 scm_list_2 (scm_strerror (scm_from_int (en
)),
651 return scm_stat2scm (&stat_temp
);
656 /* {Modifying Directories}
660 SCM_DEFINE (scm_link
, "link", 2, 0, 0,
661 (SCM oldpath
, SCM newpath
),
662 "Creates a new name @var{newpath} in the file system for the\n"
663 "file named by @var{oldpath}. If @var{oldpath} is a symbolic\n"
664 "link, the link may or may not be followed depending on the\n"
666 #define FUNC_NAME s_scm_link
670 STRING2_SYSCALL (oldpath
, c_oldpath
,
672 val
= link (c_oldpath
, c_newpath
));
675 return SCM_UNSPECIFIED
;
678 #endif /* HAVE_LINK */
681 #define my_rename rename
684 my_rename (const char *oldname
, const char *newname
)
688 SCM_SYSCALL (rv
= link (oldname
, newname
));
691 SCM_SYSCALL (rv
= unlink (oldname
));
693 /* unlink failed. remove new name */
694 SCM_SYSCALL (unlink (newname
));
700 SCM_DEFINE (scm_rename
, "rename-file", 2, 0, 0,
701 (SCM oldname
, SCM newname
),
702 "Renames the file specified by @var{oldname} to @var{newname}.\n"
703 "The return value is unspecified.")
704 #define FUNC_NAME s_scm_rename
708 STRING2_SYSCALL (oldname
, c_oldname
,
710 rv
= my_rename (c_oldname
, c_newname
));
713 return SCM_UNSPECIFIED
;
718 SCM_DEFINE (scm_delete_file
, "delete-file", 1, 0, 0,
720 "Deletes (or \"unlinks\") the file specified by @var{path}.")
721 #define FUNC_NAME s_scm_delete_file
724 STRING_SYSCALL (str
, c_str
, ans
= unlink (c_str
));
727 return SCM_UNSPECIFIED
;
732 SCM_DEFINE (scm_mkdir
, "mkdir", 1, 1, 0,
733 (SCM path
, SCM mode
),
734 "Create a new directory named by @var{path}. If @var{mode} is omitted\n"
735 "then the permissions of the directory file are set using the current\n"
736 "umask. Otherwise they are set to the decimal value specified with\n"
737 "@var{mode}. The return value is unspecified.")
738 #define FUNC_NAME s_scm_mkdir
743 if (SCM_UNBNDP (mode
))
747 STRING_SYSCALL (path
, c_path
, rv
= mkdir (c_path
, 0777 ^ mask
));
751 STRING_SYSCALL (path
, c_path
, rv
= mkdir (c_path
, scm_to_uint (mode
)));
755 return SCM_UNSPECIFIED
;
758 #endif /* HAVE_MKDIR */
761 SCM_DEFINE (scm_rmdir
, "rmdir", 1, 0, 0,
763 "Remove the existing directory named by @var{path}. The directory must\n"
764 "be empty for this to succeed. The return value is unspecified.")
765 #define FUNC_NAME s_scm_rmdir
769 STRING_SYSCALL (path
, c_path
, val
= rmdir (c_path
));
772 return SCM_UNSPECIFIED
;
779 /* {Examining Directories}
782 scm_t_bits scm_tc16_dir
;
785 SCM_DEFINE (scm_directory_stream_p
, "directory-stream?", 1, 0, 0,
787 "Return a boolean indicating whether @var{object} is a directory\n"
788 "stream as returned by @code{opendir}.")
789 #define FUNC_NAME s_scm_directory_stream_p
791 return scm_from_bool (SCM_DIRP (obj
));
796 SCM_DEFINE (scm_opendir
, "opendir", 1, 0, 0,
798 "Open the directory specified by @var{path} and return a directory\n"
800 #define FUNC_NAME s_scm_opendir
803 STRING_SYSCALL (dirname
, c_dirname
, ds
= opendir (c_dirname
));
806 SCM_RETURN_NEWSMOB (scm_tc16_dir
| (SCM_DIR_FLAG_OPEN
<<16), ds
);
811 /* FIXME: The glibc manual has a portability note that readdir_r may not
812 null-terminate its return string. The circumstances outlined for this
813 are not clear, nor is it clear what should be done about it. Lets use
814 NAMLEN and worry about what else should be done if/when someone can
817 SCM_DEFINE (scm_readdir
, "readdir", 1, 0, 0,
819 "Return (as a string) the next directory entry from the directory stream\n"
820 "@var{stream}. If there is no remaining entry to be read then the\n"
821 "end of file object is returned.")
822 #define FUNC_NAME s_scm_readdir
824 struct dirent_or_dirent64
*rdent
;
826 SCM_VALIDATE_DIR (1, port
);
827 if (!SCM_DIR_OPEN_P (port
))
828 SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port
));
831 /* As noted in the glibc manual, on various systems (such as Solaris) the
832 d_name[] field is only 1 char and you're expected to size the dirent
833 buffer for readdir_r based on NAME_MAX. The SCM_MAX expressions below
834 effectively give either sizeof(d_name) or NAME_MAX+1, whichever is
837 On solaris 10 there's no NAME_MAX constant, it's necessary to use
838 pathconf(). We prefer NAME_MAX though, since it should be a constant
839 and will therefore save a system call. We also prefer it since dirfd()
840 is not available everywhere.
842 An alternative to dirfd() would be to open() the directory and then use
843 fdopendir(), if the latter is available. That'd let us hold the fd
844 somewhere in the smob, or just the dirent size calculated once. */
846 struct dirent_or_dirent64 de
; /* just for sizeof */
847 DIR *ds
= (DIR *) SCM_SMOB_DATA_1 (port
);
850 char buf
[SCM_MAX (sizeof (de
),
851 sizeof (de
) - sizeof (de
.d_name
) + NAME_MAX
+ 1)];
854 long name_max
= fpathconf (dirfd (ds
), _PC_NAME_MAX
);
857 buf
= alloca (SCM_MAX (sizeof (de
),
858 sizeof (de
) - sizeof (de
.d_name
) + name_max
+ 1));
862 SCM_SYSCALL (readdir_r_or_readdir64_r (ds
, (struct dirent_or_dirent64
*) buf
, &rdent
));
868 namlen
= NAMLEN (rdent
);
870 return (rdent
? scm_from_locale_stringn (rdent
->d_name
, NAMLEN (rdent
))
876 scm_dynwind_begin (0);
877 scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex
);
880 SCM_SYSCALL (rdent
= readdir_or_readdir64 ((DIR *) SCM_SMOB_DATA_1 (port
)));
884 ret
= (rdent
? scm_from_locale_stringn (rdent
->d_name
, NAMLEN (rdent
))
895 SCM_DEFINE (scm_rewinddir
, "rewinddir", 1, 0, 0,
897 "Reset the directory port @var{stream} so that the next call to\n"
898 "@code{readdir} will return the first directory entry.")
899 #define FUNC_NAME s_scm_rewinddir
901 SCM_VALIDATE_DIR (1, port
);
902 if (!SCM_DIR_OPEN_P (port
))
903 SCM_MISC_ERROR ("Directory ~S is not open.", scm_list_1 (port
));
905 rewinddir ((DIR *) SCM_SMOB_DATA_1 (port
));
907 return SCM_UNSPECIFIED
;
912 SCM_DEFINE (scm_closedir
, "closedir", 1, 0, 0,
914 "Close the directory stream @var{stream}.\n"
915 "The return value is unspecified.")
916 #define FUNC_NAME s_scm_closedir
918 SCM_VALIDATE_DIR (1, port
);
920 if (SCM_DIR_OPEN_P (port
))
924 SCM_SYSCALL (sts
= closedir ((DIR *) SCM_SMOB_DATA_1 (port
)));
928 SCM_SET_SMOB_DATA_0 (port
, scm_tc16_dir
);
931 return SCM_UNSPECIFIED
;
937 scm_dir_print (SCM exp
, SCM port
, scm_print_state
*pstate SCM_UNUSED
)
939 scm_puts ("#<", port
);
940 if (!SCM_DIR_OPEN_P (exp
))
941 scm_puts ("closed: ", port
);
942 scm_puts ("directory stream ", port
);
943 scm_uintprint (SCM_SMOB_DATA_1 (exp
), 16, port
);
944 scm_putc ('>', port
);
952 if (SCM_DIR_OPEN_P (p
))
953 closedir ((DIR *) SCM_SMOB_DATA_1 (p
));
958 /* {Navigating Directories}
962 SCM_DEFINE (scm_chdir
, "chdir", 1, 0, 0,
964 "Change the current working directory to @var{path}.\n"
965 "The return value is unspecified.")
966 #define FUNC_NAME s_scm_chdir
970 STRING_SYSCALL (str
, c_str
, ans
= chdir (c_str
));
973 return SCM_UNSPECIFIED
;
978 SCM_DEFINE (scm_getcwd
, "getcwd", 0, 0, 0,
980 "Return the name of the current working directory.")
981 #define FUNC_NAME s_scm_getcwd
988 wd
= scm_malloc (size
);
989 while ((rv
= getcwd (wd
, size
)) == 0 && errno
== ERANGE
)
993 wd
= scm_malloc (size
);
997 int save_errno
= errno
;
1002 result
= scm_from_locale_stringn (wd
, strlen (wd
));
1007 #endif /* HAVE_GETCWD */
1013 /* check that element is a port or file descriptor. if it's a port
1014 and its buffer is ready for use, add it to the ports_ready list.
1015 otherwise add its file descriptor to *set. the type of list can be
1016 determined from pos: SCM_ARG1 for reads, SCM_ARG2 for writes,
1017 SCM_ARG3 for excepts. */
1019 set_element (SELECT_TYPE
*set
, SCM
*ports_ready
, SCM element
, int pos
)
1023 if (scm_is_integer (element
))
1025 fd
= scm_to_int (element
);
1031 element
= SCM_COERCE_OUTPORT (element
);
1032 SCM_ASSERT (SCM_OPFPORTP (element
), element
, pos
, "select");
1033 if (pos
== SCM_ARG1
)
1035 /* check whether port has buffered input. */
1036 scm_t_port
*pt
= SCM_PTAB_ENTRY (element
);
1038 if (pt
->read_pos
< pt
->read_end
)
1041 else if (pos
== SCM_ARG2
)
1043 /* check whether port's output buffer has room. */
1044 scm_t_port
*pt
= SCM_PTAB_ENTRY (element
);
1046 /* > 1 since writing the last byte in the buffer causes flush. */
1047 if (pt
->write_end
- pt
->write_pos
> 1)
1050 fd
= use_buf
? -1 : SCM_FPORT_FDES (element
);
1053 *ports_ready
= scm_cons (element
, *ports_ready
);
1059 /* check list_or_vec, a list or vector of ports or file descriptors,
1060 adding each member to either the ports_ready list (if it's a port
1061 with a usable buffer) or to *set. the kind of list_or_vec can be
1062 determined from pos: SCM_ARG1 for reads, SCM_ARG2 for writes,
1063 SCM_ARG3 for excepts. */
1065 fill_select_type (SELECT_TYPE
*set
, SCM
*ports_ready
, SCM list_or_vec
, int pos
)
1069 if (scm_is_simple_vector (list_or_vec
))
1071 int i
= SCM_SIMPLE_VECTOR_LENGTH (list_or_vec
);
1075 int fd
= set_element (set
, ports_ready
,
1076 SCM_SIMPLE_VECTOR_REF (list_or_vec
, i
), pos
);
1084 while (!SCM_NULL_OR_NIL_P (list_or_vec
))
1086 int fd
= set_element (set
, ports_ready
, SCM_CAR (list_or_vec
), pos
);
1090 list_or_vec
= SCM_CDR (list_or_vec
);
1097 /* if element (a file descriptor or port) appears in *set, cons it to
1098 list. return list. */
1100 get_element (SELECT_TYPE
*set
, SCM element
, SCM list
)
1104 if (scm_is_integer (element
))
1106 fd
= scm_to_int (element
);
1110 fd
= SCM_FPORT_FDES (SCM_COERCE_OUTPORT (element
));
1112 if (FD_ISSET (fd
, set
))
1113 list
= scm_cons (element
, list
);
1117 /* construct component of scm_select return value.
1118 set: pointer to set of file descriptors found by select to be ready
1119 ports_ready: ports ready due to buffering
1120 list_or_vec: original list/vector handed to scm_select.
1121 the return value is a list/vector of ready ports/file descriptors.
1122 works by finding the objects in list which correspond to members of
1123 *set and appending them to ports_ready. result is converted to a
1124 vector if list_or_vec is a vector. */
1126 retrieve_select_type (SELECT_TYPE
*set
, SCM ports_ready
, SCM list_or_vec
)
1128 SCM answer_list
= ports_ready
;
1130 if (scm_is_simple_vector (list_or_vec
))
1132 int i
= SCM_SIMPLE_VECTOR_LENGTH (list_or_vec
);
1136 answer_list
= get_element (set
,
1137 SCM_SIMPLE_VECTOR_REF (list_or_vec
, i
),
1140 return scm_vector (answer_list
);
1144 /* list_or_vec must be a list. */
1145 while (!SCM_NULL_OR_NIL_P (list_or_vec
))
1147 answer_list
= get_element (set
, SCM_CAR (list_or_vec
), answer_list
);
1148 list_or_vec
= SCM_CDR (list_or_vec
);
1154 /* Static helper functions above refer to s_scm_select directly as s_select */
1155 SCM_DEFINE (scm_select
, "select", 3, 2, 0,
1156 (SCM reads
, SCM writes
, SCM excepts
, SCM secs
, SCM usecs
),
1157 "This procedure has a variety of uses: waiting for the ability\n"
1158 "to provide input, accept output, or the existence of\n"
1159 "exceptional conditions on a collection of ports or file\n"
1160 "descriptors, or waiting for a timeout to occur.\n"
1161 "It also returns if interrupted by a signal.\n\n"
1162 "@var{reads}, @var{writes} and @var{excepts} can be lists or\n"
1163 "vectors, with each member a port or a file descriptor.\n"
1164 "The value returned is a list of three corresponding\n"
1165 "lists or vectors containing only the members which meet the\n"
1166 "specified requirement. The ability of port buffers to\n"
1167 "provide input or accept output is taken into account.\n"
1168 "Ordering of the input lists or vectors is not preserved.\n\n"
1169 "The optional arguments @var{secs} and @var{usecs} specify the\n"
1170 "timeout. Either @var{secs} can be specified alone, as\n"
1171 "either an integer or a real number, or both @var{secs} and\n"
1172 "@var{usecs} can be specified as integers, in which case\n"
1173 "@var{usecs} is an additional timeout expressed in\n"
1174 "microseconds. If @var{secs} is omitted or is @code{#f} then\n"
1175 "select will wait for as long as it takes for one of the other\n"
1176 "conditions to be satisfied.\n\n"
1177 "The scsh version of @code{select} differs as follows:\n"
1178 "Only vectors are accepted for the first three arguments.\n"
1179 "The @var{usecs} argument is not supported.\n"
1180 "Multiple values are returned instead of a list.\n"
1181 "Duplicates in the input vectors appear only once in output.\n"
1182 "An additional @code{select!} interface is provided.")
1183 #define FUNC_NAME s_scm_select
1185 struct timeval timeout
;
1186 struct timeval
* time_ptr
;
1187 SELECT_TYPE read_set
;
1188 SELECT_TYPE write_set
;
1189 SELECT_TYPE except_set
;
1193 /* these lists accumulate ports which are ready due to buffering.
1194 their file descriptors don't need to be added to the select sets. */
1195 SCM read_ports_ready
= SCM_EOL
;
1196 SCM write_ports_ready
= SCM_EOL
;
1199 if (scm_is_simple_vector (reads
))
1201 read_count
= SCM_SIMPLE_VECTOR_LENGTH (reads
);
1205 read_count
= scm_ilength (reads
);
1206 SCM_ASSERT (read_count
>= 0, reads
, SCM_ARG1
, FUNC_NAME
);
1208 if (scm_is_simple_vector (writes
))
1210 write_count
= SCM_SIMPLE_VECTOR_LENGTH (writes
);
1214 write_count
= scm_ilength (writes
);
1215 SCM_ASSERT (write_count
>= 0, writes
, SCM_ARG2
, FUNC_NAME
);
1217 if (scm_is_simple_vector (excepts
))
1219 except_count
= SCM_SIMPLE_VECTOR_LENGTH (excepts
);
1223 except_count
= scm_ilength (excepts
);
1224 SCM_ASSERT (except_count
>= 0, excepts
, SCM_ARG3
, FUNC_NAME
);
1227 FD_ZERO (&read_set
);
1228 FD_ZERO (&write_set
);
1229 FD_ZERO (&except_set
);
1231 max_fd
= fill_select_type (&read_set
, &read_ports_ready
, reads
, SCM_ARG1
);
1234 int write_max
= fill_select_type (&write_set
, &write_ports_ready
,
1236 int except_max
= fill_select_type (&except_set
, NULL
,
1239 if (write_max
> max_fd
)
1241 if (except_max
> max_fd
)
1242 max_fd
= except_max
;
1245 /* if there's a port with a ready buffer, don't block, just
1246 check for ready file descriptors. */
1247 if (!scm_is_null (read_ports_ready
) || !scm_is_null (write_ports_ready
))
1250 timeout
.tv_usec
= 0;
1251 time_ptr
= &timeout
;
1253 else if (SCM_UNBNDP (secs
) || scm_is_false (secs
))
1257 if (scm_is_unsigned_integer (secs
, 0, ULONG_MAX
))
1259 timeout
.tv_sec
= scm_to_ulong (secs
);
1260 if (SCM_UNBNDP (usecs
))
1261 timeout
.tv_usec
= 0;
1263 timeout
.tv_usec
= scm_to_long (usecs
);
1267 double fl
= scm_to_double (secs
);
1269 if (!SCM_UNBNDP (usecs
))
1270 SCM_WRONG_TYPE_ARG (4, secs
);
1272 SCM_OUT_OF_RANGE (4, secs
);
1273 timeout
.tv_sec
= (long) fl
;
1274 timeout
.tv_usec
= (long) ((fl
- timeout
.tv_sec
) * 1000000);
1276 time_ptr
= &timeout
;
1280 int rv
= scm_std_select (max_fd
+ 1,
1281 &read_set
, &write_set
, &except_set
,
1286 return scm_list_3 (retrieve_select_type (&read_set
, read_ports_ready
, reads
),
1287 retrieve_select_type (&write_set
, write_ports_ready
, writes
),
1288 retrieve_select_type (&except_set
, SCM_EOL
, excepts
));
1291 #endif /* HAVE_SELECT */
1296 SCM_DEFINE (scm_fcntl
, "fcntl", 2, 1, 0,
1297 (SCM object
, SCM cmd
, SCM value
),
1298 "Apply @var{command} to the specified file descriptor or the underlying\n"
1299 "file descriptor of the specified port. @var{value} is an optional\n"
1300 "integer argument.\n\n"
1301 "Values for @var{command} are:\n\n"
1304 "Duplicate a file descriptor\n"
1306 "Get flags associated with the file descriptor.\n"
1308 "Set flags associated with the file descriptor to @var{value}.\n"
1310 "Get flags associated with the open file.\n"
1312 "Set flags associated with the open file to @var{value}\n"
1314 "Get the process ID of a socket's owner, for @code{SIGIO} signals.\n"
1316 "Set the process that owns a socket to @var{value}, for @code{SIGIO} signals.\n"
1317 "@item FD_CLOEXEC\n"
1318 "The value used to indicate the \"close on exec\" flag with @code{F_GETFL} or\n"
1321 #define FUNC_NAME s_scm_fcntl
1327 object
= SCM_COERCE_OUTPORT (object
);
1329 if (SCM_OPFPORTP (object
))
1330 fdes
= SCM_FPORT_FDES (object
);
1332 fdes
= scm_to_int (object
);
1334 if (SCM_UNBNDP (value
))
1337 ivalue
= scm_to_int (value
);
1339 SCM_SYSCALL (rv
= fcntl (fdes
, scm_to_int (cmd
), ivalue
));
1342 return scm_from_int (rv
);
1345 #endif /* HAVE_FCNTL */
1347 SCM_DEFINE (scm_fsync
, "fsync", 1, 0, 0,
1349 "Copies any unwritten data for the specified output file descriptor to disk.\n"
1350 "If @var{port/fd} is a port, its buffer is flushed before the underlying\n"
1351 "file descriptor is fsync'd.\n"
1352 "The return value is unspecified.")
1353 #define FUNC_NAME s_scm_fsync
1357 object
= SCM_COERCE_OUTPORT (object
);
1359 if (SCM_OPFPORTP (object
))
1362 fdes
= SCM_FPORT_FDES (object
);
1365 fdes
= scm_to_int (object
);
1367 if (fsync (fdes
) == -1)
1369 return SCM_UNSPECIFIED
;
1374 SCM_DEFINE (scm_symlink
, "symlink", 2, 0, 0,
1375 (SCM oldpath
, SCM newpath
),
1376 "Create a symbolic link named @var{path-to} with the value (i.e., pointing to)\n"
1377 "@var{path-from}. The return value is unspecified.")
1378 #define FUNC_NAME s_scm_symlink
1382 STRING2_SYSCALL (oldpath
, c_oldpath
,
1384 val
= symlink (c_oldpath
, c_newpath
));
1387 return SCM_UNSPECIFIED
;
1390 #endif /* HAVE_SYMLINK */
1392 #ifdef HAVE_READLINK
1393 SCM_DEFINE (scm_readlink
, "readlink", 1, 0, 0,
1395 "Return the value of the symbolic link named by @var{path} (a\n"
1396 "string), i.e., the file that the link points to.")
1397 #define FUNC_NAME s_scm_readlink
1405 scm_dynwind_begin (0);
1407 c_path
= scm_to_locale_string (path
);
1408 scm_dynwind_free (c_path
);
1410 buf
= scm_malloc (size
);
1412 while ((rv
= readlink (c_path
, buf
, size
)) == size
)
1416 buf
= scm_malloc (size
);
1420 int save_errno
= errno
;
1425 result
= scm_take_locale_stringn (buf
, rv
);
1431 #endif /* HAVE_READLINK */
1434 SCM_DEFINE (scm_lstat
, "lstat", 1, 0, 0,
1436 "Similar to @code{stat}, but does not follow symbolic links, i.e.,\n"
1437 "it will return information about a symbolic link itself, not the\n"
1438 "file it points to. @var{path} must be a string.")
1439 #define FUNC_NAME s_scm_lstat
1442 struct stat_or_stat64 stat_temp
;
1444 STRING_SYSCALL (str
, c_str
, rv
= lstat_or_lstat64 (c_str
, &stat_temp
));
1449 SCM_SYSERROR_MSG ("~A: ~S",
1450 scm_list_2 (scm_strerror (scm_from_int (en
)), str
),
1453 return scm_stat2scm (&stat_temp
);
1456 #endif /* HAVE_LSTAT */
1458 SCM_DEFINE (scm_copy_file
, "copy-file", 2, 0, 0,
1459 (SCM oldfile
, SCM newfile
),
1460 "Copy the file specified by @var{path-from} to @var{path-to}.\n"
1461 "The return value is unspecified.")
1462 #define FUNC_NAME s_scm_copy_file
1464 char *c_oldfile
, *c_newfile
;
1468 struct stat_or_stat64 oldstat
;
1470 scm_dynwind_begin (0);
1472 c_oldfile
= scm_to_locale_string (oldfile
);
1473 scm_dynwind_free (c_oldfile
);
1474 c_newfile
= scm_to_locale_string (newfile
);
1475 scm_dynwind_free (c_newfile
);
1477 oldfd
= open_or_open64 (c_oldfile
, O_RDONLY
);
1482 SCM_SYSCALL (rv
= fstat_Win32 (oldfd
, &oldstat
));
1484 SCM_SYSCALL (rv
= fstat_or_fstat64 (oldfd
, &oldstat
));
1487 goto err_close_oldfd
;
1489 /* use POSIX flags instead of 07777?. */
1490 newfd
= open_or_open64 (c_newfile
, O_WRONLY
| O_CREAT
| O_TRUNC
,
1491 oldstat
.st_mode
& 07777);
1499 while ((n
= read (oldfd
, buf
, sizeof buf
)) > 0)
1500 if (write (newfd
, buf
, n
) != n
)
1507 if (close (newfd
) == -1)
1511 return SCM_UNSPECIFIED
;
1516 /* Filename manipulation */
1520 SCM_DEFINE (scm_dirname
, "dirname", 1, 0, 0,
1522 "Return the directory name component of the file name\n"
1523 "@var{filename}. If @var{filename} does not contain a directory\n"
1524 "component, @code{.} is returned.")
1525 #define FUNC_NAME s_scm_dirname
1528 unsigned long int len
;
1530 SCM_VALIDATE_STRING (1, filename
);
1532 len
= scm_i_string_length (filename
);
1536 while (i
>= 0 && (scm_i_string_ref (filename
, i
) == '/'
1537 || scm_i_string_ref (filename
, i
) == '\\'))
1539 while (i
>= 0 && (scm_i_string_ref (filename
, i
) != '/'
1540 && scm_i_string_ref (filename
, i
) != '\\'))
1542 while (i
>= 0 && (scm_i_string_ref (filename
, i
) == '/'
1543 || scm_i_string_ref (filename
, i
) == '\\'))
1546 while (i
>= 0 && scm_i_string_ref (filename
, i
) == '/')
1548 while (i
>= 0 && scm_i_string_ref (filename
, i
) != '/')
1550 while (i
>= 0 && scm_i_string_ref (filename
, i
) == '/')
1552 #endif /* ndef __MINGW32__ */
1556 if (len
> 0 && (scm_i_string_ref (filename
, 0) == '/'
1557 || scm_i_string_ref (filename
, 0) == '\\'))
1559 if (len
> 0 && scm_i_string_ref (filename
, 0) == '/')
1560 #endif /* ndef __MINGW32__ */
1561 return scm_c_substring (filename
, 0, 1);
1563 return scm_dot_string
;
1566 return scm_c_substring (filename
, 0, i
+ 1);
1570 SCM_DEFINE (scm_basename
, "basename", 1, 1, 0,
1571 (SCM filename
, SCM suffix
),
1572 "Return the base name of the file name @var{filename}. The\n"
1573 "base name is the file name without any directory components.\n"
1574 "If @var{suffix} is provided, and is equal to the end of\n"
1575 "@var{basename}, it is removed also.")
1576 #define FUNC_NAME s_scm_basename
1580 SCM_VALIDATE_STRING (1, filename
);
1581 len
= scm_i_string_length (filename
);
1583 if (SCM_UNBNDP (suffix
))
1587 SCM_VALIDATE_STRING (2, suffix
);
1588 j
= scm_i_string_length (suffix
) - 1;
1592 while (i
>= 0 && (scm_i_string_ref (filename
, i
) == '/'
1593 || scm_i_string_ref (filename
, i
) == '\\'))
1596 while (i
>= 0 && scm_i_string_ref (filename
, i
) == '/')
1598 #endif /* ndef __MINGW32__ */
1600 while (i
>= 0 && j
>= 0
1601 && (scm_i_string_ref (filename
, i
)
1602 == scm_i_string_ref (suffix
, j
)))
1610 while (i
>= 0 && (scm_i_string_ref (filename
, i
) != '/'
1611 && scm_i_string_ref (filename
, i
) != '\\'))
1614 while (i
>= 0 && scm_i_string_ref (filename
, i
) != '/')
1616 #endif /* ndef __MINGW32__ */
1620 if (len
> 0 && (scm_i_string_ref (filename
, 0) == '/'
1621 || scm_i_string_ref (filename
, 0) == '\\'))
1623 if (len
> 0 && scm_i_string_ref (filename
, 0) == '/')
1624 #endif /* ndef __MINGW32__ */
1625 return scm_c_substring (filename
, 0, 1);
1627 return scm_dot_string
;
1630 return scm_c_substring (filename
, i
+1, end
+1);
1634 SCM_DEFINE (scm_canonicalize_path
, "canonicalize-path", 1, 0, 0,
1636 "Return the canonical path of @var{path}. A canonical path has\n"
1637 "no @code{.} or @code{..} components, nor any repeated path\n"
1638 "separators (@code{/}) nor symlinks.\n\n"
1639 "Raises an error if any component of @var{path} does not exist.")
1640 #define FUNC_NAME s_scm_canonicalize_path
1644 SCM_VALIDATE_STRING (1, path
);
1646 str
= scm_to_locale_string (path
);
1647 canon
= canonicalize_file_name (str
);
1651 return scm_take_locale_string (canon
);
1663 scm_tc16_dir
= scm_make_smob_type ("directory", 0);
1664 scm_set_smob_free (scm_tc16_dir
, scm_dir_free
);
1665 scm_set_smob_print (scm_tc16_dir
, scm_dir_print
);
1667 scm_dot_string
= scm_from_locale_string (".");
1670 scm_c_define ("O_RDONLY", scm_from_int (O_RDONLY
));
1673 scm_c_define ("O_WRONLY", scm_from_int (O_WRONLY
));
1676 scm_c_define ("O_RDWR", scm_from_int (O_RDWR
));
1679 scm_c_define ("O_CREAT", scm_from_int (O_CREAT
));
1682 scm_c_define ("O_EXCL", scm_from_int (O_EXCL
));
1685 scm_c_define ("O_NOCTTY", scm_from_int (O_NOCTTY
));
1688 scm_c_define ("O_TRUNC", scm_from_int (O_TRUNC
));
1691 scm_c_define ("O_APPEND", scm_from_int (O_APPEND
));
1694 scm_c_define ("O_NONBLOCK", scm_from_int (O_NONBLOCK
));
1697 scm_c_define ("O_NDELAY", scm_from_int (O_NDELAY
));
1700 scm_c_define ("O_SYNC", scm_from_int (O_SYNC
));
1703 scm_c_define ("O_LARGEFILE", scm_from_int (O_LARGEFILE
));
1707 scm_c_define ("F_DUPFD", scm_from_int (F_DUPFD
));
1710 scm_c_define ("F_GETFD", scm_from_int (F_GETFD
));
1713 scm_c_define ("F_SETFD", scm_from_int (F_SETFD
));
1716 scm_c_define ("F_GETFL", scm_from_int (F_GETFL
));
1719 scm_c_define ("F_SETFL", scm_from_int (F_SETFL
));
1722 scm_c_define ("F_GETOWN", scm_from_int (F_GETOWN
));
1725 scm_c_define ("F_SETOWN", scm_from_int (F_SETOWN
));
1728 scm_c_define ("FD_CLOEXEC", scm_from_int (FD_CLOEXEC
));
1731 #include "libguile/filesys.x"