Sujet : Fine, let's see you using pathconf(3) on Windows (was: Re: Then there's PATH_MAX)
De : vallor (at) *nospam* cultnix.org (vallor)
Groupes : comp.os.linux.advocacyDate : 10. Dec 2024, 14:58:17
Autres entêtes
Message-ID : <lrqvnoF55oU2@mid.individual.net>
References : 1 2
User-Agent : Pan/0.161 (Hmm2; be402cc9; Linux-6.12.4)
On Tue, 10 Dec 2024 13:12:03 +0000, Farley Flud <
fsquared@fsquared.linux>
wrote in <
180fd2f32d5884e5$6049$1734$802601b3@news.usenetexpress.com>:
On Mon, 09 Dec 2024 06:09:40 +0000, vallor wrote:
#include <stdio.h> #include <limits.h>
#ifdef __linux__ #include <linux/limits.h>
#endif
int main (void)
{
printf("%d\n",PATH_MAX);
return 0;
}
This is bullshit.
PATH_MAX is filesystem dependent and since GNU/Linux, unlike that pile
of garbage Microslop, supports many, many different filesystems the
PATH_MAX macro is unreliable and may be undefined on some machines.
The best and only way to determine file name/path parameters is to use
"pathconf" of "fpathconf:"
https://pubs.opengroup.org/onlinepubs/9799919799/
From the link:
"The pathconf() function was proposed immediately after the sysconf()
function when it was realized that some configurable values may differ
across file system, directory, or device boundaries."
Of course, "Flud" (after morphing -- AGAIN) couldn't be
bothered to provide a program that builds on both Linux and Windows
to demonstrate.
(I doubt Windows has pathconf(), but would love to be proved wrong. I
downloaded the tcc winapi headers, and I don't see it in there...)
- - cut here %<- - -
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char * argv[], char * envp[])
{
int result = 0;
char * path;
if(argv[1])
{
path = argv[1];
}
else
{
path = "/";
}
errno = 0;
result = pathconf(path,_PC_PATH_MAX);
if(result == -1)
{
perror("pathconf() returned -1:");
return 1;
}
printf("%d\n",result);
return 0;
}
- - cut here %<- - -
-- -v System76 Thelio Mega v1.1 x86_64 NVIDIA RTX 3090 Ti OS: Linux 6.12.4 Release: Mint 21.3 Mem: 258G "Honey, PLEASE don't pick up the PH$@#*&$^(#@&$^%(*NO CARRIER"