# 0xmedl/get_next_line architecture

> Architecture diagram of the GitHub repository 0xmedl/get_next_line, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xmedl/get_next_line
- Repository: https://github.com/0xmedl/get_next_line

## Overview

This is a small C library that returns one line per call from a file descriptor, retaining unread bytes between calls. The standard and bonus implementations follow the same workflow: validate the descriptor, fill a persistent stash in fixed-size reads, determine and allocate a line, then remove consumed bytes. The bonus variant keeps separate stash state per descriptor. The source excerpts show the runtime calls; headers are included as public interface components, not runtime stages.

Main entry points: [`get_next_line.c`](https://github.com/0xmedl/get_next_line/blob/main/get_next_line.c) (Line reader), [`get_next_line_bonus.c`](https://github.com/0xmedl/get_next_line/blob/main/get_next_line_bonus.c) (Per-FD reader), [`get_next_line_utils.c`](https://github.com/0xmedl/get_next_line/blob/main/get_next_line_utils.c) (Stash utilities), [`get_next_line_utils_bonus.c`](https://github.com/0xmedl/get_next_line/blob/main/get_next_line_utils_bonus.c) (Per-FD utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_standard["Standard variant"]
  node_standard_api["Line reader<br/>[get_next_line.c]"]
  node_standard_header["Public interface<br/>[get_next_line.h]"]
  node_standard_stash["Stash utilities"]
end

subgraph group_bonus["Bonus variant"]
  node_bonus_api["Per-FD reader"]
  node_bonus_header["Bonus interface"]
  node_bonus_stash["Per-FD utilities"]
end

subgraph group_shared["Line and stash helpers"]
end

node_caller(("Library caller"))
node_fd["File descriptor"]

node_caller -->|"calls"| node_standard_api
node_caller -->|"calls"| node_bonus_api
node_standard_api -->|"reads"| node_fd
node_bonus_api -->|"reads"| node_fd
node_standard_api -->|"uses helpers"| node_standard_stash
node_bonus_api -->|"uses helpers"| node_bonus_stash
node_standard_api -->|"returns line"| node_caller
node_bonus_api -->|"returns line"| node_caller

click node_standard_api "https://github.com/0xmedl/get_next_line/blob/main/get_next_line.c"
click node_standard_header "https://github.com/0xmedl/get_next_line/blob/main/get_next_line.h"
click node_standard_stash "https://github.com/0xmedl/get_next_line/blob/main/get_next_line_utils.c"
click node_bonus_api "https://github.com/0xmedl/get_next_line/blob/main/get_next_line_bonus.c"
click node_bonus_header "https://github.com/0xmedl/get_next_line/blob/main/get_next_line_bonus.h"
click node_bonus_stash "https://github.com/0xmedl/get_next_line/blob/main/get_next_line_utils_bonus.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_standard_api,node_standard_header,node_standard_stash toneBlue
class node_bonus_api,node_bonus_header,node_bonus_stash toneAmber
class node_caller,node_fd toneIndigo
```

## Components

### Standard variant

- [Line reader](https://github.com/0xmedl/get_next_line/blob/main/get_next_line.c): `get_next_line.c`
- [Public interface](https://github.com/0xmedl/get_next_line/blob/main/get_next_line.h): `get_next_line.h`
- [Stash utilities](https://github.com/0xmedl/get_next_line/blob/main/get_next_line_utils.c): `get_next_line_utils.c`

### Bonus variant

- [Per-FD reader](https://github.com/0xmedl/get_next_line/blob/main/get_next_line_bonus.c): `get_next_line_bonus.c`
- [Bonus interface](https://github.com/0xmedl/get_next_line/blob/main/get_next_line_bonus.h): `get_next_line_bonus.h`
- [Per-FD utilities](https://github.com/0xmedl/get_next_line/blob/main/get_next_line_utils_bonus.c): `get_next_line_utils_bonus.c`

### Other components

- **Library caller**
- **File descriptor**

## Connections

- Library caller → Line reader: calls (evidence: `README.md`)
- Library caller → Per-FD reader: calls (evidence: `README.md`)
- Line reader → File descriptor: reads (evidence: `get_next_line.c`)
- Per-FD reader → File descriptor: reads (evidence: `get_next_line_bonus.c`)
- Line reader → Stash utilities: uses helpers (evidence: `get_next_line.c`)
- Per-FD reader → Per-FD utilities: uses helpers (evidence: `get_next_line_bonus.c`)
- Line reader → Library caller: returns line (evidence: `get_next_line.c`)
- Per-FD reader → Library caller: returns line (evidence: `get_next_line_bonus.c`)
