{"id":18358060,"url":"https://github.com/archer-01/get_next_line","last_synced_at":"2025-04-10T02:38:30.105Z","repository":{"id":52190311,"uuid":"440137892","full_name":"Archer-01/get_next_line","owner":"Archer-01","description":"C function to read file one line at a time","archived":false,"fork":false,"pushed_at":"2023-12-06T15:53:51.000Z","size":6,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T18:35:51.787Z","etag":null,"topics":["c","memory-management","static-variables"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Archer-01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-12-20T10:59:25.000Z","updated_at":"2023-08-05T14:28:09.000Z","dependencies_parsed_at":"2023-12-06T16:47:15.814Z","dependency_job_id":null,"html_url":"https://github.com/Archer-01/get_next_line","commit_stats":null,"previous_names":["archer-01/get_next_line"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Archer-01%2Fget_next_line","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Archer-01%2Fget_next_line/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Archer-01%2Fget_next_line/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Archer-01%2Fget_next_line/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Archer-01","download_url":"https://codeload.github.com/Archer-01/get_next_line/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248144696,"owners_count":21054970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","memory-management","static-variables"],"created_at":"2024-11-05T22:16:38.149Z","updated_at":"2025-04-10T02:38:30.077Z","avatar_url":"https://github.com/Archer-01.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Get Next Line\n\n*Reading a line on a \u003ca href=\"https://en.wikipedia.org/wiki/File_descriptor\" target=\"_blank\"\u003efile descriptor\u003c/a\u003e is way too tedious*\n\n## Normal Version\n\n### Description\n* A function that reads a line from a file descriptor on each call.\n* Behaviour is undefined when using this function on different file descriptors\n\n### Prototype\n\n```h\nchar\t*get_next_line(int fd);\n```\n\n### Usage\n\n```sh\ngit clone https://github.com/Archer-01/get_next_line.git\ncd get_next_line\ntouch main.c\n```\n```c\n#include \u003cfcntl.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstdbool.h\u003e\n#include \"get_next_line.h\"\n\nint\tmain(void)\n{\n\tint\t\tfd;\n\tchar\t*line;\n\n\tfd = open(\"file.txt\", O_RDONLY);\n\tif (fd == -1)\n\t{\n\t\tfprintf(stderr, \"Couldn't open file.txt\");\n\t\texit(EXIT_FAILURE);\n\t}\n\n    line = get_next_line(fd);\n\twhile (line != NULL)\n\t{\n\t\tprintf(\"%s\", line);\n\t\tfree(line);\n        line = get_next_line(fd);\n\t}\n\treturn (0);\n}\n```\n```sh\necho \"Hello from file\" \u003e file.txt\necho \"Bye from file\" \u003e\u003e file.txt\ngcc -D BUFFER_SIZE=42 get_next_line.c get_next_line_utils.c main.c\n./a.out\n```\n\n## Bonus version\n\n### Description\n\n* Behaves just like the normal version but also handles multiple file descriptors at once (Up to 10240 file)\n\n### Prototype\n\n```h\nchar\t*get_next_line(int fd);\n```\n\n### Usage\n\n```sh\ngit clone https://github.com/Archer-01/get_next_line.git\ncd get_next_line\ntouch main.c\n```\n```c\n#include \u003cfcntl.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \u003cstdbool.h\u003e\n#include \"get_next_line_bonus.h\"\n\nint\tmain(void)\n{\n\tint\t\tfd1;\n\tint\t\tfd2;\n\tchar\t*line;\n\n\tfd1 = open(\"file1.txt\", O_RDONLY);\n\tfd2 = open(\"file2.txt\", O_RDONLY);\n\tif (fd1 == -1)\n\t{\n\t\tfprintf(stderr, \"Couldn't open file1.txt\");\n\t\texit(EXIT_FAILURE);\n\t}\n\tif (fd2 == -1)\n\t{\n\t\tfprintf(stderr, \"Couldn't open file2.txt\");\n\t\texit(EXIT_FAILURE);\n\t}\n\n    line = get_next_line(fd1);\n    printf(\"%s\", line);\n    free(line);\n\n    line = get_next_line(fd2);\n    printf(\"%s\", line);\n    free(line);\n\n    line = get_next_line(fd1);\n    printf(\"%s\", line);\n    free(line);\n\n    line = get_next_line(fd2);\n    printf(\"%s\", line);\n    free(line);\n\n\treturn (0);\n}\n```\n```sh\necho \"Hello from file 1\" \u003e file1.txt\necho \"Another hello from file 1\" \u003e\u003e file1.txt\necho \"Hello from file 2\" \u003e file2.txt\necho \"Another hello from file 2\" \u003e\u003e file2.txt\ngcc -D BUFFER_SIZE=42 get_next_line_bonus.c get_next_line_utils_bonus.c main.c\n./a.out\n```\n\n[![forthebadge](https://forthebadge.com/images/badges/made-with-c.svg)](https://forthebadge.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farcher-01%2Fget_next_line","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farcher-01%2Fget_next_line","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farcher-01%2Fget_next_line/lists"}