summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2011-07-12 23:57:57 +0200
committerLudovic Courtès <ludo@gnu.org>2011-07-13 00:02:00 +0200
commit126a32243146d9ad238a3a5adb8d6af5a87ad2aa (patch)
treecefaeb936c2cd82023d3e6b65cfcb796247512de
parent3565df4546d97da4be573610a73f333d45a6287a (diff)
downloadguile-126a32243146d9ad238a3a5adb8d6af5a87ad2aa.tar.gz
Fix `open' mode bits on GNU/Hurd.
* libguile/filesys.c (scm_open): Fix check for read-write flags for systems such as GNU/Hurd, where O_RDWR == (O_WRONLY | O_RDONLY) and O_RDONLY != 0.
-rw-r--r--libguile/filesys.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 5e547a493..f60032818 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -261,8 +261,10 @@ SCM_DEFINE (scm_open, "open", 2, 1, 0,
fd = scm_to_int (scm_open_fdes (path, flags, mode));
iflags = SCM_NUM2INT (2, flags);
- if (iflags & O_RDWR)
+
+ if ((iflags & O_RDWR) == O_RDWR)
{
+ /* Opened read-write. */
if (iflags & O_APPEND)
port_mode = "a+";
else if (iflags & O_CREAT)
@@ -270,14 +272,17 @@ SCM_DEFINE (scm_open, "open", 2, 1, 0,
else
port_mode = "r+";
}
- else {
- if (iflags & O_APPEND)
- port_mode = "a";
- else if (iflags & O_WRONLY)
- port_mode = "w";
- else
- port_mode = "r";
- }
+ else
+ {
+ /* Opened read-only or write-only. */
+ if (iflags & O_APPEND)
+ port_mode = "a";
+ else if (iflags & O_WRONLY)
+ port_mode = "w";
+ else
+ port_mode = "r";
+ }
+
newpt = scm_fdes_to_port (fd, port_mode, path);
return newpt;
}