X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687968671; x=1690560671; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ePWi3XA5FoSz6hVCHCYpY6KKzU5ia5TdtAvy6kK10N0=; b=NXWKCrcTuGj5kWpVbSWYgmnhCJHZx9lHHAdfA1ubO5SfzKMIlrha/74iK0ozCJJmSO kWdiK2YApRG37l/uO1gZ0IzCYRbWssGhbBguP3Mgd/F2hr8Vu8F7reC2s2thvkIMnXf2 AwkwajP24gmxId6RFijGLUoW2Q4u8GJfJATCM9tndyqMlRyQaCsQtwcIP8t2kUfvI8HH GqE0/ozzMZAQ1eHGRvAznNrU3fGLLXlSI5dAbDGBgRvxZ84XR6ObVuIRtfVpkLhbwlBt TZ8I+PyQzKhXxCTeBCCF5XxLHJpqCZysIANasC7hvGgshKYQQjtqPcp72P7eXtmnY7qr NYpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687968671; x=1690560671; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ePWi3XA5FoSz6hVCHCYpY6KKzU5ia5TdtAvy6kK10N0=; b=YE3yWX1l8kWbuTfeeEYNHlOG5D9FOHKKZTAtoc1YkINYGXWFa3LsuiN7OwdKmyjA0v V1SZOhIFVGXIIeVYYGFUQQpm7qVm69WTCfpjlNudm+Y1VWHcHQi/TinVjt3+rF0QTCxF vSP3W67z6YwJzgsitxMH/EsCmbXL8D5ST08rdDzz07r7HIkC6uxy2HPHOszB5ovX4WS5 CSA1r0g5+1deXjYdFvXSfzoLOxVWMjBkOjnaHkulyJqYalxsew3RKZp0hWBEGPAspCs6 FKxWx8xwoC8cuYIn1G7mxQA/IjRCyTbWp5nM9+7IoX74TLQJQ3Yjdg6lQpfJF5ATcZUZ +BRw== X-Gm-Message-State: AC+VfDweQKQqdlJ8uDFNnu4trGDsUEFmJmxaLti1oQExEeu9t0Qy4/n1 nPsvXG4J2kuaHOn+7BEmJW4uk5FROpM= X-Google-Smtp-Source: ACHHUZ4UZK59NoMe+3Q6Yil4KRcw4RBtO1kT4U4KHU+A3+hQyoto05av8ETFWsAAjIr1X+MMM+PlUg== X-Received: by 2002:a2e:7819:0:b0:2b4:7fc5:21ab with SMTP id t25-20020a2e7819000000b002b47fc521abmr19062650ljc.51.1687968671333; Wed, 28 Jun 2023 09:11:11 -0700 (PDT) Message-ID: <5a7896dd-2f76-d043-bcd3-a40526766465@gmail.com> Date: Wed, 28 Jun 2023 18:11:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: fcntl() fails to pass option flags to fs-ext handler Content-Language: en-US From: "J.W. Jagersma (jwjagersma AT gmail DOT com) [via djgpp AT delorie DOT com]" To: djgpp AT delorie DOT com Cc: gvanem AT yahoo DOT no References: <7cb7c635-4f9f-6904-6171-264266ef4fb6 AT gmail DOT com> In-Reply-To: <7cb7c635-4f9f-6904-6171-264266ef4fb6@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com On 2023-06-28 17:04, J.W. Jagersma wrote: > Hi all, > > I was trying to make a non-blocking socket in Watt32 via: > > fcntl(sock, F_SETFL, O_NONBLOCK); > > To my surprise, it did nothing. Replacing fcntl() with fcntlsocket() does set > the flag correctly, but that's not a portable solution. > > Looking at the libc code, I see the fsext handler is invoked via: > > int > fcntl(int fd, int cmd, ...) > { > > /* ... */ > > func = __FSEXT_get_function(fd); > if (func) > { > int rv; > if (__FSEXT_func_wrapper(func, __FSEXT_fcntl, &rv, fd, cmd)) > return rv; > } > > /* ... */ > > } > > From what I can tell, the flags (in va_list) are never passed through to the > fsext handler. Has this ever worked? It seems like a bug to me. I see ioctl() suffers from the same issue (and doesn't even pass cmd). If I may propose a patch: diff --git a/src/libc/compat/ioctl/ioctl.c b/src/libc/compat/ioctl/ioctl.c index f4382755..182be1a6 100644 --- a/src/libc/compat/ioctl/ioctl.c +++ b/src/libc/compat/ioctl/ioctl.c @@ -336,8 +336,17 @@ int ioctl(int fd, int cmd, ...) ** see if this is a file system extension file ** */ - if (func && __FSEXT_func_wrapper(func, __FSEXT_ioctl, &rv, fd)) - return rv; + if (func) + { + char *arg; + + va_start(args, cmd); + arg = va_arg(args, char *); + va_end(args); + + if (__FSEXT_func_wrapper(func, __FSEXT_ioctl, &rv, fd, cmd, arg)) + return rv; + } va_start(args, cmd); diff --git a/src/libc/posix/fcntl/fcntl.c b/src/libc/posix/fcntl/fcntl.c index e08ffe2b..1d43c0ff 100644 --- a/src/libc/posix/fcntl/fcntl.c +++ b/src/libc/posix/fcntl/fcntl.c @@ -281,8 +281,13 @@ fcntl(int fd, int cmd, ...) func = __FSEXT_get_function(fd); if (func) { - int rv; - if (__FSEXT_func_wrapper(func, __FSEXT_fcntl, &rv, fd, cmd)) + int rv, arg; + + va_start(ap, cmd); + arg = va_arg(ap, int); + va_end(ap); + + if (__FSEXT_func_wrapper(func, __FSEXT_fcntl, &rv, fd, cmd, arg)) return rv; }