Using getopt() for more coherence with the other tools
This commit is contained in:
parent
75787b99e0
commit
ec5ff3d4c8
18
src/unlink.c
18
src/unlink.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,13 +21,13 @@
|
|||
|
||||
|
||||
/* unlink */
|
||||
static int _unlink(char * file)
|
||||
static int _unlink(char const * file)
|
||||
{
|
||||
if(unlink(file) == -1)
|
||||
{
|
||||
fputs("unlink: ", stderr);
|
||||
perror(file);
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -44,7 +44,15 @@ static int _usage(void)
|
|||
/* main */
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
if(argc != 2)
|
||||
int o;
|
||||
|
||||
while((o = getopt(argc, argv, "")) != -1)
|
||||
switch(o)
|
||||
{
|
||||
default:
|
||||
return _usage();
|
||||
}
|
||||
if(optind != argc - 1)
|
||||
return _usage();
|
||||
return _unlink(argv[1]);
|
||||
return (_unlink(argv[optind]) == 0) ? 0 : 2;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user