Thanks for fixing my mistake :-)
On Sat, Nov 3, 2012 at 6:57 PM, Christiano F. Haesbaert <[email protected]> wrote: > On Tue, Oct 30, 2012 at 04:44:36PM +0100, rustyBSD wrote: >> Le 30/10/2012 15:32, Christiano F. Haesbaert a ?crit : >> > That should be an access(2) call. >> Yes.Something like this - also moved len to size_t, >> as strlen() is size_t: >> >> >> --- dired.c Wed Mar 14 14:56:35 2012 >> +++ dired.c Tue Oct 30 16:23:00 2012 >> @@ -724,9 +724,10 @@ >> dired_(char *dname) >> { >> struct buffer *bp; >> - int len, i; >> + int i; >> + size_t len; >> >> - if ((fopen(dname,"r")) == NULL) { >> + if (access(dname, R_OK) == -1) { >> if (errno == EACCES) >> ewprintf("Permission denied"); >> return (NULL); >> > > Your diff got mangled, it replaced tabs for spaces, anyway, I think we > should also check for X_OK, otherwise we can't list the directory > anyway. > > We still get the message "File is not readable", but I believe it's more > useful than showing an empty directory. > > Index: dired.c > =================================================================== > RCS file: /cvs/src/usr.bin/mg/dired.c,v > retrieving revision 1.51 > diff -d -u -p -r1.51 dired.c > --- dired.c 14 Mar 2012 13:56:35 -0000 1.51 > +++ dired.c 3 Nov 2012 14:47:18 -0000 > @@ -724,9 +724,10 @@ struct buffer * > dired_(char *dname) > { > struct buffer *bp; > - int len, i; > + int i; > + size_t len; > > - if ((fopen(dname,"r")) == NULL) { > + if ((access(dname, R_OK | X_OK)) == -1) { > if (errno == EACCES) > ewprintf("Permission denied"); > return (NULL); > -- Brightest day, Blackest night, No bug shall escape my sight, And those who worship evil's mind, be wary of my powers, puffy lantern's light !
