Skip to content

Commit

Permalink
Update test_program.c
Browse files Browse the repository at this point in the history
  • Loading branch information
saleha-muzammil authored Nov 8, 2024
1 parent a5178aa commit cf3bda8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test_program.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
FILE *file = fopen("flake.nix", "r");
Expand All @@ -13,5 +15,17 @@ int main() {
perror("fopen");
return EXIT_FAILURE;
}
int fd = open("flake.nix", O_RDONLY);
if (fd != -1) {
char buffer[100];
ssize_t bytes = read(fd, buffer, sizeof(buffer)-1);
if (bytes > 0) {
buffer[bytes] = '\0';
printf("Read from open: %s\n", buffer);
}
close(fd);
} else {
perror("open");
}
return EXIT_SUCCESS;
}

0 comments on commit cf3bda8

Please sign in to comment.