]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
touch: fix diagnostic on macOS 26
authorGrisha Levit <grishalevit@gmail.com>
Fri, 19 Sep 2025 00:40:59 +0000 (20:40 -0400)
committerCollin Funk <collin.funk1@gmail.com>
Fri, 19 Sep 2025 18:29:37 +0000 (11:29 -0700)
* src/touch.c (touch): Do not use open_errno == EEXIST for diagnostic
if file was a directory as macOS 26 sets it for open("/", O_CREAT, ...).

src/touch.c

index bc6b23840e70f1130356358709246793f5295c60..20b5f487b6d37a38a9826e111eb66b29365c0f27 100644 (file)
@@ -180,11 +180,12 @@ touch (char const *file)
          would give a bogus diagnostic for e.g., 'touch /' (assuming we
          don't own / or have write access).  On Solaris 10 and probably
          other systems, opening a directory like "." fails with EINVAL.
-         (On SunOS 4 it was EPERM but that's obsolete.)  */
+         (On SunOS 4 it was EPERM but that's obsolete.)  On macOS 26
+         opening "/" fails with EEXIST.  */
       struct stat st;
       if (open_errno
           && ! (open_errno == EISDIR
-                || (open_errno == EINVAL
+                || ((open_errno == EINVAL || open_errno == EEXIST)
                     && stat (file, &st) == 0 && S_ISDIR (st.st_mode))))
         {
           /* The wording of this diagnostic should cover at least two cases: