public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Intended semantics for syscalls function _read?
@ 2016-11-21 13:16 s.achterop
  2016-11-21 15:06 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: s.achterop @ 2016-11-21 13:16 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 885 bytes --]

   Hello list,

The documentation of this function does not describe how this function is to behave.
Is it blocking, or can it also be non-blocking.
What is the meaning of the return value? Or is it intentionally left ambiguous?
My guess would be:
   >=0  number of characters actually read
         zero meaning: zero characters read.
   < 0  error code (including eof?)

I want to use this function to read from serial/usb ports, using (man 2) read and scanf.
But also to test for the availability of a character on a port: a character_ready function.

Can I use (man 2) read in a non-blocking way? Or is there an other way?
Or should I directly use the _read function to make the character_ready function?

   Thanks in advance,
       Sietse Achterop


PS. I am using newlib as part of the GNU Embedded toolchain for a number of arm systems (stm32f4 based).


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3619 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Intended semantics for syscalls function _read?
  2016-11-21 13:16 Intended semantics for syscalls function _read? s.achterop
@ 2016-11-21 15:06 ` Eric Blake
  2016-11-21 15:24   ` s.achterop
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2016-11-21 15:06 UTC (permalink / raw)
  To: s.achterop, newlib


[-- Attachment #1.1: Type: text/plain, Size: 748 bytes --]

On 11/21/2016 07:16 AM, s.achterop@rug.nl wrote:
>    Hello list,
> 
> The documentation of this function does not describe how this function is to behave.
> Is it blocking, or can it also be non-blocking.
> What is the meaning of the return value? Or is it intentionally left ambiguous?

Your _read() function is supposed to behave similarly to the
POSIX-defined read(2) function:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html

> Can I use (man 2) read in a non-blocking way? Or is there an other way?

If you've properly implemented fcntl(2), then you can set O_NONBLOCK to
get non-blocking reads.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Intended semantics for syscalls function _read?
  2016-11-21 15:06 ` Eric Blake
@ 2016-11-21 15:24   ` s.achterop
  0 siblings, 0 replies; 3+ messages in thread
From: s.achterop @ 2016-11-21 15:24 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

On 11/21/2016 04:06 PM, Eric Blake wrote:
> On 11/21/2016 07:16 AM, s.achterop@rug.nl wrote:
>>    Hello list,
>>
>> The documentation of this function does not describe how this function is to behave.
>> Is it blocking, or can it also be non-blocking.
>> What is the meaning of the return value? Or is it intentionally left ambiguous?
> 
> Your _read() function is supposed to behave similarly to the
> POSIX-defined read(2) function:
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html

   Hello Eric,
thanks for the to the point answer.
Until now I interpreted the syscalls (wrongly) as some low level interface,
probably because I used it in that way in my embedded systems.
 Thanks again,
     Sietse




[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3619 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-11-21 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-21 13:16 Intended semantics for syscalls function _read? s.achterop
2016-11-21 15:06 ` Eric Blake
2016-11-21 15:24   ` s.achterop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).