[libc-commits] [libc] [libc] implement fgetws (PR #196161)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Thu May 7 06:26:47 PDT 2026
================
@@ -0,0 +1,63 @@
+//===-- Implementation of fgetws ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/wchar/fgetws.h"
+#include "hdr/types/FILE.h"
+#include "src/__support/File/file.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(wchar_t *, fgetws,
+ (wchar_t *__restrict ws, int count,
+ ::FILE *__restrict stream)) {
+ if (count <= 0)
+ return nullptr;
+
+ LIBC_CRASH_ON_NULLPTR(ws);
+ LIBC_CRASH_ON_NULLPTR(stream);
+
+ auto *f = reinterpret_cast<File *>(stream);
+
+ if (count == 1) {
+ ws[0] = L'\0';
+ return ws;
+ }
+
+ f->lock();
+
+ wchar_t *result = ws;
+ int chars_read = 0;
+ wchar_t c = L'\0';
+
+ for (; chars_read < count - 1 && c != '\n'; ++chars_read) {
----------------
bassiounix wrote:
`c` is not used outside the loop
```suggestion
for (wchar_t c = L'\0'; chars_read < count - 1 && c != '\n'; ++chars_read) {
```
https://github.com/llvm/llvm-project/pull/196161
More information about the libc-commits
mailing list