Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
7.2.1 : minor optimisations and simplifications
Browse files Browse the repository at this point in the history
Signed-off-by: Ari Archer <[email protected]>
  • Loading branch information
Ari Archer committed Mar 1, 2023
1 parent 57a4203 commit 178fd4a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion baz
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ "$BAZ_DEBUG" ] && set -x

export BAZ_VERSION='7.2.0'
export BAZ_VERSION='7.2.1'
export BAZ_DIR="$HOME/.local/share/baz"
export BAZ_CONFDIR="$HOME/.config/baz"
export BAZ_CONF="$BAZ_CONFDIR/config.env"
Expand Down
2 changes: 1 addition & 1 deletion loader/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void alloc_file(const char *path, File *f) {

lseek(fd, 0, SEEK_SET);

if (content_size >= f->content_size)
if (content_size > f->content_size)
f->content = mem_realloc(f->content, content_size + 2);

f->content_size = content_size;
Expand Down
14 changes: 6 additions & 8 deletions loader/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ chop_str(const char *str, const unsigned long begin, const unsigned long end) {
if (begin >= end)
return NULL;

buf = mem_alloc((sizeof str[0]) * (end - begin) + 1);
buf = mem_alloc((end - begin + 1) * sizeof(char));

for (idx = begin; idx <= end; ++idx)
buf[idx - begin] = str[idx];
Expand All @@ -33,25 +33,23 @@ static char *get_base(const char *path) {
const size_t len = strlen(path);
unsigned long last_slash = 0, idx;

for (idx = 0; idx < len; ++idx) {
for (idx = 0; idx < len; ++idx)
if (path[idx] == '/')
last_slash = idx;
}

return chop_str(path, last_slash + 1, len);
}

static unsigned char path_exists(const char *path) {
struct stat buffer;
return stat(path, &buffer) == 0;
return access(path, F_OK) == 0;
}

static struct dirent *readdir_visible(DIR *dp) {
struct dirent *ep;

while ((ep = readdir(dp)))
if (ep->d_name[0] != '.')
break;
do {
ep = readdir(dp);
} while (ep && ep->d_name[0] == '.');

return ep;
}
Expand Down
7 changes: 1 addition & 6 deletions loader/str.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include <stddef.h>
#endif

struct struct_Str {
size_t len, idx;
char *string;
};

typedef struct {
size_t len, idx;
char *string;
Expand All @@ -19,7 +14,7 @@ static void str_free(Str *);

#ifdef STR_IMPL
static void str_append(Str *str, const char chr) {
if (str->idx >= str->len)
if (str->idx == str->len)
str->string = mem_realloc(str->string, (str->len += STR_GROWTH));

str->string[str->idx++] = chr;
Expand Down

0 comments on commit 178fd4a

Please sign in to comment.