Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 provide a poor man's fmemopen()
details: https://anonhg.NetBSD.org/src/rev/433196261046
branches: trunk
changeset: 328807:433196261046
user: christos <christos%NetBSD.org@localhost>
date: Fri Apr 18 21:53:44 2014 +0000
description:
provide a poor man's fmemopen()
diffstat:
usr.bin/xlint/lint1/main1.c | 38 +++++++++++++++++++++++++++++++-------
1 files changed, 31 insertions(+), 7 deletions(-)
diffs (78 lines):
diff -r 535474e5caed -r 433196261046 usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c Fri Apr 18 21:45:22 2014 +0000
+++ b/usr.bin/xlint/lint1/main1.c Fri Apr 18 21:53:44 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main1.c,v 1.24 2014/04/18 02:17:14 christos Exp $ */
+/* $NetBSD: main1.c,v 1.25 2014/04/18 21:53:44 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.24 2014/04/18 02:17:14 christos Exp $");
+__RCSID("$NetBSD: main1.c,v 1.25 2014/04/18 21:53:44 christos Exp $");
#endif
#include <sys/types.h>
@@ -128,13 +128,37 @@
static void usage(void);
-#if !HAVE_NBTOOL_CONFIG_H
static const char builtins[] =
"int __builtin_isinf(long double);\n"
"int __builtin_isnan(long double);\n"
"int __builtin_copysign(long double, long double);\n"
;
+static size_t builtinlen = sizeof(builtins) - 1;
+
+static FILE *
+bltin(void)
+{
+#if HAVE_NBTOOL_CONFIG_H
+ char template[] = "/tmp/lint.XXXXXX";
+ int fd;
+ FILE *fp;
+ if ((fd = mkstemp(template)) == -1)
+ return NULL;
+ (void)unlink(template);
+ if ((fp = fdopen(fd, "r+")) == NULL) {
+ close(fd);
+ return NULL;
+ }
+ if (fwrite(builtins, 1, builtinlen, fp) != builtinlen) {
+ fclose(fp);
+ return NULL;
+ }
+ rewind(fp);
+ return fp;
+#else
+ return fmemopen(__UNCONST(builtins), builtinlen, "r");
#endif
+}
/*ARGSUSED*/
static void
@@ -222,16 +246,16 @@
initscan();
initmtab();
-#if !HAVE_NBTOOL_CONFIG_H
- if ((yyin = fmemopen(__UNCONST(builtins), sizeof(builtins) - 1, "r"))
- == NULL)
+ if ((yyin = bltin()) == NULL)
err(1, "cannot open builtins");
yyparse();
-#endif
+ fclose(yyin);
+
/* open the input file */
if ((yyin = fopen(argv[0], "r")) == NULL)
err(1, "cannot open '%s'", argv[0]);
yyparse();
+ fclose(yyin);
/* Following warnings cannot be suppressed by LINTED */
lwarn = LWARN_ALL;
Home |
Main Index |
Thread Index |
Old Index