[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: So you think you are (or wanna be) a hacker



On Thursday 12 August 2004 15:38, Jason Rennie wrote:

> Something a bit safer...
>
> char *home = getenv("HOME");
> if (home == NULL || cfgfile == NULL) hittheuseronthehead();
> int sz = strlen(home) + strlen(cfgfile) + 2;
> char *configfile = malloc(sizeof(char)*sz);
> sprintf(configfile,"%s/%s",home,cfgfile);
>
> I'm sure someone can do better (and be more creative :)

I'm partial to:

    if not os.getenv('HOME') or not cfgfile:
        raise ForgotToSetConfigfileError
    return '%s/%s' % (os.getenv('HOME'), cfgfile)

but that's just me.  ;-)
-- 
Kirk Strauser

Attachment: pgpemK0nSFWb3.pgp
Description: signature


Reply to: