Tar compiles on BSD, thanks Roberto E. Vargas Caballero. Also remove tons of trailing whitespace.

This commit is contained in:
David Galos 2013-07-20 01:27:42 -04:00
parent 43c4213631
commit 9f8deb4b23
25 changed files with 78 additions and 85 deletions

View File

@ -9,8 +9,8 @@ MIT/X Consortium License
© 2011 Random832 <random832@fastmail.us> © 2011 Random832 <random832@fastmail.us>
© 2012 William Haddon <william@haddonthethird.net> © 2012 William Haddon <william@haddonthethird.net>
© 2012 Kurt H. Maier <khm@intma.in> © 2012 Kurt H. Maier <khm@intma.in>
© 2012 Christoph Lohmann <20h@r-36.net> © 2012 Christoph Lohmann <20h@r-36.net>
© 2012 David Galos <galosd83@students.rowan.edu> © 2012 David Galos <galosd83@students.rowan.edu>
© 2012 Robert Ransom <rransom.8774@gmail.com> © 2012 Robert Ransom <rransom.8774@gmail.com>
© 2013 Jakob Kramer <jakob.kramer@gmx.de> © 2013 Jakob Kramer <jakob.kramer@gmx.de>

View File

@ -8,13 +8,13 @@ chgrp \- change the file group ownership
.I file... .I file...
.SH DESCRIPTION .SH DESCRIPTION
.B chgrp .B chgrp
sets the group id of the files specified by sets the group id of the files specified by
.IR file .IR file
to the gid of the group named to the gid of the group named
.IR group. .IR group.
If the If the
.IR R .IR R
flag is specified, this process is recursively applied to flag is specified, this process is recursively applied to
everything in everything in
.IR file. .IR file.

View File

@ -9,15 +9,15 @@ chroot \- invoke a command with a different root directory
.SH DESCRIPTION .SH DESCRIPTION
.B chroot .B chroot
runs runs
.IR command .IR command
after changing the root directory to after changing the root directory to
.IR dir .IR dir
with the with the
.B chroot .B chroot
system call, and changing the working directory to the new root. system call, and changing the working directory to the new root.
If If
.IR command .IR command
is not specified, an interactive shell is started in the new root. is not specified, an interactive shell is started in the new root.

View File

@ -8,16 +8,16 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
char *shell[] = {"/bin/sh", "-i", NULL}; char *shell[] = {"/bin/sh", "-i", NULL};
if(getenv("SHELL")) if(getenv("SHELL"))
shell[0] = getenv("SHELL"); shell[0] = getenv("SHELL");
if(argc < 2) if(argc < 2)
usage(); usage();
if(chroot(argv[1]) == -1) if(chroot(argv[1]) == -1)
eprintf("chroot: '%s':", argv[1]); eprintf("chroot: '%s':", argv[1]);
if(chdir("/") == -1) if(chdir("/") == -1)
eprintf("chroot:"); eprintf("chroot:");
@ -26,7 +26,7 @@ main(int argc, char **argv)
} else { } else {
execvp(argv[2], argv+2); execvp(argv[2], argv+2);
} }
eprintf("chroot: '%s':", argv[2]); eprintf("chroot: '%s':", argv[2]);
return 1; return 1;
} }

2
chvt.1
View File

@ -6,6 +6,6 @@ chvt \- change foreground virtual terminal
.I N .I N
.SH DESCRIPTION .SH DESCRIPTION
.B chvt .B chvt
brings /dev/ttyN to the foreground. This has the brings /dev/ttyN to the foreground. This has the
same effect as Ctrl-Alt-FN. same effect as Ctrl-Alt-FN.

4
cp.c
View File

@ -9,7 +9,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct stat st; struct stat st;
ARGBEGIN { ARGBEGIN {
case 'r': case 'r':
cp_rflag = true; cp_rflag = true;
@ -17,7 +17,7 @@ main(int argc, char *argv[])
default: default:
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} ARGEND; } ARGEND;
if(argc > 2 && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode))) if(argc > 2 && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode)))
eprintf("%s: not a directory\n", argv[argc-1]); eprintf("%s: not a directory\n", argv[argc-1]);
enmasse(argc, argv, cp); enmasse(argc, argv, cp);

