Skip to content

Commit

Permalink
Fix for duplicate definition of fcntl()
Browse files Browse the repository at this point in the history
  • Loading branch information
smuehlst committed Mar 3, 2024
1 parent 9ffed7f commit 2fadd10
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libs/circle-newlib
22 changes: 19 additions & 3 deletions samples/05-smoketest/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <string>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

using namespace std;

Expand Down Expand Up @@ -597,7 +598,7 @@ CKernel::IoTest (void)
}

{
Report ("dup () and dup2 () tests");
Report ("dup (), dup2 (), fcntl () tests");

int const original_fd = fileno (redirected_stdout);

Expand Down Expand Up @@ -628,9 +629,19 @@ CKernel::IoTest (void)

assert (fd_copy2 > fd_copy);

if (write (fd_copy2, dup_text, sizeof (dup_text) - 1) == -1)
int const fd_copy3 = fcntl (fd_copy2, F_DUPFD, 0);

if (fd_copy3 == -1)
{
PErrorExit ("fcntl () failed");
}

assert (fd_copy3 > fd_copy);
assert (fd_copy3 > fd_copy2);

if (write (fd_copy3, dup_text, sizeof (dup_text) - 1) == -1)
{
PErrorExit ("write () via fd_copy2 failed");
PErrorExit ("write () via fd_copy3 failed");
}

if (close (fd_copy) < 0)
Expand All @@ -642,6 +653,11 @@ CKernel::IoTest (void)
{
PErrorExit ("close (fd_copy2) failed");
}

if (close (fd_copy3) < 0)
{
PErrorExit ("close (fd_copy3) failed");
}
}

if (fclose (redirected_stdout) != 0)
Expand Down

0 comments on commit 2fadd10

Please sign in to comment.