]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Factorize at/non-at functions
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 17 Sep 2022 19:47:57 +0000 (19:47 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 17 Sep 2022 19:58:30 +0000 (19:58 +0000)
Non-at functions can be implemented by just calling the corresponding at
function with AT_FDCWD and zero at_flags.

In the linkat case, the at behavior is different (O_NOLINK), so this introduces
__linkat_common to pass O_NOLINK as appropriate.

lstat functions can also be implemented with fstatat by adding
__fstatat64_common which takes a flags parameter in addition to the at_flags
parameter,

In the end this factorizes chmod, chown, link, lstat64, mkdir, readlink,
rename, stat64, symlink, unlink, utimes.

This also makes __lstat, __lxstat64, __stat and __xstat64 directly use
__fstatat64_common instead of __lstat64 or __stat64.

29 files changed:
include/sys/stat.h
include/time.h
include/unistd.h
sysdeps/mach/hurd/chmod.c
sysdeps/mach/hurd/chown.c
sysdeps/mach/hurd/fchmodat.c
sysdeps/mach/hurd/fchownat.c
sysdeps/mach/hurd/fstatat64.c
sysdeps/mach/hurd/fstatat_common.h [new file with mode: 0644]
sysdeps/mach/hurd/futimesat.c
sysdeps/mach/hurd/link.c
sysdeps/mach/hurd/linkat.c
sysdeps/mach/hurd/linkat_common.h [new file with mode: 0644]
sysdeps/mach/hurd/lstat.c
sysdeps/mach/hurd/lstat64.c
sysdeps/mach/hurd/lxstat64.c
sysdeps/mach/hurd/mkdir.c
sysdeps/mach/hurd/mkdirat.c
sysdeps/mach/hurd/readlink.c
sysdeps/mach/hurd/readlinkat.c
sysdeps/mach/hurd/rename.c
sysdeps/mach/hurd/stat.c
sysdeps/mach/hurd/stat64.c
sysdeps/mach/hurd/symlink.c
sysdeps/mach/hurd/symlinkat.c
sysdeps/mach/hurd/unlink.c
sysdeps/mach/hurd/unlinkat.c
sysdeps/mach/hurd/utimes.c
sysdeps/mach/hurd/xstat64.c

index 13e777b3c78bc06d1acaa1413048bbba55b18a51..4a29e842defc73dbf2f017875673b2d490f20535 100644 (file)
@@ -66,10 +66,12 @@ hidden_proto (__fstatat64_time64);
 extern int __chmod (const char *__file, __mode_t __mode);
 libc_hidden_proto (__chmod)
 extern int __fchmod (int __fd, __mode_t __mode);
+extern int __fchmodat (int __fd, const char *__file, mode_t __mode, int __flag);
 libc_hidden_proto (fchmodat)
 extern __mode_t __umask (__mode_t __mask);
 extern int __mkdir (const char *__path, __mode_t __mode);
 libc_hidden_proto (__mkdir)
+extern int __mkdirat (int __fd, const char *__path, mode_t __mode);
 
 extern int __mknodat (int fd, const char *path, mode_t mode, dev_t dev);
 libc_hidden_proto (__mknodat);
index a64eff54f5c35d51bcdf73411c236f3bfc055590..20abea69d4e58d2ba43ac29fd4171e2c0f76645d 100644 (file)
@@ -196,6 +196,7 @@ extern int __utimensat64_helper (int fd, const char *file,
                                  const struct __timespec64 tsp[2], int flags);
 libc_hidden_proto (__utimensat64_helper);
 
+extern int __futimesat (int __fd, const char *__file, const struct timeval __tvp[2]);
 #if __TIMESIZE == 64
 # define __futimes64 __futimes
 # define __futimesat64 __futimesat
index af795a37c83cd79b1fc086efe115cee78e76617e..4345d08d608469d815aff894b6afb8fe2195b1a9 100644 (file)
@@ -78,6 +78,7 @@ extern int __chown (const char *__file,
 libc_hidden_proto (__chown)
 extern int __fchown (int __fd,
                     __uid_t __owner, __gid_t __group);
+extern int __fchownat (int __fd, const char *__file, uid_t __owner, gid_t __group, int __flag);
 extern int __lchown (const char *__file, __uid_t __owner,
                     __gid_t __group);
 extern int __chdir (const char *__path) attribute_hidden;
@@ -148,9 +149,12 @@ libc_hidden_proto (_Fork);
 extern int __isatty (int __fd) attribute_hidden;
 extern int __link (const char *__from, const char *__to);
 extern int __symlink (const char *__from, const char *__to);
+extern int __symlinkat (const char *__from, int __fd, const char *__to);
 extern ssize_t __readlink (const char *__path, char *__buf, size_t __len)
      attribute_hidden;
+extern ssize_t __readlinkat (int __fd, const char *__file_name, char *__buf, size_t __len);
 extern int __unlink (const char *__name) attribute_hidden;
+extern int __unlinkat (int __fd, const char *__name, int __flag);
 extern int __gethostname (char *__name, size_t __len) attribute_hidden;
 extern int __revoke (const char *__file);
 extern int __profil (unsigned short int *__sample_buffer, size_t __size,
index 7b79d249900106323663c76216e594f3671a7b3a..313483193d07dd687e64e3d640e66f4ddf34d1a7 100644 (file)
 int
 __chmod (const char *file, mode_t mode)
 {
-  error_t err;
-  file_t port = __file_name_lookup (file, 0, 0);
-  if (port == MACH_PORT_NULL)
-    return -1;
-  err = __file_chmod (port, mode);
-  __mach_port_deallocate (__mach_task_self (), port);
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __fchmodat (AT_FDCWD, file, mode, 0);
 }
 
 libc_hidden_def (__chmod)
index 0c5565bea3b152512c5c7b459eb421d6bd17da71..f2915211c53cffd3057b0bf6feb32db42aa605c2 100644 (file)
 int
 __chown (const char *file, uid_t owner, gid_t group)
 {
-  error_t err;
-  file_t port = __file_name_lookup (file, 0, 0);
-  if (port == MACH_PORT_NULL)
-    return -1;
-  err = __file_chown (port, owner, group);
-  __mach_port_deallocate (__mach_task_self (), port);
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __fchownat (AT_FDCWD, file, owner, group, 0);
 }
 libc_hidden_def (__chown)
 weak_alias (__chown, chown)
index 5bdd5c4f25dec0866221777fa26913610422b039..44385cc07e02bfbcf75af03ff2be8e53f950f9e5 100644 (file)
@@ -25,7 +25,7 @@
 #include <hurd/fd.h>
 
 int
-fchmodat (int fd, const char *file, mode_t mode, int flag)
+__fchmodat (int fd, const char *file, mode_t mode, int flag)
 {
   error_t err;
   file_t port = __file_name_lookup_at (fd, flag, file, 0, 0);
@@ -37,4 +37,6 @@ fchmodat (int fd, const char *file, mode_t mode, int flag)
     return __hurd_fail (err);
   return 0;
 }
+
+weak_alias (__fchmodat, fchmodat)
 libc_hidden_def (fchmodat)
index a34632c63e88708c07b71d68ee568597120b6502..580f38f05751a68a339e1f49d709db3c2d0dd9d9 100644 (file)
@@ -26,7 +26,7 @@
 
 /* Change the owner and group of FILE.  */
 int
-fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
+__fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
 {
   error_t err;
   file_t port = __file_name_lookup_at (fd, flag, file, 0, 0);
@@ -38,3 +38,4 @@ fchownat (int fd, const char *file, uid_t owner, gid_t group, int flag)
     return __hurd_fail (err);
   return 0;
 }
+weak_alias (__fchownat, fchownat)
index 56c1291b7715b5780a1556742d72d3c4eb57669e..ca60ba43c4ffc5b4538d0f3446212e933a6c73b7 100644 (file)
 #include <hurd.h>
 #include <hurd/fd.h>
 
+#include <fstatat_common.h>
+
 /* Get information about the file descriptor FD in BUF.  */
 int
-__fstatat64 (int fd, const char *filename, struct stat64 *buf, int flag)
+__fstatat64_common (int fd, const char *filename, struct stat64 *buf, int at_flags, int flags)
 {
   error_t err;
   io_t port;
 
-  port = __file_name_lookup_at (fd, flag, filename, 0, 0);
+  port = __file_name_lookup_at (fd, at_flags, filename, flags, 0);
   if (port == MACH_PORT_NULL)
     return -1;
 
@@ -39,5 +41,11 @@ __fstatat64 (int fd, const char *filename, struct stat64 *buf, int flag)
 
   return __hurd_fail (err);
 }
+
+int
+__fstatat64 (int fd, const char *filename, struct stat64 *buf, int at_flags)
+{
+  return __fstatat64_common (fd, filename, buf, at_flags, 0);
+}
 libc_hidden_def (__fstatat64)
 weak_alias (__fstatat64, fstatat64)
diff --git a/sysdeps/mach/hurd/fstatat_common.h b/sysdeps/mach/hurd/fstatat_common.h
new file mode 100644 (file)
index 0000000..dd95a70
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef        _FSTATAT_COMMON_H
+#define        _FSTATAT_COMMON_H       1
+
+extern int __fstatat64_common (int fd, const char *filename, struct stat64 *buf, int at_flags, int flags);
+
+#endif /* link_common.h */
index 9745a3936b5bff1f1ed030d60be303753b9cd5c3..0976f2dfa93ca9c7c364a699aa3f70a62eb3105d 100644 (file)
@@ -27,7 +27,7 @@
 /* Change the access time of FILE relative to FD to TVP[0] and
    the modification time of FILE to TVP[1].  */
 int
-futimesat (int fd, const char *file, const struct timeval tvp[2])
+__futimesat (int fd, const char *file, const struct timeval tvp[2])
 {
   error_t err;
   file_t port;
@@ -43,3 +43,4 @@ futimesat (int fd, const char *file, const struct timeval tvp[2])
     return __hurd_fail (err);
   return 0;
 }
+weak_alias (__futimesat, futimesat)
index 48856bdce9c050605330cb5632aa9e0f68274f2e..2267ae0732b3f9097dbcc4928cf46a222e17c068 100644 (file)
 #include <unistd.h>
 #include <hurd.h>
 
+#include <linkat_common.h>
+
 /* Make a link to FROM called TO.  */
 int
 __link (const char *from, const char *to)
 {
-  error_t err;
-  file_t oldfile, linknode, todir;
-  char *toname;
-
-  oldfile = __file_name_lookup (from, 0, 0);
-  if (oldfile == MACH_PORT_NULL)
-    return -1;
-
-  /* The file_getlinknode RPC returns the port that should be passed to
-     the receiving filesystem (the one containing TODIR) in dir_link.  */
-
-  err = __file_getlinknode (oldfile, &linknode);
-  __mach_port_deallocate (__mach_task_self (), oldfile);
-  if (err)
-    return __hurd_fail (err);
-
-  todir = __file_name_split (to, &toname);
-  if (todir != MACH_PORT_NULL)
-    {
-      err = __dir_link (todir, linknode, toname, 1);
-      __mach_port_deallocate (__mach_task_self (), todir);
-    }
-  __mach_port_deallocate (__mach_task_self (), linknode);
-  if (todir == MACH_PORT_NULL)
-    return -1;
-
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __linkat_common (AT_FDCWD, from, AT_FDCWD, to, 0, 0);
 }
 
 weak_alias (__link, link)
index 2433614cfb796e2ffcf8cd4fe1946d2bb074d7b5..9ccef6f33403756e22ebb26ea0a61428ab26c741 100644 (file)
 #include <hurd.h>
 #include <hurd/fd.h>
 
+#include <linkat_common.h>
 
 /* Make a link to FROM relative to FROMFD called TO relative to TOFD.  */
 int
-linkat (int fromfd, const char *from, int tofd, const char *to, int flags)
+__linkat_common (int fromfd, const char *from, int tofd, const char *to, int at_flags, int flags)
 {
   error_t err;
   file_t oldfile, linknode, todir;
   char *toname;
 
-  /* POSIX says linkat doesn't follow symlinks by default, so pass
-     O_NOLINK.  That can be overridden by AT_SYMLINK_FOLLOW in FLAGS.  */
-  oldfile = __file_name_lookup_at (fromfd, flags, from, O_NOLINK, 0);
+  oldfile = __file_name_lookup_at (fromfd, at_flags, from, flags, 0);
   if (oldfile == MACH_PORT_NULL)
     return -1;
 
@@ -60,3 +59,12 @@ linkat (int fromfd, const char *from, int tofd, const char *to, int flags)
     return __hurd_fail (err);
   return 0;
 }
+
+int
+__linkat (int fromfd, const char *from, int tofd, const char *to, int at_flags)
+{
+  /* POSIX says linkat doesn't follow symlinks by default, so pass
+     O_NOLINK.  That can be overridden by AT_SYMLINK_FOLLOW in FLAGS.  */
+  return __linkat_common (fromfd, from, tofd, to, at_flags, O_NOLINK);
+}
+weak_alias (__linkat, linkat)
diff --git a/sysdeps/mach/hurd/linkat_common.h b/sysdeps/mach/hurd/linkat_common.h
new file mode 100644 (file)
index 0000000..6c98c57
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef        _LINKAT_COMMON_H
+#define        _LINKAT_COMMON_H        1
+
+extern int __linkat_common (int fromfd, const char *from, int tofd, const char *to, int at_flags, int flags);
+
+#endif /* link_common.h */
index 2acfda1934409803bdc5d8315cb28c26fd46ba5f..4fdc31218629d76f5a823284fe54d39ac9ad1640 100644 (file)
@@ -18,6 +18,9 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <stddef.h>
+#include <fcntl.h>
+
+#include <fstatat_common.h>
 
 #include "statconv.c"
 
@@ -25,6 +28,7 @@ int
 __lstat (const char *file, struct stat *buf)
 {
   struct stat64 buf64;
-  return __lstat64 (file, &buf64) ?: stat64_conv (buf, &buf64);
+  return __fstatat64_common (AT_FDCWD, file, &buf64, 0, O_NOLINK) ?:
+                             stat64_conv (buf, &buf64);
 }
 weak_alias (__lstat, lstat)
index 55ce1552b3405eae57e7d8d501d95c10ba903936..d67daf9f61fdb8c901ae4d44b20de47d83ad87fa 100644 (file)
 #include <fcntl.h>
 #include <hurd.h>
 
+#include <fstatat_common.h>
+
 /* Get information about the file descriptor FD in BUF.  */
 int
 __lstat64 (const char *file, struct stat64 *buf)
 {
-  error_t err;
-  file_t port;
-
-  port = __file_name_lookup (file, O_NOLINK, 0);
-  if (port == MACH_PORT_NULL)
-    return -1;
-  err = __io_stat (port, buf);
-  __mach_port_deallocate (__mach_task_self (), port);
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __fstatat64_common (AT_FDCWD, file, buf, 0, O_NOLINK);
 }
 hidden_def (__lstat64)
 weak_alias (__lstat64, lstat64)
index 450fed0cad392d2debc587b1ae58bc076727fcf6..7cd86ab4d737bab03b23110d2ac695f7b9c47cf3 100644 (file)
@@ -22,6 +22,8 @@
 #include <hurd.h>
 #include <shlib-compat.h>
 
+#include <fstatat_common.h>
+
 #if LIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_33)
 
 /* Get information about the file descriptor FD in BUF.  */
@@ -31,6 +33,6 @@ __lxstat64 (int vers, const char *file, struct stat64 *buf)
   if (vers != _STAT_VER)
     return __hurd_fail (EINVAL);
 
-  return __lstat64 (file, buf);
+  return __fstatat64_common (AT_FDCWD, file, buf, 0, O_NOLINK);
 }
 #endif
index 06a7c16945b51aa8f38bb454388595ecf4195269..9dbb47b77b98daf54814d3e4c92ab18dbdae1d92 100644 (file)
 int
 __mkdir (const char *file_name, mode_t mode)
 {
-  error_t err;
-  const char *name;
-  file_t parent;
-  if (!strcmp (file_name, "/"))
-    return __hurd_fail (EEXIST);
-  parent = __directory_name_split (file_name, (char **) &name);
-  if (parent == MACH_PORT_NULL)
-    return -1;
-  err = __dir_mkdir (parent, name, mode & ~_hurd_umask);
-  __mach_port_deallocate (__mach_task_self (), parent);
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __mkdirat (AT_FDCWD, file_name, mode);
 }
 
 libc_hidden_def (__mkdir)
index 367b2d0052238269d51fb2c635ff0a5919eb57ce..b27da52faf66abbd68884b0693ffe91a834c90cb 100644 (file)
@@ -24,7 +24,7 @@
 #include <string.h>
 
 int
-mkdirat (int fd, const char *path, mode_t mode)
+__mkdirat (int fd, const char *path, mode_t mode)
 {
   error_t err;
   const char *name;
@@ -40,3 +40,5 @@ mkdirat (int fd, const char *path, mode_t mode)
     return __hurd_fail (err);
   return 0;
 }
+
+weak_alias (__mkdirat, mkdirat)
index 34f132cb92cde825f032c484a5f99f5610b6be8f..ddad3d291926e75f3bb571d142e8941223b8c0f8 100644 (file)
 ssize_t
 __readlink (const char *file_name, char *buf, size_t len)
 {
-  error_t err;
-  file_t file_stat;
-  struct stat64 st;
-
-  file_stat = __file_name_lookup (file_name, O_NOLINK, 0);
-  if (file_stat == MACH_PORT_NULL)
-    return -1;
-
-  err = __io_stat (file_stat, &st);
-  if (! err)
-    if (S_ISLNK (st.st_mode))
-      {
-       enum retry_type doretry;
-       char retryname[1024];
-       file_t file;
-       char *rbuf = buf;
-
-       err = __dir_lookup (file_stat, "", O_READ | O_NOLINK, 0, &doretry, retryname, &file);
-       if (! err && (doretry != FS_RETRY_NORMAL || retryname[0] != '\0'))
-         err = EGRATUITOUS;
-       if (! err)
-         {
-           err = __io_read (file, &rbuf, &len, 0, len);
-           if (!err && rbuf != buf)
-             {
-               memcpy (buf, rbuf, len);
-               __vm_deallocate (__mach_task_self (), (vm_address_t)rbuf, len);
-             }
-
-           __mach_port_deallocate (__mach_task_self (), file);
-         }
-      }
-    else
-      err = EINVAL;
-
-  __mach_port_deallocate (__mach_task_self (), file_stat);
-
-  if (err)
-    return __hurd_fail (err);
-  else
-    return len;
+  return __readlinkat (AT_FDCWD, file_name, buf, len);
 }
 weak_alias (__readlink, readlink)
index 278a0b5b00be6b10d0411eb953920debb3edaa53..b5e7781bd5c2d01c2667855ea57e866104dc8e33 100644 (file)
@@ -26,7 +26,7 @@
    than LEN bytes of BUF.  The contents are not null-terminated.
    Returns the number of characters read, or -1 for errors.  */
 ssize_t
-readlinkat (int fd, const char *file_name, char *buf, size_t len)
+__readlinkat (int fd, const char *file_name, char *buf, size_t len)
 {
   error_t err;
   file_t file_stat;
@@ -67,4 +67,5 @@ readlinkat (int fd, const char *file_name, char *buf, size_t len)
 
   return err ? __hurd_fail (err) : len;
 }
+weak_alias (__readlinkat, readlinkat)
 libc_hidden_def (readlinkat)
index 75b4e75e9355541116bf3c7dd0aab247771989f4..cf2fa1991399743968bca2acdf42bb4fcb2d9c61 100644 (file)
 int
 rename (const char *old, const char *new)
 {
-  error_t err;
-  file_t olddir, newdir;
-  const char *oldname, *newname;
-
-  olddir = __directory_name_split (old, (char **) &oldname);
-  if (olddir == MACH_PORT_NULL)
-    return -1;
-  newdir = __directory_name_split (new, (char **) &newname);
-  if (newdir == MACH_PORT_NULL)
-    {
-       __mach_port_deallocate (__mach_task_self (), olddir);
-      return -1;
-    }
-
-  err = __dir_rename (olddir, oldname, newdir, newname, 0);
-  __mach_port_deallocate (__mach_task_self (), olddir);
-  __mach_port_deallocate (__mach_task_self (), newdir);
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __renameat2 (AT_FDCWD, old, AT_FDCWD, new, 0);
 }
index 224b11a79c9ac44c6d89d851ea39d056d40003ee..ffcdf226f0bccc5b4feaf435bac738ade0f31b7e 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <fcntl.h>
 #include <sys/stat.h>
 
+#include <fstatat_common.h>
+
 #include "statconv.c"
 
 /* Get file information about FILE in BUF.  */
@@ -25,6 +28,6 @@ int
 __stat (const char *file, struct stat *buf)
 {
   struct stat64 buf64;
-  return __stat64 (file, &buf64) ?: stat64_conv (buf, &buf64);
+  return __fstatat64_common (AT_FDCWD, file, &buf64, 0, 0) ?: stat64_conv (buf, &buf64);
 }
 weak_alias (__stat, stat)
index bb73d5f0180ae62c2ddea1f5a0cae2c9af8f23ac..6796783fa56689ee1b36724690fff8872b8240e3 100644 (file)
 int
 __stat64 (const char *file, struct stat64 *buf)
 {
-  error_t err;
-  file_t port;
-
-  port = __file_name_lookup (file, 0, 0);
-  if (port == MACH_PORT_NULL)
-    return -1;
-  err = __io_stat (port, buf);
-  __mach_port_deallocate (__mach_task_self (), port);
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __fstatat64 (AT_FDCWD, file, buf, 0);
 }
 hidden_def (__stat64)
 weak_alias (__stat64, stat64)
index bb73ea3529026f54dccd9f37bb237411b98e3ecf..a987e41048669d73179ab561f237fe1daec93af6 100644 (file)
 int
 __symlink (const char *from, const char *to)
 {
-  error_t err;
-  file_t dir, node;
-  char *name;
-  const size_t len = strlen (from) + 1;
-  char buf[sizeof (_HURD_SYMLINK) + len];
-
-  /* A symlink is a file whose translator is "/hurd/symlink\0target\0".  */
-
-  memcpy (buf, _HURD_SYMLINK, sizeof (_HURD_SYMLINK));
-  memcpy (&buf[sizeof (_HURD_SYMLINK)], from, len);
-
-  dir = __file_name_split (to, &name);
-  if (dir == MACH_PORT_NULL)
-    return -1;
-
-  /* Create a new, unlinked node in the target directory.  */
-  err = __dir_mkfile (dir, O_WRITE, 0777 & ~_hurd_umask, &node);
-
-  if (! err)
-    {
-      /* Set the node's translator to make it a symlink.  */
-      err = __file_set_translator (node,
-                                   FS_TRANS_EXCL|FS_TRANS_SET,
-                                   FS_TRANS_EXCL|FS_TRANS_SET, 0,
-                                   buf, sizeof (_HURD_SYMLINK) + len,
-                                   MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND);
-
-      if (! err)
-        /* Link the node, now a valid symlink, into the target directory.  */
-        err = __dir_link (dir, node, name, 1);
-
-      __mach_port_deallocate (__mach_task_self (), node);
-    }
-
-  __mach_port_deallocate (__mach_task_self (), dir);
-
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __symlinkat (from, AT_FDCWD, to);
 }
 
 weak_alias (__symlink, symlink)
index c70650948e9904193b2e0df5374a637cf8b76ee8..91ea7520c2d6ed952bb04dff5ea5a9d7dd147eee 100644 (file)
@@ -28,7 +28,7 @@
 
 /* Make a link to FROM called TO relative to FD.  */
 int
-symlinkat (const char *from, int fd, const char *to)
+__symlinkat (const char *from, int fd, const char *to)
 {
   error_t err;
   file_t dir, node;
@@ -70,3 +70,5 @@ symlinkat (const char *from, int fd, const char *to)
     return __hurd_fail (err);
   return 0;
 }
+
+weak_alias (__symlinkat, symlinkat)
index fa6763fca25aa6cdf25e3d5ecf004ac685e1718d..fe4761006ca867d7116dff77bc41857d27fb5787 100644 (file)
 int
 __unlink (const char *name)
 {
-  error_t err;
-  file_t dir;
-  const char *file;
-
-  dir = __directory_name_split (name, (char **) &file);
-  if (dir == MACH_PORT_NULL)
-    return -1;
-
-  err = __dir_unlink (dir, file);
-  __mach_port_deallocate (__mach_task_self (), dir);
-
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __unlinkat (AT_FDCWD, name, 0);
 }
 
 weak_alias (__unlink, unlink)
index f402e6d5d5d5d8a09da7be97c73bfb545f563945..4f3492ea8e2d1bf698a7638b87789ea2a287a80b 100644 (file)
@@ -26,7 +26,7 @@
 
 /* Remove the link named NAME.  */
 int
-unlinkat (int fd, const char *name, int flag)
+__unlinkat (int fd, const char *name, int flag)
 {
   error_t err;
   file_t dir;
@@ -49,3 +49,5 @@ unlinkat (int fd, const char *name, int flag)
     return __hurd_fail (err);
   return 0;
 }
+
+weak_alias (__unlinkat, unlinkat)
index c5998788871a09ca7862635714f7784d0f2eea99..b0a71bbefccc818fa67a4c73ffe67b86353d0e9f 100644 (file)
 int
 __utimes (const char *file, const struct timeval tvp[2])
 {
-  error_t err;
-  file_t port;
-
-  port = __file_name_lookup (file, 0, 0);
-  if (port == MACH_PORT_NULL)
-    return -1;
-
-  err = hurd_futimes (port, tvp);
-
-  __mach_port_deallocate (__mach_task_self (), port);
-  if (err)
-    return __hurd_fail (err);
-  return 0;
+  return __futimesat (AT_FDCWD, file, tvp);
 }
 weak_alias (__utimes, utimes)
index c30d457f16b36b66b1feed71524c37a4b1c969b4..5c674d31ff72824234ebf2cfafc1afc9a0225721 100644 (file)
@@ -21,6 +21,8 @@
 #include <hurd.h>
 #include <shlib-compat.h>
 
+#include <fstatat_common.h>
+
 #if LIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_33)
 
 /* Get information about the file descriptor FD in BUF.  */
@@ -30,7 +32,7 @@ __xstat64 (int vers, const char *file, struct stat64 *buf)
   if (vers != _STAT_VER)
     return __hurd_fail (EINVAL);
 
-  return __stat64 (file, buf);
+  return __fstatat64_common (AT_FDCWD, file, buf, 0, 0);
 }
 
 #endif