12
env.1
View File

@ -4,23 +4,23 @@ env \- modify the environment, then print it or run a command.
.SH SYNOPSIS .SH SYNOPSIS
.B env .B env
.RB [ \-i ] .RB [ \-i ]
.RB [ \-u .RB [ \-u
.IR name ]... .IR name ]...
.RI [ name=value ]... .RI [ name=value ]...
.RI [ cmd .RI [ cmd
.RI [ arg ...]] .RI [ arg ...]]
.SH DESCRIPTION .SH DESCRIPTION
.B env .B env
removes part of the environment according to the flags, then adds or removes part of the environment according to the flags, then adds or
sets each variable specified by sets each variable specified by
.IR name .IR name
to equal to equal
.IR value . .IR value .
If If
.IR cmd .IR cmd
is given, it is executed in this new environment; otherwise, the is given, it is executed in this new environment; otherwise, the
modified environment is printed to standard out. modified environment is printed to standard out.
.SH OPTIONS .SH OPTIONS

2
env.c
View File

@ -33,7 +33,7 @@ main(int argc, char **argv)
} }
while(environ && *environ) while(environ && *environ)
printf("%s\n", *environ++); printf("%s\n", *environ++);
return 0; return 0;
} }

View File

@ -21,7 +21,7 @@ and minor number
.IR minor . .IR minor .
.IR type .IR type
specifies what kind of special file will be created, specifies what kind of special file will be created,
and must be one of: and must be one of:
.TP .TP
.BR u \ or\ c .BR u \ or\ c
@ -33,7 +33,7 @@ A block device.
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-m "mode" .B \-m "mode"
Set the mode of the new file based on the octal value of Set the mode of the new file based on the octal value of
.IR mode . .IR mode .
.SH SEE ALSO .SH SEE ALSO

6
nice.1
View File

@ -10,9 +10,9 @@ nice \- invoke a utility with an altered nice value
.B nice .B nice
invokes invokes
.IR command .IR command
with a nice value equal to the current nice value plus with a nice value equal to the current nice value plus
.IR inc, .IR inc,
which defaults to 10 if unspecified. which defaults to 10 if unspecified.
.SH SEE ALSO .SH SEE ALSO
.IR renice (1) nice (2) .IR renice (1) nice (2)

16
paste.1
View File

@ -22,7 +22,7 @@ of
concatenates the corresponding lines of the input files. concatenates the corresponding lines of the input files.
The newline of every line except the line from the last input file is The newline of every line except the line from the last input file is
replaced with a tab. replaced with a tab.
If an end-of-file condition is detected on one or more input files, If an end-of-file condition is detected on one or more input files,
but not all input files, but not all input files,
.B paste .B paste
behaves as though empty lines were read from the files on which behaves as though empty lines were read from the files on which
@ -35,17 +35,17 @@ option is specified.
unless a backslash character appears in unless a backslash character appears in
.I list .I list
each character is an element specifying a delimiter. each character is an element specifying a delimiter.
If a backslash character appears, that and one or more characters If a backslash character appears, that and one or more characters
following it are an element specifying a delimiter. following it are an element specifying a delimiter.
These elements specify one or more characters to use, These elements specify one or more characters to use,
instead of the default tab, to replace the newline of the input instead of the default tab, to replace the newline of the input
lines. The elements in lines. The elements in
.I list .I list
are used circularly; that is, when the are used circularly; that is, when the
.I list .I list
is exhausted the first element from the list is reused. is exhausted the first element from the list is reused.
When the When the
.B \-s .B \-s
option is specified, the last newline in a file is not be modified. option is specified, the last newline in a file is not be modified.
The delimiter is reset to the first element of list after each file The delimiter is reset to the first element of list after each file
operand is processed. operand is processed.
@ -69,9 +69,9 @@ If Any other characters follow the backslash, results are unspecified.
.RE .RE
.TP .TP
.B \-s .B \-s
concatenate all of the lines of each separate input file in command line concatenate all of the lines of each separate input file in command line
order. The newline of every line except the last line in each input file order. The newline of every line except the last line in each input file
are replaced with the tab, unless otherwise specified by the are replaced with the tab, unless otherwise specified by the
.B \-d .B \-d
option. option.
.PP .PP

View File

@ -7,12 +7,12 @@ printenv \- print out the environment or the values of specific variables.
.SH DESCRIPTION .SH DESCRIPTION
.B printenv .B printenv
prints the entire environment as key=values pairs when prints the entire environment as key=values pairs when
no no
.IR var .IR var
is specified. Otherwise, in the order specified, is specified. Otherwise, in the order specified,
.B printenv .B printenv
prints the value only of each prints the value only of each
.IR var, .IR var,
one per line. one per line.
.SH SEE ALSO .SH SEE ALSO

View File

@ -20,7 +20,7 @@ The
utility requests that the nice values of one or more utility requests that the nice values of one or more
running processes be changed. By default, the applicable processes running processes be changed. By default, the applicable processes
are specified by their process IDs. When a process group is specified are specified by their process IDs. When a process group is specified
(see (see
.B -g .B -g
), the request applies to all processes in the process group. If the ), the request applies to all processes in the process group. If the
requested increment would raise or lower the nice value of the requested increment would raise or lower the nice value of the

View File

@ -18,8 +18,8 @@ will be successful, but
.nf .nf
rmdir foo foo/bar rmdir foo foo/bar
.fi .fi
will only succeed in removing will only succeed in removing
.BR foo/bar. .BR foo/bar.
.SH SEE ALSO .SH SEE ALSO
.IR rm (1) rmdir (2) unlink (1) unlink (2) .IR rm (1) rmdir (2) unlink (1) unlink (2)

6
seq.1
View File

@ -2,7 +2,7 @@
.SH NAME .SH NAME
seq \- print a sequence of numbers seq \- print a sequence of numbers
.SH SYNOPSIS .SH SYNOPSIS
.B seq .B seq
.RB [ \-w ] .RB [ \-w ]
.RB [ \-f .RB [ \-f
.IR fmt ] .IR fmt ]
@ -12,8 +12,8 @@ seq \- print a sequence of numbers
.RI [ step ]] .RI [ step ]]
.IR end .IR end
.SH DESCRIPTION .SH DESCRIPTION
.B seq .B seq
will print a sequence of numbers from will print a sequence of numbers from
.I start .I start
(default 1) to (default 1) to
.IR end , .IR end ,

20
split.1
View File

@ -4,18 +4,18 @@ split \- split up a file
.SH SYNOPSIS .SH SYNOPSIS
.B split .B split
.RB [ \-d ] .RB [ \-d ]
.RB [ \-a .RB [ \-a
.IR len ] .IR len ]
.RB [ \-b .RB [ \-b
.RI [ bytes [k|m|g]]] .RI [ bytes [k|m|g]]]
.RB [ \-l .RB [ \-l
.RI [ lines ]] .RI [ lines ]]
.RI [ input .RI [ input
.RI [ prefix ]] .RI [ prefix ]]
.SH DESCRIPTION .SH DESCRIPTION
.B split .B split
Reads a file, splitting it into smaller files, every Reads a file, splitting it into smaller files, every
.IR bytes .IR bytes
bytes bytes
or or
@ -23,9 +23,9 @@ or
lines. If lines. If
.B split .B split
runs out of filenames before all the data can be written, it stops at the runs out of filenames before all the data can be written, it stops at the
last valid filename, leaving all the written data on the disk. last valid filename, leaving all the written data on the disk.
The The
.IR b .IR b
and and
.IR l .IR l
@ -38,19 +38,19 @@ Use decimal suffixes rather than alphabetical.
.TP .TP
.B \-a "len" .B \-a "len"
Set the suffix length to Set the suffix length to
.IR len .IR len
characters long. characters long.
.TP .TP
.B \-b [bytes[k|m|g]] .B \-b [bytes[k|m|g]]
Start a new file every Start a new file every
.IR bytes .IR bytes
bytes. The units k, m, and g are case insensitive, and powers of 2, not 10. bytes. The units k, m, and g are case insensitive, and powers of 2, not 10.
.TP .TP
.B \-l [lines] .B \-l [lines]
Start a new file every Start a new file every
.IR lines .IR lines
lines. lines.

