add directory gnu
This commit is contained in:
1
gnu/glibc/glibc-1.03/sysdeps/posix/Dist
Normal file
1
gnu/glibc/glibc-1.03/sysdeps/posix/Dist
Normal file
@@ -0,0 +1 @@
|
||||
mk-stdiolim.c
|
||||
28
gnu/glibc/glibc-1.03/sysdeps/posix/Makefile
Normal file
28
gnu/glibc/glibc-1.03/sysdeps/posix/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
# Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
# Cambridge, MA 02139, USA.
|
||||
|
||||
$(objpfx)stdio_lim.h: $(objpfx)mk-stdiolim
|
||||
$(dir $<)$(notdir $<) > $@-tmp
|
||||
mv $@-tmp $@
|
||||
|
||||
vpath %.h $(..)
|
||||
$(objpfx)mk-stdiolim.o: posix1_lim.h local_lim.h
|
||||
|
||||
ifeq ($(subdir),posix)
|
||||
dont_distribute := $(dont_distribute) stdio_lim.h # Generated.
|
||||
endif
|
||||
30
gnu/glibc/glibc-1.03/sysdeps/posix/__dup.c
Normal file
30
gnu/glibc/glibc-1.03/sysdeps/posix/__dup.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
/* Duplicate FD, returning a new file descriptor open on the same file. */
|
||||
int
|
||||
DEFUN(__dup, (fd), int fd)
|
||||
{
|
||||
return fcntl(fd, F_DUPFD, 0);
|
||||
}
|
||||
52
gnu/glibc/glibc-1.03/sysdeps/posix/__dup2.c
Normal file
52
gnu/glibc/glibc-1.03/sysdeps/posix/__dup2.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
/* Duplicate FD to FD2, closing the old FD2 and making FD2 be
|
||||
open the same file as FD is. Return FD2 or -1. */
|
||||
int
|
||||
DEFUN(__dup2, (fd, fd2), int fd AND int fd2)
|
||||
{
|
||||
int save;
|
||||
|
||||
if (fd2 < 0)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check if FD is kosher. */
|
||||
if (fcntl (fd, F_GETFL) < 0)
|
||||
return -1;
|
||||
|
||||
if (fd == fd2)
|
||||
return fd2;
|
||||
|
||||
/* This is not atomic. */
|
||||
|
||||
save = errno;
|
||||
(void) close (fd2);
|
||||
errno = save;
|
||||
|
||||
return fcntl (fd, F_DUPFD, fd2);
|
||||
}
|
||||
114
gnu/glibc/glibc-1.03/sysdeps/posix/__fpathcon.c
Normal file
114
gnu/glibc/glibc-1.03/sysdeps/posix/__fpathcon.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
/* Get file-specific information about descriptor FD. */
|
||||
long int
|
||||
DEFUN(__fpathconf, (fd, name), int fd AND int name)
|
||||
{
|
||||
if (fd < 0)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (name)
|
||||
{
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
||||
case _PC_LINK_MAX:
|
||||
#ifdef LINK_MAX
|
||||
return LINK_MAX;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_MAX_CANON:
|
||||
#ifdef MAX_CANON
|
||||
return MAX_CANON;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_MAX_INPUT:
|
||||
#ifdef MAX_INPUT
|
||||
return MAX_INPUT;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_NAME_MAX:
|
||||
#ifdef NAME_MAX
|
||||
return NAME_MAX;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_PATH_MAX:
|
||||
#ifdef PATH_MAX
|
||||
return PATH_MAX;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_PIPE_BUF:
|
||||
#ifdef PIPE_BUF
|
||||
return PIPE_BUF;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_CHOWN_RESTRICTED:
|
||||
#ifdef _POSIX_CHOWN_RESTRICTED
|
||||
return _POSIX_CHOWN_RESTRICTED;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_NO_TRUNC:
|
||||
#ifdef _POSIX_NO_TRUNC
|
||||
return _POSIX_NO_TRUNC;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _PC_VDISABLE:
|
||||
#ifdef _POSIX_VDISABLE
|
||||
return _POSIX_VDISABLE;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
47
gnu/glibc/glibc-1.03/sysdeps/posix/__getdtsz.c
Normal file
47
gnu/glibc/glibc-1.03/sysdeps/posix/__getdtsz.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Return the maximum number of file descriptors
|
||||
the current process could possibly have. */
|
||||
int
|
||||
DEFUN_VOID(__getdtablesize)
|
||||
{
|
||||
#ifdef OPEN_MAX
|
||||
return OPEN_MAX;
|
||||
#else
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef OPEN_MAX
|
||||
|
||||
#ifdef HAVE_GNU_LD
|
||||
|
||||
#include <gnu-stabs.h>
|
||||
|
||||
stub_warning(__getdtablesize);
|
||||
|
||||
#endif /* GNU stabs. */
|
||||
|
||||
#endif
|
||||
66
gnu/glibc/glibc-1.03/sysdeps/posix/__gettod.c
Normal file
66
gnu/glibc/glibc-1.03/sysdeps/posix/__gettod.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* Get the current time of day and timezone information,
|
||||
putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
|
||||
Returns 0 on success, -1 on errors. */
|
||||
int
|
||||
DEFUN(__gettimeofday, (tv, tz),
|
||||
struct timeval *tv AND struct timezone *tz)
|
||||
{
|
||||
if (tv == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tv->tv_sec = (long int) time ((time_t *) NULL);
|
||||
tv->tv_usec = 0L;
|
||||
|
||||
if (tz != NULL)
|
||||
{
|
||||
CONST time_t timer = tv->tv_sec;
|
||||
CONST struct tm *tm;
|
||||
|
||||
CONST long int save_timezone = __timezone;
|
||||
CONST long int save_daylight = __daylight;
|
||||
char *save_tzname[2];
|
||||
save_tzname[0] = __tzname[0];
|
||||
save_tzname[1] = __tzname[1];
|
||||
|
||||
tm = localtime (&timer);
|
||||
|
||||
tz->tz_minuteswest = __timezone / 60;
|
||||
tz->tz_dsttime = __daylight;
|
||||
|
||||
__timezone = save_timezone;
|
||||
__daylight = save_daylight;
|
||||
__tzname[0] = save_tzname[0];
|
||||
__tzname[1] = save_tzname[1];
|
||||
|
||||
if (tm == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
37
gnu/glibc/glibc-1.03/sysdeps/posix/__isatty.c
Normal file
37
gnu/glibc/glibc-1.03/sysdeps/posix/__isatty.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
|
||||
/* Return 1 if FD is a terminal, 0 if not. */
|
||||
int
|
||||
DEFUN(__isatty, (fd), int fd)
|
||||
{
|
||||
int save;
|
||||
int is_tty;
|
||||
struct termios term;
|
||||
|
||||
save = errno;
|
||||
is_tty = __tcgetattr(fd, &term) == 0;
|
||||
errno = save;
|
||||
|
||||
return is_tty;
|
||||
}
|
||||
53
gnu/glibc/glibc-1.03/sysdeps/posix/__sigblock.c
Normal file
53
gnu/glibc/glibc-1.03/sysdeps/posix/__sigblock.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
/* Block signals in MASK, returning the old mask. */
|
||||
int
|
||||
DEFUN(__sigblock, (mask), int mask)
|
||||
{
|
||||
register int sig;
|
||||
sigset_t set, oset;
|
||||
|
||||
if (__sigemptyset(&set) < 0)
|
||||
return -1;
|
||||
|
||||
if (sizeof (mask) == sizeof (set))
|
||||
set = mask;
|
||||
else
|
||||
for (sig = 1; sig < NSIG; ++sig)
|
||||
if ((mask & sigmask(sig)) &&
|
||||
__sigaddset(&set, sig) < 0)
|
||||
return -1;
|
||||
|
||||
if (sigprocmask(SIG_BLOCK, &set, &oset) < 0)
|
||||
return -1;
|
||||
|
||||
mask = 0;
|
||||
if (sizeof (mask) == sizeof (oset))
|
||||
mask = oset;
|
||||
else
|
||||
for (sig = 1; sig < NSIG; ++sig)
|
||||
if (__sigismember(&oset, sig))
|
||||
mask |= sigmask(sig);
|
||||
|
||||
return mask;
|
||||
}
|
||||
30
gnu/glibc/glibc-1.03/sysdeps/posix/__sigpause.c
Normal file
30
gnu/glibc/glibc-1.03/sysdeps/posix/__sigpause.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
/* Set the mask of blocked signals to MASK,
|
||||
wait for a signal to arrive, and then restore the mask. */
|
||||
int
|
||||
DEFUN(__sigpause, (mask), int mask)
|
||||
{
|
||||
sigset_t set = mask;
|
||||
return sigsuspend (&set);
|
||||
}
|
||||
53
gnu/glibc/glibc-1.03/sysdeps/posix/__sigstmsk.c
Normal file
53
gnu/glibc/glibc-1.03/sysdeps/posix/__sigstmsk.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
/* Set the mask of blocked signals to MASK, returning the old mask. */
|
||||
int
|
||||
DEFUN(__sigsetmask, (mask), int mask)
|
||||
{
|
||||
register int sig;
|
||||
sigset_t set, oset;
|
||||
|
||||
if (__sigemptyset(&set) < 0)
|
||||
return -1;
|
||||
|
||||
if (sizeof (mask) == sizeof (set))
|
||||
set = mask;
|
||||
else
|
||||
for (sig = 1; sig < NSIG; ++sig)
|
||||
if ((mask & sigmask(sig)) &&
|
||||
__sigaddset(&set, sig) < 0)
|
||||
return -1;
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &set, &oset) < 0)
|
||||
return -1;
|
||||
|
||||
mask = 0;
|
||||
if (sizeof (mask) == sizeof (oset))
|
||||
mask = oset;
|
||||
else
|
||||
for (sig = 1; sig < NSIG; ++sig)
|
||||
if (__sigismember(&oset, sig))
|
||||
mask |= sigmask(sig);
|
||||
|
||||
return mask;
|
||||
}
|
||||
140
gnu/glibc/glibc-1.03/sysdeps/posix/__sigvec.c
Normal file
140
gnu/glibc/glibc-1.03/sysdeps/posix/__sigvec.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/* We use a wrapper handler to support SV_RESETHAND. */
|
||||
|
||||
static __sighandler_t wrapped_handlers[NSIG];
|
||||
static sigset_t wrapped_masks[NSIG];
|
||||
|
||||
static void
|
||||
DEFUN(wrapper_handler, (sig), int sig)
|
||||
{
|
||||
int save;
|
||||
struct sigaction act;
|
||||
|
||||
act.sa_handler = SIG_DFL;
|
||||
act.sa_mask = wrapped_masks[sig];
|
||||
act.sa_flags = 0;
|
||||
save = errno;
|
||||
(void) __sigaction(sig, &act, (struct sigaction *) NULL);
|
||||
errno = save;
|
||||
|
||||
(*wrapped_handlers[sig])(sig);
|
||||
}
|
||||
|
||||
static
|
||||
#ifdef __GNUC__
|
||||
inline
|
||||
#endif
|
||||
int
|
||||
DEFUN(convert_mask, (set, mask), sigset_t *set AND CONST int mask)
|
||||
{
|
||||
register int sig;
|
||||
|
||||
if (sizeof(*set) == sizeof(mask))
|
||||
{
|
||||
*(int *) set = mask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (__sigemptyset(set) < 0)
|
||||
return -1;
|
||||
|
||||
for (sig = 1; sig < NSIG; ++sig)
|
||||
if (mask & sigmask(sig))
|
||||
if (__sigaddset(set, sig) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If VEC is non-NULL, set the handler for SIG to the `sv_handler' member
|
||||
of VEC. The signals in `sv_mask' will be blocked while the handler runs.
|
||||
If the SV_RESETHAND bit is set in `sv_flags', the handler for SIG will be
|
||||
reset to SIG_DFL before `sv_handler' is entered. If OVEC is non-NULL,
|
||||
it is filled in with the old information for SIG. */
|
||||
int
|
||||
DEFUN(__sigvec, (sig, vec, ovec),
|
||||
int sig AND CONST struct sigvec *vec AND struct sigvec *ovec)
|
||||
{
|
||||
struct sigaction old;
|
||||
|
||||
if (vec == NULL || !(vec->sv_flags & SV_RESETHAND))
|
||||
{
|
||||
struct sigaction new, *n;
|
||||
|
||||
if (vec == NULL)
|
||||
n = NULL;
|
||||
else
|
||||
{
|
||||
n = &new;
|
||||
n->sa_handler = vec->sv_handler;
|
||||
if (convert_mask(&n->sa_mask, vec->sv_mask) < 0)
|
||||
return -1;
|
||||
n->sa_flags = (((vec->sv_flags & SV_ONSTACK) ? SA_ONSTACK : 0) |
|
||||
(!(vec->sv_flags & SV_INTERRUPT) ? SA_RESTART : 0));
|
||||
}
|
||||
|
||||
if (__sigaction(sig, n, &old) < 0)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
struct sigaction wrapper;
|
||||
|
||||
wrapper.sa_handler = wrapper_handler;
|
||||
wrapped_handlers[sig] = vec->sv_handler;
|
||||
if (convert_mask(&wrapped_masks[sig], vec->sv_mask) < 0)
|
||||
return -1;
|
||||
|
||||
if (__sigaction(sig, &wrapper, &old) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ovec != NULL)
|
||||
{
|
||||
register int i;
|
||||
int mask = 0;
|
||||
|
||||
if (sizeof (int) == sizeof (sigset_t))
|
||||
mask = old.sa_mask;
|
||||
else
|
||||
for (i = 1; i < NSIG; ++i)
|
||||
if (__sigismember(&old.sa_mask, i))
|
||||
mask |= sigmask(i);
|
||||
|
||||
ovec->sv_mask = mask;
|
||||
ovec->sv_flags = (((old.sa_flags & SA_ONSTACK) ? SV_ONSTACK : 0) |
|
||||
(!(old.sa_flags & SA_RESTART) ? SV_INTERRUPT : 0));
|
||||
if (old.sa_handler == wrapper_handler)
|
||||
{
|
||||
ovec->sv_flags |= SV_RESETHAND;
|
||||
ovec->sv_handler = wrapped_handlers[sig];
|
||||
}
|
||||
else
|
||||
ovec->sv_handler = old.sa_handler;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
175
gnu/glibc/glibc-1.03/sysdeps/posix/__sysconf.c
Normal file
175
gnu/glibc/glibc-1.03/sysdeps/posix/__sysconf.c
Normal file
@@ -0,0 +1,175 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
extern int EXFUN(__getdtablesize, (NOARGS));
|
||||
|
||||
/* Get the value of the system variable NAME. */
|
||||
long int
|
||||
DEFUN(__sysconf, (name), int name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
||||
case _SC_ARG_MAX:
|
||||
#ifdef ARG_MAX
|
||||
return ARG_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_CHILD_MAX:
|
||||
#ifdef CHILD_MAX
|
||||
return CHILD_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_CLK_TCK:
|
||||
return 60;
|
||||
case _SC_NGROUPS_MAX:
|
||||
#ifdef NGROUPS_MAX
|
||||
return NGROUPS_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_OPEN_MAX:
|
||||
return __getdtablesize ();
|
||||
|
||||
case _SC_STREAM_MAX:
|
||||
return FOPEN_MAX;
|
||||
|
||||
case _SC_TZNAME_MAX:
|
||||
return __tzname_max ();
|
||||
|
||||
case _SC_JOB_CONTROL:
|
||||
#ifdef _POSIX_JOB_CONTROL
|
||||
return 1;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
case _SC_SAVED_IDS:
|
||||
#ifdef _POSIX_SAVED_IDS
|
||||
return 1;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
case _SC_VERSION:
|
||||
return _POSIX_VERSION;
|
||||
|
||||
case _SC_BC_BASE_MAX:
|
||||
#ifdef BC_BASE_MAX
|
||||
return BC_BASE_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_BC_DIM_MAX:
|
||||
#ifdef BC_DIM_MAX
|
||||
return BC_DIM_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_BC_SCALE_MAX:
|
||||
#ifdef BC_SCALE_MAX
|
||||
return BC_SCALE_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_BC_STRING_MAX:
|
||||
#ifdef BC_STRING_MAX
|
||||
return BC_STRING_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_EQUIV_CLASS_MAX:
|
||||
#ifdef EQUIV_CLASS_MAX
|
||||
return EQUIV_CLASS_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_EXPR_NEST_MAX:
|
||||
#ifdef EXPR_NEST_MAX
|
||||
return EXPR_NEST_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_LINE_MAX:
|
||||
#ifdef LINE_MAX
|
||||
return LINE_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_RE_DUP_MAX:
|
||||
#ifdef RE_DUP_MAX
|
||||
return RE_DUP_MAX;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
|
||||
case _SC_2_VERSION:
|
||||
/* This is actually supposed to return the version
|
||||
of the 1003.2 utilities on the system {POSIX2_VERSION}. */
|
||||
return _POSIX2_C_VERSION;
|
||||
|
||||
case _SC_2_C_BIND:
|
||||
#ifdef _POSIX2_C_BIND
|
||||
return _POSIX2_C_BIND;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_2_C_DEV:
|
||||
#ifdef _POSIX2_C_DEV
|
||||
return _POSIX2_C_DEV;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_2_FORT_DEV:
|
||||
#ifdef _POSIX2_FORT_DEV
|
||||
return _POSIX2_FORT_DEV;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
case _SC_2_SW_DEV:
|
||||
#ifdef _POSIX2_SW_DEV
|
||||
return _POSIX2_SW_DEV;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
29
gnu/glibc/glibc-1.03/sysdeps/posix/__wait.c
Normal file
29
gnu/glibc/glibc-1.03/sysdeps/posix/__wait.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
|
||||
/* Wait for a child to die. When one does, put its status in *STAT_LOC
|
||||
and return its process ID. For errors, return (pid_t) -1. */
|
||||
__pid_t
|
||||
DEFUN(__wait, (stat_loc), __WAIT_STATUS stat_loc)
|
||||
{
|
||||
return __waitpid(WAIT_ANY, (int *) stat_loc, 0);
|
||||
}
|
||||
34
gnu/glibc/glibc-1.03/sysdeps/posix/clock.c
Normal file
34
gnu/glibc/glibc-1.03/sysdeps/posix/clock.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <sys/times.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Return the time used by the program so far (user time + system time). */
|
||||
clock_t
|
||||
DEFUN_VOID(clock)
|
||||
{
|
||||
struct tms buf;
|
||||
clock_t result;
|
||||
|
||||
if (__times(&buf) < 0)
|
||||
return (clock_t) -1;
|
||||
|
||||
return ((buf.tms_utime + buf.tms_stime) * CLK_TCK * CLOCKS_PER_SEC);
|
||||
}
|
||||
39
gnu/glibc/glibc-1.03/sysdeps/posix/ctermid.c
Normal file
39
gnu/glibc/glibc-1.03/sysdeps/posix/ctermid.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* Return the name of the controlling terminal.
|
||||
If S is not NULL, the name is copied into it (it should be at
|
||||
least L_ctermid bytes long), otherwise a static buffer is used. */
|
||||
char *
|
||||
DEFUN(ctermid, (s), char *s)
|
||||
{
|
||||
static char name[L_ctermid];
|
||||
|
||||
if (name[0] == '\0')
|
||||
(void) strcpy(name, "/dev/tty");
|
||||
|
||||
if (s == NULL)
|
||||
return(name);
|
||||
|
||||
return(strcpy(s, name));
|
||||
}
|
||||
46
gnu/glibc/glibc-1.03/sysdeps/posix/cuserid.c
Normal file
46
gnu/glibc/glibc-1.03/sysdeps/posix/cuserid.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pwd.h>
|
||||
|
||||
extern int EXFUN(geteuid, (NOARGS));
|
||||
|
||||
|
||||
/* Return the username of the caller.
|
||||
If S is not NULL, it points to a buffer of at least L_cuserid bytes
|
||||
into which the name is copied; otherwise, a static buffer is used. */
|
||||
char *
|
||||
DEFUN(cuserid, (s), char *s)
|
||||
{
|
||||
static char name[L_cuserid];
|
||||
struct passwd *pwent = getpwuid(geteuid());
|
||||
|
||||
if (pwent == NULL)
|
||||
{
|
||||
if (s != NULL)
|
||||
s[0] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (s == NULL)
|
||||
s = name;
|
||||
return strcpy(s, pwent->pw_name);
|
||||
}
|
||||
80
gnu/glibc/glibc-1.03/sysdeps/posix/defs.c
Normal file
80
gnu/glibc/glibc-1.03/sysdeps/posix/defs.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* Definitions of global stdio data structures.
|
||||
|
||||
Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* This file defines all the global internal variables for stdio. */
|
||||
|
||||
/* Standard streams. */
|
||||
#define READ 1, 0
|
||||
#define WRITE 0, 1
|
||||
#define BUFFERED 0
|
||||
#define UNBUFFERED 1
|
||||
#define stdstream(name, next, fd, readwrite, unbuffered) \
|
||||
{ \
|
||||
_IOMAGIC, \
|
||||
NULL, NULL, NULL, NULL, 0, \
|
||||
(next), \
|
||||
&(name)->__fileno, fd, \
|
||||
'\0', NULL, 0, \
|
||||
0, 0, \
|
||||
unbuffered, 0, \
|
||||
0, 0, \
|
||||
{ readwrite, /* ... */ }, \
|
||||
{ NULL, NULL, NULL, NULL }, \
|
||||
{ NULL, NULL }, \
|
||||
0, 0 \
|
||||
}
|
||||
static FILE stdstreams[3] =
|
||||
{
|
||||
stdstream (&stdstreams[0], &stdstreams[1], STDIN_FILENO, READ, BUFFERED),
|
||||
stdstream (&stdstreams[1], &stdstreams[2], STDOUT_FILENO, WRITE, BUFFERED),
|
||||
stdstream (&stdstreams[2], NULL, STDERR_FILENO, WRITE, UNBUFFERED),
|
||||
};
|
||||
FILE *stdin = &stdstreams[0];
|
||||
FILE *stdout = &stdstreams[1];
|
||||
FILE *stderr = &stdstreams[2];
|
||||
|
||||
/* Pointer to the first stream in the list. */
|
||||
FILE *__stdio_head = &stdstreams[0];
|
||||
|
||||
/* This function MUST be in this file!
|
||||
This is because we want _cleanup to go into the __libc_atexit set
|
||||
when any stdio code is used (and to use any stdio code, one must reference
|
||||
something defined in this file), and since only local symbols can be made
|
||||
set elements, having the set element stab entry here and _cleanup elsewhere
|
||||
loses; and having them both elsewhere loses because there is no reference
|
||||
to cause _cleanup to be linked in. */
|
||||
|
||||
void
|
||||
DEFUN_VOID(_cleanup)
|
||||
{
|
||||
(void) fclose((FILE *) NULL);
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_GNU_LD
|
||||
#include <gnu-stabs.h>
|
||||
|
||||
text_set_element(__libc_atexit, _cleanup);
|
||||
#endif
|
||||
52
gnu/glibc/glibc-1.03/sysdeps/posix/fdopen.c
Normal file
52
gnu/glibc/glibc-1.03/sysdeps/posix/fdopen.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* Defined in fopen.c. */
|
||||
extern int EXFUN(__getmode, (CONST char *mode, __io_mode *mptr));
|
||||
|
||||
/* Open a new stream on a given system file descriptor. */
|
||||
FILE *
|
||||
DEFUN(fdopen, (fd, mode), int fd AND CONST char *mode)
|
||||
{
|
||||
register FILE *stream;
|
||||
__io_mode m;
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!__getmode(mode, &m))
|
||||
return NULL;
|
||||
|
||||
stream = __newstream();
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
|
||||
stream->__fileno = fd;
|
||||
stream->__cookie = (PTR) &stream->__fileno;
|
||||
stream->__mode = m;
|
||||
|
||||
return stream;
|
||||
}
|
||||
194
gnu/glibc/glibc-1.03/sysdeps/posix/getcwd.c
Normal file
194
gnu/glibc/glibc-1.03/sysdeps/posix/getcwd.c
Normal file
@@ -0,0 +1,194 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* Get the pathname of the current working directory,
|
||||
and put it in SIZE bytes of BUF. Returns NULL if the
|
||||
directory couldn't be determined or SIZE was too small.
|
||||
If successful, returns BUF. In GNU, if BUF is NULL,
|
||||
an array is allocated with `malloc'; the array is SIZE
|
||||
bytes long, unless SIZE <= 0, in which case it is as
|
||||
big as necessary. */
|
||||
char *
|
||||
DEFUN(getcwd, (buf, size), char *buf AND size_t size)
|
||||
{
|
||||
static CONST char dots[]
|
||||
= "../../../../../../../../../../../../../../../../../../../../../../../\
|
||||
../../../../../../../../../../../../../../../../../../../../../../../../../../\
|
||||
../../../../../../../../../../../../../../../../../../../../../../../../../..";
|
||||
CONST char *dotp, *dotlist;
|
||||
size_t dotsize;
|
||||
dev_t rootdev, thisdev;
|
||||
ino_t rootino, thisino;
|
||||
char path[PATH_MAX + 1];
|
||||
register char *pathp;
|
||||
struct stat st;
|
||||
|
||||
if (buf != NULL && size == 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pathp = &path[sizeof(path)];
|
||||
*--pathp = '\0';
|
||||
|
||||
if (stat (".", &st) < 0)
|
||||
return NULL;
|
||||
thisdev = st.st_dev;
|
||||
thisino = st.st_ino;
|
||||
|
||||
if (stat ("/", &st) < 0)
|
||||
return NULL;
|
||||
rootdev = st.st_dev;
|
||||
rootino = st.st_ino;
|
||||
|
||||
dotsize = sizeof (dots) - 1;
|
||||
dotp = &dots[sizeof (dots)];
|
||||
dotlist = dots;
|
||||
while (!(thisdev == rootdev && thisino == rootino))
|
||||
{
|
||||
register DIR *dirstream;
|
||||
register struct dirent *d;
|
||||
dev_t dotdev;
|
||||
ino_t dotino;
|
||||
char mount_point;
|
||||
|
||||
/* Look at the parent directory. */
|
||||
if (dotp == dotlist)
|
||||
{
|
||||
/* My, what a deep directory tree you have, Grandma. */
|
||||
char *new;
|
||||
if (dotlist == dots)
|
||||
{
|
||||
new = malloc (dotsize * 2 + 1);
|
||||
if (new == NULL)
|
||||
return NULL;
|
||||
memcpy (new, dots, dotsize);
|
||||
}
|
||||
else
|
||||
{
|
||||
new = realloc ((PTR) dotlist, dotsize * 2 + 1);
|
||||
if (new == NULL)
|
||||
goto lose;
|
||||
}
|
||||
memcpy (&new[dotsize], new, dotsize);
|
||||
dotp = &new[dotsize];
|
||||
dotsize *= 2;
|
||||
new[dotsize] = '\0';
|
||||
dotlist = new;
|
||||
}
|
||||
|
||||
dotp -= 3;
|
||||
|
||||
/* Figure out if this directory is a mount point. */
|
||||
if (stat (dotp, &st) < 0)
|
||||
goto lose;
|
||||
dotdev = st.st_dev;
|
||||
dotino = st.st_ino;
|
||||
mount_point = dotdev != thisdev;
|
||||
|
||||
/* Search for the last directory. */
|
||||
dirstream = opendir (dotp);
|
||||
if (dirstream == NULL)
|
||||
goto lose;
|
||||
while ((d = readdir (dirstream)) != NULL)
|
||||
{
|
||||
if (d->d_name[0] == '.' &&
|
||||
(d->d_namlen == 1 || (d->d_namlen == 2 && d->d_name[1] == '.')))
|
||||
continue;
|
||||
if (mount_point || d->d_fileno == thisino)
|
||||
{
|
||||
char *name = __alloca (dotlist + dotsize - dotp +
|
||||
1 + d->d_namlen + 1);
|
||||
memcpy (name, dotp, dotlist + dotsize - dotp);
|
||||
name[dotlist + dotsize - dotp] = '/';
|
||||
memcpy (&name[dotlist + dotsize - dotp + 1],
|
||||
d->d_name, d->d_namlen + 1);
|
||||
if (stat (name, &st) < 0)
|
||||
{
|
||||
int save = errno;
|
||||
(void) closedir (dirstream);
|
||||
errno = save;
|
||||
goto lose;
|
||||
}
|
||||
if (st.st_dev == thisdev && st.st_ino == thisino)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (d == NULL)
|
||||
{
|
||||
int save = errno;
|
||||
(void) closedir (dirstream);
|
||||
errno = save;
|
||||
goto lose;
|
||||
}
|
||||
else
|
||||
{
|
||||
pathp -= d->d_namlen;
|
||||
(void) memcpy (pathp, d->d_name, d->d_namlen);
|
||||
*--pathp = '/';
|
||||
(void) closedir (dirstream);
|
||||
}
|
||||
|
||||
thisdev = dotdev;
|
||||
thisino = dotino;
|
||||
}
|
||||
|
||||
if (pathp == &path[sizeof(path) - 1])
|
||||
*--pathp = '/';
|
||||
|
||||
if (dotlist != dots)
|
||||
free ((PTR) dotlist);
|
||||
|
||||
{
|
||||
size_t len = &path[sizeof(path)] - pathp;
|
||||
if (buf == NULL)
|
||||
{
|
||||
if (len < (size_t) size)
|
||||
len = size;
|
||||
buf = (char *) malloc(len);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else if ((size_t) size < len)
|
||||
{
|
||||
errno = ERANGE;
|
||||
return NULL;
|
||||
}
|
||||
(void) memcpy((PTR) buf, (PTR) pathp, len);
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
||||
lose:
|
||||
if (dotlist != dots)
|
||||
free ((PTR) dotlist);
|
||||
return NULL;
|
||||
}
|
||||
41
gnu/glibc/glibc-1.03/sysdeps/posix/getenv.c
Normal file
41
gnu/glibc/glibc-1.03/sysdeps/posix/getenv.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef HAVE_GNU_LD
|
||||
#define __environ environ
|
||||
#endif
|
||||
|
||||
/* Return the value of the environment variable NAME. */
|
||||
char *
|
||||
DEFUN(getenv, (name), register CONST char *name)
|
||||
{
|
||||
register CONST size_t len = strlen(name);
|
||||
register char **ep;
|
||||
|
||||
for (ep = __environ; *ep != NULL; ++ep)
|
||||
if (!strncmp(*ep, name, len) && (*ep)[len] == '=')
|
||||
return &(*ep)[len + 1];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
37
gnu/glibc/glibc-1.03/sysdeps/posix/killpg.c
Normal file
37
gnu/glibc/glibc-1.03/sysdeps/posix/killpg.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
/* Send SIG to all processes in process group PGRP.
|
||||
If PGRP is zero, send SIG to all processes in
|
||||
the current process's process group. */
|
||||
int
|
||||
DEFUN(killpg, (pgrp, sig), int pgrp AND int sig)
|
||||
{
|
||||
if (pgrp < 0)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return __kill (- pgrp, sig);
|
||||
}
|
||||
34
gnu/glibc/glibc-1.03/sysdeps/posix/mk-stdiolim.c
Normal file
34
gnu/glibc/glibc-1.03/sysdeps/posix/mk-stdiolim.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <posix1_lim.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
printf("#define L_tmpnam %u\n", sizeof("/usr/tmp/") + 8);
|
||||
printf("#define TMP_MAX %u\n", 52 * 52 * 52);
|
||||
puts ("#ifdef __USE_POSIX");
|
||||
printf("#define L_ctermid %u\n", sizeof("/dev/tty"));
|
||||
printf("#define L_cuserid 9\n");
|
||||
puts ("#endif");
|
||||
printf("#define FOPEN_MAX %u\n", OPEN_MAX);
|
||||
printf("#define FILENAME_MAX %u\n", PATH_MAX);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
58
gnu/glibc/glibc-1.03/sysdeps/posix/mktemp.c
Normal file
58
gnu/glibc/glibc-1.03/sysdeps/posix/mktemp.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Generate a unique temporary file name from TEMPLATE.
|
||||
The last six characters of TEMPLATE must be "XXXXXX";
|
||||
they are replaced with a string that makes the filename unique. */
|
||||
char *
|
||||
DEFUN(mktemp, (template), char *template)
|
||||
{
|
||||
static CONST char letters[]
|
||||
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
static pid_t oldpid = (pid_t) 0;
|
||||
pid_t pid = __getpid();
|
||||
static size_t count;
|
||||
size_t len;
|
||||
char c;
|
||||
|
||||
len = strlen(template);
|
||||
if (len < 6 || strcmp(&template[len - 6], "XXXXXX"))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return template;
|
||||
}
|
||||
|
||||
if (pid != oldpid)
|
||||
count = 0;
|
||||
|
||||
c = letters[count++];
|
||||
count %= sizeof(letters) - 1;
|
||||
|
||||
if (sprintf(&template[len - 6], "%c%.5u",
|
||||
c, (unsigned int) pid % 100000) != 6)
|
||||
return NULL;
|
||||
|
||||
return template;
|
||||
}
|
||||
188
gnu/glibc/glibc-1.03/sysdeps/posix/pipestream.c
Normal file
188
gnu/glibc/glibc-1.03/sysdeps/posix/pipestream.c
Normal file
@@ -0,0 +1,188 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define SH_PATH "/bin/sh" /* Shell to run. */
|
||||
#define SH_NAME "sh" /* Name to give it. */
|
||||
|
||||
/* Structure describing a popen child. */
|
||||
struct child
|
||||
{
|
||||
/* It is important that the first member of this structure be an `int' that
|
||||
is the file descriptor. This is because the `fileno' function assumes
|
||||
that __cookie(STREAM) points to the file descriptor. */
|
||||
int fd;
|
||||
pid_t pid;
|
||||
};
|
||||
|
||||
#ifndef FORK
|
||||
#define FORK fork
|
||||
#endif
|
||||
|
||||
/* Open a new stream that is a one-way pipe to a
|
||||
child process running the given shell command. */
|
||||
FILE *
|
||||
DEFUN(popen, (command, mode), CONST char *command AND CONST char *mode)
|
||||
{
|
||||
pid_t pid;
|
||||
int pipedes[2];
|
||||
FILE *stream;
|
||||
struct child *child;
|
||||
|
||||
if (command == NULL || mode == NULL || (*mode != 'r' && *mode != 'w'))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create the pipe. */
|
||||
if (pipe(pipedes) < 0)
|
||||
return NULL;
|
||||
|
||||
/* Fork off the child. */
|
||||
pid = FORK();
|
||||
if (pid == (pid_t) -1)
|
||||
{
|
||||
/* The fork failed. */
|
||||
(void) close(pipedes[0]);
|
||||
(void) close(pipedes[1]);
|
||||
return NULL;
|
||||
}
|
||||
else if (pid == (pid_t) 0)
|
||||
{
|
||||
/* We are the child side. Make the write side of
|
||||
the pipe be stdin or the read side be stdout. */
|
||||
|
||||
CONST char *new_argv[4];
|
||||
|
||||
if ((*mode == 'w' ? dup2(pipedes[STDIN_FILENO], STDIN_FILENO) :
|
||||
dup2(pipedes[STDOUT_FILENO], STDOUT_FILENO)) < 0)
|
||||
_exit(127);
|
||||
|
||||
/* Close the pipe descriptors. */
|
||||
(void) close(pipedes[STDIN_FILENO]);
|
||||
(void) close(pipedes[STDOUT_FILENO]);
|
||||
|
||||
/* Exec the shell. */
|
||||
new_argv[0] = SH_NAME;
|
||||
new_argv[1] = "-c";
|
||||
new_argv[2] = command;
|
||||
new_argv[3] = NULL;
|
||||
(void) execve(SH_PATH, (char *CONST *) new_argv, environ);
|
||||
/* Die if it failed. */
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
/* We are the parent side. */
|
||||
|
||||
/* Close the irrelevant side of the pipe and open the relevant side as a
|
||||
new stream. Mark our side of the pipe to close on exec, so new children
|
||||
won't see it. */
|
||||
if (*mode == 'r')
|
||||
{
|
||||
(void) close(pipedes[STDOUT_FILENO]);
|
||||
(void) fcntl (pipedes[STDIN_FILENO], F_SETFD, FD_CLOEXEC);
|
||||
stream = fdopen(pipedes[STDIN_FILENO], mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void) close(pipedes[STDIN_FILENO]);
|
||||
(void) fcntl (pipedes[STDOUT_FILENO], F_SETFD, FD_CLOEXEC);
|
||||
stream = fdopen(pipedes[STDOUT_FILENO], mode);
|
||||
}
|
||||
|
||||
if (stream == NULL)
|
||||
goto error;
|
||||
|
||||
child = (struct child *) malloc(sizeof(struct child));
|
||||
if (child == NULL)
|
||||
goto error;
|
||||
child->fd = fileno(stream);
|
||||
child->pid = pid;
|
||||
stream->__cookie = (PTR) child;
|
||||
stream->__ispipe = 1;
|
||||
return stream;
|
||||
|
||||
error:;
|
||||
{
|
||||
/* The stream couldn't be opened or the child structure couldn't be
|
||||
allocated. Kill the child and close the other side of the pipe. */
|
||||
int save = errno;
|
||||
(void) kill(pid, SIGKILL);
|
||||
if (stream == NULL)
|
||||
(void) close(pipedes[*mode == 'r' ? STDOUT_FILENO : STDIN_FILENO]);
|
||||
else
|
||||
(void) fclose(stream);
|
||||
#ifndef NO_WAITPID
|
||||
(void) waitpid(pid, (int *) NULL, 0);
|
||||
#else
|
||||
{
|
||||
pid_t dead;
|
||||
do
|
||||
dead = wait ((int *) NULL);
|
||||
while (dead > 0 && dead != pid);
|
||||
}
|
||||
#endif
|
||||
errno = save;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Close a stream opened by popen and return its status.
|
||||
Returns -1 if the stream was not opened by popen. */
|
||||
int
|
||||
DEFUN(pclose, (stream), register FILE *stream)
|
||||
{
|
||||
pid_t pid, dead;
|
||||
int status;
|
||||
|
||||
if (!__validfp(stream) || !stream->__ispipe)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid = ((struct child *) stream->__cookie)->pid;
|
||||
free(stream->__cookie);
|
||||
stream->__cookie = (PTR) &stream->__fileno;
|
||||
stream->__ispipe = 0;
|
||||
if (fclose(stream))
|
||||
return -1;
|
||||
|
||||
#ifndef NO_WAITPID
|
||||
dead = waitpid (pid, &status, 0);
|
||||
#else
|
||||
do
|
||||
dead = wait (&status);
|
||||
while (dead > 0 && dead != pid);
|
||||
#endif
|
||||
if (dead != pid)
|
||||
status = -1;
|
||||
|
||||
return status;
|
||||
}
|
||||
80
gnu/glibc/glibc-1.03/sysdeps/posix/putenv.c
Normal file
80
gnu/glibc/glibc-1.03/sysdeps/posix/putenv.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef HAVE_GNU_LD
|
||||
#define __environ environ
|
||||
#endif
|
||||
|
||||
/* Put STRING, which is of the form "NAME=VALUE", in the environment. */
|
||||
int
|
||||
DEFUN(putenv, (string), CONST char *string)
|
||||
{
|
||||
CONST char *CONST name_end = strchr(string, '=');
|
||||
register size_t size;
|
||||
register char **ep;
|
||||
|
||||
if (name_end == NULL)
|
||||
{
|
||||
/* Remove the variable from the environment. */
|
||||
size = strlen(string);
|
||||
for (ep = __environ; *ep != NULL; ++ep)
|
||||
if (!strncmp(*ep, string, size) && (*ep)[size] == '=')
|
||||
{
|
||||
while (ep[1] != NULL)
|
||||
{
|
||||
ep[0] = ep[1];
|
||||
++ep;
|
||||
}
|
||||
*ep = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size = 0;
|
||||
for (ep = __environ; *ep != NULL; ++ep)
|
||||
if (!strncmp(*ep, string, name_end - string) &&
|
||||
(*ep)[name_end - string] == '=')
|
||||
break;
|
||||
else
|
||||
++size;
|
||||
|
||||
if (*ep == NULL)
|
||||
{
|
||||
static char **last_environ = NULL;
|
||||
char **new_environ = (char **) malloc((size + 2) * sizeof(char *));
|
||||
if (new_environ == NULL)
|
||||
return -1;
|
||||
(void) memcpy((PTR) new_environ, (PTR) __environ, size * sizeof(char *));
|
||||
new_environ[size] = (char *) string;
|
||||
new_environ[size + 1] = NULL;
|
||||
if (last_environ != NULL)
|
||||
free((PTR) last_environ);
|
||||
last_environ = new_environ;
|
||||
__environ = new_environ;
|
||||
}
|
||||
else
|
||||
*ep = (char *) string;
|
||||
|
||||
return 0;
|
||||
}
|
||||
28
gnu/glibc/glibc-1.03/sysdeps/posix/raise.c
Normal file
28
gnu/glibc/glibc-1.03/sysdeps/posix/raise.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Raise the signal SIG. */
|
||||
int
|
||||
DEFUN(raise, (sig), int sig)
|
||||
{
|
||||
return __kill(__getpid(), sig);
|
||||
}
|
||||
67
gnu/glibc/glibc-1.03/sysdeps/posix/readv.c
Normal file
67
gnu/glibc/glibc-1.03/sysdeps/posix/readv.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
/* Read data from file descriptor FD, and put the result in the
|
||||
buffers described by VECTOR, which is a vector of COUNT `struct iovec's.
|
||||
The buffers are filled in the order specified.
|
||||
Operates just like `read' (see <unistd.h>) except that data are
|
||||
put in VECTOR instead of a contiguous buffer. */
|
||||
int
|
||||
DEFUN(readv, (fd, vector, count),
|
||||
int fd AND CONST struct iovec *vector AND size_t count)
|
||||
{
|
||||
char *buffer;
|
||||
size_t bytes;
|
||||
int bytes_read;
|
||||
register size_t i;
|
||||
|
||||
/* Find the total number of bytes to be read. */
|
||||
bytes = 0;
|
||||
for (i = 0; i < count; ++i)
|
||||
bytes += vector[i].iov_len;
|
||||
|
||||
/* Allocate a temporary buffer to hold the data. */
|
||||
buffer = (char *) __alloca(bytes);
|
||||
|
||||
/* Read the data. */
|
||||
bytes_read = read(fd, buffer, bytes);
|
||||
if (bytes_read <= 0)
|
||||
return -1;
|
||||
|
||||
/* Copy the data from BUFFER into the memory specified by VECTOR. */
|
||||
bytes = bytes_read;
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
#define min(a, b) ((a) > (b) ? (b) : (a))
|
||||
size_t copy = min(vector[i].iov_len, bytes);
|
||||
|
||||
(void) memcpy((PTR) vector[i].iov_base, (PTR) buffer, copy);
|
||||
|
||||
buffer += copy;
|
||||
bytes -= copy;
|
||||
if (bytes == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return bytes_read;
|
||||
}
|
||||
48
gnu/glibc/glibc-1.03/sysdeps/posix/rename.c
Normal file
48
gnu/glibc/glibc-1.03/sysdeps/posix/rename.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Rename the file OLD to NEW. */
|
||||
int
|
||||
DEFUN(rename, (old, new), CONST char *old AND CONST char *new)
|
||||
{
|
||||
int save = errno;
|
||||
if (__link(old, new) < 0)
|
||||
{
|
||||
if (errno == EEXIST)
|
||||
{
|
||||
errno = save;
|
||||
/* Race condition, required for 1003.1 conformance. */
|
||||
if (__unlink(new) < 0 ||
|
||||
__link(old, new) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (__unlink(old) < 0)
|
||||
{
|
||||
save = errno;
|
||||
if (__unlink(new) == 0)
|
||||
errno = save;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
45
gnu/glibc/glibc-1.03/sysdeps/posix/signal.c
Normal file
45
gnu/glibc/glibc-1.03/sysdeps/posix/signal.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
/* Set the handler for the signal SIG to HANDLER,
|
||||
returning the old handler, or SIG_ERR on error. */
|
||||
__sighandler_t
|
||||
DEFUN(signal, (sig, handler), int sig AND __sighandler_t handler)
|
||||
{
|
||||
struct sigaction act, oact;
|
||||
|
||||
if (handler == SIG_ERR)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return SIG_ERR;
|
||||
}
|
||||
|
||||
act.sa_handler = handler;
|
||||
if (__sigemptyset(&act.sa_mask) < 0)
|
||||
return SIG_ERR;
|
||||
act.sa_flags = 0;
|
||||
if (__sigaction(sig, &act, &oact) < 0)
|
||||
return SIG_ERR;
|
||||
|
||||
return oact.sa_handler;
|
||||
}
|
||||
51
gnu/glibc/glibc-1.03/sysdeps/posix/sigsuspend.c
Normal file
51
gnu/glibc/glibc-1.03/sysdeps/posix/sigsuspend.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
/* Change the set of blocked signals to SET,
|
||||
wait until a signal arrives, and restore the set of blocked signals. */
|
||||
int
|
||||
DEFUN(sigsuspend, (set), CONST sigset_t *set)
|
||||
{
|
||||
sigset_t oset;
|
||||
int save;
|
||||
|
||||
if (set == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, set, &oset) < 0)
|
||||
return -1;
|
||||
|
||||
(void) pause();
|
||||
save = errno;
|
||||
|
||||
if (sigprocmask(SIG_SETMASK, &oset, (sigset_t *) NULL) < 0)
|
||||
return -1;
|
||||
|
||||
errno = save;
|
||||
return -1;
|
||||
}
|
||||
63
gnu/glibc/glibc-1.03/sysdeps/posix/sleep.c
Normal file
63
gnu/glibc/glibc-1.03/sysdeps/posix/sleep.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
/* SIGALRM signal handler for `sleep'. This does nothing but return,
|
||||
but SIG_IGN isn't supposed to break `pause'. */
|
||||
static void
|
||||
DEFUN(sleep_handler, (sig), int sig)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make the process sleep for SECONDS seconds, or until a signal arrives
|
||||
and is not ignored. The function returns the number of seconds less
|
||||
than SECONDS which it actually slept (zero if it slept the full time).
|
||||
If a signal handler does a `longjmp' or modifies the handling of the
|
||||
SIGALRM signal while inside `sleep' call, the handling of the SIGALRM
|
||||
signal afterwards is undefined. There is no return value to indicate
|
||||
error, but if `sleep' returns SECONDS, it probably didn't work. */
|
||||
unsigned int
|
||||
DEFUN(sleep, (seconds), unsigned int seconds)
|
||||
{
|
||||
unsigned int remaining, slept;
|
||||
__sighandler_t handler;
|
||||
time_t before, after;
|
||||
|
||||
handler = signal (SIGALRM, sleep_handler);
|
||||
if (handler == SIG_ERR)
|
||||
return seconds;
|
||||
|
||||
before = time ((time_t *) NULL);
|
||||
remaining = alarm (seconds);
|
||||
(void) pause ();
|
||||
after = time ((time_t *) NULL);
|
||||
|
||||
(void) signal (SIGALRM, handler);
|
||||
|
||||
slept = after - before;
|
||||
if (remaining > slept)
|
||||
alarm (remaining - slept);
|
||||
|
||||
return (slept > seconds ? 0 : seconds - slept);
|
||||
}
|
||||
61
gnu/glibc/glibc-1.03/sysdeps/posix/stdio_init.c
Normal file
61
gnu/glibc/glibc-1.03/sysdeps/posix/stdio_init.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Initialize STREAM as necessary.
|
||||
This may change I/O functions, give a buffer, etc.
|
||||
If no buffer is allocated, but the bufsize is set,
|
||||
the bufsize will be used to allocate the buffer. */
|
||||
void
|
||||
DEFUN(__stdio_init_stream, (stream), FILE *stream)
|
||||
{
|
||||
register CONST int fd = *(int *) stream->__cookie;
|
||||
struct stat statb;
|
||||
|
||||
if (stream->__buffer != NULL || stream->__userbuf)
|
||||
/* If's unbuffered by request, we can't do anything useful. */
|
||||
return;
|
||||
|
||||
/* Find out what sort of file this is. */
|
||||
if (__fstat(fd, &statb) < 0)
|
||||
return;
|
||||
|
||||
if (S_ISFIFO(statb.st_mode))
|
||||
{
|
||||
/* It's a named pipe (FIFO). Make it unbuffered. */
|
||||
stream->__userbuf = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (S_ISCHR(statb.st_mode))
|
||||
{
|
||||
/* It's a character device.
|
||||
Make it line-buffered if it's a terminal. */
|
||||
if (__isatty(fd))
|
||||
stream->__linebuf = 1;
|
||||
}
|
||||
|
||||
/* Use the block-size field to determine
|
||||
the system's optimal buffering size. */
|
||||
stream->__bufsize = statb.st_blksize;
|
||||
}
|
||||
296
gnu/glibc/glibc-1.03/sysdeps/posix/sysd-stdio.c
Normal file
296
gnu/glibc/glibc-1.03/sysdeps/posix/sysd-stdio.c
Normal file
@@ -0,0 +1,296 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Read N bytes into BUF from COOKIE. */
|
||||
int
|
||||
DEFUN(__stdio_read, (cookie, buf, n),
|
||||
PTR cookie AND register char *buf AND register size_t n)
|
||||
{
|
||||
#ifdef EINTR
|
||||
CONST int fd = *(int *) cookie;
|
||||
int save = errno;
|
||||
int nread;
|
||||
|
||||
try:;
|
||||
errno = 0;
|
||||
nread = __read(fd, buf, (int) n);
|
||||
if (nread < 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
goto try;
|
||||
return -1;
|
||||
}
|
||||
errno = save;
|
||||
return nread;
|
||||
|
||||
#else /* No EINTR. */
|
||||
return __read(*(int *) cookie, buf, (int) n);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* Write N bytes from BUF to COOKIE. */
|
||||
int
|
||||
DEFUN(__stdio_write, (cookie, buf, n),
|
||||
PTR cookie AND register CONST char *buf AND register size_t n)
|
||||
{
|
||||
CONST int fd = *(int *) cookie;
|
||||
register size_t written = 0;
|
||||
int save = errno;
|
||||
|
||||
errno = 0;
|
||||
while (n > 0)
|
||||
{
|
||||
int count = __write(fd, buf, (int) n);
|
||||
if (count > 0)
|
||||
{
|
||||
buf += count;
|
||||
written += count;
|
||||
n -= count;
|
||||
}
|
||||
else if (count < 0)
|
||||
{
|
||||
/* Write error. */
|
||||
#ifdef EINTR
|
||||
if (errno != EINTR)
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
errno = save;
|
||||
return (int) written;
|
||||
}
|
||||
|
||||
|
||||
/* Move COOKIE's file position *POS bytes, according to WHENCE.
|
||||
The new file position is stored in *POS.
|
||||
Returns zero if successful, nonzero if not. */
|
||||
int
|
||||
DEFUN(__stdio_seek, (cookie, pos, whence),
|
||||
PTR cookie AND fpos_t *pos AND int whence)
|
||||
{
|
||||
off_t new;
|
||||
new = __lseek(*(int *) cookie, (off_t) *pos, whence);
|
||||
if (new < 0)
|
||||
return 1;
|
||||
*pos = (fpos_t) new;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Close COOKIE. */
|
||||
int
|
||||
DEFUN(__stdio_close, (cookie), PTR cookie)
|
||||
{
|
||||
return __close(*(int *) cookie);
|
||||
}
|
||||
|
||||
|
||||
/* Open the given file with the mode given in the __io_mode argument. */
|
||||
PTR
|
||||
DEFUN(__stdio_open, (filename, m, fdptr),
|
||||
CONST char *filename AND __io_mode m AND int *fdptr)
|
||||
{
|
||||
int mode;
|
||||
|
||||
if (m.__read && m.__write)
|
||||
mode = O_RDWR;
|
||||
else
|
||||
mode = m.__read ? O_RDONLY : O_WRONLY;
|
||||
|
||||
if (m.__append)
|
||||
mode |= O_APPEND;
|
||||
if (m.__exclusive)
|
||||
mode |= O_EXCL;
|
||||
if (m.__truncate)
|
||||
mode |= O_TRUNC;
|
||||
|
||||
if (m.__create)
|
||||
*fdptr = __open(filename, mode | O_CREAT,
|
||||
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
|
||||
else
|
||||
*fdptr = __open(filename, mode);
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/* Write a message to the error output.
|
||||
Try hard to make it really get out. */
|
||||
void
|
||||
DEFUN(__stdio_errmsg, (msg, len), CONST char *msg AND size_t len)
|
||||
{
|
||||
while (len > 0)
|
||||
{
|
||||
register int count = __write(2, msg, (int) len);
|
||||
if (count > 0)
|
||||
{
|
||||
msg += count;
|
||||
len -= count;
|
||||
}
|
||||
else if (count < 0)
|
||||
#ifdef EINTR
|
||||
if (errno != EINTR)
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Return nonzero if DIR is an existent directory. */
|
||||
static int
|
||||
DEFUN(diraccess, (dir), CONST char *dir)
|
||||
{
|
||||
struct stat buf;
|
||||
return __stat(dir, &buf) == 0 && S_ISDIR(buf.st_mode);
|
||||
}
|
||||
|
||||
/* Return nonzero if FILE exists. */
|
||||
static int
|
||||
DEFUN(exists, (file), CONST char *file)
|
||||
{
|
||||
int fd = __open(file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
(void) __close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* These are the characters used in temporary filenames. */
|
||||
static CONST char letters[] =
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
/* Generate a temporary filename.
|
||||
If DIR_SEARCH is nonzero, DIR and PFX are used as
|
||||
described for tempnam. If not, a temporary filename
|
||||
in P_tmpdir with no special prefix is generated. If LENPTR
|
||||
is not NULL, *LENPTR is set the to length (including the
|
||||
terminating '\0') of the resultant filename, which is returned.
|
||||
This goes through a cyclic pattern of all possible filenames
|
||||
consisting of five decimal digits of the current pid and three
|
||||
of the characters in `letters'. Data for tempnam and tmpnam
|
||||
is kept separate, but when tempnam is using P_tmpdir and no
|
||||
prefix (i.e, it is identical to tmpnam), the same data is used.
|
||||
Each potential filename is tested for an already-existing file of
|
||||
the same name, and no name of an existing file will be returned.
|
||||
When the cycle reaches its end (12345ZZZ), NULL is returned. */
|
||||
char *
|
||||
DEFUN(__stdio_gen_tempname, (dir, pfx, dir_search, lenptr),
|
||||
CONST char *dir AND CONST char *pfx AND
|
||||
int dir_search AND size_t *lenptr)
|
||||
{
|
||||
static CONST char tmpdir[] = P_tmpdir;
|
||||
static struct
|
||||
{
|
||||
char buf[3];
|
||||
char *s;
|
||||
size_t i;
|
||||
} infos[2], *info;
|
||||
static char buf[FILENAME_MAX];
|
||||
static pid_t oldpid = (pid_t) 0;
|
||||
pid_t pid = __getpid();
|
||||
register size_t len, plen, dlen;
|
||||
|
||||
if (dir_search)
|
||||
{
|
||||
register CONST char *d = getenv("TMPDIR");
|
||||
if (d != NULL && !diraccess(d))
|
||||
d = NULL;
|
||||
if (d == NULL && dir != NULL && diraccess(dir))
|
||||
d = dir;
|
||||
if (d == NULL && diraccess(tmpdir))
|
||||
d = tmpdir;
|
||||
if (d == NULL && diraccess("/tmp"))
|
||||
d = "/tmp";
|
||||
if (d == NULL)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
dir = d;
|
||||
}
|
||||
else
|
||||
dir = tmpdir;
|
||||
|
||||
dlen = strlen (dir);
|
||||
|
||||
/* Remove trailing slashes from the directory name. */
|
||||
while (dlen > 1 && dir[dlen - 1] == '/')
|
||||
--dlen;
|
||||
|
||||
if (pfx != NULL && *pfx != '\0')
|
||||
{
|
||||
plen = strlen(pfx);
|
||||
if (plen > 5)
|
||||
plen = 5;
|
||||
}
|
||||
else
|
||||
plen = 0;
|
||||
|
||||
if (dir != tmpdir && !strcmp(dir, tmpdir))
|
||||
dir = tmpdir;
|
||||
info = &infos[(plen == 0 && dir == tmpdir) ? 1 : 0];
|
||||
|
||||
if (pid != oldpid)
|
||||
{
|
||||
oldpid = pid;
|
||||
infos[0].buf[0] = infos[0].buf[1] = infos[0].buf[2] = letters[0];
|
||||
infos[0].s = infos[0].buf;
|
||||
infos[0].i = 0;
|
||||
infos[1].buf[0] = infos[1].buf[1] = infos[1].buf[2] = letters[0];
|
||||
infos[1].s = infos[1].buf;
|
||||
infos[1].i = 0;
|
||||
}
|
||||
|
||||
len = dlen + 1 + plen + 8;
|
||||
for (;;)
|
||||
{
|
||||
*info->s = letters[info->i];
|
||||
if (sprintf(buf, "%.*s/%.*s%.5d%.3s", (int) dlen, dir, (int) plen,
|
||||
pfx, pid % 100000, info->buf) != (int) len)
|
||||
return NULL;
|
||||
if (!exists(buf))
|
||||
break;
|
||||
++info->i;
|
||||
|
||||
if (info->i > sizeof(letters) - 2)
|
||||
{
|
||||
info->i = 0;
|
||||
if (info->s == &info->buf[2])
|
||||
return NULL;
|
||||
++info->s;
|
||||
}
|
||||
}
|
||||
|
||||
if (lenptr != NULL)
|
||||
*lenptr = len + 1;
|
||||
return buf;
|
||||
}
|
||||
136
gnu/glibc/glibc-1.03/sysdeps/posix/system.c
Normal file
136
gnu/glibc/glibc-1.03/sysdeps/posix/system.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/* Copyright (C) 1991, 1992 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
#ifndef HAVE_GNU_LD
|
||||
#define __environ environ
|
||||
#endif
|
||||
|
||||
#define SHELL_PATH "/bin/sh" /* Path of the shell. */
|
||||
#define SHELL_NAME "sh" /* Name to give it. */
|
||||
|
||||
#ifndef FORK
|
||||
#define FORK __fork
|
||||
#endif
|
||||
|
||||
/* Execute LINE as a shell command, returning its status. */
|
||||
int
|
||||
DEFUN(system, (line), register CONST char *line)
|
||||
{
|
||||
int status, save;
|
||||
pid_t pid;
|
||||
struct sigaction sa, intr, quit;
|
||||
sigset_t block, omask;
|
||||
|
||||
if (line == NULL)
|
||||
return 1;
|
||||
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sa.sa_flags = 0;
|
||||
__sigemptyset (&sa.sa_mask);
|
||||
|
||||
if (__sigaction (SIGINT, &sa, &intr) < 0)
|
||||
return -1;
|
||||
if (__sigaction (SIGQUIT, &sa, &quit) < 0)
|
||||
{
|
||||
save = errno;
|
||||
(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
|
||||
errno = save;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__sigemptyset (&block);
|
||||
__sigaddset (&block, SIGCHLD);
|
||||
save = errno;
|
||||
if (__sigprocmask(SIG_BLOCK, &block, &omask) < 0)
|
||||
{
|
||||
if (errno == ENOSYS)
|
||||
errno = save;
|
||||
else
|
||||
{
|
||||
save = errno;
|
||||
(void) __sigaction(SIGINT, &intr, (struct sigaction *) NULL);
|
||||
(void) __sigaction(SIGQUIT, &quit, (struct sigaction *) NULL);
|
||||
errno = save;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
pid = FORK ();
|
||||
if (pid == (pid_t) 0)
|
||||
{
|
||||
/* Child side. */
|
||||
CONST char *new_argv[4];
|
||||
new_argv[0] = SHELL_NAME;
|
||||
new_argv[1] = "-c";
|
||||
new_argv[2] = line;
|
||||
new_argv[3] = NULL;
|
||||
|
||||
/* Restore the signals. */
|
||||
(void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
|
||||
(void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
|
||||
(void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL);
|
||||
|
||||
/* Exec the shell. */
|
||||
(void) __execve (SHELL_PATH, (char *CONST *) new_argv, __environ);
|
||||
_exit (127);
|
||||
}
|
||||
else if (pid < (pid_t) 0)
|
||||
/* The fork failed. */
|
||||
status = -1;
|
||||
else
|
||||
/* Parent side. */
|
||||
#ifdef NO_WAITPID
|
||||
{
|
||||
pid_t child;
|
||||
do
|
||||
{
|
||||
child = __wait (&status);
|
||||
if (child <= -1)
|
||||
{
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
} while (child != pid);
|
||||
}
|
||||
#else
|
||||
if (__waitpid (pid, &status, 0) != pid)
|
||||
status = -1;
|
||||
#endif
|
||||
|
||||
save = errno;
|
||||
if ((__sigaction (SIGINT, &intr, (struct sigaction *) NULL) |
|
||||
__sigaction (SIGQUIT, &quit, (struct sigaction *) NULL) |
|
||||
__sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL)) != 0)
|
||||
{
|
||||
if (errno == ENOSYS)
|
||||
errno = save;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
77
gnu/glibc/glibc-1.03/sysdeps/posix/ttyname.c
Normal file
77
gnu/glibc/glibc-1.03/sysdeps/posix/ttyname.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
char *__ttyname = NULL;
|
||||
|
||||
/* Return the pathname of the terminal FD is open on, or NULL on errors.
|
||||
The returned storage is good only until the next call to this function. */
|
||||
char *
|
||||
DEFUN(ttyname, (fd), int fd)
|
||||
{
|
||||
static char dev[] = "/dev";
|
||||
char name[PATH_MAX];
|
||||
char *CONST np = &name[sizeof(dev)];
|
||||
struct stat st;
|
||||
dev_t mydev;
|
||||
ino_t myino;
|
||||
DIR *dirstream;
|
||||
struct dirent *d;
|
||||
|
||||
if (fstat(fd, &st) < 0)
|
||||
return NULL;
|
||||
if (!S_ISCHR(st.st_mode))
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
mydev = st.st_dev;
|
||||
myino = st.st_ino;
|
||||
|
||||
dirstream = opendir(dev);
|
||||
if (dirstream == NULL)
|
||||
return NULL;
|
||||
|
||||
(void) memcpy(name, dev, sizeof(dev) - 1);
|
||||
np[-1] = '/';
|
||||
while ((d = readdir(dirstream)) != NULL)
|
||||
if (d->d_fileno == myino)
|
||||
{
|
||||
(void) memcpy(np, d->d_name, d->d_namlen + 1);
|
||||
if (stat(name, &st) == 0 && st.st_dev == mydev)
|
||||
{
|
||||
static char result[PATH_MAX];
|
||||
(void) memcpy(result, name, (np - name) + d->d_namlen + 1);
|
||||
(void) closedir(dirstream);
|
||||
__ttyname = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
(void) closedir(dirstream);
|
||||
return NULL;
|
||||
}
|
||||
63
gnu/glibc/glibc-1.03/sysdeps/posix/writev.c
Normal file
63
gnu/glibc/glibc-1.03/sysdeps/posix/writev.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* Copyright (C) 1991 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 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., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
/* Write data pointed by the buffers described by VECTOR, which
|
||||
is a vector of COUNT `struct iovec's, to file descriptor FD.
|
||||
The data is written in the order specified.
|
||||
Operates just like `write' (see <unistd.h>) except that the data
|
||||
are taken from VECTOR instead of a contiguous buffer. */
|
||||
int
|
||||
DEFUN(writev, (fd, vector, count),
|
||||
int fd AND CONST struct iovec *vector AND size_t count)
|
||||
{
|
||||
char *buffer;
|
||||
register char *bp;
|
||||
size_t bytes, to_copy;
|
||||
register size_t i;
|
||||
|
||||
/* Find the total number of bytes to be written. */
|
||||
bytes = 0;
|
||||
for (i = 0; i < count; ++i)
|
||||
bytes += vector[i].iov_len;
|
||||
|
||||
/* Allocate a temporary buffer to hold the data. */
|
||||
buffer = (char *) __alloca(bytes);
|
||||
|
||||
/* Copy the data into BUFFER. */
|
||||
to_copy = bytes;
|
||||
bp = buffer;
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
#define min(a, b) ((a) > (b) ? (b) : (a))
|
||||
size_t copy = min(vector[i].iov_len, to_copy);
|
||||
|
||||
(void) memcpy((PTR) bp, (PTR) vector[i].iov_base, copy);
|
||||
|
||||
bp += copy;
|
||||
to_copy -= copy;
|
||||
if (bytes == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return write(fd, buffer, bytes);
|
||||
}
|
||||
Reference in New Issue
Block a user