On Thu, Aug 12, 2004 at 04:38:25PM -0400, 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 :)
Using a glibc extension, how about: char *configfile; asprintf (&configfile, "%s/%s", getenv ("HOME"), cfgfile); aprintf auto-mallocs a buffer of the right size. Be sure to free()! -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]