VirtualBox

source: kBuild/trunk/src/kmk/kmkbuiltin/printf.c@ 3188

Last change on this file since 3188 was 3188, checked in by bird, 7 years ago

kmk,lib,kWorker: Console output on windows cleanups.

  • Property svn:eol-style set to native
File size: 18.3 KB
Line 
1/* $NetBSD: printf.c,v 1.31 2005/03/22 23:55:46 dsl Exp $ */
2
3/*
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/*#include <sys/cdefs.h>
33#ifndef lint
34#if !defined(BUILTIN) && !defined(SHELL)
35__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
36 The Regents of the University of California. All rights reserved.\n");
37#endif
38#endif
39
40#ifndef lint
41#if 0
42static char sccsid[] = "@(#)printf.c 8.2 (Berkeley) 3/22/95";
43#else
44__RCSID("$NetBSD: printf.c,v 1.31 2005/03/22 23:55:46 dsl Exp $");
45#endif
46#endif*/ /* not lint */
47
48#if !defined(kmk_builtin_printf) && !defined(BUILTIN) && !defined(SHELL)
49# include "../makeint.h"
50# include "../filedef.h"
51# include "../variable.h"
52#else
53# include "config.h"
54#endif
55#include <sys/types.h>
56
57#include <ctype.h>
58#include "err.h"
59#include <errno.h>
60#include <inttypes.h>
61#include <limits.h>
62#include <locale.h>
63#include <stdarg.h>
64#include <stdio.h>
65#include <stdlib.h>
66#include <string.h>
67#include <unistd.h>
68#include "getopt.h"
69#ifdef __sun__
70# include "solfakes.h"
71#endif
72#ifdef _MSC_VER
73# include "mscfakes.h"
74#endif
75
76#include "../kmkbuiltin.h"
77
78#ifdef KBUILD_OS_WINDOWS
79/* This is a trick to speed up console output on windows. */
80# include "console.h"
81# undef fwrite
82# define fwrite maybe_con_fwrite
83#endif
84
85
86#if 0 /*def __GNUC__ - bird: gcc complains about non-ISO-standard escape. */
87#define ESCAPE '\e'
88#else
89#define ESCAPE 033
90#endif
91
92
93static size_t b_length;
94static char *b_fmt;
95static int rval;
96static char **gargv;
97#if !defined(kmk_builtin_printf) && !defined(BUILTIN) && !defined(SHELL)
98static char *g_o = NULL;
99#endif
100static struct option long_options[] =
101{
102 { "help", no_argument, 0, 261 },
103 { "version", no_argument, 0, 262 },
104 { 0, 0, 0, 0 },
105};
106
107
108static int common_printf(int argc, char *argv[]);
109static void conv_escape_str(char *, void (*)(int));
110static char *conv_escape(char *, char *);
111static char *conv_expand(const char *);
112static int getchr(void);
113static double getdouble(void);
114static int getwidth(void);
115static intmax_t getintmax(void);
116static uintmax_t getuintmax(void);
117static char *getstr(void);
118static char *mklong(const char *, int);
119static void check_conversion(const char *, const char *);
120static int usage(FILE *);
121
122static int flush_buffer(void);
123static void b_count(int);
124static void b_output(int);
125static int wrap_putchar(int ch);
126static int wrap_printf(const char *, ...);
127
128#ifdef BUILTIN /* csh builtin */
129#define kmk_builtin_printf progprintf
130#endif
131
132#ifdef SHELL /* sh (aka ash) builtin */
133#define kmk_builtin_printf printfcmd
134#include "../../bin/sh/bltin/bltin.h"
135#endif /* SHELL */
136
137/* Buffer the output because windows doesn't do line buffering of stdout. */
138static char g_achBuf[256];
139static size_t g_cchBuf;
140
141#define PF(f, func) { \
142 if (fieldwidth != -1) { \
143 if (precision != -1) \
144 (void)wrap_printf(f, fieldwidth, precision, func); \
145 else \
146 (void)wrap_printf(f, fieldwidth, func); \
147 } else if (precision != -1) \
148 (void)wrap_printf(f, precision, func); \
149 else \
150 (void)wrap_printf(f, func); \
151}
152
153#define APF(cpp, f, func) { \
154 if (fieldwidth != -1) { \
155 if (precision != -1) \
156 (void)asprintf(cpp, f, fieldwidth, precision, func); \
157 else \
158 (void)asprintf(cpp, f, fieldwidth, func); \
159 } else if (precision != -1) \
160 (void)asprintf(cpp, f, precision, func); \
161 else \
162 (void)asprintf(cpp, f, func); \
163}
164
165int kmk_builtin_printf(int argc, char *argv[], char **envp)
166{
167 int rc;
168 int ch;
169
170 /* kmk: reset getopt, set progname and reset buffer. */
171 g_progname = argv[0];
172 opterr = 1;
173 optarg = NULL;
174 optopt = 0;
175 optind = 0; /* init */
176
177#if !defined(SHELL) && !defined(BUILTIN) && !defined(kmk_builtin_printf) /* kmk did this already. */
178 (void)setlocale (LC_ALL, "");
179#endif
180
181 while ((ch = getopt_long(argc, argv, "", long_options, NULL)) != -1) {
182 switch (ch) {
183 case 261:
184 usage(stdout);
185 return 0;
186 case 262:
187 return kbuild_version(argv[0]);
188 case '?':
189 default:
190 return usage(stderr);
191 }
192 }
193 argc -= optind;
194 argv += optind;
195
196 if (argc < 1) {
197 return usage(stderr);
198 }
199
200 rc = common_printf(argc, argv);
201 return rc;
202}
203
204#ifndef kmk_builtin_printf
205/* entry point used by function.c $(printf ..,..). */
206char *kmk_builtin_func_printf(char *o, char **argv, const char *funcname)
207{
208 int rc;
209 int argc;
210
211 for (argc = 0; argv[argc] != NULL; argc++)
212 /* nothing */;
213
214 g_o = o;
215 rc = common_printf(argc, argv);
216 o = g_o;
217 g_o = NULL;
218
219 if (rc != 0)
220 fatal(NILF, strlen(funcname) + INTSTR_LENGTH, _("$(%s): failure rc=%d\n"), funcname, rc);
221 return o;
222}
223#endif
224
225static int common_printf(int argc, char *argv[])
226{
227 char *fmt, *start;
228 int fieldwidth, precision;
229 char nextch;
230 char *format;
231 int ch;
232
233 /* kmk: reinitialize globals */
234 b_length = 0;
235 b_fmt = NULL;
236 rval = 0;
237 gargv = NULL;
238 g_cchBuf = 0;
239
240 format = *argv;
241 gargv = ++argv;
242
243#define SKIP1 "#-+ 0"
244#define SKIP2 "*0123456789"
245 do {
246 /*
247 * Basic algorithm is to scan the format string for conversion
248 * specifications -- once one is found, find out if the field
249 * width or precision is a '*'; if it is, gather up value.
250 * Note, format strings are reused as necessary to use up the
251 * provided arguments, arguments of zero/null string are
252 * provided to use up the format string.
253 */
254
255 /* find next format specification */
256 for (fmt = format; (ch = *fmt++) != '\0';) {
257 if (ch == '\\') {
258 char c_ch;
259 fmt = conv_escape(fmt, &c_ch);
260 wrap_putchar(c_ch);
261 continue;
262 }
263 if (ch != '%' || (*fmt == '%' && ++fmt)) {
264 (void)wrap_putchar(ch);
265 continue;
266 }
267
268 /* Ok - we've found a format specification,
269 Save its address for a later printf(). */
270 start = fmt - 1;
271
272 /* skip to field width */
273 fmt += strspn(fmt, SKIP1);
274 fieldwidth = *fmt == '*' ? getwidth() : -1;
275
276 /* skip to possible '.', get following precision */
277 fmt += strspn(fmt, SKIP2);
278 if (*fmt == '.')
279 ++fmt;
280 precision = *fmt == '*' ? getwidth() : -1;
281
282 fmt += strspn(fmt, SKIP2);
283
284 ch = *fmt;
285 if (!ch) {
286 flush_buffer();
287 warnx("missing format character");
288 return (1);
289 }
290 /* null terminate format string to we can use it
291 as an argument to printf. */
292 nextch = fmt[1];
293 fmt[1] = 0;
294 switch (ch) {
295
296 case 'B': {
297 const char *p = conv_expand(getstr());
298 *fmt = 's';
299 PF(start, p);
300 break;
301 }
302 case 'b': {
303 /* There has to be a better way to do this,
304 * but the string we generate might have
305 * embedded nulls. */
306 static char *a, *t;
307 char *cp = getstr();
308 /* Free on entry in case shell longjumped out */
309 if (a != NULL)
310 free(a);
311 a = NULL;
312 if (t != NULL)
313 free(t);
314 t = NULL;
315 /* Count number of bytes we want to output */
316 b_length = 0;
317 conv_escape_str(cp, b_count);
318 t = malloc(b_length + 1);
319 if (t == NULL)
320 break;
321 memset(t, 'x', b_length);
322 t[b_length] = 0;
323 /* Get printf to calculate the lengths */
324 *fmt = 's';
325 APF(&a, start, t);
326 b_fmt = a;
327 /* Output leading spaces and data bytes */
328 conv_escape_str(cp, b_output);
329 /* Add any trailing spaces */
330 wrap_printf("%s", b_fmt);
331 break;
332 }
333 case 'c': {
334 char p = getchr();
335 PF(start, p);
336 break;
337 }
338 case 's': {
339 char *p = getstr();
340 PF(start, p);
341 break;
342 }
343 case 'd':
344 case 'i': {
345 intmax_t p = getintmax();
346 char *f = mklong(start, ch);
347 PF(f, p);
348 break;
349 }
350 case 'o':
351 case 'u':
352 case 'x':
353 case 'X': {
354 uintmax_t p = getuintmax();
355 char *f = mklong(start, ch);
356 PF(f, p);
357 break;
358 }
359 case 'e':
360 case 'E':
361 case 'f':
362 case 'g':
363 case 'G': {
364 double p = getdouble();
365 PF(start, p);
366 break;
367 }
368 default:
369 flush_buffer();
370 warnx("%s: invalid directive", start);
371 return 1;
372 }
373 *fmt++ = ch;
374 *fmt = nextch;
375 /* escape if a \c was encountered */
376 if (rval & 0x100) {
377 flush_buffer();
378 return rval & ~0x100;
379 }
380 }
381 } while (gargv != argv && *gargv);
382
383 flush_buffer();
384 return rval;
385}
386
387
388/* helper functions for conv_escape_str */
389
390static void
391/*ARGSUSED*/
392b_count(int ch)
393{
394 b_length++;
395 (void)ch;
396}
397
398/* Output one converted character for every 'x' in the 'format' */
399
400static void
401b_output(int ch)
402{
403 for (;;) {
404 switch (*b_fmt++) {
405 case 0:
406 b_fmt--;
407 return;
408 case ' ':
409 wrap_putchar(' ');
410 break;
411 default:
412 wrap_putchar(ch);
413 return;
414 }
415 }
416}
417
418static int wrap_putchar(int ch)
419{
420#ifndef kmk_builtin_printf
421 if (g_o) {
422 char sz[2];
423 sz[0] = ch; sz[1] = '\0';
424 g_o = variable_buffer_output(g_o, sz, 1);
425 return ch;
426 }
427#endif
428 /* Buffered output. */
429 if (g_cchBuf + 1 < sizeof(g_achBuf)) {
430 g_achBuf[g_cchBuf++] = ch;
431 } else {
432 int rc = flush_buffer();
433 g_achBuf[g_cchBuf++] = ch;
434 if (rc)
435 return -1;
436 }
437 return 0;
438}
439
440static int wrap_printf(const char * fmt, ...)
441{
442 ssize_t cchRet;
443 va_list va;
444 char *pszTmp;
445
446 va_start(va, fmt);
447 cchRet = vasprintf(&pszTmp, fmt, va);
448 va_end(va);
449 if (cchRet >= 0) {
450#ifndef kmk_builtin_printf
451 if (g_o) {
452 g_o = variable_buffer_output(g_o, pszTmp, cchRet);
453 } else
454#endif
455 {
456 if (cchRet + g_cchBuf <= sizeof(g_achBuf)) {
457 /* We've got space in the buffer. */
458 memcpy(&g_achBuf[g_cchBuf], pszTmp, cchRet);
459 g_cchBuf += cchRet;
460 } else {
461 /* Try write out complete lines. */
462 const char *pszLeft = pszTmp;
463 ssize_t cchLeft = cchRet;
464
465 while (cchLeft > 0) {
466 const char *pchNewLine = strchr(pszLeft, '\n');
467 ssize_t cchLine = pchNewLine ? pchNewLine - pszLeft + 1 : cchLeft;
468 if (g_cchBuf + cchLine <= sizeof(g_achBuf)) {
469 memcpy(&g_achBuf[g_cchBuf], pszLeft, cchLine);
470 g_cchBuf += cchLine;
471 } else {
472 if (flush_buffer() < 0) {
473 return -1;
474 }
475 if (fwrite(pszLeft, cchLine, 1, stdout) < 1) {
476 return -1;
477 }
478 }
479 pszLeft += cchLine;
480 cchLeft -= cchLine;
481 }
482 }
483 }
484 free(pszTmp);
485 }
486 return (int)cchRet;
487}
488
489/**
490 * Flushes the g_abBuf/g_cchBuf.
491 */
492static int flush_buffer(void)
493{
494 if (g_cchBuf > 0) {
495 ssize_t cchToWrite = g_cchBuf;
496 ssize_t cchWritten = fwrite(g_achBuf, 1, g_cchBuf, stdout);
497 g_cchBuf = 0;
498 if (cchWritten >= cchToWrite) {
499 /* likely */
500 } else {
501 ssize_t off = cchWritten;
502 if (cchWritten >= 0) {
503 off = cchWritten;
504 } else if (errno == EINTR) {
505 cchWritten = 0;
506 } else {
507 return -1;
508 }
509
510 while (off < cchToWrite) {
511 cchWritten = fwrite(&g_achBuf[off], 1, cchToWrite - off, stdout);
512 if (cchWritten > 0) {
513 off += cchWritten;
514 } else if (errno == EINTR) {
515 /* nothing */
516 } else {
517 return -1;
518 }
519 }
520 }
521 }
522 return 0;
523}
524
525
526
527/*
528 * Print SysV echo(1) style escape string
529 * Halts processing string if a \c escape is encountered.
530 */
531static void
532conv_escape_str(char *str, void (*do_putchar)(int))
533{
534 int value;
535 int ch;
536 char c;
537
538 while ((ch = *str++) != '\0') {
539 if (ch != '\\') {
540 do_putchar(ch);
541 continue;
542 }
543
544 ch = *str++;
545 if (ch == 'c') {
546 /* \c as in SYSV echo - abort all processing.... */
547 rval |= 0x100;
548 break;
549 }
550
551 /*
552 * %b string octal constants are not like those in C.
553 * They start with a \0, and are followed by 0, 1, 2,
554 * or 3 octal digits.
555 */
556 if (ch == '0') {
557 int octnum = 0, i;
558 for (i = 0; i < 3; i++) {
559 if (!isdigit((unsigned char)*str) || *str > '7')
560 break;
561 octnum = (octnum << 3) | (*str++ - '0');
562 }
563 do_putchar(octnum);
564 continue;
565 }
566
567 /* \[M][^|-]C as defined by vis(3) */
568 if (ch == 'M' && *str == '-') {
569 do_putchar(0200 | str[1]);
570 str += 2;
571 continue;
572 }
573 if (ch == 'M' && *str == '^') {
574 str++;
575 value = 0200;
576 ch = '^';
577 } else
578 value = 0;
579 if (ch == '^') {
580 ch = *str++;
581 if (ch == '?')
582 value |= 0177;
583 else
584 value |= ch & 037;
585 do_putchar(value);
586 continue;
587 }
588
589 /* Finally test for sequences valid in the format string */
590 str = conv_escape(str - 1, &c);
591 do_putchar(c);
592 }
593}
594
595/*
596 * Print "standard" escape characters
597 */
598static char *
599conv_escape(char *str, char *conv_ch)
600{
601 int value;
602 int ch;
603 char num_buf[4], *num_end;
604
605 ch = *str++;
606
607 switch (ch) {
608 case '0': case '1': case '2': case '3':
609 case '4': case '5': case '6': case '7':
610 num_buf[0] = ch;
611 ch = str[0];
612 num_buf[1] = ch;
613 num_buf[2] = ch ? str[1] : 0;
614 num_buf[3] = 0;
615 value = strtoul(num_buf, &num_end, 8);
616 str += num_end - (num_buf + 1);
617 break;
618
619 case 'x':
620 /* Hexadecimal character constants are not required to be
621 supported (by SuS v1) because there is no consistent
622 way to detect the end of the constant.
623 Supporting 2 byte constants is a compromise. */
624 ch = str[0];
625 num_buf[0] = ch;
626 num_buf[1] = ch ? str[1] : 0;
627 num_buf[2] = 0;
628 value = strtoul(num_buf, &num_end, 16);
629 str += num_end - num_buf;
630 break;
631
632 case '\\': value = '\\'; break; /* backslash */
633 case '\'': value = '\''; break; /* single quote */
634 case '"': value = '"'; break; /* double quote */
635 case 'a': value = '\a'; break; /* alert */
636 case 'b': value = '\b'; break; /* backspace */
637 case 'e': value = ESCAPE; break; /* escape */
638 case 'f': value = '\f'; break; /* form-feed */
639 case 'n': value = '\n'; break; /* newline */
640 case 'r': value = '\r'; break; /* carriage-return */
641 case 't': value = '\t'; break; /* tab */
642 case 'v': value = '\v'; break; /* vertical-tab */
643
644 default:
645 warnx("unknown escape sequence `\\%c'", ch);
646 rval = 1;
647 value = ch;
648 break;
649 }
650
651 *conv_ch = value;
652 return str;
653}
654
655/* expand a string so that everything is printable */
656
657static char *
658conv_expand(const char *str)
659{
660 static char *conv_str;
661 static char no_memory[] = "<no memory>";
662 char *cp;
663 int ch;
664
665 if (conv_str)
666 free(conv_str);
667 /* get a buffer that is definitely large enough.... */
668 conv_str = malloc(4 * strlen(str) + 1);
669 if (!conv_str)
670 return no_memory;
671 cp = conv_str;
672
673 while ((ch = *(const unsigned char *)str++) != '\0') {
674 switch (ch) {
675 /* Use C escapes for expected control characters */
676 case '\\': ch = '\\'; break; /* backslash */
677 case '\'': ch = '\''; break; /* single quote */
678 case '"': ch = '"'; break; /* double quote */
679 case '\a': ch = 'a'; break; /* alert */
680 case '\b': ch = 'b'; break; /* backspace */
681 case ESCAPE: ch = 'e'; break; /* escape */
682 case '\f': ch = 'f'; break; /* form-feed */
683 case '\n': ch = 'n'; break; /* newline */
684 case '\r': ch = 'r'; break; /* carriage-return */
685 case '\t': ch = 't'; break; /* tab */
686 case '\v': ch = 'v'; break; /* vertical-tab */
687 default:
688 /* Copy anything printable */
689 if (isprint(ch)) {
690 *cp++ = ch;
691 continue;
692 }
693 /* Use vis(3) encodings for the rest */
694 *cp++ = '\\';
695 if (ch & 0200) {
696 *cp++ = 'M';
697 ch &= ~0200;
698 }
699 if (ch == 0177) {
700 *cp++ = '^';
701 *cp++ = '?';
702 continue;
703 }
704 if (ch < 040) {
705 *cp++ = '^';
706 *cp++ = ch | 0100;
707 continue;
708 }
709 *cp++ = '-';
710 *cp++ = ch;
711 continue;
712 }
713 *cp++ = '\\';
714 *cp++ = ch;
715 }
716
717 *cp = 0;
718 return conv_str;
719}
720
721static char *
722mklong(const char *str, int ch)
723{
724 static char copy[64];
725 size_t len;
726
727 len = strlen(str) - 1;
728 if (len > sizeof(copy) - 5) {
729 warnx("format %s too complex\n", str);
730 len = 4;
731 }
732 (void)memmove(copy, str, len);
733#ifndef _MSC_VER
734 copy[len++] = 'j';
735#else
736 copy[len++] = 'I';
737 copy[len++] = '6';
738 copy[len++] = '4';
739#endif
740 copy[len++] = ch;
741 copy[len] = '\0';
742 return copy;
743}
744
745static int
746getchr(void)
747{
748 if (!*gargv)
749 return 0;
750 return (int)**gargv++;
751}
752
753static char *
754getstr(void)
755{
756 static char empty[] = "";
757 if (!*gargv)
758 return empty;
759 return *gargv++;
760}
761
762static int
763getwidth(void)
764{
765 long val;
766 char *s, *ep;
767
768 s = *gargv;
769 if (!*gargv)
770 return (0);
771 gargv++;
772
773 errno = 0;
774 val = strtoul(s, &ep, 0);
775 check_conversion(s, ep);
776
777 /* Arbitrarily 'restrict' field widths to 1Mbyte */
778 if (val < 0 || val > 1 << 20) {
779 warnx("%s: invalid field width", s);
780 return 0;
781 }
782
783 return val;
784}
785
786static intmax_t
787getintmax(void)
788{
789 intmax_t val;
790 char *cp, *ep;
791
792 cp = *gargv;
793 if (cp == NULL)
794 return 0;
795 gargv++;
796
797 if (*cp == '\"' || *cp == '\'')
798 return *(cp+1);
799
800 errno = 0;
801 val = strtoimax(cp, &ep, 0);
802 check_conversion(cp, ep);
803 return val;
804}
805
806static uintmax_t
807getuintmax(void)
808{
809 uintmax_t val;
810 char *cp, *ep;
811
812 cp = *gargv;
813 if (cp == NULL)
814 return 0;
815 gargv++;
816
817 if (*cp == '\"' || *cp == '\'')
818 return *(cp + 1);
819
820 /* strtoumax won't error -ve values */
821 while (isspace(*(unsigned char *)cp))
822 cp++;
823 if (*cp == '-') {
824 warnx("%s: expected positive numeric value", cp);
825 rval = 1;
826 return 0;
827 }
828
829 errno = 0;
830 val = strtoumax(cp, &ep, 0);
831 check_conversion(cp, ep);
832 return val;
833}
834
835static double
836getdouble(void)
837{
838 double val;
839 char *ep;
840
841 if (!*gargv)
842 return (0.0);
843
844 if (**gargv == '\"' || **gargv == '\'')
845 return (double) *((*gargv++)+1);
846
847 errno = 0;
848 val = strtod(*gargv, &ep);
849 check_conversion(*gargv++, ep);
850 return val;
851}
852
853static void
854check_conversion(const char *s, const char *ep)
855{
856 if (*ep) {
857 if (ep == s)
858 warnx("%s: expected numeric value", s);
859 else
860 warnx("%s: not completely converted", s);
861 rval = 1;
862 } else if (errno == ERANGE) {
863 warnx("%s: %s", s, strerror(ERANGE));
864 rval = 1;
865 }
866}
867
868static int
869usage(FILE *pf)
870{
871 fprintf(pf, "usage: %s format [arg ...]\n"
872 " or: %s --help\n"
873 " or: %s --version\n",
874 g_progname, g_progname, g_progname);
875 return 1;
876}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette