[libc-commits] [libc] [libc][stdio] Implement getline and getdelim POSIX functions (PR #219601)

Victor Campos via libc-commits libc-commits at lists.llvm.org
Tue Sep 8 02:59:04 PDT 2026


================
@@ -0,0 +1,80 @@
+//===-- Implementation for getline and getdelim -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--------------------------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDIO_INLINE_GETLINE_H
+#define LLVM_LIBC_SRC_STDIO_INLINE_GETLINE_H
+
+#include "hdr/func/free.h"
+#include "hdr/func/malloc.h"
+#include "hdr/func/realloc.h"
+#include "hdr/types/FILE.h"
+#include "hdr/types/size_t.h"
+#include "hdr/types/ssize_t.h"
+#include "src/__support/File/file.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+
+constexpr int INIT_BASE = 32;
+
+namespace LIBC_NAMESPACE_DECL {
+
+LIBC_INLINE ssize_t __getline(char **__restrict lineptr, size_t *__restrict n,
+                               int del, ::FILE *__restrict stream) {
+  if (!lineptr || !n || !stream) {
----------------
vhscampos wrote:

`stream` being null is undefined behaviour. In the LLVM libc, this is usually handled with `LIBC_CRASH_ON_NULLPTR(ptr)`.

```suggestion
  LIBC_CRASH_ON_NULLPTR(stream);
  if (!lineptr || !n) {
    libc_errno = EINVAL;
    return -1;
 }
```

https://github.com/llvm/llvm-project/pull/219601


More information about the libc-commits mailing list