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