Skip to content

Commit

Permalink
Fix syscall calls
Browse files Browse the repository at this point in the history
Use named constants instead of just integers
  • Loading branch information
0152la committed Apr 22, 2024
1 parent cd39a1d commit d91f5e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tests/simple_fopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>

void
Expand All @@ -18,12 +19,12 @@ by_fopen()
void
by_syscall()
{
int fd = syscall(5, "tmp", O_CREAT); // open
int fd = syscall(SYS_open, "tmp", O_CREAT); // open
if (fd == -1)
{
err(1, "Error in open: ");
}
syscall(6, fd); // close
syscall(SYS_close, fd); // close
}

void
Expand Down
3 changes: 2 additions & 1 deletion tests/simple_syscall_getpid.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <assert.h>
#include <sys/syscall.h>
#include <unistd.h>

int
main(void)
{
long int sc_pid = syscall(20);
long int sc_pid = syscall(SYS_getpid);
pid_t pid = getpid();
assert(pid == sc_pid);
return 0;
Expand Down
3 changes: 2 additions & 1 deletion tests/simple_syscall_write.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <err.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>

int
main(void)
{
char *buf = "Hello World!\n";
long int sc_write = syscall(4, STDOUT_FILENO, buf, strlen(buf));
long int sc_write = syscall(SYS_write, STDOUT_FILENO, buf, strlen(buf));
if (sc_write == -1)
{
err(1, "Error calling `syscall`:");
Expand Down

0 comments on commit d91f5e8

Please sign in to comment.