Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tarot
gnulib
Commits
49bfafdb
Commit
49bfafdb
authored
Aug 23, 2009
by
Bruno Haible
Browse files
Tweak the dup2 test.
parent
3fc40328
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
49bfafdb
2009-08-23 Bruno Haible <bruno@clisp.org>
Tweak the dup2 test.
* tests/test-dup2.c (main): Create the test file empty. Verify that an
out-of-range fd yields EBADF. Verify that after writing to /dev/null,
the test file is still empty. Fix argument order of lseek.
2009-08-23 Bruno Haible <bruno@clisp.org>
Avoid test link errors when the modules getopt-gnu, gettext are used.
tests/test-dup2.c
View file @
49bfafdb
...
...
@@ -65,7 +65,7 @@ main ()
{
const
char
*
file
=
"test-dup2.tmp"
;
char
buffer
[
1
];
int
fd
=
open
(
file
,
O_CREAT
|
O_RDWR
,
0600
);
int
fd
=
open
(
file
,
O_CREAT
|
O_TRUNC
|
O_RDWR
,
0600
);
/* Assume std descriptors were provided by invoker. */
ASSERT
(
STDERR_FILENO
<
fd
);
...
...
@@ -94,6 +94,9 @@ main ()
errno
=
0
;
ASSERT
(
dup2
(
fd
,
-
2
)
==
-
1
);
ASSERT
(
errno
==
EBADF
);
errno
=
0
;
ASSERT
(
dup2
(
fd
,
10000000
)
==
-
1
);
ASSERT
(
errno
==
EBADF
);
/* Using dup2 can skip fds. */
ASSERT
(
dup2
(
fd
,
fd
+
2
)
==
fd
+
2
);
...
...
@@ -101,14 +104,15 @@ main ()
ASSERT
(
!
is_open
(
fd
+
1
));
ASSERT
(
is_open
(
fd
+
2
));
/*
Prove
that dup2 closes the previous occupant of a fd. */
/*
Verify
that dup2 closes the previous occupant of a fd. */
ASSERT
(
open
(
"/dev/null"
,
O_WRONLY
,
0600
)
==
fd
+
1
);
ASSERT
(
dup2
(
fd
+
1
,
fd
)
==
fd
);
ASSERT
(
close
(
fd
+
1
)
==
0
);
ASSERT
(
write
(
fd
,
"1"
,
1
)
==
1
);
ASSERT
(
dup2
(
fd
+
2
,
fd
)
==
fd
);
ASSERT
(
lseek
(
fd
,
0
,
SEEK_END
)
==
0
);
ASSERT
(
write
(
fd
+
2
,
"2"
,
1
)
==
1
);
ASSERT
(
lseek
(
fd
,
SEEK_SET
,
0
)
==
0
);
ASSERT
(
lseek
(
fd
,
0
,
SEEK_SET
)
==
0
);
ASSERT
(
read
(
fd
,
buffer
,
1
)
==
1
);
ASSERT
(
*
buffer
==
'2'
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment