Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions test/unistd/test_unistd_write_broken_link.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
Expand All @@ -10,21 +11,23 @@ int main() {
printf("link result: %d\n", res);
int src_fd = open("link_source", O_CREAT | O_WRONLY, 0777);
printf("source_fd: %d, errno: %d %s\n", src_fd, errno, strerror(errno));
write(src_fd, "abc", 3);
write(src_fd, "abc\0", 4);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a little odd to write null byte to a text file.. but I guess its not important here.

close(src_fd);
{
int target_fd = open("link_target", O_RDONLY);
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
char buf[10];
read(target_fd, buf, 10);
size_t r = read(target_fd, buf, 10);
assert(r == 4);
printf("buf: '%s'\n", buf);
close(target_fd);
}
{
int target_fd = open("link_source", O_RDONLY);
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
char buf[10];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative here I suppose would be intialize buf on the stack with char buf[10] = { '\0' };

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I could go either way on that, do you have a preference?

read(target_fd, buf, 10);
size_t r = read(target_fd, buf, 10);
assert(r == 4);
printf("buf: '%s'\n", buf);
close(target_fd);
}
Expand Down
Loading