dry-75 commented on code in PR #2456:
URL: https://github.com/apache/nuttx-apps/pull/2456#discussion_r1699920300


##########
nshlib/nsh_ddcmd.c:
##########
@@ -385,7 +385,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char 
**argv)
   if (dd.skip)
     {
       ret = lseek(dd.infd, dd.skip * dd.sectsize, SEEK_SET);
-      if (ret < -1)
+      if (ret < 0)

Review Comment:
   What Yamamoto seems to assert ( but he didn't specifically linked to it) is 
that in the old if not outdated POSIX  - see under Rationale in your link 
provided @xiaoxiang781216 
   "...The POSIX.1-1990 standard did not specifically prohibit lseek() from 
returning a negative offset..." etc.
   
   In same URL,  and all way to updated POSIX 2024 page of lseek, that 
Rationalte section is under header  / page section titled  "_The following 
sections are informative_".  One way to read that is, Information FYI nice to 
know history. 
   
   But at the same time, the return value para does not still explicitly state 
that the offset from beginning of the file cannot be negative.
   
   > RETURN VALUE
   Upon successful completion, the resulting offset, as measured in bytes from 
the beginning of the file, shall be returned. Otherwise, -1 shall be returned, 
errno shall be set to indicate the error, and the file offset shall remain 
unchanged.
   
   To which POSIX whole of NuttX conforms I do not know, and if this special 
case if of any use in current base. My guess is if this suggested change would 
work for most cases and only breaks when using some files which return negative 
other than -1 to signal error , well they are broken.
   
   I can submit this change, otherwise if anyone is interested to dig more into 
this I would have to pass as I would like to focus on other things.
   
   I found the comment/discussion informative however, as I always used lseek 
with closed eyes wrt. to the possibility of it returning a negative while not 
in error.  (But then again, all use cases I recall using it, It would never 
make sense for it to return a valid negative value which would not signal and 
error, whatever it would be actually).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to