-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mkdirTemp to System module #536
Add mkdirTemp to System module #536
Conversation
b84c6c1
to
b220b78
Compare
strcpy(tmpl, "XXXXXX"); | ||
} | ||
|
||
char *tmpDir = mkdtemp(tmpl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth using the Result type here as mkdtemp can fail. In those situations it would be good to give some indication as to why it failed, we can do that by unwrapping a Result type
src/optionals/system.c
Outdated
char *tmpl = {0}; | ||
|
||
if (template[0] != '\0') { | ||
tmpl = malloc(strlen(template)+1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to avoid uses of malloc / alloc etc where possible and try to use the memory macros, this means if in the future we ever needed to change the memory allocator it's a simple switch.
We'll need to ensure we're freeing things up too since on success where creating a new string rather than inheriting the already alloc'd one.
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
b220b78
to
d5edce6
Compare
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
Signed-off-by: Brian Downs <brian.downs@gmail.com>
src/optionals/system.c
Outdated
if (template[0] != '\0') { | ||
tmpl = ALLOCATE(vm, char, strlen(template)); | ||
strcpy(tmpl, template); | ||
} else { | ||
tmpl = ALLOCATE(vm, char, PATH_MAX); | ||
strcpy(tmpl, "XXXXXX"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to allocate for the terminating char too. My thinking here also is that if no template is passed the directory would be made via the 6 digits of XXXXXX template right? Doesn't that mean we only need to allocate for these 6 + \0?
if (template[0] != '\0') { | |
tmpl = ALLOCATE(vm, char, strlen(template)); | |
strcpy(tmpl, template); | |
} else { | |
tmpl = ALLOCATE(vm, char, PATH_MAX); | |
strcpy(tmpl, "XXXXXX"); | |
} | |
if (template[0] != '\0') { | |
tmpl = ALLOCATE(vm, char, strlen(template) + 1); | |
strcpy(tmpl, template); | |
} else { | |
tmpl = ALLOCATE(vm, char, 7); | |
strcpy(tmpl, "XXXXXX"); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also probably keep reference to the length rather than calculating again via strlen in the takeString call
Signed-off-by: Brian Downs <brian.downs@gmail.com>
I see it's failing on the ubuntu machines, I'll need to give that a test and see whats going on but I don't have access to a machine until later on in the week now sorry! |
Nevermind, found the issue! The test didn't setup the template to end with |
Thanks. Been swamped this week. Was gonna get back to it this weekend. |
No worries at all! I'd just noticed the issue after another quick scan of the PR and thought I'd get it in. Appreciate the PRs you've been opening! |
Signed-off-by: Brian Downs brian.downs@gmail.com
Well detailed description of the change :
Adds the ability to create temporary directories.
Resolves: #
Type of change:
Bug fix
New feature
Breaking change (fix or feature that would cause existing functionality to not work as expected)
Housekeeping
Tests have been updated to reflect the changes done within this PR (if applicable).
Documentation has been updated to reflect the changes done within this PR (if applicable).
Preview (Screenshots) :