summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--popt.c19
-rw-r--r--popt.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/popt.c b/popt.c
index d8e1885..1552217 100644
--- a/popt.c
+++ b/popt.c
@@ -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) {
diff --git a/popt.h b/popt.h
index 18f764c..47de002 100644
--- a/popt.h
+++ b/popt.h
@@ -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] */
/*@}*/