Converted getopt use to px4_getopt

In the posix and qurt builds, getopt is not thread safe so px4_getopt
should be used instead.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-06-19 11:39:08 -07:00
parent 878284701d
commit f7fe6a037d
5 changed files with 86 additions and 62 deletions
+6 -3
View File
@@ -44,6 +44,7 @@
#include <px4_config.h>
#include <px4_defines.h>
#include <px4_getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/prctl.h>
@@ -895,10 +896,12 @@ int sdlog2_thread_main(int argc, char *argv[])
* set error flag instead */
bool err_flag = false;
while ((ch = getopt(argc, argv, "r:b:eatx")) != EOF) {
int myoptind = 1;
const char *myoptarg = NULL;
while ((ch = px4_getopt(argc, argv, "r:b:eatx", &myoptind, &myoptarg)) != EOF) {
switch (ch) {
case 'r': {
unsigned long r = strtoul(optarg, NULL, 10);
unsigned long r = strtoul(myoptarg, NULL, 10);
if (r == 0) {
r = 1;
@@ -909,7 +912,7 @@ int sdlog2_thread_main(int argc, char *argv[])
break;
case 'b': {
unsigned long s = strtoul(optarg, NULL, 10);
unsigned long s = strtoul(myoptarg, NULL, 10);
if (s < 1) {
s = 1;