bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about adding a tiny tool into GNU coreutils


From: Daniel Borkmann
Subject: Question about adding a tiny tool into GNU coreutils
Date: Wed, 06 Jan 2010 17:56:54 +0100
User-agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706)

Dear Coreutils team,

I was wondering if it's possible to add a tiny little program (next to
true and false ;) ) into the gnu coreutils package? The program I've
written is called "errno" and does nothing less than writing an error
string according to the user-specified error number.

Very often, programs or kernel modules only show/log a return value, but
not the actual error message, so you manually have to look it up. This
_tiny_ tool helps doing this automatically ;)

I think it would rather fit into the coreutils than having it's own
distribution package. What do you think? (Source attached)

Of course, I'd adapt it to the GNU standards the other programs have.
Feedback is welcomed ;)

Best regards,
Daniel
/*
 * errno
 *
 * Copyright (C) 2010  Daniel Borkmann <address@hidden>
 *
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 2 of the License, or (at 
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>

#define PROGNAME_STRING "errno"
#define VERSION_STRING  "1.0"

void help(void)
{
        printf("%s %s\n\n", PROGNAME_STRING, VERSION_STRING);
        printf("%s is a tiny tool that returns the error message string of an 
error code,\n", PROGNAME_STRING);
        printf("e.g. `%s -n $?` returns the error message according to the last 
exit code.\n", PROGNAME_STRING);
        printf("\n");
        printf("Options:\n");
        printf("    -n <num>    returns the error message string according to 
<num>\n");
        printf("                    this equals `%s <num>`\n", PROGNAME_STRING);
        printf("    -v          prints out version\n");
        printf("    -h          prints out this help\n");
        printf("\n");
        printf("Please report bugs to <address@hidden>\n");
        printf("Copyright (C) 2010 Daniel Borkmann\n");
        printf("License: GNU GPL version 2\n");
        printf("This is free software: you are free to change and redistribute 
it.\n");
        printf("There is NO WARRANTY, to the extent permitted by law.\n");

        exit(0);
}

void version(void)
{
        printf("%s %s\n\n", PROGNAME_STRING, VERSION_STRING);
        printf("%s is a tiny tool that returns the error message string of an 
error code,\n", PROGNAME_STRING);
        printf("e.g. `%s -n $?` returns the error message according to the last 
exit code.\n", PROGNAME_STRING);
        printf("\n");
        printf("Please report bugs to <address@hidden>\n");
        printf("Copyright (C) 2010 Daniel Borkmann\n");
        printf("License: GNU GPL version 2\n");
        printf("This is free software: you are free to change and redistribute 
it.\n");
        printf("There is NO WARRANTY, to the extent permitted by law.\n");

        exit(0);
}

int main(int argc, char **argv)
{
        int i, c;
        int num = 0;

        while ((c = getopt(argc, argv, "vhn:")) != EOF) {
                switch (c) {
                case 'h':
                        {
                                help();
                                break;
                        }
                case 'v':
                        {
                                version();
                                break;
                        }
                case 'n':
                        {
                                num = atoi(optarg);
                                break;
                        }
                case '?':
                        {
                                switch (optopt) {
                                case 'n':
                                        {
                                                fprintf(stderr, "Option -%c 
requires an argument\n", optopt);
                                                break;
                                        }
                                default:
                                        {
                                                if (isprint(optopt)) {
                                                        fprintf(stderr, 
"Unknown option character `0x%X\'\n", optopt);
                                                }
                                                break;
                                        }
                                }

                                return 1;
                        }
                default:
                        {
                                abort();
                        }
                }
        }

        for (i = optind; i < argc; ++i) {
                num = atoi(argv[i]);
        }

        /* Main routine ;) */
        printf("%s\n", strerror(num));

        return 0;
}

#
# Makefile for errno
#

CC               = gcc
LIBS             = 
INCLUDE          = 
CFLAGS           = -Wall -O2

NAME             = errno
OBJECTS          = errno.o

BINDIR           = bin
MANDIR           = usr/share/man/man1
MANDIR_LOCAL     = doc

all: clean errno

errno: $(OBJECTS)
        $(CC) -o $(NAME) $(OBJECTS) $(LIBS)

%.o: %.c
        $(CC) -c $(CFLAGS) $(INCLUDE) $<

install:
        install -D $(NAME) $(DESTDIR)/$(BINDIR)/$(NAME)
        cat $(MANDIR_LOCAL)/$(NAME).1 | gzip --best > 
$(MANDIR_LOCAL)/$(NAME).1.gz
        install -D $(MANDIR_LOCAL)/$(NAME).1.gz 
$(DESTDIR)/$(MANDIR)/$(NAME).1.gz

clean:
        rm *.o $(NAME) $(MANDIR_LOCAL)/$(NAME).1.gz || true

uninstall:
        rm $(DESTDIR)/$(BINDIR)/$(NAME) || true
        rm $(DESTDIR)/$(MANDIR)/$(NAME).1.gz || true


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]