diff --git a/src/link.c b/src/link.c index 4ba0311..5d05ce7 100644 --- a/src/link.c +++ b/src/link.c @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2007 Pierre Pronchery */ +/* Copyright (c) 2009 Pierre Pronchery */ /* This file is part of DeforaOS Unix utils */ /* utils is not free software; you can redistribute it and/or modify it under * the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 @@ -21,16 +21,22 @@ /* link */ +static int _link_error(char const * message, int ret); + static int _link(char * file1, char * file2) { if(link(file1, file2) == -1) - { - perror("link"); - return 1; - } + return _link_error(file2, 1); return 0; } +static int _link_error(char const * message, int ret) +{ + fputs("link: ", stderr); + perror(message); + return ret; +} + /* usage */ static int _usage(void) @@ -43,7 +49,15 @@ static int _usage(void) /* main */ int main(int argc, char* argv[]) { - if(argc != 3) + int o; + + while((o = getopt(argc, argv, "")) != -1) + switch(o) + { + default: + return _usage(); + } + if(optind != argc - 2) return _usage(); - return _link(argv[1], argv[2]) == 0 ? 0 : 2; + return (_link(argv[optind], argv[optind + 1]) == 0) ? 0 : 2; }