View Issue Details

IDProjectCategoryView StatusLast Update
00003181003.1(2004)/Issue 6System Interfacespublic2013-04-16 13:06
Reporterajosey Assigned Toajosey  
PrioritynormalSeverityObjectionTypeClarification Requested
Status ClosedResolutionAccepted 
NameAndrew Josey
OrganizationThe Open Group
User ReferenceXSHbug2.txt Enhancement Request Number 248
Sectiongetopt
Page Number541
Line Number17820
Interp Status---
Final Accepted Text
Summary0000318: getopt() does not give any significance to a value of zero for optind
DescriptionThe description of getopt() does not give any significance to a
value of zero for optind. It just says "The variable optind is the
index of the next element of the argv[] vector to be processed. It
shall be initialized to 1 by the system, and getopt() shall update it
when it finishes with each element of argv[]."

Based on this, an application writer might expect that if they
have an argument vector consisting just of options and operands
(i.e. no utility name or equivalent in argv[0]), then they should
be able to use getopt() to process this vector from the beginning
by setting optind to zero before the first call.

However, in practice this is not portable because some
implementations treat an optind value of zero in a special way.
(According to Michael Kerrisk, for the glibc getopt() an optind of
zero causes a reinitialisation of extended features. Resetting it
to 1 in order to scan a new vector only works if extensions are not
used. BSD apparently treats an optind of zero as a reset for
compatibility with glibc.)

Either the POSIX description should be updated to say that if
optind is zero the behaviour is unspecified, or the rationale should
be updated to say that treating an optind of zero as special is not
conforming. The action below does the former.
Desired ActionOn line 17820 after "and getopt() shall update it when it finishes
with each element of argv[]", add a new sentence:

    "If the application sets optind to zero before calling getopt(),
    the behavior is unspecified."
Tagstc1-2008

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2010-09-17 08:45 ajosey New Issue
2010-09-17 08:45 ajosey Status New => Under Review
2010-09-17 08:45 ajosey Assigned To => ajosey
2010-09-17 08:45 ajosey Name => Andrew Josey
2010-09-17 08:45 ajosey Organization => The Open Group
2010-09-17 08:45 ajosey User Reference => XSHbug2.txt Enhancement Request Number 248
2010-09-17 08:45 ajosey Section => getopt
2010-09-17 08:45 ajosey Page Number => 541
2010-09-17 08:45 ajosey Line Number => 17820
2010-09-17 08:45 ajosey Interp Status => ---
2010-09-17 08:46 ajosey Status Under Review => Resolved
2010-09-17 08:46 ajosey Resolution Open => Accepted
2010-09-17 08:46 ajosey Tag Attached: tc1-2008
2013-04-16 13:06 ajosey Status Resolved => Closed