diff options
-rw-r--r-- | popt.c | 19 | ||||
-rw-r--r-- | popt.h | 1 |
2 files changed, 20 insertions, 0 deletions
@@ -645,12 +645,23 @@ static void poptStripArg(/*@special@*/ poptContext con, int which) /*@=compdef@*/ } +/*@unchecked@*/ +static unsigned int seed = 0; + int poptSaveLong(long * arg, int argInfo, long aLong) { /* XXX Check alignment, may fail on funky platforms. */ if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1))) return POPT_ERROR_NULLARG; + if (aLong != 0 && argInfo & POPT_ARGFLAG_RANDOM) { + if (!seed) { + srandom((unsigned)getpid()); + srandom((unsigned)random()); + } + aLong = random() % (aLong > 0 ? aLong : -aLong); + aLong++; + } if (argInfo & POPT_ARGFLAG_NOT) aLong = ~aLong; switch (argInfo & POPT_ARGFLAG_LOGICALOPS) { @@ -679,6 +690,14 @@ int poptSaveInt(/*@null@*/ int * arg, int argInfo, long aLong) if (arg == NULL || (((unsigned long)arg) & (sizeof(*arg)-1))) return POPT_ERROR_NULLARG; + if (aLong != 0 && argInfo & POPT_ARGFLAG_RANDOM) { + if (!seed) { + srandom((unsigned)getpid()); + srandom((unsigned)random()); + } + aLong = random() % (aLong > 0 ? aLong : -aLong); + aLong++; + } if (argInfo & POPT_ARGFLAG_NOT) aLong = ~aLong; switch (argInfo & POPT_ARGFLAG_LOGICALOPS) { @@ -61,6 +61,7 @@ /*!< clear arg bit(s) */ #define POPT_ARGFLAG_SHOW_DEFAULT 0x00800000 /*!< show default value in --help */ +#define POPT_ARGFLAG_RANDOM 0x00400000 /*<! random value in [1,arg] */ /*@}*/ |