9016d288f1
We've already seen the issue with echo(1): Before we changed it to ignore "--", the command $ echo -- did not work as expected. Given POSIX mandated this and makes most sense, in the interest of consistency the other tools need to be streamlined for that as well. Looking at yes(1) for instance, there's no reason to skip "--" in the argument list. We do not have long options like GNU does and there's no reason to tinker with that here. The majority of tools changed are ones taking lists of arguments or only a single one. There's no reason why dirname should "fail" on "--". In the end, this is a valid name. The practice of hand-holding the user was established with the GNU coreutils. "--help" and "--version" long-options are a disgrace to what could've been done properly with manpages.
34 lines
585 B
C
34 lines
585 B
C
/* See LICENSE file for copyright and license details. */
|
|
#include <stdio.h>
|
|
|
|
#include "text.h"
|
|
#include "util.h"
|
|
|
|
static void
|
|
usage(void)
|
|
{
|
|
eprintf("usage: %s file\n", argv0);
|
|
}
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
FILE *fp, *tmpfp;
|
|
|
|
argv0 = argv[0], argc--, argv++;
|
|
|
|
if (argc != 1)
|
|
usage();
|
|
|
|
if (!(tmpfp = tmpfile()))
|
|
eprintf("tmpfile:");
|
|
concat(stdin, "<stdin>", tmpfp, "<tmpfile>");
|
|
rewind(tmpfp);
|
|
|
|
if (!(fp = fopen(argv[0], "w")))
|
|
eprintf("fopen %s:", argv[0]);
|
|
concat(tmpfp, "<tmpfile>", fp, argv[0]);
|
|
|
|
return !!(fshut(fp, argv[0]) + fshut(tmpfp, "<tmpfile>"));
|
|
}
|