From owner-freebsd-questions@freebsd.org Fri Nov 1 04:56:26 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0964F1A4707 for ; Fri, 1 Nov 2019 04:56:26 +0000 (UTC) (envelope-from kh@panix.com) Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4748zY53b3z4J3j for ; Fri, 1 Nov 2019 04:56:25 +0000 (UTC) (envelope-from kh@panix.com) Received: from rain.home (pool-72-74-69-77.bstnma.fios.verizon.net [72.74.69.77]) by mailbackend.panix.com (Postfix) with ESMTPSA id 4748zX66jCzytS for ; Fri, 1 Nov 2019 00:56:24 -0400 (EDT) Subject: Re: grep for ascii nul To: freebsd-questions@freebsd.org References: <20191101024817.GA60134@admin.sibptus.ru> <558fd145-ad3e-90dc-5930-c01ca0c27d3c@panix.com> From: Kurt Hackenberg Message-ID: <61f96c80-7965-9c80-30dc-b153e418b668@panix.com> Date: Fri, 1 Nov 2019 00:56:18 -0400 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <558fd145-ad3e-90dc-5930-c01ca0c27d3c@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4748zY53b3z4J3j X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of kh@panix.com designates 166.84.1.89 as permitted sender) smtp.mailfrom=kh@panix.com X-Spamd-Result: default: False [-5.46 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:166.84.0.0/16:c]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; DMARC_NA(0.00)[panix.com]; RCVD_IN_DNSWL_MED(-0.20)[89.1.84.166.list.dnswl.org : 127.0.5.2]; IP_SCORE(-2.97)[ip: (-8.86), ipnet: 166.84.0.0/16(-3.28), asn: 2033(-2.63), country: US(-0.05)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:2033, ipnet:166.84.0.0/16, country:US]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Nov 2019 04:56:26 -0000 On 2019-11-01 00:44, Kurt Hackenberg wrote: > You could use the attached program, which I wrote some time ago for this > purpose. Huh. The attachment didn't come through. Does this list forbid attachments? Anyway, here's the program inline. It's C. ---------------------------- #include #include #include typedef int BOOL; #define TRUE 1 #define FALSE 0 static void qerror(char *me, char *thing) { char tmp[1024 + 255 + 2 + 1]; /* max pathname + max filename + junk + NUL */ sprintf(tmp, "%s: %s", me, thing); perror(tmp); } static BOOL doit(FILE *fin) { int c; while ((c = getc(fin)) != EOF) if (c == '\0') return TRUE; return FALSE; } int main(int argc, char *argv[], char *envp[]) { FILE *fin; char *me; if ((me = strrchr(*argv, '/')) != NULL) me++; else me = *argv; argc--, argv++; if (argc > 0) do { if ((fin = fopen(*argv, "r")) != NULL) { if (doit(fin)) printf("%s\n", *argv); if (fclose(fin) != 0) qerror(me, *argv); } else qerror(me, *argv); } while (++argv, --argc > 0); else if (doit(stdin)) printf("\n"); return errno; }