Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2013-11-13 13:09:45 +0400
committerCorinna Vinschen <corinna@vinschen.de>2013-11-13 13:09:45 +0400
commit02365c20643dc9daf97ff00deb9487d973d96ec3 (patch)
tree7771da65c3855bda3c5dba3760a58f51ea2e71f1 /newlib/libc/stdlib
parent8246caa9426b512c1797b3e520a87870a06ce158 (diff)
* newlib/libc/include/getopt.h (struct option): name field should be
"const char *". * newlib/libc/stdlib/getopt.c (getopt_internal): Use fputs()/fputc() instead of fprintf() to save code space. Fix signed/unsigned comparison.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r--newlib/libc/stdlib/getopt.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/newlib/libc/stdlib/getopt.c b/newlib/libc/stdlib/getopt.c
index 2a4e7d4a2..2ab53aa6d 100644
--- a/newlib/libc/stdlib/getopt.c
+++ b/newlib/libc/stdlib/getopt.c
@@ -177,7 +177,9 @@ write_globals (struct getopt_data *data)
optwhere = data->optwhere;
}
-/* getopt_internal: the function that does all the dirty work */
+/* getopt_internal: the function that does all the dirty work
+ NOTE: to reduce the code and RAM footprint this function uses
+ fputs()/fputc() to do output to stderr instead of fprintf(). */
static int
getopt_internal (int argc, char *const argv[], const char *shortopts,
const struct option *longopts, int *longind, int only,
@@ -301,7 +303,7 @@ getopt_internal (int argc, char *const argv[], const char *shortopts,
match_chars) == 0)
{
/* do we have an exact match? */
- if (match_chars == (int) (strlen (longopts[optindex].name)))
+ if (match_chars == strlen (longopts[optindex].name))
{
longopt_match = optindex;
break;
@@ -315,12 +317,14 @@ getopt_internal (int argc, char *const argv[], const char *shortopts,
{
/* we have ambiguous options */
if (data->opterr)
- fprintf (stderr, "%s: option `%s' is ambiguous "
- "(could be `--%s' or `--%s')\n",
- argv[0],
- argv[data->optind],
- longopts[longopt_match].name,
- longopts[optindex].name);
+ fputs (argv[0], stderr);
+ fputs (": option `", stderr);
+ fputs (argv[data->optind], stderr);
+ fputs ("' is ambiguous (could be `--", stderr);
+ fputs (longopts[longopt_match].name, stderr);
+ fputs ("' or `--", stderr);
+ fputs (longopts[optindex].name, stderr);
+ fputs ("')\n", stderr);
return (data->optopt = '?');
}
}
@@ -338,9 +342,10 @@ getopt_internal (int argc, char *const argv[], const char *shortopts,
{
/* couldn't find option in shortopts */
if (data->opterr)
- fprintf (stderr,
- "%s: invalid option -- `-%c'\n",
- argv[0], argv[data->optind][data->optwhere]);
+ fputs (argv[0], stderr);
+ fputs (": invalid option -- `-", stderr);
+ fputc (argv[data->optind][data->optwhere], stderr);
+ fputs ("'\n", stderr);
data->optwhere++;
if (argv[data->optind][data->optwhere] == '\0')
{
@@ -377,17 +382,20 @@ getopt_internal (int argc, char *const argv[], const char *shortopts,
{
if (data->opterr)
{
- fprintf (stderr, "%s: argument required for option `", argv[0]);
+ fputs (argv[0], stderr);
+ fputs (": argument required for option `-", stderr);
if (longopt_match >= 0)
{
- fprintf (stderr, "--%s'\n", longopts[longopt_match].name);
+ fputc ('-', stderr);
+ fputs (longopts[longopt_match].name, stderr);
data->optopt = initial_colon ? ':' : '\?';
}
else
{
- fprintf (stderr, "-%c'\n", *cp);
+ fputc (*cp, stderr);
data->optopt = *cp;
}
+ fputs ("'\n", stderr);
}
data->optind++;
return initial_colon ? ':' : '\?';