diff --git a/src/autocomplete.c b/src/autocomplete.c index 03588ca..5468131 100644 --- a/src/autocomplete.c +++ b/src/autocomplete.c @@ -107,10 +107,9 @@ int complete_line(ToxWindow *self, const void *list, size_t n_items, size_t size return -1; } - const char *L = (char *) list; + const char *L = (const char *) list; const char *endchrs = " "; - char ubuf[MAX_STR_SIZE]; - memset(ubuf, 0, sizeof(ubuf)); + char ubuf[MAX_STR_SIZE] = {0}; /* work with multibyte string copy of buf for simplicity */ if (wcs_to_mbs_buf(ubuf, ctx->line, sizeof(ubuf)) == -1) { diff --git a/src/execute.c b/src/execute.c index 58711a0..f70d328 100644 --- a/src/execute.c +++ b/src/execute.c @@ -129,10 +129,9 @@ static const char special_commands[SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = { /* Returns true if input command is in the special_commands array. */ static bool is_special_command(const char *input) { - int s = char_find(0, input, ' '); - int i; + const int s = char_find(0, input, ' '); - for (i = 0; i < SPECIAL_COMMANDS; ++i) { + for (int i = 0; i < SPECIAL_COMMANDS; ++i) { if (strncmp(input, special_commands[i], s) == 0) { return true; } diff --git a/src/groupchat.c b/src/groupchat.c index 3427d78..de5bdba 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -512,7 +512,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) } #ifdef PYTHON - else if (wcsncmp(ctx->line, L"/run \"", wcslen(L"/run ")) == 0) { + else if (wcsncmp(ctx->line, L"/run ", wcslen(L"/run ")) == 0) { diff = dir_match(self, m, ctx->line, L"/run"); } diff --git a/src/misc_tools.c b/src/misc_tools.c index 8da3b2e..bb5324f 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -481,22 +481,25 @@ bool file_exists(const char *path) return stat(path, &s) == 0; } -/* Returns 0 if path points to a directory. - * Returns 1 if path points to a regular file. - * Returns -1 on any other result. +/* + * Checks the file type path points to and returns a File_Type enum value. + * + * Returns FILE_TYPE_DIRECTORY if path points to a directory. + * Returns FILE_TYPE_REGULAR if path points to a regular file. + * Returns FILE_TYPE_OTHER on any other result, including an invalid path. */ -int file_type(const char *path) +File_Type file_type(const char *path) { struct stat s; stat(path, &s); switch (s.st_mode & S_IFMT) { case S_IFDIR: - return 0; + return FILE_TYPE_DIRECTORY; case S_IFREG: - return 1; + return FILE_TYPE_REGULAR; default: - return -1; + return FILE_TYPE_OTHER; } } diff --git a/src/misc_tools.h b/src/misc_tools.h index c149488..92f48ee 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -39,6 +39,14 @@ #define net_to_host(x, y) hst_to_net(x, y) #endif +typedef enum File_Type +{ + FILE_TYPE_REGULAR, + FILE_TYPE_DIRECTORY, + FILE_TYPE_OTHER, +} File_Type; + + void hst_to_net(uint8_t *num, uint16_t numbytes); /* @@ -146,11 +154,14 @@ void bytes_convert_str(char *buf, int size, uint64_t bytes); /* checks if a file exists. Returns true or false */ bool file_exists(const char *path); -/* Returns 0 if path points to a directory. - * Returns 1 if path points to a regular file. - * Returns -1 on any other result. +/* + * Checks the file type path points to and returns a File_Type enum value. + * + * Returns FILE_TYPE_DIRECTORY if path points to a directory. + * Returns FILE_TYPE_REGULAR if path points to a regular file. + * Returns FILE_TYPE_OTHER on any other result, including an invalid path. */ -int file_type(const char *path); +File_Type file_type(const char *path); /* returns file size. If file doesn't exist returns 0. */ off_t file_size(const char *path);