Skip to content

afeies/raw-cat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

raw-cat

A minimal implementation of the Unix cat command in raw C with zero library dependencies for macOS ARM64. All system calls are made via inline assembly (svc #0x80), making this an educational project for learning low-level systems programming.

Quick Start

Build

make                 # Build all milestones + cat
make cat             # Build only the final cat implementation

Run

./cat [FILE...]      # Concatenate files to stdout

Usage Examples

Read from stdin:

echo "Hello, world!" | ./cat

Display a single file:

./cat /etc/hosts

Concatenate multiple files:

./cat file1.txt file2.txt file3.txt

Mix files and stdin (use - for stdin):

echo "middle content" | ./cat header.txt - footer.txt

Error handling (continues on error):

./cat valid.txt /nonexistent/file.txt another.txt
# Prints valid.txt, shows error for nonexistent file, then prints another.txt

Performance tuning (custom buffer size):

cc -nostdlib -e __start -O2 -lSystem -DBUF_SIZE=16384 -o cat cat.c

Features

  • ✅ Read from stdin (no arguments or - argument)
  • ✅ Read and concatenate multiple files
  • ✅ Error handling with messages to stderr
  • ✅ Continues processing remaining files after errors
  • ✅ Configurable buffer size (default 8192 bytes)
  • ✅ Zero external dependencies (no libc, raw syscalls)

Learning Path

This project includes 7 incremental milestones (milestones/m1_exit.c through milestones/m7_errors.c), each teaching a specific systems programming concept. See docs/plan.md for the full learning roadmap.

About

Implementing the Unix cat command in C for learning purposes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors