Re: Use `if (retval == -1)' instead of 'if (retval < 0)'
I don't see any problem. ok yasuoka On Wed, 14 Aug 2019 16:12:01 +0900 (JST) Masato Asou wrote: > Additional information. > > From: Masato Asou > Subject: Use `if (retval == -1)' instead of 'if (retval < 0)' > Date: Wed, 14 Aug 2019 13:42:13 +0900 (JST) > >> Hi tech, >> >> Use `if (retval == -1)' instead of 'if (retval < 0)' when check the >> return value of system call. >> >> How about it? >> >> RCS file: /cvs/src/lib/libedit/readline.c,v >> retrieving revision 1.28 >> diff -u -p -u -r1.28 readline.c >> --- readline.c 28 Jun 2019 13:32:42 - 1.28 >> +++ readline.c 14 Aug 2019 04:38:55 - >> @@ -2112,7 +2112,7 @@ _rl_event_read_char(EditLine *el, wchar_ >> return -1; >> #endif >> >> - if (num_read < 0 && errno == EAGAIN) >> + if (num_read == -1 && errno == EAGAIN) >> continue; >> if (num_read == 0) >> continue; >> -- >> ASOU Masato > > The valiable num_read has a return value of READ(2) system call as follows: > >2090 while (rl_event_hook) { >2091 >2092 (*rl_event_hook)(); >2093 >2094 #if defined(FIONREAD) >2095 if (ioctl(el->el_infd, FIONREAD, ) == -1) >2096 return -1; >2097 if (n) >2098 num_read = read(el->el_infd, , 1); >2099 else >2100 num_read = 0; >2101 #elif defined(F_SETFL) && defined(O_NDELAY) >2102 if ((n = fcntl(el->el_infd, F_GETFL)) == -1) >2103 return -1; >2104 if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) == >-1) >2105 return -1; >2106 num_read = read(el->el_infd, , 1); >2107 if (fcntl(el->el_infd, F_SETFL, n)) >2108 return -1; >2109 #else >2110 /* not non-blocking, but what you gonna do? */ >2111 num_read = read(el->el_infd, , 1); >2112 return -1; >2113 #endif >2114 >2115 if (num_read < 0 && errno == EAGAIN) >2116 continue; >2117 if (num_read == 0) >2118 continue; >2119 break; >2120 } > -- > ASOU Masato >
Re: Use `if (retval == -1)' instead of 'if (retval < 0)'
Additional information. From: Masato Asou Subject: Use `if (retval == -1)' instead of 'if (retval < 0)' Date: Wed, 14 Aug 2019 13:42:13 +0900 (JST) > Hi tech, > > Use `if (retval == -1)' instead of 'if (retval < 0)' when check the > return value of system call. > > How about it? > > RCS file: /cvs/src/lib/libedit/readline.c,v > retrieving revision 1.28 > diff -u -p -u -r1.28 readline.c > --- readline.c 28 Jun 2019 13:32:42 - 1.28 > +++ readline.c 14 Aug 2019 04:38:55 - > @@ -2112,7 +2112,7 @@ _rl_event_read_char(EditLine *el, wchar_ > return -1; > #endif > > - if (num_read < 0 && errno == EAGAIN) > + if (num_read == -1 && errno == EAGAIN) > continue; > if (num_read == 0) > continue; > -- > ASOU Masato The valiable num_read has a return value of READ(2) system call as follows: 2090 while (rl_event_hook) { 2091 2092 (*rl_event_hook)(); 2093 2094 #if defined(FIONREAD) 2095 if (ioctl(el->el_infd, FIONREAD, ) == -1) 2096 return -1; 2097 if (n) 2098 num_read = read(el->el_infd, , 1); 2099 else 2100 num_read = 0; 2101 #elif defined(F_SETFL) && defined(O_NDELAY) 2102 if ((n = fcntl(el->el_infd, F_GETFL)) == -1) 2103 return -1; 2104 if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) == -1) 2105 return -1; 2106 num_read = read(el->el_infd, , 1); 2107 if (fcntl(el->el_infd, F_SETFL, n)) 2108 return -1; 2109 #else 2110 /* not non-blocking, but what you gonna do? */ 2111 num_read = read(el->el_infd, , 1); 2112 return -1; 2113 #endif 2114 2115 if (num_read < 0 && errno == EAGAIN) 2116 continue; 2117 if (num_read == 0) 2118 continue; 2119 break; 2120 } -- ASOU Masato
Use `if (retval == -1)' instead of 'if (retval < 0)'
Hi tech, Use `if (retval == -1)' instead of 'if (retval < 0)' when check the return value of system call. How about it? RCS file: /cvs/src/lib/libedit/readline.c,v retrieving revision 1.28 diff -u -p -u -r1.28 readline.c --- readline.c 28 Jun 2019 13:32:42 - 1.28 +++ readline.c 14 Aug 2019 04:38:55 - @@ -2112,7 +2112,7 @@ _rl_event_read_char(EditLine *el, wchar_ return -1; #endif - if (num_read < 0 && errno == EAGAIN) + if (num_read == -1 && errno == EAGAIN) continue; if (num_read == 0) continue; -- ASOU Masato