Using getopt() for coherence with the other tools
This commit is contained in:
parent
83ba791afe
commit
84b191ee5b
28
src/link.c
28
src/link.c
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2007 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user