Skip to content

Commit

Permalink
Modified source.c
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandMarchand committed Jul 24, 2022
1 parent 9986915 commit 07e7d76
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/scanner/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,22 @@ struct source *source_new(const char *file)

int fd = open(file, O_RDONLY);
char *code = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
ASSERT(close(fd) != -1, "Failed to deallocate the file descriptor.");

struct source *sf = malloc(sizeof(struct source));

ASSERT(fd != -1 && code != MAP_FAILED && sf != NULL,
"Failed to allocate source file.");

*sf = (struct source){
.string = code,
.file_name = file,
.size = sb.st_size,
.file_descriptor = fd
};

return sf;
}

void source_close(struct source *sf)
{
ASSERT(munmap(sf->string, sf->size) != -1 &&
close(sf->file_descriptor) != -1, "Unable to close source file.");

ASSERT(munmap(sf->string, sf->size) != -1, "Unable to close source file.");
free(sf);
sf = NULL;
}

0 comments on commit 07e7d76

Please sign in to comment.