#include<ftw.h>
+#include<fs.h>
#include<hash.h>
#include<hashmap.h>
#include<log.h>
-#include<util.h>
#define ADD_MESSAGE_ADDING_TORRENT "adding all files in %s to torrent named %s\n"
#define ADD_MESSAGE_ADDED_FILE "added file %s\n"
#include<sodium.h>
#include<block.h>
-#include<util.h>
+#include<fs.h>
struct file {
char *name;
-#ifndef __UTIL_H_
-#define __UTIL_H_
+#ifndef __FS_H_
+#define __FS_H_
#include<dirent.h>
#include<stdio.h>
#include<libgen.h>
#include<string.h>
+#include<fs.h>
#include<log.h>
#include<session.h>
#include<torrent.h>
-#include<util.h>
enum file_filters {
FILE_FILTER_IGNORE_DOTFILES,
-#include<util.h>
+#include<fs.h>
char *concat(const char *a, const char *b) {
int len_a, len_b;
if(NULL==p) { return NULL; }
strcpy(p,a);
- if(a[len_a-1]!='/') {
- strcat(p,"/");
+
+ if(a[len_a-1]=='/') {
+ if(b[0]=='/') {
+ p[len_a-1] = '\0';
+ }
+ } else {
+ if(b[0]!='/') {
+ strcat(p,"/");
+ }
}
+
strcat(p,b);
return p;
-#include<util.h>
+#include<fs.h>
int is_directory(const char *path) {
struct stat st;
-#include<util.h>
+#include<fs.h>
int is_file(const char *path) {
struct stat st;
-#include<util.h>
+#include<fs.h>
int file_filter_all(const char *path) {
return 1;
-DNDEBUG
endif
-check_PROGRAMS = bencode.tests block.tests file.tests hash.tests hashmap.tests torrent.tests tree.tests fs.filter.tests
+check_PROGRAMS = bencode.tests block.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests torrent.tests tree.tests
TESTS = $(check_PROGRAMS)
if ENABLE_MEMCHECK
$(top_srcdir)/src/file.c \
$(top_srcdir)/src/hash.c
+fs_concat_tests_SOURCES = \
+ $(common_SOURCES) \
+ fs.concat.tests.c \
+ $(top_srcdir)/src/fs/concat.c
+
+fs_filter_tests_SOURCES = \
+ $(common_SOURCES) \
+ fs.filter.tests.c \
+ $(top_srcdir)/src/fs/filter.c
+
hash_tests_SOURCES = \
$(common_SOURCES) \
hash.tests.c \
$(top_srcdir)/src/file.c \
$(top_srcdir)/src/hash.c \
$(top_srcdir)/src/tree.c
-
-fs_filter_tests_SOURCES = \
- $(common_SOURCES) \
- fs.filter.tests.c \
- $(top_srcdir)/src/fs/filter.c
--- /dev/null
+#include<test_utils.h>
+
+#include<fs.h>
+
+int main();
+static void concat_basic_test();
+
+int main() {
+ setup_env();
+
+ concat_basic_test();
+
+ clean_env();
+
+ return EXIT_SUCCESS;
+}
+
+static void concat_basic_test() {
+ char *p;
+
+ p = concat(NULL,"test");
+ assert(NULL==p);
+
+ p = concat("test",NULL);
+ assert(NULL==p);
+
+ p = concat("","test");
+ assert(NULL==p);
+
+ p = concat("tesotijset","");
+ assert(NULL==p);
+
+ p = concat("alsidfjalskdjfasdf","alsdkfjlsakdfj");
+ assert(strcmp(p,"alsidfjalskdjfasdf/alsdkfjlsakdfj")==0);
+ free(p);
+
+ p = concat("/asdofijsd/asdofijasdf/asodiifjasoidf/","/asdlkfjsdklf/a/sdldf/adklj");
+ assert(strcmp(p,"/asdofijsd/asdofijasdf/asodiifjasoidf/asdlkfjsdklf/a/sdldf/adklj")==0);
+ free(p);
+
+ p = concat("/dkjflaskdjfalksdjflkajsd","/");
+ assert(strcmp(p,"/dkjflaskdjfalksdjflkajsd/")==0);
+ free(p);
+}
#include<test_utils.h>
-#include<util.h>
+#include<fs.h>
int main();
static void file_filter_all_basic_tests();
return EXIT_SUCCESS;
}
-void file_filter_all_basic_tests() {
+static void file_filter_all_basic_tests() {
assert(1==file_filter_all(TEST_FILE_1));
assert(1==file_filter_all(TEST_FILE_2));
}
-void file_filter_ignore_dotfiles_basic_tests() {
+static void file_filter_ignore_dotfiles_basic_tests() {
assert(1==file_filter_ignore_dotfiles(TEST_FILE_1));
assert(1==file_filter_ignore_dotfiles(TEST_FILE_2));
assert(-1==file_filter_ignore_dotfiles(TEST_FILE_3));