Skip to content

On GNU/Linux, set POSIXLY_CORRECT=1 or else mergehex will hang. #3

@lowfatcomputing

Description

@lowfatcomputing

One cannot expect optind to approach argc. On GNU/Linux:

The following will hang because getopt will, by default, permute argv such that options are in front and nonoptions are at the end of argv.
$ ../../PSOC_programmer/bin/mergehex -nm ../../PSOC_compiler/../PSOC_programmer/config/nm.hex -c demo_tmp.hex > demo.hex

Setting POSIXLY_CORRECT functions as a workaround and mergehex will run just fine.
$ POSIXLY_CORRECT=1 ../../PSOC_programmer/bin/mergehex -nm ../../PSOC_compiler/../PSOC_programmer/config/nm.hex -c demo_tmp.hex > demo.hex

Relevant paragraph from man 3 getopt

By default, getopt() permutes the contents of argv as it scans, so
that eventually all the nonoptions are at the end. Two other modes
are also implemented. If the first character of optstring is '+' or
the environment variable POSIXLY_CORRECT is set, then option process‐
ing stops as soon as a nonoption argument is encountered. If the
first character of optstring is '-', then each nonoption argv-element
is handled as if it were the argument of an option with character code

  1. (This is used by programs that were written to expect options and
    other argv-elements in any order and that care about the ordering of
    the two.) The special argument "--" forces an end of option-scanning
    regardless of the scanning mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions