Some fixes for getopt_long

This commit is contained in:
px4dev
2012-09-10 00:16:30 -07:00
parent 68d4a26b9e
commit b1767480d2
3 changed files with 17 additions and 14 deletions

View File

@@ -87,9 +87,7 @@ gpietsch@comcast.net
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef GETOPT_H
#include "getopt_long.h"
#endif
/* macros */
@@ -143,8 +141,8 @@ is_option (char *argv_element, int only)
/* getopt_internal: the function that does all the dirty work */
static int
getopt_internal (int argc, char **argv, char *shortopts,
GETOPT_LONG_OPTION_T * longopts, int *longind, int only)
getopt_internal (int argc, char **argv, const char *shortopts,
const GETOPT_LONG_OPTION_T * longopts, int *longind, int only)
{
GETOPT_ORDERING_T ordering = PERMUTE;
static size_t optwhere = 0;
@@ -178,7 +176,7 @@ getopt_internal (int argc, char **argv, char *shortopts,
shortopts++;
}
else
ordering = (getenv ("POSIXLY_CORRECT") != NULL) ? REQUIRE_ORDER : PERMUTE;
ordering = /*(getenv ("POSIXLY_CORRECT") != NULL) ? REQUIRE_ORDER :*/ PERMUTE;
/*
* based on ordering, find our next option, if we're at the beginning of
@@ -381,22 +379,24 @@ getopt_internal (int argc, char **argv, char *shortopts,
return optopt;
}
#if 0
int
getopt (int argc, char **argv, char *optstring)
{
return getopt_internal (argc, argv, optstring, NULL, NULL, 0);
}
#endif
int
getopt_long (int argc, char **argv, char *shortopts,
GETOPT_LONG_OPTION_T * longopts, int *longind)
getopt_long (int argc, char **argv, const char *shortopts,
const GETOPT_LONG_OPTION_T * longopts, int *longind)
{
return getopt_internal (argc, argv, shortopts, longopts, longind, 0);
}
int
getopt_long_only (int argc, char **argv, char *shortopts,
GETOPT_LONG_OPTION_T * longopts, int *longind)
getopt_long_only (int argc, char **argv, const char *shortopts,
const GETOPT_LONG_OPTION_T * longopts, int *longind)
{
return getopt_internal (argc, argv, shortopts, longopts, longind, 1);
}

View File

@@ -121,11 +121,13 @@ extern "C"
extern int optopt;
/* function prototypes */
#if 0
int getopt (int argc, char **argv, char *optstring);
int getopt_long (int argc, char **argv, char *shortopts,
GETOPT_LONG_OPTION_T * longopts, int *longind);
int getopt_long_only (int argc, char **argv, char *shortopts,
GETOPT_LONG_OPTION_T * longopts, int *longind);
#endif
int getopt_long (int argc, char **argv, const char *shortopts,
const GETOPT_LONG_OPTION_T * longopts, int *longind);
int getopt_long_only (int argc, char **argv, const char *shortopts,
const GETOPT_LONG_OPTION_T * longopts, int *longind);
#ifdef __cplusplus
};

View File

@@ -176,7 +176,8 @@ int carrier_get_board_info(struct carrier_board_info_s *info)
int ret;
int fd = open("/dev/eeprom", O_RDONLY | O_NONBLOCK);
if (fd < 0) fprintf(stderr, "[boardinfo carrier] ERROR opening carrier eeprom\n");
if (fd < 0)
return -1; /* no board */
ret = read(fd, info, sizeof(struct carrier_board_info_s));