Module Name: src Committed By: christos Date: Fri Apr 18 21:53:44 UTC 2014
Modified Files: src/usr.bin/xlint/lint1: main1.c Log Message: provide a poor man's fmemopen() To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/xlint/lint1/main1.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/lint1/main1.c diff -u src/usr.bin/xlint/lint1/main1.c:1.24 src/usr.bin/xlint/lint1/main1.c:1.25 --- src/usr.bin/xlint/lint1/main1.c:1.24 Thu Apr 17 22:17:14 2014 +++ src/usr.bin/xlint/lint1/main1.c Fri Apr 18 17:53:44 2014 @@ -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 @@ sig_atomic_t fpe; 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 @@ main(int argc, char *argv[]) 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;