X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxsel.c;h=ef25cdb574e2a6cf7fe4bb95112be1e05e52b947;hb=095072fa46b2d7b8beafaddb2f873d2f500a1e10;hp=0383faa69d02624c9d459afb046f7d0177705687;hpb=406d2d8a3274bf325f7e356076de8065b5118ad4;p=PuTTY.git diff --git a/unix/uxsel.c b/unix/uxsel.c index 0383faa6..ef25cdb5 100644 --- a/unix/uxsel.c +++ b/unix/uxsel.c @@ -19,7 +19,7 @@ struct fd { int fd; int rwx; /* 4=except 2=write 1=read */ uxsel_callback_fn callback; - int id; /* for uxsel_input_remove */ + uxsel_id *id; /* for uxsel_input_remove */ }; static tree234 *fds; @@ -62,29 +62,28 @@ void uxsel_init(void) void uxsel_set(int fd, int rwx, uxsel_callback_fn callback) { - struct fd *newfd = snew(struct fd); - struct fd *oldfd; + struct fd *newfd; - newfd->fd = fd; - newfd->rwx = rwx; - newfd->callback = callback; + assert(fd >= 0); - oldfd = find234(fds, newfd, NULL); - if (oldfd) { - uxsel_input_remove(oldfd->id); - del234(fds, oldfd); - sfree(oldfd); - } + uxsel_del(fd); - add234(fds, newfd); - newfd->id = uxsel_input_add(fd, rwx); + if (rwx) { + newfd = snew(struct fd); + newfd->fd = fd; + newfd->rwx = rwx; + newfd->callback = callback; + newfd->id = uxsel_input_add(fd, rwx); + add234(fds, newfd); + } } void uxsel_del(int fd) { struct fd *oldfd = find234(fds, &fd, uxsel_fd_findcmp); if (oldfd) { - uxsel_input_remove(oldfd->id); + if (oldfd->id) + uxsel_input_remove(oldfd->id); del234(fds, oldfd); sfree(oldfd); }