lkml.org 
[lkml]   [2023]   [Aug]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 2/2] selftests/nolibc: add testcase for pipe

Aug 1, 2023 14:23:22 Yuan Tan <tanyuan@tinylab.org>:

>>> Would this be fine?
>>>
>>> static int test_pipe(void)
>>> {
>>>         const char *const msg = "hello, nolibc";
>>>         int pipefd[2];
>>>         char buf[32];
>>>         ssize_t len;
>>>
>>>         if (pipe(pipefd) == -1)
>>>                 return 1;
>>>
>>>         write(pipefd[1], msg, strlen(msg));
>>>         close(pipefd[1]);
>>>         len = read(pipefd[0], buf, sizeof(buf));
>>>         close(pipefd[0]);
>>>
>>>         if (len != strlen(msg))
>>>                 return 1;
>>>
>>>         return !!memcmp(buf, msg, len);
>>> }
>>
>> Looks good!
>>
>> The return value of write() could also be validated but given we
>> validate the return value from read() it shouldn't make a difference.
>>
>> (Also the manual manipulation of "buf" is gone that necessitated the
>> check in v1 of the series)
>>
>
> I am sorry that I didn't catch your last sentence.
>
> Did you mean this piece of code does not need any further modifications
> right?

Yes, for me this is great!
Sorry for being unclear.

\
 
 \ /
  Last update: 2023-08-01 16:47    [W:0.061 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site