1111#include < string.h>
1212#include < wchar.h>
1313
14+ #include " style.hpp"
15+
1416char *musl_optarg;
1517int musl_optind = 1 , musl_opterr = 1 , musl_optopt;
1618int musl_optreset = 0 ;
1719static int musl_optpos;
1820
19- static void musl_getopt_msg (char const *a , char const *b, char const *c, size_t l ) {
21+ static void musl_getopt_msg (char const *msg , char const *param, size_t len ) {
2022 FILE *f = stderr;
2123
22- if (fputs (a, f) >= 0 && fwrite (b, strlen (b), 1 , f) && fwrite (c, 1 , l, f) == l) {
24+ style_Set (f, STYLE_RED, true );
25+ fputs (" error: " , f);
26+ style_Reset (f);
27+
28+ if (fwrite (msg, strlen (msg), 1 , f) && fwrite (param, 1 , len, f) == len) {
2329 putc (' \n ' , f);
2430 }
2531}
@@ -90,7 +96,7 @@ static int getopt(int argc, char *argv[], char const *optstring) {
9096 if (d != c || c == ' :' ) {
9197 musl_optopt = c;
9298 if (optstring[0 ] != ' :' && musl_opterr) {
93- musl_getopt_msg (argv[ 0 ], " : unrecognized option: " , optchar, k);
99+ musl_getopt_msg (" unrecognized option: " , optchar, k);
94100 }
95101 return ' ?' ;
96102 }
@@ -106,7 +112,7 @@ static int getopt(int argc, char *argv[], char const *optstring) {
106112 return ' :' ;
107113 }
108114 if (musl_opterr) {
109- musl_getopt_msg (argv[ 0 ], " : option requires an argument: " , optchar, k);
115+ musl_getopt_msg (" option requires an argument: " , optchar, k);
110116 }
111117 return ' ?' ;
112118 }
@@ -228,8 +234,7 @@ static int musl_getopt_long_core(
228234 return ' ?' ;
229235 }
230236 musl_getopt_msg (
231- argv[0 ],
232- " : option does not take an argument: " ,
237+ " option does not take an argument: " ,
233238 longopts[i].name ,
234239 strlen (longopts[i].name )
235240 );
@@ -247,10 +252,7 @@ static int musl_getopt_long_core(
247252 return ' ?' ;
248253 }
249254 musl_getopt_msg (
250- argv[0 ],
251- " : option requires an argument: " ,
252- longopts[i].name ,
253- strlen (longopts[i].name )
255+ " option requires an argument: " , longopts[i].name , strlen (longopts[i].name )
254256 );
255257 return ' ?' ;
256258 }
@@ -269,8 +271,7 @@ static int musl_getopt_long_core(
269271 musl_optopt = 0 ;
270272 if (!colon && musl_opterr) {
271273 musl_getopt_msg (
272- argv[0 ],
273- cnt ? " : option is ambiguous: " : " : unrecognized option: " ,
274+ cnt ? " option is ambiguous: " : " unrecognized option: " ,
274275 argv[musl_optind] + 2 ,
275276 strlen (argv[musl_optind] + 2 )
276277 );
0 commit comments