From 7ca743c1dc21aa8c78ebad9c55180cd5be52f50d Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Mon, 19 Oct 2009 21:36:43 +0000 Subject: [PATCH] Using getopt() for coherence with the other tools --- src/dirname.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/dirname.c b/src/dirname.c index f6ad4d5..d3ca1df 100644 --- a/src/dirname.c +++ b/src/dirname.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 @@ -16,6 +16,7 @@ +#include #include #include @@ -39,7 +40,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 _dirname(argv[1]); + return _dirname(argv[optind]); }