code quality updates based on clang output
This commit is contained in:
parent
bb4262319d
commit
eade6ab65b
9
Makefile
9
Makefile
@ -1,16 +1,19 @@
|
||||
SOURCE := main.c opts.c directive.c file_utils.c error.c dictate.c remove_all.c
|
||||
SOURCE := $(addprefix source/, ${SOURCE})
|
||||
|
||||
CFLAGS += -Wno-unused-label
|
||||
|
||||
ifeq (${DEBUG}, 1)
|
||||
CPPFLAGS += -DDEBUG
|
||||
CFLAGS += -O0 -ggdb -Wall -Wpedantic
|
||||
CFLAGS += -fsanitize=address
|
||||
CPPFLAGS += -DDEBUG
|
||||
ifeq (${CC}, clang)
|
||||
CFLAGS += -Weverything -Wno-switch-default -std=c23 -Wno-pre-c23-compat
|
||||
endif
|
||||
else
|
||||
CFLAGS += -O3 -flto=auto -fomit-frame-pointer
|
||||
endif
|
||||
|
||||
CFLAGS += -Wno-unused-label
|
||||
|
||||
OUT := vimdir
|
||||
|
||||
${OUT}: ${SOURCE}
|
||||
|
@ -33,7 +33,7 @@ int path_cmp(const char * a, const char * b) {
|
||||
if (*b == '/' && *a != '\0') { return 1; }
|
||||
|
||||
end:
|
||||
return *(unsigned char *)a - *(unsigned char *)b;
|
||||
return *(const unsigned char *)a - *(const unsigned char *)b;
|
||||
}
|
||||
|
||||
static
|
||||
@ -136,11 +136,11 @@ int init_directive_c(const char * const folder) {
|
||||
}
|
||||
|
||||
int deinit_directive_c(void) {
|
||||
for (int i = 0; i < entries.n; i++) {
|
||||
for (size_t i = 0; i < entries.n; i++) {
|
||||
free(kv_A(entries, i).name);
|
||||
}
|
||||
|
||||
for (int i = 0; i < move_data.n; i++) {
|
||||
for (size_t i = 0; i < move_data.n; i++) {
|
||||
move_data_t move = kv_A(move_data, i);
|
||||
free(move.orig_name);
|
||||
free(move.curt_name);
|
||||
@ -156,10 +156,10 @@ int deinit_directive_c(void) {
|
||||
}
|
||||
|
||||
int make_directive_file(FILE * f) {
|
||||
for (int i = 0; i < entries.n; i++) {
|
||||
for (size_t i = 0; i < entries.n; i++) {
|
||||
entry_t * entry = &kv_A(entries, i);
|
||||
// ID
|
||||
fprintf(f, "%03d",
|
||||
fprintf(f, "%03ld",
|
||||
i
|
||||
);
|
||||
// Permissions
|
||||
@ -354,7 +354,7 @@ int execute_directive_file(FILE * f) {
|
||||
}
|
||||
|
||||
// Deletion
|
||||
for (int i = 0; i < entries.n; i++) {
|
||||
for (size_t i = 0; i < entries.n; i++) {
|
||||
entry_t * entry = &kv_A(entries, i);
|
||||
if (!entry->is_mentioned) {
|
||||
CHECK(mydelete(entry->name));
|
||||
@ -362,7 +362,7 @@ int execute_directive_file(FILE * f) {
|
||||
}
|
||||
|
||||
// Swap (move)
|
||||
for (int i = 0; i < move_data.n; i++) {
|
||||
for (size_t i = 0; i < move_data.n; i++) {
|
||||
move_data_t move = kv_A(move_data, i);
|
||||
// NOTE: we could be overwritting here;
|
||||
// thats the behaviour the user would expect
|
||||
@ -386,7 +386,7 @@ int execute_directive_file(FILE * f) {
|
||||
* Therefor, files waiting to be swapped (possessing a temporary name) are restored back
|
||||
* (if possible, if we run into another error, theres not much to do).
|
||||
*/
|
||||
for (int i = 0; i < move_data.n; i++) {
|
||||
for (size_t i = 0; i < move_data.n; i++) {
|
||||
move_data_t move = kv_A(move_data, i);
|
||||
if (!access(move.orig_name, F_OK)) {
|
||||
mymove(move.curt_name, move.orig_name);
|
||||
|
@ -21,10 +21,11 @@ enum {
|
||||
extern void errorn(int n, ...);
|
||||
extern void notice(const char * fmt, ...);
|
||||
|
||||
#define CHECK_OPEN(f, n, E) \
|
||||
if (!f) { \
|
||||
errorn(E_FILE_ACCESS, n); \
|
||||
E; \
|
||||
}
|
||||
#define CHECK_OPEN(f, n, E) do { \
|
||||
if (!f) { \
|
||||
errorn(E_FILE_ACCESS, n); \
|
||||
E; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
@ -70,7 +71,7 @@ int init_file_utils(bool is_dry_run, const char * custom_rm_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int deinit_file_utis() {
|
||||
int deinit_file_utis(void) {
|
||||
mytouch = NULL;
|
||||
mydelete = NULL;
|
||||
mychmod = NULL;
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
extern int init_file_utils(bool is_dry_run, const char * custom_rm_);
|
||||
extern int deinit_file_utis();
|
||||
extern int deinit_file_utis(void);
|
||||
|
||||
extern char * trim_trailing_slashes(char * path);
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include "global.h"
|
||||
#include "error.h"
|
||||
#include "opts.h"
|
||||
#include "directive.h"
|
||||
@ -17,6 +18,7 @@ bool is_recursive = false;
|
||||
bool do_permissions = false;
|
||||
bool do_owner = false;
|
||||
|
||||
static
|
||||
int get_tmpfile_name(char * name_buffer) {
|
||||
#if DEBUG == 1
|
||||
strcpy(name_buffer, "vimdir_test_file.vimdir");
|
||||
@ -32,6 +34,7 @@ int get_tmpfile_name(char * name_buffer) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
int edit(const char * filename) {
|
||||
size_t cmd_len = strlen(editor) + sizeof(' ') + strlen(filename) + 1;
|
||||
char cmd[cmd_len];
|
||||
@ -67,7 +70,7 @@ signed main(int argc, char * * argv) {
|
||||
folder = trim_trailing_slashes(folder);
|
||||
|
||||
create:
|
||||
FILE * tmpfile;
|
||||
FILE * tmpfile = NULL;
|
||||
char tmpfile_name[32];
|
||||
|
||||
CHECK(get_tmpfile_name(tmpfile_name));
|
||||
|
Loading…
x
Reference in New Issue
Block a user