"Dmitrij D. Czarkoff" <czark...@gmail.com> writes: > Gilles Chehade said: >> without commenting on the need for the utility itself, the code you have >> provided does not respect the coding style of OpenBSD, and your main >> function shouldn't be returning errno > > Sorry, I was not paying enough attention to style.
Not discussing the usefulness of unlink(1), but it's bikeshedding time here. Sorry. :) > What about this one: > > ======================================================================== > unlink.c > ======================================================================== > /* > * Copyright (c) 2014 Dmitrij D. Czarkoff <czark...@gmail.com> > * > * Permission to use, copy, modify, and distribute this software for any > * purpose with or without fee is hereby granted, provided that the above > * copyright notice and this permission notice appear in all copies. > * > * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES > * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF > * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR > * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES > * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN > * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF > * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > */ > > #include <errno.h> > #include <locale.h> > #include <stdio.h> > #include <stdlib.h> > #include <unistd.h> > > extern char *__progname; > > static void usage(void); > > int > main(int argc, char **argv) > { > setlocale(LC_ALL, ""); > > if (argc != 2) > usage(); I suggest using getopt() and the usual "argc -= optind, argv += optind" dance, for consistency at the source level and to handle "--" transparently. > else if (unlink(*(argv + 1))) { With what I said above, this becomes "*argv". > perror(__progname); > return (1); err() can do this in one line, while giving you a more rich error message: err(1, "unable to delete `%s'", *argv); > } > return (0); > } > > static void > usage(void) > { > (void)fprintf(stderr, "usage: %s file\n", __progname); Now that we have getprogname(), maybe we could start using it? > exit(1); > } > ======================================================================== -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE