Skip to content

Commit

Permalink
Do not use strlcpy and strlcat
Browse files Browse the repository at this point in the history
They are not standard yet.  Better for now to avoid them.
  • Loading branch information
guillaumechereau committed Jul 16, 2024
1 parent ae070d1 commit edcb5a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/goxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ static inline float smoothstep(float edge0, float edge1, float x)
return x * x * (3.0f - 2.0f * x);
}

// Fallback for strlcpy if it doesn't exists.
#ifndef strlcpy
#define strlcpy(dst, src, size) snprintf(dst, size, "%s", src)
#endif

/*
* Function: mix
* Linear blend of x and y.
Expand Down
12 changes: 7 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,24 @@ static void split_path_and_file(

sep = strrchr(path_and_file, '/');
if (!sep) {
strlcpy(path, path_and_file, path_size);
file[0] = '\0';
snprintf(file, file_size, "%s", path_and_file);
path[0] = '\0';
} else {
path_len = (int)(sep - path_and_file);
snprintf(path, path_size, "%.*s", path_len, path_and_file);
strlcpy(file, sep + 1, file_size);
snprintf(file, file_size, "%s", sep + 1);
}
}

static void filters_to_nfd_spec(
const char *const *filters, char buf[], size_t buf_size)
{
int i;
size_t len = 0;

buf[0] = '\0';
for (i = 0; filters[i]; i++) {
strlcat(buf, filters[i] + 2, buf_size);
len += snprintf(buf + len, buf_size - len, "%s", filters[i] + 2);
}
}

Expand Down Expand Up @@ -356,7 +358,7 @@ static bool open_dialog(
&(nfdsavedialogu8args_t){
.filterList = &filter,
.filterCount = 1,
.defaultPath = default_path,
.defaultPath = default_path[0] ? default_path : NULL,
.defaultName = default_name,
.parentWindow = nfd_window,
});
Expand Down

0 comments on commit edcb5a4

Please sign in to comment.