Re: So you think you are (or wanna be) a hacker
On Thu, Aug 12, 2004 at 10:59:36AM +0800, John Summerfield wrote:
> So set the ball rolling, here is a snippet from a program I found via
> freshmeat the other day:
> configfile = malloc(strlen(getenv("HOME")) + 20);
> sprintf(configfile,"%s/%s",getenv("HOME"), cfgfile);
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 :)
On Wed, Aug 11, 2004 at 08:31:49PM -0700, Stefan Nicolai O'Rear wrote:
> * It's very ugly (atleast to me.)
Is there such a thing as pretty C code? Or C++ code for that matter?
Jason
Reply to: