diff options
author | Bryan Drewery <bryan@shatow.net> | 2017-07-31 20:04:36 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2017-07-31 20:04:36 +0300 |
commit | 0270d74cfd4573e57973dc9b423f287aea8e4c68 (patch) | |
tree | 7a33c5b60307a1d25c105cea724e72fd3fee338a /src/poudriere-sh | |
parent | f6b85702ad09b0c36fafcb84d13b39173031da19 (diff) |
unlink only needs to be a builtin, not an external
Diffstat (limited to 'src/poudriere-sh')
-rw-r--r-- | src/poudriere-sh/unlink.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/poudriere-sh/unlink.c b/src/poudriere-sh/unlink.c new file mode 100644 index 00000000..477f7a3b --- /dev/null +++ b/src/poudriere-sh/unlink.c @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2017 Bryan Drewery <bdrewery@FreeBSD.org> + * 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 + * in this position and unchanged. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR(S) 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. + */ + +#include <err.h> +#include <stdlib.h> +#include <stdio.h> +#include <sysexits.h> +#include <unistd.h> + +#ifdef SHELL +#define main unlinkcmd +#include "bltin/bltin.h" +#include <errno.h> +#define err(exitstatus, fmt, ...) error(fmt ": %s", __VA_ARGS__, strerror(errno)) +#endif + +/** + * Just call unlink(2) on the params. + */ +int +main(int argc, char **argv) +{ + + if (argc != 2) + errx(EX_USAGE, "Usage: unlink file"); + + if (unlink(argv[1])) +#ifdef SHELL + error("%s", strerror(errno)); +#else + err(EXIT_FAILURE, NULL); +#endif + + return (0); +} |