Module Name: src
Committed By: rin
Date: Sat Jun 29 07:56:57 UTC 2024
Modified Files:
src/common/lib/libc/stdlib: getopt.c
Log Message:
getopt(): Make this built for _KERNEL || _STANDALONE
NFC as a libc routine.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/common/lib/libc/stdlib/getopt.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/common/lib/libc/stdlib/getopt.c
diff -u src/common/lib/libc/stdlib/getopt.c:1.1 src/common/lib/libc/stdlib/getopt.c:1.2
--- src/common/lib/libc/stdlib/getopt.c:1.1 Sat Jun 29 07:55:05 2024
+++ src/common/lib/libc/stdlib/getopt.c Sat Jun 29 07:56:56 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: getopt.c,v 1.1 2024/06/29 07:55:05 rin Exp $ */
+/* $NetBSD: getopt.c,v 1.2 2024/06/29 07:56:56 rin Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -30,7 +30,16 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: getopt.c,v 1.1 2024/06/29 07:55:05 rin Exp $");
+__RCSID("$NetBSD: getopt.c,v 1.2 2024/06/29 07:56:56 rin Exp $");
+
+#if defined(_KERNEL) || defined(_STANDALONE)
+
+#include <lib/libsa/stand.h>
+#include <lib/libkern/libkern.h>
+
+#define EPRINTF(fmt, args...) printf(fmt, ##args)
+
+#else
#include "namespace.h"
@@ -45,6 +54,11 @@ __RCSID("$NetBSD: getopt.c,v 1.1 2024/06
__weak_alias(getopt,_getopt)
#endif
+#define EPRINTF(fmt, args...) \
+ fprintf(stderr, "%s: " fmt, getprogname(), ##args)
+
+#endif /* !_KERNEL && !_STANDALONE */
+
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
@@ -99,9 +113,7 @@ getopt(int nargc, char * const nargv[],
if (*place == 0)
++optind;
if (opterr && *ostr != ':')
- (void)fprintf(stderr,
- "%s: unknown option -- %c\n", getprogname(),
- optopt);
+ (void)EPRINTF("unknown option -- %c\n", optopt);
return (BADCH);
}
@@ -130,9 +142,9 @@ getopt(int nargc, char * const nargv[],
if (*ostr == ':')
return (BADARG);
if (opterr)
- (void)fprintf(stderr,
- "%s: option requires an argument -- %c\n",
- getprogname(), optopt);
+ (void)EPRINTF(
+ "option requires an argument -- %c\n",
+ optopt);
return (BADCH);
}
place = EMSG;