Skip to content

Instantly share code, notes, and snippets.

View cho0h5's full-sized avatar
🤯

Youngho Cho cho0h5

🤯
  • Chung-Ang University
  • Korea
  • 05:07 (UTC +09:00)
View GitHub Profile
@cho0h5
cho0h5 / file_read.c
Last active December 18, 2021 04:02
c file io
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main() {
int fd = open("foo.txt", O_RDWR | O_CREAT, 0644);
if(fd < 0) {
printf("failed\n");
return -1;
#include <unistd.h>
#include <stdio.h>
int main() {
write(0, "write 0\n", 8);
write(1, "write 1\n", 8);
write(2, "write 2\n", 8);
fprintf(stdin, "fprintf stdin\n");
fprintf(stdout, "fprintf stdout\n");
use libc::{write, open, close};
use libc::{O_CREAT, O_RDWR};
use libc::{c_char, c_void};
fn main() {
let filename: *const c_char = "text.txt\0".as_ptr() as *const c_char;
let contents: *const c_void = "hello\n".as_ptr() as *const c_void;
unsafe {
let fd = open(filename, O_CREAT | O_RDWR, 0o0644);
@cho0h5
cho0h5 / control_light.c
Last active December 3, 2021 06:22
C 정적 라이브러리
#include "control_light.h"
#include <stdio.h>
int turn_on(int id) {
printf("turn on %d\n", id);
return 0;
}
int turn_off(int id) {
@cho0h5
cho0h5 / control_light.c
Created December 3, 2021 06:56
C 동적 라이브러리
#include "control_light.h"
#include <stdio.h>
int turn_on(int id) {
printf("turn on %d\n", id);
return 0;
}
int turn_off(int id) {
package main
import (
"io"
"fmt"
)
type DummyReader struct {
}
#include <stdio.h>
#include <unistd.h>
int main() {
printf("PID: %d\n", getpid());
pid_t pid = fork();
printf("fork ret: %d\n", pid);
return 0;
#include <unistd.h>
#include <stdio.h>
int main() {
char buffer[10] = { 0, };
int fd[2];
if(pipe(fd) == -1) printf("pipe failed");
printf("fd[0] == %d\n", fd[0]);
@cho0h5
cho0h5 / dup.c
Created December 21, 2021 13:36
dup and dup2
#include <stdio.h>
#include <unistd.h>
int main() {
char buf[] = "dummy string\n";
write(1, buf, 14); // write to stdout
int duplicated_fd = dup(1);
printf("duplicated fd: %d\n", duplicated_fd);
.data
msg:
.ascii "hello, world\n"
len = . - msg
.text
.global _start
_start:
mov x0, #1