View File

@ -12,7 +12,7 @@ static void usage(void);
static int base = 26, start = 'a'; static int base = 26, start = 'a';
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int plen, slen = 2; int plen, slen = 2;
@ -36,7 +36,7 @@ main(int argc, char **argv)
tmp = ARGF(); tmp = ARGF();
if(tmp == NULL) if(tmp == NULL)
break; break;
size = strtoull(tmp, &end, 10); size = strtoull(tmp, &end, 10);
if(*end == '\0') if(*end == '\0')
break; break;

8
sync.1
View File

@ -1,13 +1,13 @@
.TH SYNC 1 sbase\-VERSION .TH SYNC 1 sbase\-VERSION
.SH NAME .SH NAME
sync \- flush disk cache sync \- flush disk cache
.SH SYNOPSIS .SH SYNOPSIS
.B sync .B sync
.SH DESCRIPTION .SH DESCRIPTION
.B sync .B sync
invokes invokes
.IR sync(2) .IR sync(2)
to flush all unwritten changes to the disk. This is to flush all unwritten changes to the disk. This is
usually done before shutting down, rebooting or halting. usually done before shutting down, rebooting or halting.
.SH SEE ALSO .SH SEE ALSO

10
tar.1
View File

@ -27,11 +27,11 @@ tar \- create, list or extract a tape archive
.B tar .B tar
.RB [ \-C .RB [ \-C
.IR dir ] .IR dir ]
.B x|tf .B x|tf
.I tarfile .I tarfile
.SH DESCRIPTION .SH DESCRIPTION
.B tar .B tar
is the standard file archiver. Generally the archives is the standard file archiver. Generally the archives
created with it are further compressed. created with it are further compressed.
.SH OPTIONS .SH OPTIONS
@ -42,9 +42,9 @@ extract tarball from stdin
.B t .B t
list all files in tarball from stdin list all files in tarball from stdin
.TP .TP
.BI c\ path .BI c\ path
creates tarball from creates tarball from
.I path .I path
and prints it to stdout and prints it to stdout
.TP .TP
.BI f\ tarfile .BI f\ tarfile

17
tar.c
View File

