zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.61k stars 6.5k forks source link

libc: implement `getc()` #66943

Open ycsin opened 9 months ago

ycsin commented 9 months ago

This was originally added as a ticket under POSIX, but getc() is not a POSIX function. It is from C89.

https://en.cppreference.com/w/c/io/getc

The expectation from the POSIX API is that this function is implemented as part of whatever C library is in use.

cfriedt commented 9 months ago

Is this not already in the minimal libc??

00thirdeye00 commented 2 months ago

Hej @ycsin, @cfriedt, If this issue is not worked, I would like to take this. It would be helpful if you can guide and share some reference about this issue.

cfriedt commented 2 months ago

I would like to take this. It would be helpful if you can guide and share some reference about this issue.

Hi @00thirdeye00 - getc(FILE *stream) shouldn't be too difficult.

From a very high level, it should be as simple as

  1. lock the fdtable entry associated with stream (and verify that it is valid)
  2. read a character and report it back, or EOF if there is an error.
  3. unlock the fdtable entry

Do we still have zvfs_read() or was that reverted? With that, it would be trivial to implement.

00thirdeye00 commented 2 months ago

@cfriedt hej, thank you, since i am new to zephyr, it can be helpful if you can provide any references to files, implementation and flow

cfriedt commented 2 months ago

@00thirdeye00 -

lib/os/fdtable.c <-- ftdable and some ZVFS functions lib/c_lib/common/ <-- common libc components

https://docs.zephyrproject.org/latest/contribute/index.html