fix misleading/wrong fd checks

This commit is contained in:
BurnZeZ 2018-10-20 18:44:09 +00:00
parent 292cce2ad1
commit 84e019aba3
12 changed files with 16 additions and 16 deletions

View file

@ -153,7 +153,7 @@ char *dir;
if ((ofd = openout(to, asb, islink(to, asb), 1)) < 0) {
return (-1);
}
if (ofd > 0) {
if (ofd >= 0) {
passdata(from, ifd, to, ofd);
}
tstamp[0] = asb->sb_atime;

View file

@ -129,7 +129,7 @@ xfidopen(Xfid *x)
* though, we'd need to squirrel away the data in case it's
* modified during the operation, e.g. by |sort
*/
if(w->rdselfd > 0){
if(w->rdselfd >= 0){
winunlock(w);
respond(x, &fc, Einuse);
return;

View file

@ -127,7 +127,7 @@ main(int argc, char **argv)
origargs = procgetname();
/* see if we should use a larger message size */
fd = open("/dev/draw", OREAD);
if(fd > 0){
if(fd >= 0){
ms = iounit(fd);
if(msgsize < ms+IOHDRSZ)
msgsize = ms+IOHDRSZ;

View file

@ -77,7 +77,7 @@ filefree(Node *node)
if(fp == 0)
return;
if(fp->fd > 0){
if(fp->fd >= 0){
ntmp--;
close(fp->fd);
remove(fp->template);

View file

@ -52,7 +52,7 @@ writelog(HConnect *c, char *fmt, ...)
/* verbose logfile, for research on web traffic */
logfd = logall[today & 1];
if(logfd > 0){
if(logfd >= 0){
if(c->hstop == c->header || c->hstop[-1] != '\n')
*c->hstop = '\n';
*c->hstop = '\0';

View file

@ -55,7 +55,7 @@ lookup(char *object, int section, Hit **list)
snprint(file, sizeof(file), "/sys/man/%d/INDEX", section);
fd = open(file, OREAD);
if(fd > 0){
if(fd >= 0){
Binit(&b, fd, OREAD);
for(;;){
p = Brdline(&b, '\n');

View file

@ -2758,7 +2758,7 @@ main(int argc, char **argv)
snprint(buf, sizeof buf, "%sctl", dev);
cfd = open(buf, ORDWR);
}
if(cfd > 0){
if(cfd >= 0){
if(baud)
fprint(cfd, "b%d", baud);
fprint(cfd, "m1"); /* cts/rts flow control (and fifo's) on */

View file

@ -110,7 +110,7 @@ redistrib(uchar *buf, int len)
uh = (Udphdr *)buf;
for (tp = forwtarg; tp < forwtarg + forwtcount; tp++)
if (tp->fd > 0) {
if (tp->fd >= 0) {
memmove(uh->raddr, tp->addr, sizeof tp->addr);
hnputs(uh->rport, 53); /* dns port */
if (write(tp->fd, buf, len) != len) {

View file

@ -516,7 +516,7 @@ cd(String *str)
if(chdir(s))
syserror("chdir");
fd = open("/dev/wdir", OWRITE);
if(fd > 0)
if(fd >= 0)
write(fd, s, strlen(s));
dprint("!\n");
Strinit(&owd);

View file

@ -670,7 +670,7 @@ hplumb(int nc)
s = alloc(nc);
for(i=0; i<nc; i++)
s[i] = getch();
if(plumbfd > 0){
if(plumbfd >= 0){
m = plumbunpack(s, nc);
if(m != 0)
plumbsend(plumbfd, m);

View file

@ -151,7 +151,7 @@ openf(void)
Bflush(output);
Bterm(output);
if(fd > 0)
if(fd >= 0)
close(fd);
fd = create(name,OWRITE,0666);
if(fd < 0) {

View file

@ -336,7 +336,7 @@ print2(int fd, int ofd, char *fmt, ...)
return -1;
m = strlen(s);
n = write(fd, s, m);
if(ofd > 0)
if(ofd >= 0)
write(ofd, s, m);
return n;
}
@ -350,7 +350,7 @@ write2(int fd, int ofd, char *buf, int n, int nofrom)
if(fd >= 0)
m = write(fd, buf, n);
if(ofd <= 0)
if(ofd < 0)
return m;
if(nofrom == 0)
@ -463,7 +463,7 @@ mesgsend(Message *m)
}
ofd = open(outgoing, OWRITE|OCEXEC); /* no error check necessary */
if(ofd > 0){
if(ofd >= 0){
/* From dhog Fri Aug 24 22:13:00 EDT 2001 */
now = ctime(time(0));
fprint(ofd, "From %s %s", user, now);
@ -537,14 +537,14 @@ mesgsend(Message *m)
write2(p[1], ofd, "\n", 1, 0);
/* these look like pseudo-attachments in the "outgoing" box */
if(ofd>0 && natt>0){
if(ofd>=0 && natt>0){
for(i=0; i<natt; i++)
if(included[i])
fprint(ofd, "=====> Include: %s\n", attlist[i]);
else
fprint(ofd, "=====> Attach: %s\n", attlist[i]);
}
if(ofd > 0)
if(ofd >= 0)
write(ofd, "\n", 1);
for(i=0; i<natt; i++)