Skip to content

Instantly share code, notes, and snippets.

View mts0629's full-sized avatar

KURAMOCHI Kenta mts0629

  • Tokyo, Japan
View GitHub Profile
@mts0629
mts0629 / free_with_null.c
Created March 13, 2022 15:22
free with NULL clear to avoid double-free
#include <stdio.h>
#include <stdlib.h>
// free and set NULL
// need to specify address of pointer of allocated memory block
void free_with_null(void **ptr)
{
free(*ptr);
*ptr = NULL;
}
@mts0629
mts0629 / timer_kern_module.c
Created September 29, 2019 10:05
example of kernel module: one-shot timer
// ****************************************
// timer_kern_module.c
// based on: https://windhole.booth.pm/items/1169009
// ****************************************
#include <linux/module.h>
#include <linux/debugfs.h>
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("John Doe");
@mts0629
mts0629 / jpegtest.c
Last active December 20, 2021 02:37
Read/write JPEG image with libjpeg
/*********************************
jpegtest.c
$ gcc jpegtest.c -std=c11 -ljpeg
*********************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <jpeglib.h>
@mts0629
mts0629 / hello.asm
Created August 31, 2018 15:26
Hello world with NASM for X86_64
; ==================================================
; hello.asm
;
; $ nasm -f elf64 hello.asm -l hello.lst -o hello.o
; $ ld -s -o hello hello.o
; ==================================================
bits 64
section .text