Skip to content

Instantly share code, notes, and snippets.

@chrislattman
Last active May 13, 2024 07:16
Show Gist options
  • Save chrislattman/f550ead7a1f19fee57984da8c17fefed to your computer and use it in GitHub Desktop.
Save chrislattman/f550ead7a1f19fee57984da8c17fefed to your computer and use it in GitHub Desktop.
#include <sys/syscall.h> // includes SYS_write
#include <unistd.h> // includes STDOUT_FILENO
#include <string.h>
// #include <stdio.h>
#if defined(__APPLE__)
#ifndef _SYS_SYSCALL_H_
#define SYS_write 4
#endif
#elif defined(__linux__)
#ifndef _SYSCALL_H
#if defined(__amd64__)
#define SYS_write 1
#elif defined(__aarch64__)
#define SYS_write 64
#endif
#endif
#endif
int main(void)
{
const char *str = "Hello, world!\n";
size_t len = strlen(str);
// printf("%s", str);
// puts(str);
// write(STDOUT_FILENO, str, len);
syscall(SYS_write, STDOUT_FILENO, str, len);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment