diff options
author | Miles Bader <miles@gnu.org> | 1997-02-23 22:09:31 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1997-02-23 22:09:31 +0000 |
commit | 6bac11d99322f3cdf751b43dc3b3456039fab26c (patch) | |
tree | bdec620c134a6b498fc21ea5d3825762a79ed558 /sysdeps/mach/hurd/readlink.c | |
parent | 4dea6fa212ba120779f4a1f9237e02b20ab74aa5 (diff) | |
download | glibc-6bac11d99322f3cdf751b43dc3b3456039fab26c.tar glibc-6bac11d99322f3cdf751b43dc3b3456039fab26c.tar.gz glibc-6bac11d99322f3cdf751b43dc3b3456039fab26c.tar.bz2 glibc-6bac11d99322f3cdf751b43dc3b3456039fab26c.zip |
(__libc_argv, __libc_argc): Make extern. (__hurd_threadvar_max, __hurd_threadvar_stack_offset, __hurd_threadvar_stack_mask): New variables.cvs/libc-970224
Diffstat (limited to 'sysdeps/mach/hurd/readlink.c')
-rw-r--r-- | sysdeps/mach/hurd/readlink.c | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/sysdeps/mach/hurd/readlink.c b/sysdeps/mach/hurd/readlink.c index 2f51e200b5..d04ae1e07a 100644 --- a/sysdeps/mach/hurd/readlink.c +++ b/sysdeps/mach/hurd/readlink.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1997 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 @@ -32,45 +32,33 @@ DEFUN(__readlink, (file_name, buf, len), { error_t err; file_t file; - char mybuf[2048], *transp = mybuf; - mach_msg_type_number_t translen = sizeof (mybuf); + struct stat st; - file = __file_name_lookup (file_name, O_NOTRANS, 0); + file = __file_name_lookup (file_name, O_READ | O_NOLINK, 0); if (file == MACH_PORT_NULL) return -1; - err = __file_get_translator (file, &transp, &translen); + err = __io_stat (file, &st); + if (! err) + if (S_ISLNK (st.st_mode)) + { + char *rbuf = buf; + + 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); + } + } + else + err = EINVAL; + __mach_port_deallocate (__mach_task_self (), file); if (err) return __hurd_fail (err); - - if (translen < sizeof (_HURD_SYMLINK) || - memcmp (transp, _HURD_SYMLINK, sizeof (_HURD_SYMLINK))) - /* The file is not actually a symlink. */ - err = EINVAL; else - { - /* This is a symlink; its translator is "/hurd/symlink\0target\0". */ - if (len >= translen - sizeof (_HURD_SYMLINK)) - { - len = translen - sizeof (_HURD_SYMLINK); - if (transp[translen - 1] == '\0') - /* Remove the null terminator. */ - --len; - } - if (buf == NULL) - /* This call is just to find out how large a buffer is required. */ - len = translen - sizeof (_HURD_SYMLINK) - 1; - else - /* Copy into the user's buffer. */ - memcpy (buf, transp + sizeof (_HURD_SYMLINK), len); - } - - if (transp != mybuf) - __vm_deallocate (__mach_task_self (), (vm_address_t) transp, translen); - - return err ? __hurd_fail (err) : len; + return len; } - weak_alias (__readlink, readlink) |