delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/04/18/08:48:35

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 222DC3857703
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1681822077;
bh=jpFyusgE1MEIjf20D/ZvSiGExpuB07IqVTbPadoX8o8=;
h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post:
List-Help:List-Subscribe:From:Reply-To:From;
b=wZdaJzRw9IxNMeRJAx1vD9iM/XfyB8ln8AO3OTpvX3uAnDJZeMCE29yVFaGXGQI/t
JmAZN3Q6VRQNSgzrh7uiPnqO2zbh9R7nBwOZrHRHLeOEduD7qIUWSO74118uLDmcga
ZtTNLM70KXSkfTjN0r/mPUeupl8GYz/Jw9d8Y+6E=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C02623858D1E
ARC-Seal: i=1; a=rsa-sha256; t=1681822037; cv=none;
d=strato.com; s=strato-dkim-0002;
b=d77wvVUm6u5g/fBqeewbfppmY5RWlXnukEz/ZS6FQ7ht6j0e5WlUqi8oR1TKXKaTPh
SoXB3OQ02T75oxa6O7+j0X1AraMMIoVeF9NShMXeS1Bte7aW6QpHztd3cDONsNfD1Cp8
AqDDIIP82hLsMhpkeab6G7JC+r4eRGvfxsoFa+EhnP2tp5YMYffSkr8NGSMpsQgp6njO
Jg9nEZzmhZhDnLeoA6CycmeRXBDcwCaPY7GMfAoGGi+NhSKbjPGHmVYWyGj47kO/JgOa
xcZlcsvRLSI0b8PkyHrYWLZf6nEtoBYWWk9J1NPb6wx8CsWPXB+iv+lnt6nVOxlxqsEG
WeMQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1681822037;
s=strato-dkim-0002; d=strato.com;
h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender;
bh=3KiiNYf76jxm4FDuaq0XhR9QbO6zaZSGMbfXwJRc+Mw=;
b=Gh4RLjdNYcCxNQHR/j9/Kk/GTgNig2PkkniNCaV6sI26kxNBD8Z2iQ335RMdIhldhu
z2qRRKT81CQgTPGGApURaEgd8g1Aog/xllTcFFHH4DuqEgL2nT93dGkrkiUvK01FSzmG
heQO86XDCjzGKMYnGG8XUpFUXg4HumLEiUHP6pUq6UWP3X5extKsrhbfAfY+47CtN1aI
Y/4fNs5cM9F+AxCU8AKq1/AOgzcXE3cdgImNcQRIXA5vRf6G5r8uWkrsPHnkLlT9Q5ck
EV7MWuNLMV94eUhj6nGvin6NernO0PMNKHKP8bdMPPbrVJIyUpZMlPwgU1YTJBqEal6F
5P6A==
ARC-Authentication-Results: i=1; strato.com;
arc=none;
dkim=none
X-RZG-CLASS-ID: mo00
X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94zq68+3cfpOT2vN+j99710EKugYHXkRHprwZvw=="
To: cygwin AT cygwin DOT com
Subject: renameat2 works differently than on Linux
Date: Tue, 18 Apr 2023 14:47:16 +0200
Message-ID: <1745205.A0I09U8b9p@nimes>
MIME-Version: 1.0
X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, KAM_SHORT,
RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Bruno Haible via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Bruno Haible <bruno AT clisp DOT org>
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

Hi,

The renameat2 function is "Linux-specific", says the man page [1]; however,
Cygwin implements it as well.

In Cygwin 3.4.6, in a specific case, it operates differently than the
Linux function. Namely, if the old* arguments and the new* arguments
are the same and the flag RENAME_NOREPLACE is specified.

How to reproduce:
================================ foo.c ================================
#ifdef __CYGWIN__
 #include <cygwin/fs.h>
#else
 #define _GNU_SOURCE 1
 #ifdef __linux__
 # include <sys/syscall.h>
 #endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>

int
main (void)
{
  system ("rm -rf sub2");
  int dfd = open (".", O_RDONLY);
  if (dfd < 0) perror ("open");
  int ret = mkdir ("sub2", 0700);
  if (ret < 0) perror ("mkdir");
  close (creat ("sub2/file", 0600));
#if defined __CYGWIN__ || defined __GLIBC__
  ret = renameat2 (dfd, "sub2/file", dfd, "sub2/file", RENAME_NOREPLACE);
#else /* musl libc */
  ret = syscall (SYS_renameat2, dfd, "sub2/file", dfd, "sub2/file", 1);
#endif
  if (ret >= 0)
    printf ("ret=%d\n", ret);
  else
    printf ("ret=%d, errno=%d%s\n", ret, errno, errno == EEXIST ? "=EEXIST" : "");
}
===============================================================================
Output on Linux (glibc, musl libc):
ret=-1, errno=17=EEXIST

Output on Cygwin 3.4.6:
ret=0

Note that there is some ambiguity about this case in [1]: One one hand,
there is the general statement about rename():
  "If oldpath and newpath are existing hard links referring to the
   same file, then rename() does nothing, and returns a success status."
On the other hand, the text regarding RENAME_NOREPLACE says:
  "Return an error if newpath already exists."

Bruno

[1] https://man7.org/linux/man-pages/man2/rename.2.html




-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019