Austin Group Defect Tracker

Aardvark Mark III


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001180 [1003.1(2016)/Issue7+TC2] Base Definitions and Headers Editorial Clarification Requested 2017-12-20 22:51 2017-12-20 22:51
Reporter cgraff View Status public  
Assigned To
Priority normal Resolution Open  
Status New  
Name Christopher M. Graff
Organization
User Reference
Section getopt
Page Number 0
Line Number 0
Interp Status ---
Final Accepted Text
Summary 0001180: getopt example uses exit(2) and should be EIXT_FAILURE
Description The usage of exit(2) in the getopt example seems like a non-standard exit code for a failed utility. Typically, I see either exit(1) or exit(EXIT_FAILURE) and the value of EXIT_FAILURE is generally 1 or exit(1).
if (errflg) {
    fprintf(stderr, "usage: . . . ");
    exit(2);
}
Desired Action This example is updated to include actions from my previous report about mismatched brackets and to use EXIT_FAILURE.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>


int
main(int argc, char *argv[ ])
{
    int c;
    int bflg = 0, aflg = 0, errflg = 0;
    char *ifile;
    char *ofile;
    . . .
    while ((c = getopt(argc, argv, ":abf:o:")) != -1) {
        switch(c) {
        case 'a':
            if (bflg)
                errflg++;
            else
                aflg++;
            break;
        case 'b':
            if (aflg)
                errflg++;
            else
                bflg++;
            break;
        case 'f':
            ifile = optarg;
            break;
        case 'o':
            ofile = optarg;
            break;
        case ':': /* -f or -o without operand */
            fprintf(stderr,
                "Option -%c requires an operand\n", optopt);
            errflg++;
            break;
        case '?':
            fprintf(stderr,
                "Unrecognized option: '-%c'\n", optopt);
            errflg++;
        }
    }
    if (errflg) {
        fprintf(stderr, "usage: . . . ");
        exit(EXIT_FAILURE);
    }
    for ( ; optind < argc; optind++) {
        if (access(argv[optind], R_OK)) {
            . . .
        }
    }
}
Tags No tags attached.
Attached Files

- Relationships

There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2017-12-20 22:51 cgraff New Issue
2017-12-20 22:51 cgraff Name => Christopher M. Graff
2017-12-20 22:51 cgraff Section => getopt
2017-12-20 22:51 cgraff Page Number => 0
2017-12-20 22:51 cgraff Line Number => 0


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker