Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: sizeof environment variables array = 1? Date: Thu, 08 Jun 2017 15:12:34 -0700 Organization: None to speak of Lines: 57 Message-ID: References: <878tl2v5ge.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="e40ff83086fdd10e487ed4dffbe7e58b"; logging-data="20541"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191u4qeDzQGLfUVwofLpzWz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tqI3zOLhzoBqrI85l3GxTOi/ZaQ= sha1:LnncmFCyN1719RwcaTOydXpFIZs= Xref: csiph.com comp.lang.c:111865 DFS writes: > On 6/8/2017 4:18 PM, jak wrote: >> Why don't you use the getenv fuction? It comes with standard libraries >> (stdio.h). > > Thanks for the hint. > > What I was wanting to do was check the Windows Path to see if they had > the GNUWin32 packages installed. It would be rare, but if they do have > them I can use the 'file' command, same as on Linux. > > On Linux I don't think I'll need to check the environ vars; the 'file' > command is installed by default as far as I know. > > I'll try getenv here on Windows. > > Edit: it's a few lines. > > if (strstr(getenv("Path"),"string") != NULL) > printf("string found in Path\n"); > else > printf("string not found in path\n"); You're still trying to use the "file" command for this? There is no clear distinction between text files and binary files. Invoking the "file" command (which may or may not be available) on a file will not reliably tell you whether a file is text or binary. The output of the "file" command is intended for human consumption, and is not designed to be parseable (unless you ask it for the MIME type, but even that is likely to be unsuitable for your purpose). I think you have a classic XY problem . Your underlying problem is to determine whether an input file is valid for your program. You've decided that the first step in solving that problem is to determine whether the file is text or binary, and you've been on a wild goose chase figuring out how to do that. Instead, I strongly suggest you define what constitutes valid input for your program, and check for that. What characters are acceptable? Printable ASCII characters? ASCII control characters? Non-ASCII accented letters? If the file turns out to be valid, will you read it as text? Are multibyte characters acceptable? Is there a maximum acceptable line length? And so on. For example, if I feed a binary file named "c.c" to gcc, it doesn't check whether it's text or binary; it simply tries to parse it as C source code and prints error messages if it fails. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"