lkml.org 
[lkml]   [2008]   [Apr]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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




\
 
 \ /
  Last update: 2008-04-28 07:13    [W:0.308 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site