Skip to content

Instantly share code, notes, and snippets.

@hapejot
Created December 11, 2021 22:34
Show Gist options
  • Select an option

  • Save hapejot/a729d22bc0acc81d6b6a7d3118abaf14 to your computer and use it in GitHub Desktop.

Select an option

Save hapejot/a729d22bc0acc81d6b6a7d3118abaf14 to your computer and use it in GitHub Desktop.
build name of a config file in home directory
char *create_config_name( const char *name )
{
char *p1 = getenv( "HOME" );
char *p2 = "/.";
int len = strlen( p1 ) + strlen( p2 ) + strlen( name ) + 1;
char *p3 = malloc( len );
assert( p3 );
strcpy( p3, p1 );
strcat( p3, p2 );
strcat( p3, name );
assert( strlen( p3 ) < len );
return p3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment