mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-22 10:50:07 +00:00
0dee67386c
1998-10-21 14:38 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysdep.h (INLINE_SYSCALL): New macro. Simply call __syscall_* function. * sysdeps/unix/sysv/linux/aio_sigqueue.c: Use INLINE_SYSCALL instead of calling __syscall_* function. * sysdeps/unix/sysv/linux/fxstat.c: Likewise. * sysdeps/unix/sysv/linux/fxstat64.c: Likewise. * sysdeps/unix/sysv/linux/getcwd.c: Likewise. * sysdeps/unix/sysv/linux/getdents.c: Likewise. * sysdeps/unix/sysv/linux/getpriority.c: Likewise. * sysdeps/unix/sysv/linux/getresgid.c: Likewise. * sysdeps/unix/sysv/linux/getresuid.c: Likewise. * sysdeps/unix/sysv/linux/lxstat.c: Likewise. * sysdeps/unix/sysv/linux/lxstat64.c: Likewise. * sysdeps/unix/sysv/linux/poll.c: Likewise. * sysdeps/unix/sysv/linux/pread.c: Likewise. * sysdeps/unix/sysv/linux/pread64.c: Likewise. * sysdeps/unix/sysv/linux/ptrace.c: Likewise. * sysdeps/unix/sysv/linux/pwrite.c: Likewise. * sysdeps/unix/sysv/linux/pwrite64.c: Likewise. * sysdeps/unix/sysv/linux/readv.c: Likewise. * sysdeps/unix/sysv/linux/reboot.c: Likewise. * sysdeps/unix/sysv/linux/sigaction.c: Likewise. * sysdeps/unix/sysv/linux/siglist.h: Likewise. * sysdeps/unix/sysv/linux/sigpending.c: Likewise. * sysdeps/unix/sysv/linux/sigprocmask.c: Likewise. * sysdeps/unix/sysv/linux/sigqueue.c: Likewise. * sysdeps/unix/sysv/linux/sigsuspend.c: Likewise. * sysdeps/unix/sysv/linux/sigtimedwait.c: Likewise. * sysdeps/unix/sysv/linux/sigwaitinfo.c: Likewise. * sysdeps/unix/sysv/linux/syscalls.list: Likewise. * sysdeps/unix/sysv/linux/sysctl.c: Likewise. * sysdeps/unix/sysv/linux/ustat.c: Likewise. * sysdeps/unix/sysv/linux/writev.c: Likewise. * sysdeps/unix/sysv/linux/xmknod.c: Likewise. * sysdeps/unix/sysv/linux/xstat.c: Likewise. * sysdeps/unix/sysv/linux/xstat64.c: Likewise. * sysdeps/unix/sysv/linux/i386/chown.c: Likewise. * sysdeps/unix/sysv/linux/i386/getgroups.c: Likewise. * sysdeps/unix/sysv/linux/i386/setfsgid.c: Likewise. * sysdeps/unix/sysv/linux/i386/setfsuid.c: Likewise. * sysdeps/unix/sysv/linux/i386/setgid.c: Likewise. * sysdeps/unix/sysv/linux/i386/setgroups.c: Likewise. * sysdeps/unix/sysv/linux/i386/setresgid.c: Likewise. * sysdeps/unix/sysv/linux/i386/setresuid.c: Likewise. * sysdeps/unix/sysv/linux/i386/setuid.c: Likewise. * sysdeps/unix/sysv/linux/i386/sysdep.h: Define INLINE_SYSCALL using inline assembler. * sysdeps/unix/sysv/linux/i386/syscalls.list: Remove various __syscall_* definitions. * sysdeps/unix/sysv/linux/syscalls.list: Move various __syscall_* definitions to... * sysdeps/unix/sysv/linux/alpha/syscalls.list: ...here... * sysdeps/unix/sysv/linux/arm/syscalls.list: ...and here... * sysdeps/unix/sysv/linux/m68k/syscalls.list: ...and here... * sysdeps/unix/sysv/linux/mips/syscalls.list: ...and here... * sysdeps/unix/sysv/linux/powerpc/syscalls.list: ...and here... * sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list: ...and here... * sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: ...and here. * sysdeps/unix/sysv/linux/i386/Makefile [subdir=misc] (sysdep_routines): Remove s_pread64 and s_pwrite64. * sysdeps/unix/sysv/linux/i386/pread.c: New file. * sysdeps/unix/sysv/linux/i386/pread64.c: New file. * sysdeps/unix/sysv/linux/i386/pwrite.c: New file. * sysdeps/unix/sysv/linux/i386/pwrite64.c: New file. * sysdeps/unix/sysv/linux/i386/s_pread64.S: Removed. * sysdeps/unix/sysv/linux/i386/s_pwrite64.S: Removed. 1998-10-21 Andreas Jaeger <aj@arthur.rhein-neckar.de> * sysdeps/unix/sysv/linux/siglist.h: Fix some typos in these files and bring them in synch. * sysdeps/unix/siglist.c: Likewise. Reported by Vladimir Michl <michlv@risc.upol.cz> [PR libc/832]. 1998-10-20 Andreas Schwab <schwab@issan.cs.uni-dortmund.de> * sysdeps/unix/sysv/linux/i386/setresuid.c: Allow -1 as arguments. * sysdeps/unix/sysv/linux/i386/setresgid.c: Likewise. * sysdeps/unix/sysv/linux/i386/setreuid.c: New file. * sysdeps/unix/sysv/linux/i386/setregid.c: New file. * sysdeps/unix/sysv/linux/m68k/setreuid.c: New file. * sysdeps/unix/sysv/linux/m68k/setregid.c: New file. * sysdeps/unix/sysv/linux/arm/setreuid.c: New file. * sysdeps/unix/sysv/linux/arm/setregid.c: New file. * sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c: New file. * sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c: New file. * sysdeps/unix/sysv/linux/i386/syscalls.list: Add s_setreuid and s_setregid. * sysdeps/unix/sysv/linux/m68k/syscalls.list: Likewise. * sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list: Likewise. 1998-10-20 Andreas Schwab <schwab@issan.cs.uni-dortmund.de> * sunrpc/rpc_main.c (close_output, close_input): New functions. (c_output, h_output, s_output, l_output, t_output, svc_output, clnt_output, mkfile_output): Call them at the end. 1998-10-19 Andreas Schwab <schwab@issan.cs.uni-dortmund.de> * db/Makefile (LDFLAGS-db1.so): New variable, to avoid duplicating link command. 1998-10-18 Zack Weinberg <zack@rabi.phys.columbia.edu> * sysdeps/unix/opendir.c: Check at runtime for kernel support for O_DIRECTORY. 1998-10-20 H.J. Lu <hjl@gnu.org> * sysdeps/unix/sysv/linux/i386/setresuid.c (__setresuid): Fix argument types.
171 lines
4.2 KiB
C
171 lines
4.2 KiB
C
/* Determine current working directory. Linux version.
|
|
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public License as
|
|
published by the Free Software Foundation; either version 2 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
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with the GNU C Library; see the file COPYING.LIB. If not,
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
#include <errno.h>
|
|
#include <limits.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#include <sysdep.h>
|
|
#include <sys/syscall.h>
|
|
|
|
|
|
/* The "proc" filesystem provides an easy method to retrieve the value.
|
|
For each process, the corresponding directory contains a symbolic link
|
|
named `cwd'. Reading the content of this link immediate gives us the
|
|
information. But we have to take care for systems which do not have
|
|
the proc filesystem mounted. Use the POSIX implementation in this case. */
|
|
static char *generic_getcwd (char *buf, size_t size) internal_function;
|
|
|
|
#ifdef __NR_getcwd
|
|
/* Kernel 2.1.92 introduced a third way to get the current working
|
|
directory: a syscall. We've got to be careful that even when
|
|
compiling under 2.1.92+ the libc still runs under older kernels. */
|
|
extern int __syscall_getcwd (char *buf, unsigned long size);
|
|
static int no_syscall_getcwd;
|
|
static int no_new_dcache = 1;
|
|
#else
|
|
# define no_syscall_getcwd 1
|
|
static int no_new_dcache;
|
|
#endif
|
|
|
|
char *
|
|
__getcwd (char *buf, size_t size)
|
|
{
|
|
int save_errno;
|
|
char *path;
|
|
int n;
|
|
char *result;
|
|
size_t alloc_size = size;
|
|
|
|
if (no_syscall_getcwd && no_new_dcache)
|
|
return generic_getcwd (buf, size);
|
|
|
|
if (size == 0)
|
|
{
|
|
if (buf != NULL)
|
|
{
|
|
__set_errno (EINVAL);
|
|
return NULL;
|
|
}
|
|
|
|
alloc_size = PATH_MAX;
|
|
}
|
|
|
|
if (buf != NULL)
|
|
path = buf;
|
|
else
|
|
{
|
|
path = malloc (alloc_size);
|
|
if (path == NULL)
|
|
return NULL;
|
|
}
|
|
|
|
save_errno = errno;
|
|
|
|
#ifdef __NR_getcwd
|
|
if (!no_syscall_getcwd)
|
|
{
|
|
int retval;
|
|
|
|
retval = INLINE_SYSCALL (getcwd, 2, path, alloc_size);
|
|
if (retval >= 0)
|
|
{
|
|
if (buf == NULL)
|
|
{
|
|
buf = realloc (path, (size_t) retval);
|
|
if (buf == NULL)
|
|
/* `realloc' failed but we still have the original string. */
|
|
buf = path;
|
|
}
|
|
return buf;
|
|
}
|
|
|
|
if (errno == ENOSYS)
|
|
{
|
|
no_syscall_getcwd = 1;
|
|
no_new_dcache = 0; /* Now we will try the /proc method. */
|
|
}
|
|
else if (errno != ERANGE || buf != NULL)
|
|
{
|
|
if (buf == NULL)
|
|
free (path);
|
|
return NULL;
|
|
}
|
|
|
|
__set_errno (save_errno);
|
|
}
|
|
#endif
|
|
|
|
n = __readlink ("/proc/self/cwd", path, alloc_size - 1);
|
|
if (n != -1)
|
|
{
|
|
if (path[0] == '/')
|
|
{
|
|
if (n >= alloc_size - 1)
|
|
{
|
|
if (buf == NULL)
|
|
free (path);
|
|
return NULL;
|
|
}
|
|
|
|
path[n] = '\0';
|
|
if (buf == NULL)
|
|
{
|
|
buf = realloc (path, (size_t) n + 1);
|
|
if (buf == NULL)
|
|
/* `relloc' failed but we still have the original string. */
|
|
buf = path;
|
|
}
|
|
return buf;
|
|
}
|
|
else
|
|
no_new_dcache = 1;
|
|
}
|
|
|
|
/* Set to no_new_dcache only if error indicates that proc doesn't exist. */
|
|
if (errno != EACCES && errno != ENAMETOOLONG)
|
|
no_new_dcache = 1;
|
|
|
|
/* Something went wrong. Restore the error number and use the generic
|
|
version. */
|
|
__set_errno (save_errno);
|
|
|
|
/* Don't put restrictions on the length of the path unless the user does. */
|
|
if (size == 0)
|
|
{
|
|
free (path);
|
|
path = NULL;
|
|
}
|
|
|
|
result = generic_getcwd (path, size);
|
|
|
|
if (result == NULL && buf == NULL && size != 0)
|
|
free (path);
|
|
|
|
return result;
|
|
}
|
|
weak_alias (__getcwd, getcwd)
|
|
|
|
/* Get the code for the generic version. */
|
|
#define GETCWD_RETURN_TYPE static char * internal_function
|
|
#define __getcwd generic_getcwd
|
|
#include <sysdeps/posix/getcwd.c>
|