This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
PATCH: Another portability oddity addressed
- From: Loren James Rittle <rittle at latour dot waar dot labs dot mot dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 20 Jan 2005 19:38:44 -0600 (CST)
- Subject: PATCH: Another portability oddity addressed
- Reply-to: rittle at labs dot mot dot com
In testsuite/27_io/basic_filebuf/open/char/9507.cc, we find:
// The use of ios_base::ate implies an attempt to seek on the file
// descriptor. The seek will fail. Thus, at the OS level, this
// call to "fbuf.open" will result in a call to "open" (which will
// succeed), a call to "lseek" (which will fail), and, finally, a
// call to "close" (which will succeed). Thus, after this call, the
// file should be closed.
This plain C program (which mirrors the system call sequence executed
with that test):
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
int main (void)
{
const char* name = "tmp_fifo2";
signal (SIGPIPE, SIG_IGN);
unlink (name);
mkfifo (name, S_IRWXU);
int f = open (name, O_RDWR);
if (f == 0) abort ();
int r = lseek (f, 0, SEEK_END);
if (r == -1) abort ();
}
works on at least some platforms thus invalidating the above comment.
We might argue over whether POSIX allows that sequence to execute but
it clearly does on FreeBSD 5 (and it appears to be a deliberate design
improvement from FreeBSD 4). The original PR suggests that we had a
mismatch between the return value and the true state. This patch
makes the test look for the true condition that was buggy rather than
assuming that a kernel call sequence must fail in a particular manner.
I have no idea if lseek works in general on fifo on FreeBSD 5 (the
various tests I ran seem to work), but (IMHO) it doesn't matter since
a later IO call will see the failed lseek and report it, etc.
Regards,
Loren
* testsuite/27_io/basic_filebuf/open/char/9507.cc: Allow
lseek on fifo to succeed. Thus, check for consistent report.
Index: libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc,v
retrieving revision 1.9
diff -c -r1.9 9507.cc
*** libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc 5 Jan 2005 16:13:46 -0000 1.9
--- libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc 21 Jan 2005 01:28:25 -0000
***************
*** 54,61 ****
std::ios_base::in
| std::ios_base::out
| std::ios_base::ate);
! VERIFY( !fbuf.is_open() );
! VERIFY( r == NULL );
}
int
--- 54,63 ----
std::ios_base::in
| std::ios_base::out
| std::ios_base::ate);
! if (r == NULL)
! VERIFY( !fbuf.is_open() );
! else
! VERIFY( fbuf.is_open() );
}
int