{"id":19483552,"url":"https://github.com/librity/ft_get_next_line","last_synced_at":"2026-03-06T07:32:26.688Z","repository":{"id":53847613,"uuid":"338103300","full_name":"librity/ft_get_next_line","owner":"librity","description":"42 São Paulo - get_next_line","archived":false,"fork":false,"pushed_at":"2022-08-06T19:20:38.000Z","size":51,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T16:46:06.590Z","etag":null,"topics":["42","42born2code","42saopaulo","42school","c","cursus","gnl","norminette"],"latest_commit_sha":null,"homepage":"https://www.42sp.org.br/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/librity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-11T17:39:37.000Z","updated_at":"2024-11-24T00:35:39.000Z","dependencies_parsed_at":"2022-08-22T22:30:48.222Z","dependency_job_id":null,"html_url":"https://github.com/librity/ft_get_next_line","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/librity/ft_get_next_line","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_get_next_line","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_get_next_line/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_get_next_line/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_get_next_line/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/librity","download_url":"https://codeload.github.com/librity/ft_get_next_line/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fft_get_next_line/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30165627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T04:43:31.446Z","status":"ssl_error","status_checked_at":"2026-03-06T04:40:30.133Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["42","42born2code","42saopaulo","42school","c","cursus","gnl","norminette"],"created_at":"2024-11-10T20:15:32.376Z","updated_at":"2026-03-06T07:32:26.663Z","avatar_url":"https://github.com/librity.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch3 align=\"center\"\u003e42 São Paulo - ft_get_next_line\u003c/h3\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![norminette](https://github.com/librity/ft_get_next_line/actions/workflows/norminette.yml/badge.svg)](https://github.com/librity/ft_get_next_line/actions/workflows/norminette.yml)\n![42 São Paulo](https://img.shields.io/badge/42-SP-1E2952)\n![License](https://img.shields.io/github/license/librity/ft_get_next_line?color=yellow)\n![Code size in bytes](https://img.shields.io/github/languages/code-size/librity/ft_get_next_line?color=blue)\n![Lines of code](https://img.shields.io/tokei/lines/github/librity/ft_get_next_line?color=blueviolet)\n![Top language](https://img.shields.io/github/languages/top/librity/ft_get_next_line?color=ff69b4)\n![Last commit](https://img.shields.io/github/last-commit/librity/ft_get_next_line?color=orange)\n\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e A function that reads a file line-by-line.\n  \u003cbr\u003e\n\u003c/p\u003e\n\n---\n\n## 📜 Table of Contents\n\n- [About](#about)\n- [Getting Started](#getting_started)\n- [Github Actions](#github_actions)\n- [42 São Paulo](#ft_sp)\n\n## 🧐 About \u003ca name = \"about\"\u003e\u003c/a\u003e\n\nWhat can I say that\n[@harm-smits](https://harm-smits.github.io/42docs/projects/get_next_line)\nhasn't said already?\n\n`get_next_line` is a function that reads an entire line\nfrom a file indexed by a file descriptor `fd`.\nIt then alocates a string with the contents\nof that line without the linebreak `'\\n'` and points `line` to it.\n\nWe don't have to pass anything allocated to `get_next_line`,\nwe just pass the address of a pointer that will point to the allocated string.\n`line` should be freeable with `free()` after the function call\nunless an error occured.\n\nWe will incrementally read the file with `read()`,\nwhich advances its position in the file dexample escriptor automatically.\n\nWe need to use a static pointer as a read buffer\nto access what was read in previous calls.\n\nWe need to handle the following situations:\n\n1. If the read buffer doesn't have a `'\\n'`, we concatenate\n   with the previous buffer and call read again.\n2. If the read buffer has a `'\\n'`,\n   we concatenate with the previous buffer up to `'\\n'`.\n3. If we reach the end of the file (`read() == 0`),\n   we concatenate with the previous buffer.\n4. We finally point `line` to an allocated string\n   that contains the entire line without the `'\\n'`.\n   Then we release the memory allocated in the intermediate strings\n   and return `1` or `0` for `'\\n'` and `end_of_file` respectively.\n5. If the parameters have any problems (`BUFFER_SIZE \u003c= 0`),\n   or if in any operation we were unable to allocate memory,\n   we free whatever memory was allocated and return -1.\n\n### pt-br\n\nTem essa documentacao bem legal do\n[@harm-smits](https://harm-smits.github.io/42docs/projects/get_next_line).\n\nO `get_next_line` lê uma linha inteira do arquivo indexado por `fd`,\ne faz o ponterio `line` apontar para uma string allocada\ncom os conteudos dessa linha sem a quebra de linha `'\\n'`.\n\nNao temos que passar nada allocado para o get_next_line,\napenas passar o endereco de um ponteiro que vai apontar para a string allocada.\nPrecisamos poder dar `free()` nessa string allocada depois da chamada.\n\nA gente vai ler o arquivo com a funcao `read()`,\nque avanca a sua posicao no file descriptor automaticamente.\n\nA gente precisa usar um ponteiro estatico como buffer do read\npara poder acessar o que foi lido pelo read nas chamadas anteriores.\n\nPrecisamos tratar as seguintes situacoes:\n\n1. Se o buffer lido nao tem `'\\n'`,\n   concatenamos com o buffer anterior e chamamos read novamente.\n2. Se o buffer lido tem `'\\n'`,\n   concatenamos com o buffer anterior ate o `'\\n'`.\n3. Se chegamos no final do arquivo (`read() = 0`),\n   concatenamos com o buffer anterior.\n4. Finalmente temos que apontar o ponteiro line passado\n   para uma string allocada que contenha a linha inteira sem o `'\\n'`.\n   Depois liberamos a memoria allocada nas strings intermediarias\n   e retornamos 1 ou 0 para '\\n' ou final do arquivo respectivamente.\n5. Se os parametros tem algum problema (`BUFFER_SIZE \u003c= 0`),\n   ou em alguma dessas operacaoes nao conseguimos allocar memoria,\n   liberamos toda a memoria allocada e retornamos -1.\n\n## 🏁 Getting Started \u003ca name = \"getting_started\"\u003e\u003c/a\u003e\n\n### ⚙️ Prerequisites\n\nAll you need is a shell and a C compiler like `gcc` or `clang`.\n\n### 🖥️ Installing\n\nTo compile the entire thing just clone the repo and run `make`\nwith a positive `BUFFER_SIZE`:\n\n```bash\n$ git clone https://github.com/librity/ft_get_next_line.git\n$ cd ft_get_next_line\n$ make d=\"'BUFFER_SIZE=42'\"\n```\n\nThis will generate a `get_next_line.a` archive, which you can compile with\nthe example file:\n\n```bash\n$ gcc -g -D BUFFER_SIZE=42 -I ./includes ./examples/example.c get_next_line.a\n$ ./a.out\n```\n\n## 🐙 Github Actions \u003ca name = \"github_actions\"\u003e\u003c/a\u003e\n\n[Norminette Github Action](https://github.com/AdrianWR/libft/blob/master/.github/workflows/norminette.yaml)\nby [@AdrianWR](https://github.com/AdrianWR)\n\n## 🛸 42 São Paulo \u003ca name = \"ft_sp\"\u003e\u003c/a\u003e\n\nPart of the larger [42 Network](https://www.42.fr/42-network/),\n[42 São Paulo](https://www.42sp.org.br/) is a software engineering school\nthat offers a healthy alternative to traditional education:\n\n- It doesn't have any teachers and classes.\n- Students learn by cooperating\n  and correcting each other's work (peer-to-peer learning).\n- Its focus is as much on social skills as it is on technical skills.\n- It's completely free to anyone that passes its selection process -\n  [**The Piscine**](https://42.fr/en/admissions/42-piscine/)\n\nIt's an amazing school, and I'm grateful for the opportunity.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrity%2Fft_get_next_line","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibrity%2Fft_get_next_line","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrity%2Fft_get_next_line/lists"}