[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: KStandardDirs
From:       Matt Newell <newellm () blur ! com>
Date:       2003-06-05 19:23:44
[Download RAW message or body]

On Thursday 05 June 2003 11:45, Stephan Kulow wrote:
> Am Thursday 05 June 2003 19:42 schrieb Amilcar do Carmo Lucas:
> > static void fixHomeDir(QString &dir)
> > {
> >    if (dir[0] == '~' && dir[1] == '/')
> >    {
> >       dir = QDir::homeDirPath() + dir.mid(1);
> >    }
> >    else
> >    {
> >       dir = "/home/" + dir.mid(1);
> >    }
> > }
>
> Well, who set KDEDIR to ~foo/kde and expects it to work?  :)
> But your suggested code is even more buggy ;(
>
> Greetings, Stephan

No, ~username at the front of a path is supposed to be expanded to the home 
directory of username.  I just read about this yesterday in some unix 
programming faq. The correct(untested) code is.

#include <pwd.h>
#include <sys/types.h>

static void fixHomeDir(QString &dir)
{
	if (dir[0] == '~')
	{
		if( dir[1] == '/')
		{
			dir = QDir::homeDirPath() + dir.mid(1);
			return;
		}
		struct passwd * ps = getpwnam( dir.section('/',0,0).mid(1).latin1() );
		if( !ps )
			return;
		QString home(ps->pw_dir);
		if( home.size()==0 || home[home.size()-1]!='/' )
			home+='/';
		dir = home + dir.section( '/',1 );
	}
}

Matt

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic