From 7d084f49e9d48b760208ca02786895b5870981d7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:09:08 +0000 Subject: [PATCH 1/2] Initial plan From 12cc685280e99a7f671a99b9c6ee45f06eb5ff0c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 14:12:13 +0000 Subject: [PATCH 2/2] chore: improve README and add GitHub Pages index Co-authored-by: ElyassShinwari <219741598+ElyassShinwari@users.noreply.github.com> --- README.md | 60 +++++++++++++++---------------------------------- docs/index.html | 17 ++++++++++++++ 2 files changed, 35 insertions(+), 42 deletions(-) create mode 100644 docs/index.html diff --git a/README.md b/README.md index e1ea671..92b231d 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,33 @@ -# get_next_line (short) +# Get Next Line (C) -Get Next Line is a small C implementation of get_next_line to read lines from a file descriptor. It is designed for simple file I/O tasks and learning C buffer-handling and line parsing. +Get Next Line is a compact C implementation of get_next_line for reading lines from a file descriptor. It includes example usage, a simple test harness, and minimal plain-C helper functions for buffer handling. ## Features -- Read a line from a file descriptor -- Minimal dependencies — plain C -- Example usage and simple tests included +- Read a single line from a file descriptor +- Minimal plain-C implementation (no external deps) +- Example usage and a simple test harness included ## Quick start -```sh -# build (example) -gcc -Wall -Wextra -Werror -o gnl get_next_line.c main.c -./gnl example.txt -``` - -## Build -make fclean all -Or compile manually: -```sh -gcc -D BUFFER_SIZE=32 -Wall -Wextra -Werror -I. get_next_line.c get_next_line_utils.c -o gnl +Build: ``` - -## Usage -```c -int fd = open("file.txt", O_RDONLY); -char *line; -while ((line = get_next_line(fd)) != NULL) -{ - printf("%s", line); - free(line); -} -close(fd); +gcc -Wall -Wextra -Werror -o gnl get_next_line.c get_next_line_utils.c main.c ``` -Returns a malloc'd string (includes `\n` if present). Caller must free. -## API -- `char *get_next_line(int fd);` — returns next line or `NULL` on EOF/error. +Run: +``` +./gnl example.txt +``` -## Notes -- Uses a static `leftover` buffer to keep unread data between calls. -- Avoid repeated concatenation of a growing string inside the read loop — that causGet Next Line flow chart -es O(n^2) behavior and timeouts on very large single-line files with small BUFFER_SIZE. -- For large single-line files prefer an approach that minimizes realloc/copy (chunked buffers, doubling growth, or assemble final line once). +API +- get_next_line(int fd) — returns a malloc'd string with the next line or NULL on EOF/error. See get_next_line.h for details. -## Testing -Use your usual francinette/getcheck setup: -```sh -getcheck francinette --strict -``` +Files of interest +- get_next_line.c — main implementation +- get_next_line_utils.c — helper functions +- get_next_line.h — public header +- main.c — small demo/test harness ## License This project is available under the MIT License. See LICENSE for details. -License: educational / adapt freely. - diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..f3d5947 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,17 @@ + + + + + + Get Next Line (C) - Lightweight C line reading implementation + + + +

Get Next Line (C)

+

Lightweight C implementation of get_next_line. See the README on GitHub for usage and examples.

+ + +