diff --git a/CMakeLists.txt b/CMakeLists.txt index 195b7c7..f2c0b62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,22 +6,21 @@ project(mediafire-tools) # to feed iwyu during tests set(CMAKE_EXPORT_COMPILE_COMMANDS 1) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Werror") +# the following is until we learn how to reorder the gcc arguments to correctly link on Ubuntu +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed") + add_library(mfapi SHARED mfapi/mfconn.c mfapi/file.c mfapi/folder.c mfapi/apicalls/file_get_info.c mfapi/apicalls/user_get_info.c mfapi/apicalls/file_get_links.c mfapi/apicalls/user_session.c mfapi/apicalls/folder_get_info.c mfapi/apicalls/folder_create.c mfapi/apicalls/folder_get_content.c mfapi/apicalls/folder_delete.c mfapi/apicalls/device_get_status.c mfapi/apicalls/device_get_changes.c) -set_target_properties(mfapi PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror") add_library(mfutils SHARED utils/http.c utils/json.c utils/strings.c utils/stringv.c) -set_target_properties(mfutils PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror") add_executable(mediafire-shell mfshell/main.c mfshell/mfshell.c mfshell/commands/folder.c mfshell/commands/auth.c mfshell/commands/chdir.c mfshell/commands/debug.c mfshell/commands/file.c mfshell/commands/get.c mfshell/commands/help.c mfshell/commands/host.c mfshell/commands/lcd.c mfshell/commands/links.c mfshell/commands/list.c mfshell/commands/lpwd.c mfshell/commands/mkdir.c mfshell/commands/pwd.c mfshell/commands/whoami.c mfshell/commands/rmdir.c mfshell/commands/status.c mfshell/commands/changes.c mfshell/config.c mfshell/options.c) -set_target_properties(mediafire-shell PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror") -set_target_properties(mediafire-shell PROPERTIES LINK_FLAGS "-Wl,--no-as-needed") target_link_libraries(mediafire-shell curl ssl crypto jansson mfapi mfutils) enable_testing() add_executable(mediafire-fuse fuse/main.c fuse/hashtbl.c) -set_target_properties(mediafire-fuse PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror -D_FILE_OFFSET_BITS=64") -set_target_properties(mediafire-fuse PROPERTIES LINK_FLAGS "-Wl,--no-as-needed") +set_target_properties(mediafire-fuse PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") target_link_libraries(mediafire-fuse curl ssl fuse jansson mfapi mfutils) add_test(iwyu ${CMAKE_SOURCE_DIR}/tests/iwyu.py ${CMAKE_BINARY_DIR}) diff --git a/fuse/hashtbl.c b/fuse/hashtbl.c index 0c69d73..675d832 100644 --- a/fuse/hashtbl.c +++ b/fuse/hashtbl.c @@ -16,6 +16,9 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup and struct timespec (in fuse.h) + // and S_IFDIR and S_IFREG + #include #include #include @@ -60,7 +63,12 @@ static unsigned char base36_decoding_table[] = { /* * a macro to convert a char* of the key into a hash of its first three - * characters + * characters, treating those first three characters as if they represented a + * number in base36 + * + * in the future this could be made more dynamic by using the ability of + * strtoll to convert numbers of base36 and then only retrieving the desired + * amount of high-bits for the desired size of the hashtable */ #define HASH_OF_KEY(key) base36_decoding_table[(int)(key)[0]]*36*36+\ base36_decoding_table[(int)(key)[1]]*36+\ @@ -518,7 +526,7 @@ static struct h_entry *folder_tree_lookup_path(folder_tree * tree, result = curr_dir; break; } - slash_pos = index(tmp_path, '/'); + slash_pos = strchr(tmp_path, '/'); if (slash_pos == NULL) { // no slash found in the remaining path: // find entry in current directory and return it diff --git a/fuse/main.c b/fuse/main.c index ff2e72a..c0bdc4e 100644 --- a/fuse/main.c +++ b/fuse/main.c @@ -16,6 +16,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup and struct timespec + #define FUSE_USE_VERSION 30 #include @@ -199,7 +201,7 @@ static int mediafirefs_mkdir(const char *path, mode_t mode) /* split into dirname and basename */ - basename = rindex(dirname, '/'); + basename = strrchr(dirname, '/'); if (basename == NULL) { fprintf(stderr, "cannot find slash\n"); return -ENOENT; diff --git a/mfapi/apicalls/user_session.c b/mfapi/apicalls/user_session.c index c6a43bb..5d41866 100644 --- a/mfapi/apicalls/user_session.c +++ b/mfapi/apicalls/user_session.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup + #include #include #include diff --git a/mfapi/file.c b/mfapi/file.c index e4c67fe..c8ce413 100644 --- a/mfapi/file.c +++ b/mfapi/file.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup + #include #include #include diff --git a/mfapi/mfconn.c b/mfapi/mfconn.c index 0c2e649..93fca58 100644 --- a/mfapi/mfconn.c +++ b/mfapi/mfconn.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup + #include #include #include diff --git a/mfshell/commands/auth.c b/mfshell/commands/auth.c index 2d02286..bd538c0 100644 --- a/mfshell/commands/auth.c +++ b/mfshell/commands/auth.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for getline + #include #include #include diff --git a/mfshell/commands/folder.c b/mfshell/commands/folder.c index 73eec2c..17aced2 100644 --- a/mfshell/commands/folder.c +++ b/mfshell/commands/folder.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for gmtime_r + #include #include #include diff --git a/mfshell/commands/get.c b/mfshell/commands/get.c index 41b5529..408c388 100644 --- a/mfshell/commands/get.c +++ b/mfshell/commands/get.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for PATH_MAX + #include #include #include diff --git a/mfshell/commands/host.c b/mfshell/commands/host.c index def5544..dabf80e 100644 --- a/mfshell/commands/host.c +++ b/mfshell/commands/host.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup and getline + #include #include #include diff --git a/mfshell/commands/lcd.c b/mfshell/commands/lcd.c index 270e44d..a1cad9d 100644 --- a/mfshell/commands/lcd.c +++ b/mfshell/commands/lcd.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup + #include #include #include diff --git a/mfshell/commands/lpwd.c b/mfshell/commands/lpwd.c index 3587f94..badeee7 100644 --- a/mfshell/commands/lpwd.c +++ b/mfshell/commands/lpwd.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for PATH_MAX + #include #include #include diff --git a/mfshell/config.c b/mfshell/config.c index 35eedc9..9d89493 100644 --- a/mfshell/config.c +++ b/mfshell/config.c @@ -16,6 +16,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for getline + #include #include #include diff --git a/mfshell/main.c b/mfshell/main.c index aa52faa..1ff4828 100644 --- a/mfshell/main.c +++ b/mfshell/main.c @@ -17,6 +17,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup + #include #include #include diff --git a/mfshell/mfshell.c b/mfshell/mfshell.c index 2434059..0c7c125 100644 --- a/mfshell/mfshell.c +++ b/mfshell/mfshell.c @@ -17,6 +17,9 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup and getline +#define _BSD_SOURCE // for strsep + #include #include #include diff --git a/mfshell/options.c b/mfshell/options.c index bf0b612..12a9d1e 100644 --- a/mfshell/options.c +++ b/mfshell/options.c @@ -16,6 +16,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup + #include #include #include diff --git a/utils/stringv.c b/utils/stringv.c index 403ec66..d7d116c 100644 --- a/utils/stringv.c +++ b/utils/stringv.c @@ -16,6 +16,8 @@ * */ +#define _POSIX_C_SOURCE 200809L // for strdup + #include #include #include