Sujet : Re: 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 : 11. Dec 2024, 19:02:57
Autres entêtes
Message-ID : <lru2egFdudcU1@mid.individual.net>
References : 1 2 3 4 5
User-Agent : Pan/0.161 (Hmm2; be402cc9; Linux-6.12.4)
On 10 Dec 2024 15:13:40 GMT, vallor <
vallor@cultnix.org> wrote in
<
lrr454F1u8jU1@mid.individual.net>:
On Tue, 10 Dec 2024 14:44:12 +0000, Farley Flud
<fsquared@fsquared.linux>
wrote in <180fd7fa66284739$61502$1728$802601b3@news.usenetexpress.com>:
On Tue, 10 Dec 2024 13:58:17 +0000, vallor wrote:
- - cut here %<- - -
>
>
Should be "flush here."
if(argv[1])
{
path = argv[1];
}
}
WTF!
You check for arguments like this:
if(argc != 2)
or:
if(argv[1] == NULL)
else {
path = "/";
>
>
WTF!
You are assigning a pointer with the value 0x2F.
If it's then passed to pathconf() then KABOOM!
printf("%d\n",result);
"result" is an int. pathcomp() returns a long int.
You should either have declared "result" as a long int or:
result = (int)pathconf(path,_PC_PATH_MAX)
Congrats. In a few short lines you have created a huge mess.
Thank you for your feedback. I have modified my program:
$ diff -u use_pathconf.c~ use_pathconf.c --- use_pathconf.c~ 2024-12-10
05:52:19.000000000 -0800 +++ use_pathconf.c 2024-12-10
06:57:40.671592496 -0800 @@ -4,7 +4,7 @@
int main(int argc, char * argv[], char * envp[])
{
-int result = 0;
+long result = 0;
char * path;
if(argv[1])
@@ -23,7 +23,7 @@
perror("pathconf() returned -1:");
return 1;
}
-printf("%d\n",result);
+printf("%ld\n",result);
return 0;
}
That's the only valid criticism I see -- but I do see that you are not
as familiar with C as you claim to be. (Please review your knowledge of
pointers to string literals before you embarrass yourself further.)
CC=tcc CFLAGS=-g -O2 -std=c90 -Wall -Werror -pedantic
Although I'm not sure if tcc supports -Wall -Werror, so just tried:
gcc -g -O2 -std=c90 -Wall -Werror -pedantic use_pathconf.c -o
use_pathconf
Nope, no errors.
$ gdb use_pathconf (gdb) break 19 Breakpoint 1 at 0x10d7: file
use_pathconf.c, line 19.
(gdb) run Starting program: /nfs/ds/src/vallor/path_max/use_pathconf
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main (argc=1, argv=0x7fffffffe1d8, envp=0x7fffffffe1e8) at
use_pathconf.c:19 19 errno = 0;
(gdb) print path $1 = 0x555555556004 "/"
(gdb) print *path $2 = 47 '/'
(gdb) print *(path+1)
$4 = 0 '\000'
(gdb) print "happy?"
$5 = "happy?"
Meanwhile, I still haven't seen your program that would run on Windows.
What's the matter Colonel Sanders ... chicken?
I guess that shut his trap.
BTW, if you want to get fancy:
$ rcsdiff -u ./use_pathconf.c
===================================================================
RCS file: ./RCS/use_pathconf.c,v
retrieving revision 1.1
diff -u -r1.1 ./use_pathconf.c
--- ./use_pathconf.c 2024/12/10 14:57:40 1.1
+++ ./use_pathconf.c 2024/12/11 17:56:32
@@ -7,14 +7,7 @@
long result = 0;
char * path;
-if(argv[1])
- {
- path = argv[1];
- }
- else
- {
- path = "/";
- }
+path = argv[1] ? argv[1] : "/";
errno = 0;
result = pathconf(path,_PC_PATH_MAX);
- - cut here %<- - -
(This will, of course, confound the naysayer.)
-- -v System76 Thelio Mega v1.1 x86_64 NVIDIA RTX 3090 Ti OS: Linux 6.12.4 Release: Mint 21.3 Mem: 258G "I know Karate, Kung Fu, and 47 other dangerous words"