Question about adding a tiny tool into GNU coreutils (original) (raw)

[Top][All Lists]


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


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

/*

#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 returns the error message string according to \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(CC) -o (CC)o(NAME) (OBJECTS)(OBJECTS) (OBJECTS)(LIBS)

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

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

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

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

Attachment: signature.asc
Description: OpenPGP digital signature