Permalink
Browse files

Creating branch agc_pkgs

  • Loading branch information...
1 parent 62ff15f commit 74ebd19ba66a15821aaa82a86c17336180cb2733 cvs committed Mar 27, 1994
Showing with 0 additions and 19,913 deletions.
  1. +0 −33 Makefile
  2. +0 −7 bin/Makefile
  3. +0 −5 bin/Makefile.inc
  4. +0 −6 bin/cat/Makefile
  5. +0 −129 bin/cat/cat.1
  6. +0 −286 bin/cat/cat.c
  7. +0 −6 bin/chmod/Makefile
  8. +0 −265 bin/chmod/chmod.1
  9. +0 −194 bin/chmod/chmod.c
  10. +0 −7 bin/cp/Makefile
  11. +0 −162 bin/cp/cp.1
  12. +0 −591 bin/cp/cp.c
  13. +0 −52 bin/cp/extern.h
  14. +0 −146 bin/cp/path.c
  15. +0 −41 bin/csh/Makefile
  16. +0 −543 bin/csh/alloc.c
  17. +0 −312 bin/csh/char.c
  18. +0 −97 bin/csh/char.h
  19. +0 −158 bin/csh/const.c
  20. +0 −2,139 bin/csh/csh.1
  21. +0 −1,216 bin/csh/csh.c
  22. +0 −539 bin/csh/csh.h
  23. +0 −905 bin/csh/dir.c
  24. +0 −46 bin/csh/dir.h
  25. +0 −843 bin/csh/dol.c
  26. +0 −411 bin/csh/err.c
  27. +0 −445 bin/csh/exec.c
  28. +0 −709 bin/csh/exp.c
  29. +0 −359 bin/csh/extern.h
  30. +0 −677 bin/csh/file.c
  31. +0 −1,377 bin/csh/func.c
  32. +0 −847 bin/csh/glob.c
  33. +0 −207 bin/csh/hist.c
  34. +0 −169 bin/csh/init.c
  35. +0 −1,528 bin/csh/lex.c
  36. +0 −414 bin/csh/misc.c
  37. +0 −699 bin/csh/parse.c
  38. +0 −42 bin/csh/pathnames.h
  39. +0 −189 bin/csh/print.c
  40. +0 −312 bin/csh/printf.c
  41. +0 −1,296 bin/csh/proc.c
  42. +0 −102 bin/csh/proc.h
  43. +0 −572 bin/csh/sem.c
  44. +0 −830 bin/csh/set.c
Sorry, we could not display the entire diff because too many files (11,918) changed.
View
33 Makefile
@@ -1,33 +0,0 @@
-# $Id: Makefile,v 1.18 1994/02/10 08:50:06 cgd Exp $
-
-# NOTE THAT etc *DOES NOT* BELONG IN THE LIST BELOW
-
-SUBDIR+= lib include bin libexec sbin usr.bin usr.sbin share games
-SUBDIR+= gnu
-
-SUBDIR+= sys
-
-.if exists(regress)
-.ifmake !(install)
-SUBDIR+= regress
-.endif
-
-regression-tests:
- @echo Running regression tests...
- @(cd regress && ${MAKE} regress)
-.endif
-
-afterinstall:
- (cd share/man && ${MAKE} makedb)
-
-build:
- (cd include && ${MAKE} install)
- ${MAKE} cleandir
- (cd lib && ${MAKE} depend && ${MAKE} && ${MAKE} install)
- (cd gnu/lib && ${MAKE} depend && ${MAKE} && ${MAKE} install)
-.if exists(kerberosIV)
- (cd kerberosIV && ${MAKE} depend && ${MAKE} && ${MAKE} install)
-.endif
- ${MAKE} depend && ${MAKE} && ${MAKE} install
-
-.include <bsd.subdir.mk>
View
7 bin/Makefile
@@ -1,7 +0,0 @@
-# from: @(#)Makefile 5.33.1.1 (Berkeley) 5/6/91
-# $Id: Makefile,v 1.10 1994/01/30 23:17:54 mycroft Exp $
-
-SUBDIR= cat chmod cp csh date dd df domainname echo ed expr hostname kill ln \
- ls mkdir mt mv ps pwd rcp rm rmail rmdir sh sleep stty sync test
-
-.include <bsd.subdir.mk>
View
5 bin/Makefile.inc
@@ -1,5 +0,0 @@
-# from: @(#)Makefile.inc 5.1 (Berkeley) 5/11/90
-# $Id: Makefile.inc,v 1.6 1993/11/08 02:34:22 cgd Exp $
-
-BINDIR?= /bin
-LDSTATIC= -static
View
6 bin/cat/Makefile
@@ -1,6 +0,0 @@
-# from: @(#)Makefile 5.2 (Berkeley) 5/11/90
-# $Id: Makefile,v 1.4 1993/08/01 05:48:12 mycroft Exp $
-
-PROG= cat
-
-.include <bsd.prog.mk>
View
129 bin/cat/cat.1
@@ -1,129 +0,0 @@
-.\" Copyright (c) 1989, 1990 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" the Institute of Electrical and Electronics Engineers, Inc.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" from: @(#)cat.1 6.16 (Berkeley) 6/27/91
-.\" $Id: cat.1,v 1.6 1993/11/30 00:07:58 jtc Exp $
-.\"
-.Dd June 27, 1991
-.Dt CAT 1
-.Os BSD 3
-.Sh NAME
-.Nm cat
-.Nd concatenate and print files
-.Sh SYNOPSIS
-.Nm cat
-.Op Fl benstuv
-.Op Fl
-.Op Ar
-.Sh DESCRIPTION
-The
-.Nm cat
-utility reads files sequentially, writing them to the standard output.
-The
-.Ar file
-operands are processed in command line order.
-A single dash represents standard input.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl b
-Implies the
-.Fl n
-option but doesn't number blank lines.
-.It Fl e
-Implies the
-.Fl v
-option, and displays a dollar sign
-.Pq Ql \&$
-at the end of each line
-as well.
-.It Fl n
-Number the
-.Ar output
-lines, starting at 1.
-.It Fl s
-Squeeze multiple adjacent empty lines, causing the output to be
-single spaced.
-.It Fl t
-Implies the
-.Fl v
-option, and displays tab characters as
-.Pq Ql ^I
-as well.
-.It Fl u
-The
-.Fl u
-option guarantees that the output is unbuffered.
-.It Fl v
-Displays non-printing characters so they are visible.
-Control characters print line
-.Ql ^X
-for control-X; the delete
-character (octal 0177) prints as
-.Ql ^?
-Non-ascii characters (with the high bit set) are printed as
-.Ql M-
-(for meta) followed by the character for the low 7 bits.
-.El
-.Pp
-The
-.Nm cat
-utility exits 0 on success, and >0 if an error occurs.
-.Sh BUGS
-Because of the shell language mechanism used to perform output
-redirection, the command
-.Dq Li cat file1 file 2 > file1
-will cause the original data in file1 to be destroyed!
-.Sh SEE ALSO
-.Xr head 1 ,
-.Xr more 1 ,
-.Xr pr 1 ,
-.Xr tail 1
-.Rs
-.%A Rob Pike
-.%T "UNIX Style, or cat -v Considered Harmful"
-.%J "USENIX Summer Conference Proceedings"
-.%D 1983
-.Re
-.Sh STANDARDS
-The
-.Nm cat
-utility is a superset of the
-.St -p1003.2
-standard.
-.Sh HISTORY
-A
-.Nm
-utility appeared in
-.At v6 .
View
286 bin/cat/cat.c
@@ -1,286 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kevin Fall.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-/*static char sccsid[] = "from: @(#)cat.c 5.15 (Berkeley) 5/23/91";*/
-static char rcsid[] = "$Id: cat.c,v 1.8 1993/11/19 20:00:51 jtc Exp $";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <ctype.h>
-
-int bflag, eflag, nflag, sflag, tflag, vflag;
-int rval;
-char *filename;
-
-void cook_args __P((char **));
-void cook_buf __P((FILE *));
-void raw_args __P((char **));
-void raw_cat __P((int));
-void err __P((int, const char *, ...));
-
-int
-main(argc, argv)
- int argc;
- char **argv;
-{
- extern int optind;
- int ch;
-
- setlocale(LC_ALL, "");
-
- while ((ch = getopt(argc, argv, "benstuv")) != -1)
- switch (ch) {
- case 'b':
- bflag = nflag = 1; /* -b implies -n */
- break;
- case 'e':
- eflag = vflag = 1; /* -e implies -v */
- break;
- case 'n':
- nflag = 1;
- break;
- case 's':
- sflag = 1;
- break;
- case 't':
- tflag = vflag = 1; /* -t implies -v */
- break;
- case 'u':
- setbuf(stdout, (char *)NULL);
- break;
- case 'v':
- vflag = 1;
- break;
- default:
- case '?':
- (void)fprintf(stderr,
- "usage: cat [-benstuv] [-] [file ...]\n");
- exit(1);
- }
- argv += optind;
-
- if (bflag || eflag || nflag || sflag || tflag || vflag)
- cook_args(argv);
- else
- raw_args(argv);
- if (fclose(stdout))
- err(1, "stdout: %s", strerror(errno));
- exit(rval);
-}
-
-void
-cook_args(argv)
- char **argv;
-{
- register FILE *fp;
-
- fp = stdin;
- filename = "stdin";
- do {
- if (*argv) {
- if (!strcmp(*argv, "-"))
- fp = stdin;
- else if (!(fp = fopen(*argv, "r"))) {
- err(0, "%s: %s", *argv, strerror(errno));
- ++argv;
- continue;
- }
- filename = *argv++;
- }
- cook_buf(fp);
- if (fp != stdin)
- (void)fclose(fp);
- } while (*argv);
-}
-
-void
-cook_buf(fp)
- register FILE *fp;
-{
- register int ch, gobble, line, prev;
-
- line = gobble = 0;
- for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
- if (prev == '\n') {
- if (ch == '\n') {
- if (sflag) {
- if (!gobble && putchar(ch) == EOF)
- break;
- gobble = 1;
- continue;
- }
- if (nflag && !bflag) {
- (void)fprintf(stdout, "%6d\t", ++line);
- if (ferror(stdout))
- break;
- }
- } else if (nflag) {
- (void)fprintf(stdout, "%6d\t", ++line);
- if (ferror(stdout))
- break;
- }
- }
- gobble = 0;
- if (ch == '\n') {
- if (eflag)
- if (putchar('$') == EOF)
- break;
- } else if (ch == '\t') {
- if (tflag) {
- if (putchar('^') == EOF || putchar('I') == EOF)
- break;
- continue;
- }
- } else if (vflag) {
- if (!isascii(ch)) {
- if (putchar('M') == EOF || putchar('-') == EOF)
- break;
- ch = toascii(ch);
- }
- if (iscntrl(ch)) {
- if (putchar('^') == EOF ||
- putchar(ch == '\177' ? '?' :
- ch | 0100) == EOF)
- break;
- continue;
- }
- }
- if (putchar(ch) == EOF)
- break;
- }
- if (ferror(fp)) {
- err(0, "%s: %s", filename, strerror(errno));
- clearerr(fp);
- }
- if (ferror(stdout))
- err(1, "stdout: %s", strerror(errno));
-}
-
-void
-raw_args(argv)
- char **argv;
-{
- register int fd;
-
- fd = fileno(stdin);
- filename = "stdin";
- do {
- if (*argv) {
- if (!strcmp(*argv, "-"))
- fd = fileno(stdin);
- else if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
- err(0, "%s: %s", *argv, strerror(errno));
- ++argv;
- continue;
- }
- filename = *argv++;
- }
- raw_cat(fd);
- if (fd != fileno(stdin))
- (void)close(fd);
- } while (*argv);
-}
-
-void
-raw_cat(rfd)
- register int rfd;
-{
- register int nr, nw, off, wfd;
- static int bsize;
- static char *buf;
- struct stat sbuf;
-
- wfd = fileno(stdout);
- if (!buf) {
- if (fstat(wfd, &sbuf))
- err(1, "%s: %s", filename, strerror(errno));
- bsize = MAX(sbuf.st_blksize, 1024);
- if (!(buf = malloc((u_int)bsize)))
- err(1, "%s", strerror(errno));
- }
- while ((nr = read(rfd, buf, bsize)) > 0)
- for (off = 0; off < nr; off += nw)
- if ((nw = write(wfd, buf + off, nr - off)) < 0)
- err(1, "stdout");
- if (nr < 0)
- err(0, "%s: %s", filename, strerror(errno));
-}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(int ex, const char *fmt, ...)
-#else
-err(ex, fmt, va_alist)
- int ex;
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "cat: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- if (ex)
- exit(1);
- rval = 1;
-}
View
6 bin/chmod/Makefile
@@ -1,6 +0,0 @@
-# from: @(#)Makefile 5.2 (Berkeley) 5/11/90
-# $Id: Makefile,v 1.4 1993/08/01 05:48:00 mycroft Exp $
-
-PROG= chmod
-
-.include <bsd.prog.mk>
View
265 bin/chmod/chmod.1
@@ -1,265 +0,0 @@
-.\" Copyright (c) 1989, 1990 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" the Institute of Electrical and Electronics Engineers, Inc.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" from: @(#)chmod.1 6.15 (Berkeley) 7/23/91
-.\" $Id: chmod.1,v 1.6 1994/02/10 23:23:08 cgd Exp $
-.\"
-.Dd July 23, 1991
-.Dt CHMOD 1
-.Os
-.Sh NAME
-.Nm chmod
-.Nd change file modes
-.Sh SYNOPSIS
-.Nm chmod
-.Op Fl R
-.Ar mode
-.Ar file ...
-.Sh DESCRIPTION
-The
-.Nm chmod
-utility modifies the file mode bits of the listed files
-as specified by the
-.Ar mode
-operand.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl R
-Traverse a file hierarchy.
-For each file that is of type directory,
-.Nm chmod
-changes the mode of all files in the file hierarchy below it followed
-by the mode of the directory itself.
-.El
-.Pp
-Symbolic links are not indirected through, nor are their modes altered.
-.Pp
-Only the owner of a file or the super-user is permitted to change
-the mode of a file.
-.Pp
-The
-.Nm chmod
-utility exits 0 on success, and >0 if an error occurs.
-.Sh MODES
-Modes may be absolute or symbolic.
-An absolute mode is an octal number constructed by
-.Ar or Ap ing
-the following values:
-.Pp
-.Bl -tag -width 6n -compact -offset indent
-.It Li 4000
-set-user-ID-on-execution
-.It Li 2000
-set-group-ID-on-execution
-.It Li 1000
-sticky bit, see chmod(2)
-.It Li 0400
-read by owner
-.It Li 0200
-write by owner
-.It Li 0100
-execute (or search for directories) by owner
-.It Li 0070
-read, write, execute/search by group
-.It Li 0007
-read, write, execute/search by others
-.El
-.Pp
-The read, write, and execute/search values for group and others
-are encoded as described for owner.
-.Pp
-The symbolic mode is described by the following grammar:
-.Bd -literal -offset indent
-mode ::= clause [, clause ...]
-clause ::= [who ...] [action ...] last_action
-action ::= op [perm ...]
-last_action ::= op [perm ...]
-who ::= a | u | g | o
-op ::= + | \- | =
-perm ::= r | s | t | w | x | X | u | g | o
-.Ed
-.Pp
-The
-.Ar who
-symbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
-of the mode bits, respectively.
-The
-.Ar who
-symbol ``a'' is equivalent to ``ugo''.
-.Pp
-The
-.Ar perm
-symbols represent the portions of the mode bits as follows:
-.Pp
-.Bl -tag -width Ds -compact -offset indent
-.It r
-The read bits.
-.It s
-The set-user-ID-on-execution and set-group-ID-on-execution bits.
-.It t
-The sticky bit.
-.It w
-The write bits.
-.It x
-The execute/search bits.
-.It X
-The execute/search bits if the file is a directory or any of the
-execute/search bits are set in the original (unmodified) mode.
-Operations with the
-.Ar perm
-symbol ``X'' are only meaningful in conjunction with the
-.Ar op
-symbol ``+'', and it is ignored in all other cases.
-.It u
-The user permission bits in the mode of the original file.
-.It g
-The group permission bits in the mode of the original file.
-.It o
-The other permission bits in the mode of the original file.
-.El
-.Pp
-The
-.Ar op
-symbols represent the operation performed, as follows:
-.Bl -tag -width 4n
-.It +
-If no value is supplied for
-.Ar perm ,
-the ``+'' operation has no effect.
-If no value is supplied for
-.Ar who ,
-each permission bit specified in
-.Ar perm ,
-for which the corresponding bit in the file mode creation mask
-is clear, is set.
-Otherwise, the mode bits represented by the specified
-.Ar who
-and
-.Ar perm
-values are set.
-.It \&\-
-If no value is supplied for
-.Ar perm ,
-the ``\-'' operation has no effect.
-If no value is supplied for
-.Ar who ,
-the mode bits represented by
-.Ar perm
-are cleared for the owner, group and other permissions.
-Otherwise, the mode bits represented by the specified
-.Ar who
-and
-.Ar perm
-values are cleared.
-.It =
-The mode bits specified by the
-.Ar who
-value are cleared, or, if no who value is specified, the owner, group
-and other mode bits are cleared.
-Then, if no value is supplied for
-.Ar who ,
-each permission bit specified in
-.Ar perm ,
-for which the corresponding bit in the file mode creation mask
-is clear, is set.
-Otherwise, the mode bits represented by the specified
-.Ar who
-and
-.Ar perm
-values are set.
-.El
-.Pp
-Each
-.Ar clause
-specifies one or more operations to be performed on the mode
-bits, and each operation is applied to the mode bits in the
-order specified.
-.Pp
-Operations upon the other permissions only (specified by the symbol
-``o'' by itself), in combination with the
-.Ar perm
-symbols ``s'' or ``t'', are ignored.
-.Sh EXAMPLES
-.Bl -tag -width "u=rwx,go=u-w" -compact
-.It Li 644
-make a file readable by anyone and writable by the owner only.
-.Pp
-.It Li go-w
-deny write permission to group and others.
-.Pp
-.It Li =rw,+X
-set the read and write permissions to the usual defaults, but
-retain any execute permissions that are currently set.
-.Pp
-.It Li +X
-make a directory or file searchable/executable by everyone if it is
-already searchable/executable by anyone.
-.Pp
-.It Li 755
-.It Li u=rwx,go=rx
-.It Li u=rwx,go=u-w
-make a file readable/executable by everyone and writable by the owner only.
-.Pp
-.It Li go=
-clear all mode bits for group and others.
-.Pp
-.It Li g=u-w
-set the group bits equal to the user bits, but clear the group write bit.
-.El
-.Sh BUGS
-There's no
-.Ar perm
-option for the naughty bits.
-.Sh SEE ALSO
-.Xr install 1 ,
-.Xr chmod 2 ,
-.Xr stat 2 ,
-.Xr umask 2 ,
-.Xr fts 3 ,
-.Xr setmode 3 ,
-.Xr chown 8
-.Sh STANDARDS
-The
-.Nm chmod
-utility is expected to be
-.St -p1003.2
-compatible with the exception
-of the
-.Ar perm
-symbols
-.Dq t
-and
-.Dq X
-which are not included in that standard.
View
194 bin/chmod/chmod.c
@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-/*static char sccsid[] = "from: @(#)chmod.c 5.21 (Berkeley) 1/27/92";*/
-static char rcsid[] = "$Id: chmod.c,v 1.8 1994/02/11 02:57:24 cgd Exp $";
-#endif /* not lint */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fts.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int retval;
-
-void err __P((const char *, ...));
-void error __P((char *));
-void usage __P((void));
-
-int
-main(argc, argv)
- int argc;
- char *argv[];
-{
- register FTS *fts;
- register FTSENT *p;
- register int oct, omode;
- struct stat sb;
- mode_t *set;
- int ch, fflag, rflag;
- char *ep, *mode;
-
- fflag = rflag = 0;
- while ((ch = getopt(argc, argv, "Rfrwx")) != EOF)
- switch((char)ch) {
- case 'R':
- rflag = 1;
- break;
- case 'f': /* no longer documented */
- fflag = 1;
- break;
- case 'r': /* "-[rwx]" are valid file modes */
- case 'w':
- case 'x':
- case 'u': /* as are -[ugo] */
- case 'g':
- case 'o':
- case 'X': /* -[Xts] valid but ignored later */
- case 't':
- case 's':
- --optind;
- goto done;
- case '?':
- default:
- usage();
- }
-done: argv += optind;
- argc -= optind;
-
- if (argc < 2)
- usage();
-
- mode = *argv;
- if (*mode >= '0' && *mode <= '7') {
- omode = (int)strtol(mode, &ep, 8);
- if (omode < 0 || *ep)
- err("invalid file mode: %s", mode);
- oct = 1;
- } else {
- if (!(set = setmode(mode)))
- err("invalid file mode: %s", mode);
- oct = 0;
- }
-
- retval = 0;
- if (rflag) {
- if ((fts = fts_open(++argv, FTS_PHYSICAL, 0)) == NULL)
- err("%s", strerror(errno));
- while (p = fts_read(fts))
- switch(p->fts_info) {
- case FTS_D:
- case FTS_SL:
- break;
- case FTS_DNR:
- case FTS_ERR:
- case FTS_NS:
- err("%s: %s", p->fts_path, strerror(errno));
- default:
- if (chmod(p->fts_accpath, oct ? omode :
- getmode(set, p->fts_statp->st_mode)) &&
- !fflag)
- error(p->fts_path);
- break;
- }
- exit(retval);
- }
- while (*++argv) {
- if (lstat(*argv, &sb) < 0) {
- if (!fflag)
- error(*argv);
- continue;
- }
- if (S_ISLNK(sb.st_mode))
- continue;
- if (chmod(*argv, oct ? omode : getmode(set, sb.st_mode)) &&
- !fflag)
- error(*argv);
- }
- exit(retval);
-}
-
-void
-error(name)
- char *name;
-{
- (void)fprintf(stderr, "chmod: %s: %s\n", name, strerror(errno));
- retval = 1;
-}
-
-void
-usage()
-{
- (void)fprintf(stderr, "usage: chmod [-R] mode file ...\n");
- exit(1);
-}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "chmod: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit(1);
- /* NOTREACHED */
-}
View
7 bin/cp/Makefile
@@ -1,7 +0,0 @@
-# from: @(#)Makefile 5.3 (Berkeley) 4/3/91
-# $Id: Makefile,v 1.5 1993/08/07 03:14:51 mycroft Exp $
-
-PROG= cp
-SRCS= cp.c path.c
-
-.include <bsd.prog.mk>
View
162 bin/cp/cp.1
@@ -1,162 +0,0 @@
-.\" Copyright (c) 1989, 1990 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" This code is derived from software contributed to Berkeley by
-.\" the Institute of Electrical and Electronics Engineers, Inc.
-.\"
-.\" Redistribution and use in source and binary forms, with or without
-.\" modification, are permitted provided that the following conditions
-.\" are met:
-.\" 1. Redistributions of source code must retain the above copyright
-.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
-.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-.\" SUCH DAMAGE.
-.\"
-.\" from: @(#)cp.1 6.15 (Berkeley) 7/30/91
-.\" $Id: cp.1,v 1.5 1993/08/07 03:14:54 mycroft Exp $
-.\"
-.Dd July 30, 1991
-.Dt CP 1
-.Os BSD 4
-.Sh NAME
-.Nm cp
-.Nd copy files
-.Sh SYNOPSIS
-.Nm cp
-.Op Fl Rfhip
-.Ar source_file target_file
-.Nm cp
-.Op Fl Rfhip
-.Ar source_file ... target_directory
-.Sh DESCRIPTION
-In the first synopsis form, the
-.Nm cp
-utility copies the contents of the
-.Ar source_file
-to the
-.Ar target_file .
-In the second synopsis form,
-the contents of each named
-.Ar source_file
-is copied to the destination
-.Ar target_directory .
-The names of the files themselves are not changed.
-If
-.Nm cp
-detects an attempt to copy a file to itself, the copy will fail.
-.Pp
-The following options are available:
-.Bl -tag -width flag
-.It Fl R
-If
-.Ar source_file
-designates a directory,
-.Nm cp
-copies the directory and the entire subtree connected at that point.
-This option also causes symbolic links to be copied, rather than
-indirected through, and for
-.Nm cp
-to create special files rather than copying them as normal files.
-Created directories have the same mode as the corresponding source
-directory, unmodified by the process' umask.
-.It Fl f
-For each existing destination pathname, remove it and
-create a new file, without prompting for confirmation
-regardless of its permissions.
-(The
-.Fl i
-option is ignored if the
-.Fl f
-option is specified.)
-.It Fl h
-Forces
-.Nm cp
-to follow symbolic links.
-Provided for the
-.Fl R
-option which does not follow symbolic links by default.
-.It Fl i
-Causes
-.Nm cp
-to write a prompt to standard error before copying a file that would
-overwrite an existing file.
-If the response from the standard input begins with the character
-.Sq Li y ,
-the file is copied if permissions allow the copy.
-.It Fl p
-Causes
-.Nm cp
-to preserve in the copy as many of the modification time, access time,
-file mode, user ID, and group ID as allowed by permissions.
-.Pp
-If the user ID and group ID cannot be preserved, no error message
-is displayed and the exit value is not altered.
-.Pp
-If the source file has its set user ID bit on and the user ID cannot
-be preserved, the set user ID bit is not preserved
-in the copy's permissions.
-If the source file has its set group ID bit on and the group ID cannot
-be preserved, the set group ID bit is not preserved
-in the copy's permissions.
-If the source file has both the set user ID and set group ID bits
-on and either the user ID or group ID cannot be preserved, neither
-the set user ID or set group ID bits are preserved in the copy's
-permissions.
-.El
-.Pp
-For each destination file that already exists, its contents are
-overwritten if permissions allow, but its mode, user ID, and group
-ID are unchanged.
-.Pp
-If the destination file does not exist, the mode of the source file is
-used as modified by the file mode creation mask
-.Pf ( Ic umask ,
-see
-.Xr csh 1 ) .
-If the source file has its set user ID bit on, that bit is removed
-unless both the source file and the destination file are owned by the
-same user.
-If the source file has its set group ID bit on, that bit is removed
-unless both the source file and the destination file are in the same
-group and the user is a member of that group.
-If both the set user ID and set group ID bits are set, all of the above
-conditions must be fulfilled or both bits are removed.
-.Pp
-Appropriate permissions are required for file creation or overwriting.
-.Pp
-Symbolic links are followed unless the
-.Fl R
-option is specified, in which case the link itself is copied.
-.Pp
-.Nm Cp
-exits 0 on success, >0 if an error occurred.
-.Sh SEE ALSO
-.Xr mv 1 ,
-.Xr rcp 1 ,
-.Xr umask 2
-.Sh HISTORY
-The
-.Nm cp
-command is expected to be
-.St -p1003.2
-compatible.
View
591 bin/cp/cp.c
@@ -1,591 +0,0 @@
-/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * David Hitz of Auspex Systems Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1988 The Regents of the University of California.\n\
- All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-/*static char sccsid[] = "from: @(#)cp.c 5.26 (Berkeley) 10/27/91";*/
-static char rcsid[] = "$Id: cp.c,v 1.8 1994/02/25 00:43:25 jtc Exp $";
-#endif /* not lint */
-
-/*
- * cp copies source files to target files.
- *
- * The global PATH_T structures "to" and "from" always contain paths to the
- * current source and target files, respectively. Since cp does not change
- * directories, these paths can be either absolute or dot-relative.
- *
- * The basic algorithm is to initialize "to" and "from", and then call the
- * recursive copy() function to do the actual work. If "from" is a file,
- * copy copies the data. If "from" is a directory, copy creates the
- * corresponding "to" directory, and calls itself recursively on all of
- * the entries in the "from" directory.
- */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "extern.h"
-
-static void copy __P((void));
-static void copy_dir __P((void));
-static void copy_fifo __P((struct stat *, int));
-static void copy_file __P((struct stat *, int));
-static void copy_link __P((int));
-static void copy_special __P((struct stat *, int));
-static void setfile __P((struct stat *, int));
-static void usage __P((void));
-
-PATH_T from = { from.p_path, "" };
-PATH_T to = { to.p_path, "" };
-
-uid_t myuid;
-int exit_val, myumask;
-int iflag, pflag, orflag, rflag;
-int (*statfcn)();
-char *progname;
-
-main(argc, argv)
- int argc;
- char **argv;
-{
- extern int optind;
- struct stat to_stat;
- register int c, r;
- int symfollow, lstat(), stat();
- char *old_to, *p;
-
- /*
- * The utility cp(1) is used by mv(1) -- except for usage statements,
- * print the "called as" program name.
- */
- progname = (p = rindex(*argv,'/')) ? ++p : *argv;
-
- symfollow = 0;
- while ((c = getopt(argc, argv, "Rfhipr")) != EOF) {
- switch ((char)c) {
- case 'f':
- iflag = 0;
- break;
- case 'h':
- symfollow = 1;
- break;
- case 'i':
- iflag = isatty(fileno(stdin));
- break;
- case 'p':
- pflag = 1;
- break;
- case 'R':
- rflag = 1;
- break;
- case 'r':
- orflag = 1;
- break;
- case '?':
- default:
- usage();
- break;
- }
- }
- argc -= optind;
- argv += optind;
-
- if (argc < 2)
- usage();
-
- if (rflag && orflag) {
- (void)fprintf(stderr,
- "cp: the -R and -r options are mutually exclusive.\n");
- exit(1);
- }
-
- myuid = getuid();
-
- /* copy the umask for explicit mode setting */
- myumask = umask(0);
- (void)umask(myumask);
-
- /* consume last argument first. */
- if (!path_set(&to, argv[--argc]))
- exit(1);
-
- statfcn = symfollow || !rflag ? stat : lstat;
-
- /*
- * Cp has two distinct cases:
- *
- * % cp [-rip] source target
- * % cp [-rip] source1 ... directory
- *
- * In both cases, source can be either a file or a directory.
- *
- * In (1), the target becomes a copy of the source. That is, if the
- * source is a file, the target will be a file, and likewise for
- * directories.
- *
- * In (2), the real target is not directory, but "directory/source".
- */
-
- r = stat(to.p_path, &to_stat);
- if (r == -1 && errno != ENOENT) {
- err("%s: %s", to.p_path, strerror(errno));
- exit(1);
- }
- if (r == -1 || !S_ISDIR(to_stat.st_mode)) {
- /*
- * Case (1). Target is not a directory.
- */
- if (argc > 1) {
- usage();
- exit(1);
- }
- if (!path_set(&from, *argv))
- exit(1);
- copy();
- }
- else {
- /*
- * Case (2). Target is a directory.
- */
- for (;; ++argv) {
- if (!path_set(&from, *argv))
- continue;
- if (!(old_to =
- path_append(&to, path_basename(&from), -1)))
- continue;
- copy();
- if (!--argc)
- break;
- path_restore(&to, old_to);
- }
- }
- exit(exit_val);
-}
-
-/* copy file or directory at "from" to "to". */
-static void
-copy()
-{
- struct stat from_stat, to_stat;
- int dne, statval;
-
- statval = statfcn(from.p_path, &from_stat);
- if (statval == -1) {
- err("%s: %s", from.p_path, strerror(errno));
- return;
- }
-
- /* not an error, but need to remember it happened */
- if (stat(to.p_path, &to_stat) == -1)
- dne = 1;
- else {
- if (to_stat.st_dev == from_stat.st_dev &&
- to_stat.st_ino == from_stat.st_ino) {
- (void)fprintf(stderr,
- "%s: %s and %s are identical (not copied).\n",
- progname, to.p_path, from.p_path);
- exit_val = 1;
- return;
- }
-
- if (!S_ISDIR(from_stat.st_mode) && S_ISDIR(to_stat.st_mode)) {
- (void)fprintf(stderr,
- "%s: %s: cannot overwrite directory with non-directory.\n",
- progname, to.p_path);
- exit_val = 1;
- return;
- }
- dne = 0;
- }
-
- switch(from_stat.st_mode & S_IFMT) {
- case S_IFLNK:
- copy_link(!dne);
- return;
- case S_IFDIR:
- if (!rflag && !orflag) {
- (void)fprintf(stderr,
- "%s: %s is a directory (not copied).\n",
- progname, from.p_path);
- exit_val = 1;
- return;
- }
- if (dne) {
- /*
- * If the directory doesn't exist, create the new
- * one with the from file mode plus owner RWX bits,
- * modified by the umask. Trade-off between being
- * able to write the directory (if from directory is
- * 555) and not causing a permissions race. If the
- * umask blocks owner writes cp fails.
- */
- if (mkdir(to.p_path, from_stat.st_mode|S_IRWXU) < 0) {
- err("%s: %s", to.p_path, strerror(errno));
- return;
- }
- }
- else if (!S_ISDIR(to_stat.st_mode)) {
- (void)fprintf(stderr, "%s: %s: not a directory.\n",
- progname, to.p_path);
- return;
- }
- copy_dir();
- /*
- * If not -p and directory didn't exist, set it to be the
- * same as the from directory, umodified by the umask;
- * arguably wrong, but it's been that way forever.
- */
- if (pflag)
- setfile(&from_stat, 0);
- else if (dne)
- (void)chmod(to.p_path, from_stat.st_mode);
- return;
- case S_IFCHR:
- case S_IFBLK:
- if (rflag) {
- copy_special(&from_stat, !dne);
- return;
- }
- break;
- case S_IFIFO:
- if (rflag) {
- copy_fifo(&from_stat, !dne);
- return;
- }
- break;
- }
- copy_file(&from_stat, dne);
-}
-
-static void
-copy_file(fs, dne)
- struct stat *fs;
- int dne;
-{
- static char buf[MAXBSIZE];
- register int from_fd, to_fd, rcount, wcount;
- struct stat to_stat;
- char *p;
-
- if ((from_fd = open(from.p_path, O_RDONLY, 0)) == -1) {
- err("%s: %s", from.p_path, strerror(errno));
- return;
- }
-
- /*
- * If the file exists and we're interactive, verify with the user.
- * If the file DNE, set the mode to be the from file, minus setuid
- * bits, modified by the umask; arguably wrong, but it makes copying
- * executables work right and it's been that way forever. (The
- * other choice is 666 or'ed with the execute bits on the from file
- * modified by the umask.)
- */
- if (!dne) {
- if (iflag) {
- int checkch, ch;
-
- (void)fprintf(stderr, "overwrite %s? ", to.p_path);
- checkch = ch = getchar();
- while (ch != '\n' && ch != EOF)
- ch = getchar();
- if (checkch != 'y' && checkch != 'Y') {
- (void)close(from_fd);
- return;
- }
- }
- to_fd = open(to.p_path, O_WRONLY|O_TRUNC, 0);
- } else
- to_fd = open(to.p_path, O_WRONLY|O_CREAT|O_TRUNC,
- fs->st_mode & ~(S_ISUID|S_ISGID));
-
- if (to_fd == -1) {
- err("%s: %s", to.p_path, strerror(errno));
- (void)close(from_fd);
- return;
- }
-
- /*
- * Mmap and write if less than 8M (the limit is so we don't totally
- * trash memory on big files. This is really a minor hack, but it
- * wins some CPU back.
- */
- if (fs->st_size <= 8 * 1048576) {
- if ((p = mmap(NULL, fs->st_size, PROT_READ,
- MAP_FILE, from_fd, (off_t)0)) == (char *)-1)
- err("%s: %s", from.p_path, strerror(errno));
- if (write(to_fd, p, fs->st_size) != fs->st_size)
- err("%s: %s", to.p_path, strerror(errno));
- if (munmap(p, fs->st_size) < 0)
- err("%s: %s", from.p_path, strerror(errno));
- } else {
- while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
- wcount = write(to_fd, buf, rcount);
- if (rcount != wcount || wcount == -1) {
- err("%s: %s", to.p_path, strerror(errno));
- break;
- }
- }
- if (rcount < 0)
- err("%s: %s", from.p_path, strerror(errno));
- }
- if (pflag)
- setfile(fs, to_fd);
- /*
- * If the source was setuid or setgid, lose the bits unless the
- * copy is owned by the same user and group.
- */
- else if (fs->st_mode & (S_ISUID|S_ISGID) && fs->st_uid == myuid)
- if (fstat(to_fd, &to_stat))
- err("%s: %s", to.p_path, strerror(errno));
-#define RETAINBITS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)
- else if (fs->st_gid == to_stat.st_gid && fchmod(to_fd,
- fs->st_mode & RETAINBITS & ~myumask))
- err("%s: %s", to.p_path, strerror(errno));
- (void)close(from_fd);
- if (close(to_fd))
- err("%s: %s", to.p_path, strerror(errno));
-}
-
-static void
-copy_dir()
-{
- struct stat from_stat;
- struct dirent *dp, **dir_list;
- register int dir_cnt, i;
- char *old_from, *old_to;
-
- dir_cnt = scandir(from.p_path, &dir_list, NULL, NULL);
- if (dir_cnt == -1) {
- (void)fprintf(stderr, "%s: can't read directory %s.\n",
- progname, from.p_path);
- exit_val = 1;
- }
-
- /*
- * Instead of handling directory entries in the order they appear
- * on disk, do non-directory files before directory files.
- * There are two reasons to do directories last. The first is
- * efficiency. Files tend to be in the same cylinder group as
- * their parent, whereas directories tend not to be. Copying files
- * all at once reduces seeking. Second, deeply nested tree's
- * could use up all the file descriptors if we didn't close one
- * directory before recursivly starting on the next.
- */
- /* copy files */
- for (i = 0; i < dir_cnt; ++i) {
- dp = dir_list[i];
- if (dp->d_namlen <= 2 && dp->d_name[0] == '.'
- && (dp->d_name[1] == NULL || dp->d_name[1] == '.'))
- goto done;
- if (!(old_from =
- path_append(&from, dp->d_name, (int)dp->d_namlen)))
- goto done;
-
- if (statfcn(from.p_path, &from_stat) < 0) {
- err("%s: %s", dp->d_name, strerror(errno));
- path_restore(&from, old_from);
- goto done;
- }
- if (S_ISDIR(from_stat.st_mode)) {
- path_restore(&from, old_from);
- continue;
- }
- if (old_to = path_append(&to, dp->d_name, (int)dp->d_namlen)) {
- copy();
- path_restore(&to, old_to);
- }
- path_restore(&from, old_from);
-done: dir_list[i] = NULL;
- free(dp);
- }
-
- /* copy directories */
- for (i = 0; i < dir_cnt; ++i) {
- dp = dir_list[i];
- if (!dp)
- continue;
- if (!(old_from =
- path_append(&from, dp->d_name, (int)dp->d_namlen))) {
- free(dp);
- continue;
- }
- if (!(old_to =
- path_append(&to, dp->d_name, (int)dp->d_namlen))) {
- free(dp);
- path_restore(&from, old_from);
- continue;
- }
- copy();
- free(dp);
- path_restore(&from, old_from);
- path_restore(&to, old_to);
- }
- free(dir_list);
-}
-
-static void
-copy_link(exists)
- int exists;
-{
- int len;
- char link[MAXPATHLEN];
-
- if ((len = readlink(from.p_path, link, sizeof(link))) == -1) {
- err("readlink: %s: %s", from.p_path, strerror(errno));
- return;
- }
- link[len] = '\0';
- if (exists && unlink(to.p_path)) {
- err("unlink: %s: %s", to.p_path, strerror(errno));
- return;
- }
- if (symlink(link, to.p_path)) {
- err("symlink: %s: %s", link, strerror(errno));
- return;
- }
-}
-
-static void
-copy_fifo(from_stat, exists)
- struct stat *from_stat;
- int exists;
-{
- if (exists && unlink(to.p_path)) {
- err("unlink: %s: %s", to.p_path, strerror(errno));
- return;
- }
- if (mkfifo(to.p_path, from_stat->st_mode)) {
- err("mkfifo: %s: %s", to.p_path, strerror(errno));
- return;
- }
- if (pflag)
- setfile(from_stat, 0);
-}
-
-static void
-copy_special(from_stat, exists)
- struct stat *from_stat;
- int exists;
-{
- if (exists && unlink(to.p_path)) {
- err("unlink: %s: %s", to.p_path, strerror(errno));
- return;
- }
- if (mknod(to.p_path, from_stat->st_mode, from_stat->st_rdev)) {
- err("mknod: %s: %s", to.p_path, strerror(errno));
- return;
- }
- if (pflag)
- setfile(from_stat, 0);
-}
-
-static void
-setfile(fs, fd)
- register struct stat *fs;
- int fd;
-{
- static struct timeval tv[2];
-
- fs->st_mode &= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
-
- tv[0].tv_sec = fs->st_atime;
- tv[1].tv_sec = fs->st_mtime;
- if (utimes(to.p_path, tv))
- err("utimes: %s: %s", to.p_path, strerror(errno));
- /*
- * Changing the ownership probably won't succeed, unless we're root
- * or POSIX_CHOWN_RESTRICTED is not set. Set uid/gid before setting
- * the mode; current BSD behavior is to remove all setuid bits on
- * chown. If chown fails, lose setuid/setgid bits.
- */
- if (fd ? fchown(fd, fs->st_uid, fs->st_gid) :
- chown(to.p_path, fs->st_uid, fs->st_gid)) {
- if (errno != EPERM)
- err("chown: %s: %s", to.p_path, strerror(errno));
- fs->st_mode &= ~(S_ISUID|S_ISGID);
- }
- if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode))
- err("chown: %s: %s", to.p_path, strerror(errno));
-}
-
-static void
-usage()
-{
- (void)fprintf(stderr,
-"usage: cp [-Rfhip] src target;\n cp [-Rfhip] src1 ... srcN directory\n");
- exit(1);
-}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "%s: ", progname);
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit_val = 1;
-}
View
52 bin/cp/extern.h
@@ -1,52 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)extern.h 5.3 (Berkeley) 10/27/91
- * $Id: extern.h,v 1.1 1993/08/07 03:14:57 mycroft Exp $
- */
-
-typedef struct {
- char *p_end; /* pointer to NULL at end of path */
- char p_path[MAXPATHLEN + 1]; /* pointer to the start of a path */
-} PATH_T;
-
-extern char *progname; /* program name */
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-void err __P((const char *fmt, ...));
-int path_set __P((PATH_T *, char *));
-char *path_append __P((PATH_T *, char *, int));
-char *path_basename __P((PATH_T *));
-void path_restore __P((PATH_T *, char *));
-__END_DECLS
View
146 bin/cp/path.c
@@ -1,146 +0,0 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-/*static char sccsid[] = "from: @(#)path.c 5.2 (Berkeley) 10/27/91";*/
-static char rcsid[] = "$Id: path.c,v 1.5 1993/08/07 03:14:59 mycroft Exp $";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <string.h>
-#include "extern.h"
-
-/*
- * These functions manipulate paths in PATH_T structures.
- *
- * They eliminate multiple slashes in paths when they notice them,
- * and keep the path non-slash terminated.
- *
- * Both path_set() and path_append() return 0 if the requested name
- * would be too long.
- */
-
-#define STRIP_TRAILING_SLASH(p) { \
- while ((p)->p_end > (p)->p_path && (p)->p_end[-1] == '/') \
- *--(p)->p_end = 0; \
-}
-
-/*
- * Move specified string into path. Convert "" to "." to handle BSD
- * semantics for a null path. Strip trailing slashes.
- */
-int
-path_set(p, string)
- register PATH_T *p;
- char *string;
-{
- if (strlen(string) > MAXPATHLEN) {
- err("%s: name too long", string);
- return(0);
- }
-
- (void)strcpy(p->p_path, string);
- p->p_end = p->p_path + strlen(p->p_path);
-
- if (p->p_path == p->p_end) {
- *p->p_end++ = '.';
- *p->p_end = 0;
- }
-
- STRIP_TRAILING_SLASH(p);
- return(1);
-}
-
-/*
- * Append specified string to path, inserting '/' if necessary. Return a
- * pointer to the old end of path for restoration.
- */
-char *
-path_append(p, name, len)
- register PATH_T *p;
- char *name;
- int len;
-{
- char *old;
-
- old = p->p_end;
- if (len == -1)
- len = strlen(name);
-
- /* The "+ 1" accounts for the '/' between old path and name. */
- if ((len + p->p_end - p->p_path + 1) > MAXPATHLEN) {
- err("%s/%s: name too long", p->p_path, name);
- return(0);
- }
-
- /*
- * This code should always be executed, since paths shouldn't
- * end in '/'.
- */
- if (p->p_end[-1] != '/') {
- *p->p_end++ = '/';
- *p->p_end = 0;
- }
-
- (void)strncat(p->p_end, name, len);
- p->p_end += len;
- *p->p_end = 0;
-
- STRIP_TRAILING_SLASH(p);
- return(old);
-}
-
-/*
- * Restore path to previous value. (As returned by path_append.)
- */
-void
-path_restore(p, old)
- PATH_T *p;
- char *old;
-{
- p->p_end = old;
- *p->p_end = 0;
-}
-
-/*
- * Return basename of path.
- */
-char *
-path_basename(p)
- PATH_T *p;
-{
- char *basename;
-
- basename = rindex(p->p_path, '/');
- return(basename ? basename + 1 : p->p_path);
-}
View
41 bin/csh/Makefile
@@ -1,41 +0,0 @@
-# from: @(#)Makefile 5.24 (Berkeley) 7/1/91
-# $Id: Makefile,v 1.5 1993/08/01 05:47:53 mycroft Exp $
-
-# C Shell with process control; VM/UNIX VAX Makefile
-# Bill Joy UC Berkeley; Jim Kulp IIASA, Austria
-#
-# To profile, put -DPROF in DEFS and -pg in CFLAGS, and recompile.
-
-PROG= csh
-CFLAGS+=-fstrength-reduce -DFILEC -DNLS -DSHORT_STRINGS -I.
-SRCS= alloc.c char.c const.c csh.c dir.c dol.c err.c exec.c exp.c file.c \
- func.c glob.c hist.c init.c lex.c misc.c parse.c print.c printf.c \
- proc.c sem.c set.c str.c time.c
-
-MAN1= csh.0
-MLINKS= csh.1 limit.1 csh.1 alias.1 csh.1 bg.1 csh.1 dirs.1 csh.1 fg.1 \
- csh.1 foreach.1 csh.1 history.1 csh.1 jobs.1 csh.1 popd.1 \
- csh.1 pushd.1 csh.1 rehash.1 csh.1 repeat.1 csh.1 suspend.1 \
- csh.1 stop.1 csh.1 source.1
-CLEANFILES+=err.h const.h
-
-const.h: err.h
-
-err.h: err.c
- @rm -f $@
- @echo '/* Do not edit this file, make creates it. */' > $@
- @echo '#ifndef _h_sh_err' >> $@
- @echo '#define _h_sh_err' >> $@
- egrep 'ERR_' ${.CURDIR}/$*.c | egrep '^#define' >> $@
- @echo '#endif /* _h_sh_err */' >> $@
-
-const.h: const.c
- @rm -f $@
- @echo '/* Do not edit this file, make creates it. */' > $@
- ${CC} -E ${CFLAGS} ${.CURDIR}/$*.c | egrep 'Char STR' | \
- sed -e 's/Char \([a-zA-Z0-9_]*\)\(.*\)/extern Char \1[];/' | \
- sort >> $@
-
-.depend alloc.o: const.h err.h
-
-.include <bsd.prog.mk>
View
543 bin/csh/alloc.c
@@ -1,543 +0,0 @@
-/*-
- * Copyright (c) 1983, 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-/*static char sccsid[] = "from: @(#)alloc.c 5.8 (Berkeley) 6/8/91";*/
-static char rcsid[] = "$Id: alloc.c,v 1.4 1993/08/01 19:00:53 mycroft Exp $";
-#endif /* not lint */
-
-/*
- * tc.alloc.c from malloc.c (Caltech) 2/21/82
- * Chris Kingsley, kingsley@cit-20.
- *
- * This is a very fast storage allocator. It allocates blocks of a small
- * number of different sizes, and keeps free lists of each size. Blocks that
- * don't exactly fit are passed up to the next larger size. In this
- * implementation, the available sizes are 2^n-4 (or 2^n-12) bytes long.
- * This is designed for use in a program that uses vast quantities of memory,
- * but bombs when it runs out.
- */
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#if __STDC__
-# include <stdarg.h>
-#else
-# include <varargs.h>
-#endif
-
-#include "csh.h"
-#include "extern.h"
-
-char *memtop = NULL; /* PWP: top of current memory */
-char *membot = NULL; /* PWP: bottom of allocatable memory */
-
-#ifndef SYSMALLOC
-
-#undef RCHECK
-#undef DEBUG
-
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-
-/*
- * The overhead on a block is at least 4 bytes. When free, this space
- * contains a pointer to the next free block, and the bottom two bits must
- * be zero. When in use, the first byte is set to MAGIC, and the second
- * byte is the size index. The remaining bytes are for alignment.
- * If range checking is enabled and the size of the block fits
- * in two bytes, then the top two bytes hold the size of the requested block
- * plus the range checking words, and the header word MINUS ONE.
- */
-
-#define ROUNDUP 7
-
-#define ALIGN(a) (((a) + ROUNDUP) & ~ROUNDUP)
-
-union overhead {
- union overhead *ov_next; /* when free */
- struct {
- u_char ovu_magic; /* magic number */
- u_char ovu_index; /* bucket # */
-#ifdef RCHECK
- u_short ovu_size; /* actual block size */
- u_int ovu_rmagic; /* range magic number */
-#endif
- } ovu;
-#define ov_magic ovu.ovu_magic
-#define ov_index ovu.ovu_index
-#define ov_size ovu.ovu_size
-#define ov_rmagic ovu.ovu_rmagic
-};
-
-#define MAGIC 0xfd /* magic # on accounting info */
-#define RMAGIC 0x55555555 /* magic # on range info */
-#ifdef RCHECK
-#define RSLOP sizeof (u_int)
-#else
-#define RSLOP 0
-#endif
-
-/*
- * nextf[i] is the pointer to the next free block of size 2^(i+3). The
- * smallest allocatable block is 8 bytes. The overhead information
- * precedes the data area returned to the user.
- */
-#define NBUCKETS 30
-static union overhead *nextf[NBUCKETS];
-
-static int findbucket __P((union overhead *, int));
-static void morecore __P((int));
-
-/*
- * nmalloc[i] is the difference between the number of mallocs and frees
- * for a given block size.
- */
-static u_int nmalloc[NBUCKETS];
-
-
-#ifdef DEBUG
-#define CHECK(a, str, p) \
- if (a) { \
- xprintf(str, p); \
- xprintf("memtop = %lx membot = %lx.\n", memtop, membot); \
- abort(); \
- } \
- else
-#else
-#define CHECK(a, str, p) \
- if (a) { \
- xprintf(str, p); \
- xprintf("memtop = %lx membot = %lx.\n", memtop, membot); \
- return; \
- } \
- else
-#endif
-
-ptr_t
-malloc(nbytes)
- register size_t nbytes;
-{
-#ifndef lint
- register union overhead *p;
- register int bucket = 0;
- register unsigned shiftr;
-
- /*
- * Convert amount of memory requested into closest block size stored in
- * hash buckets which satisfies request. Account for space used per block
- * for accounting.
- */
- nbytes = ALIGN(ALIGN(sizeof(union overhead)) + nbytes + RSLOP);
- shiftr = (nbytes - 1) >> 2;
-
- /* apart from this loop, this is O(1) */
- while (shiftr >>= 1)
- bucket++;
- /*
- * If nothing in hash bucket right now, request more memory from the
- * system.
- */
- if (nextf[bucket] == NULL)
- morecore(bucket);
- if ((p = (union overhead *) nextf[bucket]) == NULL) {
- child++;
-#ifndef DEBUG
- stderror(ERR_NOMEM);
-#else
- showall();
- xprintf("nbytes=%d: Out of memory\n", nbytes);
- abort();
-#endif
- /* fool lint */
- return ((ptr_t) 0);
- }
- /* remove from linked list */
- nextf[bucket] = nextf[bucket]->ov_next;
- p->ov_magic = MAGIC;
- p->ov_index = bucket;
- nmalloc[bucket]++;
-#ifdef RCHECK
- /*
- * Record allocated size of block and bound space with magic numbers.
- */
- if (nbytes <= 0x10000)
- p->ov_size = nbytes - 1;
- p->ov_rmagic = RMAGIC;
- *((u_int *) (((caddr_t) p) + nbytes - RSLOP)) = RMAGIC;
-#endif
- return ((ptr_t) (((caddr_t) p) + ALIGN(sizeof(union overhead))));
-#else
- if (nbytes)
- return ((ptr_t) 0);
- else
- return ((ptr_t) 0);
-#endif /* !lint */
-}
-
-#ifndef lint
-/*
- * Allocate more memory to the indicated bucket.
- */
-static void
-morecore(bucket)
- register int bucket;
-{
- register union overhead *op;
- register int rnu; /* 2^rnu bytes will be requested */
- register int nblks; /* become nblks blocks of the desired size */
- register int siz;
-
- if (nextf[bucket])
- return;
- /*
- * Insure memory is allocated on a page boundary. Should make getpageize
- * call?
- */
- op = (union overhead *) sbrk(0);
- memtop = (char *) op;
- if (membot == NULL)
- membot = memtop;
- if ((int) op & 0x3ff) {
- memtop = (char *) sbrk(1024 - ((int) op & 0x3ff));
- memtop += 1024 - ((int) op & 0x3ff);
- }
-
- /* take 2k unless the block is bigger than that */
- rnu = (bucket <= 8) ? 11 : bucket + 3;
- nblks = 1 << (rnu - (bucket + 3)); /* how many blocks to get */
- if (rnu < bucket)
- rnu = bucket;
- memtop = (char *) sbrk(1 << rnu); /* PWP */
- op = (union overhead *) memtop;
- memtop += 1 << rnu;
- /* no more room! */
- if ((int) op == -1)
- return;
- /*
- * Round up to minimum allocation size boundary and deduct from block count
- * to reflect.
- */
- if (((u_int) op) & ROUNDUP) {
- op = (union overhead *) (((u_int) op + (ROUNDUP + 1)) & ~ROUNDUP);
- nblks--;
- }
- /*
- * Add new memory allocated to that on free list for this hash bucket.
- */
- nextf[bucket] = op;
- siz = 1 << (bucket + 3);
- while (--nblks > 0) {
- op->ov_next = (union overhead *) (((caddr_t) op) + siz);
- op = (union overhead *) (((caddr_t) op) + siz);
- }
-}
-
-#endif
-
-#ifdef sun
-int
-#else
-void
-#endif
-free(cp)
- ptr_t cp;
-{
-#ifndef lint
- register int size;
- register union overhead *op;
-
- if (cp == NULL)
- return;
- CHECK(!memtop || !membot, "free(%lx) called before any allocations.", cp);
- CHECK(cp > (ptr_t) memtop, "free(%lx) above top of memory.", cp);
- CHECK(cp < (ptr_t) membot, "free(%lx) above top of memory.", cp);
- op = (union overhead *) (((caddr_t) cp) - ALIGN(sizeof(union overhead)));
- CHECK(op->ov_magic != MAGIC, "free(%lx) bad block.", cp);
-
-#ifdef RCHECK
- if (op->ov_index <= 13)
- CHECK(*(u_int *) ((caddr_t) op + op->ov_size + 1 - RSLOP) != RMAGIC,
- "free(%lx) bad range check.", cp);
-#endif
- CHECK(op->ov_index >= NBUCKETS, "free(%lx) bad block index.", cp);
- size = op->ov_index;
- op->ov_next = nextf[size];
- nextf[size] = op;
-
- nmalloc[size]--;
-
-#else
- if (cp == NULL)
- return;
-#endif
-}
-
-ptr_t
-calloc(i, j)
- size_t i, j;
-{
-#ifndef lint
- register char *cp, *scp;
-
- i *= j;
- scp = cp = (char *) xmalloc((size_t) i);
- if (i != 0)
- do
- *cp++ = 0;
- while (--i);
-
- return (scp);
-#else
- if (i && j)
- return ((ptr_t) 0);
- else
- return ((ptr_t) 0);
-#endif
-}
-
-/*
- * When a program attempts "storage compaction" as mentioned in the
- * old malloc man page, it realloc's an already freed block. Usually
- * this is the last block it freed; occasionally it might be farther
- * back. We have to search all the free lists for the block in order
- * to determine its bucket: 1st we make one pass thru the lists
- * checking only the first block in each; if that fails we search
- * ``realloc_srchlen'' blocks in each list for a match (the variable
- * is extern so the caller can modify it). If that fails we just copy
- * however many bytes was given to realloc() and hope it's not huge.
- */
-#ifndef lint
-int realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */
-
-#endif /* lint */
-
-ptr_t
-realloc(cp, nbytes)
- ptr_t cp;
- size_t nbytes;
-{
-#ifndef lint
- register u_int onb;
- union overhead *op;
- char *res;
- register int i;
- int was_alloced = 0;
-
- if (cp == NULL)
- return (malloc(nbytes));
- op = (union overhead *) (((caddr_t) cp) - ALIGN(sizeof(union overhead)));
- if (op->ov_magic == MAGIC) {
- was_alloced++;
- i = op->ov_index;
- }
- else
- /*
- * Already free, doing "compaction".
- *
- * Search for the old block of memory on the free list. First, check the
- * most common case (last element free'd), then (this failing) the last
- * ``realloc_srchlen'' items free'd. If all lookups fail, then assume
- * the size of the memory block being realloc'd is the smallest
- * possible.
- */
- if ((i = findbucket(op, 1)) < 0 &&
- (i = findbucket(op, realloc_srchlen)) < 0)
- i = 0;
-
- onb = ALIGN(nbytes + ALIGN(sizeof(union overhead)) + RSLOP);
-
- /* avoid the copy if same size block */
- if (was_alloced && (onb < (1 << (i + 3))) && (onb >= (1 << (i + 2))))
- return ((ptr_t) cp);
- if ((res = malloc(nbytes)) == NULL)
- return ((ptr_t) 0);
- if (cp != res) /* common optimization */
- bcopy(cp, res, nbytes);
- if (was_alloced)
- free(cp);
- return (res);
-#else
- if (cp && nbytes)
- return ((ptr_t) 0);
- else
- return ((ptr_t) 0);
-#endif /* !lint */
-}
-
-
-
-#ifndef lint
-/*
- * Search ``srchlen'' elements of each free list for a block whose
- * header starts at ``freep''. If srchlen is -1 search the whole list.
- * Return bucket number, or -1 if not found.
- */
-static int
-findbucket(freep, srchlen)
- union overhead *freep;
- int srchlen;
-{
- register union overhead *p;
- register int i, j;
-
- for (i = 0; i < NBUCKETS; i++) {
- j = 0;
- for (p = nextf[i]; p && j != srchlen; p = p->ov_next) {
- if (p == freep)
- return (i);
- j++;
- }
- }
- return (-1);
-}
-
-#endif
-
-
-#else /* SYSMALLOC */
-
-/**
- ** ``Protected versions'' of malloc, realloc, calloc, and free
- **
- ** On many systems:
- **
- ** 1. malloc(0) is bad
- ** 2. free(0) is bad
- ** 3. realloc(0, n) is bad
- ** 4. realloc(n, 0) is bad
- **
- ** Also we call our error routine if we run out of memory.
- **/
-char *
-Malloc(n)
- size_t n;
-{
- ptr_t ptr;
-
- n = n ? n : 1;
-
- if ((ptr = malloc(n)) == (ptr_t) 0) {
- child++;
- stderror(ERR_NOMEM);
- }
- return ((char *) ptr);
-}
-
-char *
-Realloc(p, n)
- ptr_t p;
- size_t n;
-{
- ptr_t ptr;
-
- n = n ? n : 1;
- if ((ptr = (p ? realloc(p, n) : malloc(n))) == (ptr_t) 0) {
- child++;
- stderror(ERR_NOMEM);
- }
- return ((char *) ptr);
-}
-
-char *
-Calloc(s, n)
- size_t s, n;
-{
- char *sptr;
- ptr_t ptr;
-
- n *= s;
- n = n ? n : 1;
- if ((ptr = malloc(n)) == (ptr_t) 0) {
- child++;
- stderror(ERR_NOMEM);
- }
-
- sptr = (char *) ptr;
- if (n != 0)
- do
- *sptr++ = 0;
- while (--n);
-
- return ((char *) ptr);
-}
-
-void
-Free(p)
- ptr_t p;
-{
- if (p)
- free(p);
-}
-
-#endif /* SYSMALLOC */
-
-/*
- * mstats - print out statistics about malloc
- *
- * Prints two lines of numbers, one showing the length of the free list
- * for each size category, the second showing the number of mallocs -
- * frees for each size category.
- */
-void
-showall()
-{
-#ifndef SYSMALLOC
- register int i, j;
- register union overhead *p;