Messages in this thread | | | Date | Sun, 27 Apr 2008 22:11:28 -0700 (PDT) | From | Davide Libenzi <> | Subject | Re: [PATCH v2] eventfd, signalfd, timerfd, epoll_create w/flags |
| |
On Sun, 27 Apr 2008, Ulrich Drepper wrote:
> + int fflags = 0; > + > + if (flags) { > + if ((flags & EFD_CLOEXEC) != 0) { > + fflags |= O_CLOEXEC; > + flags &= ~EFD_CLOEXEC; > + } > + if (flags) > + return -EINVAL; > + }
...
> + int fflags = 0; > + > + if (flags) { > + if ((flags & EPOLL_CLOEXEC) != 0) { > + fflags |= O_CLOEXEC; > + flags &= ~EPOLL_CLOEXEC; > + } > + if (flags) > + return -EINVAL; > + }
...
> + int fflags = 0; > + > + if (flags) { > + if ((flags & SFD_CLOEXEC) != 0 && ufd == -1) { > + fflags |= O_CLOEXEC; > + flags &= ~SFD_CLOEXEC; > + } > + if (flags) > + return -EINVAL; > + }
...
> + int fflags = 0; > > - if (flags) > - return -EINVAL; > + if (flags) { > + if ((flags & TFD_CLOEXEC) != 0) { > + fflags |= O_CLOEXEC; > + flags &= ~TFD_CLOEXEC; > + } > + if (flags) > + return -EINVAL; > + }
Maybe something like:
struct oflags_rmap { int f, of; };
unsigned int oflags_remap(const struct oflags_rmap *m, int n, int f, int *rf) { int i; for (i = 0, *rf = 0; i < n; i++, m++) if (f & m->f) { *rf |= m->of; f &= ~m->f; } return f ? -EINVAL: 0; }
Then, in all the cases above (modulo different "struct oflags_rmap" fillings):
const struct oflags_rmap ormap[] = { { TFD_CLOEXEC, O_CLOEXEC } };
error = oflags_remap(ormap, ARRAY_SIZE(ormap), flags, &fflags);
- Davide
| |