patacongo commented on a change in pull request #2326: URL: https://github.com/apache/incubator-nuttx/pull/2326#discussion_r527857099
########## File path: libs/libc/unistd/lib_getopt.c ########## @@ -39,257 +39,565 @@ #include <nuttx/config.h> -#include <stdbool.h> -#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> +#include <getopt.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +#define PERMUTE 0 +#define RETURN_IN_ORDER 1 +#define REQUIRE_ORDER 2 + /**************************************************************************** - * Public Data + * Private Type Definitions ****************************************************************************/ -FAR char *optarg; /* Optional argument following option */ -int optind = 1; /* Index into argv */ -int optopt = '?'; /* unrecognized option character */ +typedef struct getopt_data_s +{ + FAR char *optarg; + int optind; + int opterr; + int optopt; + int optwhere; + int permute_from; + int num_nonopts; +} getopt_data_t; Review comment: If this gets moved to TLS, I think that the int values should be changed to int16_t. C requires that : 16 <= width_of(int) <= width_of(long). So any use of type int must work if width_of(int) == 16. And this will save a lot of space in TLS. Above, sizeof(struct getopt_data_s is 48 butes on ARM. If the the int types were replaced with int16_t, the size would be 16 bytes with no loss of functionality or portability (in fact, the behavior is more portable). A significant savings if this is reserved on every stack. It would probably also require some range testing of at least optind, however. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org