/* Remove the directory FILE_NAME. */ int __rmdir (const char *file_name) { error_t err; const char *name; file_t parent = __directory_name_split (file_name, (char **) &name); if (parent == MACH_PORT_NULL) return -1; err = __dir_rmdir (parent, name); __mach_port_deallocate (__mach_task_self (), parent); if (err) return __hurd_fail (err); return 0; }
/* Remove the link named NAME. */ 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; }
file_t __directory_name_split_at (int fd, const char *directory_name, char **name) { error_t err; file_t result; if (fd == AT_FDCWD || directory_name[0] == '/') return __directory_name_split (directory_name, name); file_t startdir; error_t use_init_port (int which, error_t (*operate) (mach_port_t)) { return (which == INIT_PORT_CWDIR ? (*operate) (startdir) : _hurd_ports_use (which, operate)); } err = HURD_DPORT_USE (fd, (startdir = port, __hurd_directory_name_split (&use_init_port, &__getdport, 0, directory_name, &result, name))); return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result; }
You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ #include <stdio.h> #include <hurd.h> /* Rename the file OLD to NEW. */ 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;