; The MIT License (MIT) ; ; Copyright (c) 2026 pacman64 ; ; Permission is hereby granted, free of charge, to any person obtaining a copy ; of this software and associated documentation files (the "Software"), to deal ; in the Software without restriction, including without limitation the rights ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ; copies of the Software, and to permit persons to whom the Software is ; furnished to do so, subject to the following conditions: ; ; The above copyright notice and this permission notice shall be included in ; all copies or substantial portions of the Software. ; ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ; SOFTWARE. ; To compile this app for linux/amd64, use the commands ; ; nasm -f elf64 -o nil-linux-amd64.o nil-linux-amd64.asm ; ld -n -s nil-linux-amd64.o -o nil ; nil ; ; Emit nothing, while also discarding all bytes from the standard input, if ; data are being piped into it. stdin equ 0 statbuf_size equ 32 chunk_max_size equ 32 * 1024 sys_read equ 0 sys_fstat equ 5 sys_exit equ 60 section .text global _start _start: sub rsp, statbuf_size ; fstat(stdin, stat = rsp) mov rax, sys_fstat mov rdi, stdin mov rsi, rsp syscall cmp rax, 0 jne fail mov al, [rsp+8] cmp al, 3 jne piped add rsp, statbuf_size quit: ; exit(0) mov rax, sys_exit mov rdi, 0 syscall fail: ; exit(1) mov rax, sys_exit mov rdi, 1 syscall piped: add rsp, statbuf_size sub rsp, chunk_max_size mov rbx, rsp discard_stdin: push rbx ; read(stdin, buf = rbx, size = chunk_max_size) mov rax, sys_read mov rdi, stdin mov rsi, rbx mov rdx, chunk_max_size syscall pop rbx cmp rax, -1 je fail cmp rax, 0 je quit jmp discard_stdin