Deutsch English Français Italiano |
<lrr454F1u8jU1@mid.individual.net> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: vallor <vallor@cultnix.org> Newsgroups: comp.os.linux.advocacy Subject: Re: Fine, let's see you using pathconf(3) on Windows (was: Re: Then there's PATH_MAX) Date: 10 Dec 2024 15:13:40 GMT Lines: 124 Message-ID: <lrr454F1u8jU1@mid.individual.net> References: <lrnft4Fd071U5@mid.individual.net> <180fd2f32d5884e5$6049$1734$802601b3@news.usenetexpress.com> <lrqvnoF55oU2@mid.individual.net> <180fd7fa66284739$61502$1728$802601b3@news.usenetexpress.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net CpIUoBCSca9ZLaHY/EDiUgxZRbVNPRswg/IwgzW0otYEaW1hJn Cancel-Lock: sha1:D8oFX8bUyeDdKTIDKzl+NA+65JE= sha256:YgSSDfMf/ZxO1vxwdmSBv1/9ryzEL9Ffe79yO2LaXxs= X-Face: +McU)#<-H?9lTb(Th!zR`EpVrp<0)1p5CmPu.kOscy8LRp_\u`:tW;dxPo./(fCl CaKku`)]}.V/"6rISCIDP` User-Agent: Pan/0.161 (Hmm2; be402cc9; Linux-6.12.4) Bytes: 3762 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? -- -v System76 Thelio Mega v1.1 x86_64 NVIDIA RTX 3090 Ti OS: Linux 6.12.4 Release: Mint 21.3 Mem: 258G "Any closet is a walk-in closet if you try hard enough."