~sircmpwn/ctools

19b01a8124a6fd38db9b55c08f29f8813ac75a06 — Drew DeVault 1 year, 2 months ago 13e4664
link, unlink: abort on unspecified behavior
2 files changed, 26 insertions(+), 0 deletions(-)

M src/link.c
M src/unlink.c
M src/link.c => src/link.c +13 -0
@@ 1,4 1,5 @@
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

static void


@@ 15,6 16,18 @@ main(int argc, char *argv[])
		return 1;
	}

	struct stat s;
	if (lstat(argv[optind], &s) == -1) {
		perror("lstat");
		return 1;
	}

	if (S_ISLNK(s.st_mode)) {
		fprintf(stderr, "The behavior of link(3) is undefined when "
				"file1 is a symbolic link.\n");
		return 1;
	}

	if (link(argv[optind], argv[optind + 1]) == -1) {
		perror("link");
		return 1;

M src/unlink.c => src/unlink.c +13 -0
@@ 1,4 1,5 @@
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>

static void


@@ 15,6 16,18 @@ main(int argc, char *argv[])
		return 1;
	}

	struct stat s;
	if (lstat(argv[optind], &s) == -1) {
		perror("lstat");
		return 1;
	}

	if (S_ISLNK(s.st_mode)) {
		fprintf(stderr, "The behavior of unlink(3) is undefined when "
				"file1 is a symbolic link.\n");
		return 1;
	}

	if (unlink(argv[optind]) != 0) {
		perror("unlink");
		return 1;