Re: sasc re-write

看板DFBSD_kernel作者時間21年前 (2005/01/18 03:32), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串7/10 (看更多)
:On Mon(17)/Jan/05 - , Diane Bruce wrote: :> On Mon, Jan 17, 2005 at 09:24:53AM +0100, Simon 'corecode' Schubert wrote: :> > hey, just a few comments :> > :> ... :> :> And a nit... :> :> > >+ val = strtol(str, &ep, 10); :> > >+ if (errno) :> > >+ err(1, "strtol failed: %s", str); :> :> :> I'd not attempt to use errno as a boolean, I'd do: :> :> if (errno != 0) :> ... :> :> Especially as later on you do: :> :> >+ if (ioctl(fd, asc_setting, &asc_value) < 0) : :I disagree. errno is normally used as boolean. : :> :> > you don't reset errno to 0, so this might be not working. reading the :> > man page it might be needed :/ :> :> Indeed it would be. :> :> - Diane. : :-- :- Liam J. Foy :<liamfoy@sepulcrum.org> Diane is right. errno is only modified when something fails, which means that it tends to 'accumulate' a non-zero value even if the last 50 system calls succeeded. You are only supposed to check errno if a particular operation fails. e.g. if (lseek(...) < 0) { ... check errno } strtol() is one of those rare functions where the only safe way to check errno is to clear it prior to calling the function because the error return value may also represent a non-error value. In anycase, I recommend not bothering with errno at all for strtol(). Just check that the returned value is in a reasonable range. -Matt Matthew Dillon <dillon@backplane.com>
文章代碼(AID): #11x1Az00 (DFBSD_kernel)
文章代碼(AID): #11x1Az00 (DFBSD_kernel)