@ -40,7 +40,6 @@ enum Type {
}; };
static void putoctal(char *, unsigned, int); static void putoctal(char *, unsigned, int);
static int strlcpy(char *, const char *, int n);
static int archive(const char *, const struct stat *, int); static int archive(const char *, const struct stat *, int);
static int unarchive(char *, int, char[Blksiz]); static int unarchive(char *, int, char[Blksiz]);
static int print(char *, int , char[Blksiz]); static int print(char *, int , char[Blksiz]);
@ -142,12 +141,6 @@ putoctal(char *dst, unsigned num, int n)
snprintf(dst, n, "%.*o", n-1, num); snprintf(dst, n, "%.*o", n-1, num);
} }
int
strlcpy(char *dst, const char *src, int n)
{
return snprintf(dst, n, "%s", src);
}
int int
archive(const char* path, const struct stat* sta, int type) archive(const char* path, const struct stat* sta, int type)
{ {
@ -166,7 +159,7 @@ archive(const char* path, const struct stat* sta, int type)
gr = getgrgid(st.st_gid); gr = getgrgid(st.st_gid);
memset(b, 0, sizeof b); memset(b, 0, sizeof b);
strlcpy (h->name, path, sizeof h->name); snprintf(h->name, sizeof h->name, "%s", path);
putoctal(h->mode, (unsigned)st.st_mode&0777, sizeof h->mode); putoctal(h->mode, (unsigned)st.st_mode&0777, sizeof h->mode);
putoctal(h->uid, (unsigned)st.st_uid, sizeof h->uid); putoctal(h->uid, (unsigned)st.st_uid, sizeof h->uid);
putoctal(h->gid, (unsigned)st.st_gid, sizeof h->gid); putoctal(h->gid, (unsigned)st.st_gid, sizeof h->gid);
@ -174,8 +167,8 @@ archive(const char* path, const struct stat* sta, int type)
putoctal(h->mtime, (unsigned)st.st_mtime, sizeof h->mtime); putoctal(h->mtime, (unsigned)st.st_mtime, sizeof h->mtime);
memcpy(h->magic, "ustar", sizeof h->magic); memcpy(h->magic, "ustar", sizeof h->magic);
memcpy(h->version, "00", sizeof h->version); memcpy(h->version, "00", sizeof h->version);
strlcpy(h->uname, pw->pw_name, sizeof h->uname); snprintf(h->uname, sizeof h->uname, "%s", pw->pw_name);
strlcpy(h->gname, gr->gr_name, sizeof h->gname); snprintf(h->gname, sizeof h->gname, "%s", gr->gr_name);
mode = st.st_mode; mode = st.st_mode;
if(S_ISREG(mode)) { if(S_ISREG(mode)) {
@ -229,7 +222,7 @@ unarchive(char *fname, int l, char b[Blksiz])
break; break;
case HARDLINK: case HARDLINK:
case SYMLINK: case SYMLINK:
strlcpy(lname, h->link, sizeof lname); snprintf(lname, sizeof lname, "%s", h->link);
if(!((h->type == HARDLINK) ? link : symlink)(lname, fname)) if(!((h->type == HARDLINK) ? link : symlink)(lname, fname))
perror(fname); perror(fname);
break; break;
@ -291,7 +284,7 @@ xt(int (*fn)(char*, int, char[Blksiz]))
Header *h = (void*)b; Header *h = (void*)b;
while(fread(b, Blksiz, 1, tarfile) && h->name[0] != '\0') { while(fread(b, Blksiz, 1, tarfile) && h->name[0] != '\0') {
strlcpy(fname, h->name, sizeof fname); snprintf(fname, sizeof fname, "%s", h->name);
fn(fname, strtol(h->size, 0, 8), b); fn(fname, strtol(h->size, 0, 8), b);
} }
} }

View File

@ -6,7 +6,7 @@ unlink \- call the unlink function
.RB file .RB file
.SH DESCRIPTION .SH DESCRIPTION
.B unlink .B unlink
calls the calls the
.IR unlink .IR unlink
function on function on
.IR file. .IR file.

4
wc.c
View File

@ -19,7 +19,7 @@ main(int argc, char *argv[])
{ {
FILE *fp; FILE *fp;
int i; int i;
ARGBEGIN { ARGBEGIN {
case 'c': case 'c':
cmode = 'c'; cmode = 'c';
@ -36,7 +36,7 @@ main(int argc, char *argv[])
default: default:
eprintf("usage: %s [-clmw] [files...]\n", argv0); eprintf("usage: %s [-clmw] [files...]\n", argv0);
} ARGEND; } ARGEND;
if (argc == 0) { if (argc == 0) {
wc(stdin, NULL); wc(stdin, NULL);
} else { } else {

2
who.1
View File

@ -6,7 +6,7 @@ who \- print who has logged on
.SH DESCRIPTION .SH DESCRIPTION
.B who .B who
prints a list of who has logged on, their controlling tty, and the prints a list of who has logged on, their controlling tty, and the
time at which they logged on. time at which they logged on.
.SH BUGS .SH BUGS

2
who.c
View File

@ -33,7 +33,7 @@ main(int argc, char **argv)
return 0; return 0;
} }
void void
usage(void) usage(void)
{ {
eprintf("usage: who\n"); eprintf("usage: who\n");

6
yes.1
View File

@ -1,10 +1,10 @@
.TH YES 1 sbase\-VERSION .TH YES 1 sbase\-VERSION
.SH NAME .SH NAME
yes \- output a string repeatedly yes \- output a string repeatedly
.SH SYNOPSIS .SH SYNOPSIS
.B yes .B yes
.RB [ string ... ] .RB [ string ... ]
.SH DESCRIPTION .SH DESCRIPTION
.B yes .B yes
will repeatedly output 'y' or the strings specified. will repeatedly output 'y' or the strings specified.