Permalink
Browse files

...Part 3: Added full path handling capabilities to 'potion_initializ…

…er_name'.
  • Loading branch information...
1 parent 8797f09 commit f4d2aad0f808cd98ba3338777f932610f0dc27fb @orangea orangea committed Dec 20, 2010
Showing with 7 additions and 4 deletions.
  1. +7 −4 core/load.c
View
11 core/load.c
@@ -46,19 +46,22 @@ void potion_load_code(Potion *P, const char *filename) {
static PN potion_initializer_name(Potion *P, const char *filename, PN_SIZE len) {
PN_SIZE ext_name_len = 0;
- char *ext_name;
+ char *allocated_str, *ext_name;
PN func_name = potion_byte_str(P, "Potion_Init_");
while (*(filename + ++ext_name_len) != '.' && ext_name_len <= len);
- ext_name = malloc(ext_name_len + 1);
- if (ext_name == NULL) {
+ allocated_str = ext_name = malloc(ext_name_len + 1);
+ if (allocated_str == NULL) {
// TODO: fatal error
fprintf(stderr, "** Couldn't allocate memory.\n");
exit(1);
}
strncpy(ext_name, filename, ext_name_len);
ext_name[ext_name_len] = '\0';
+ ext_name += ext_name_len;
+ while (*--ext_name != '/' && ext_name >= allocated_str);
+ ext_name++;
pn_printf(P, func_name, "%s", ext_name);
- free(ext_name);
+ free(allocated_str);
return func_name;
}

0 comments on commit f4d2aad

Please sign in to comment.