diff --git a/build-system/CMakeLists.txt b/build-system/CMakeLists.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..85f8714f222c21a6ce71d0e3574416b0f609ff1c 100644 --- a/build-system/CMakeLists.txt +++ b/build-system/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.10) + +# set the project name +project(MainProgram) +option(TRIG_FUNCTIONS "Use trig func" ON) +set(IS_HOST_WINDOWS,ON) +configure_file(MainProgramConfig.h.in MainProgramConfig.h) +add_library(copyfile SHARED copyfile.c) +if(${CMAKE_HOST_SYSTEM_NAME}!="Windows") +set(IS_HOST_WINDOWS,OFF) +endif() +# add the executable +add_executable(MainProgram main.cpp) +target_link_libraries(MainProgram ${CMAKE_DL_LIBS} copyfile) +target_include_directories(MainProgram PUBLIC + "${PROJECT_BINARY_DIR}" + ) \ No newline at end of file diff --git a/build-system/MainProgramConfig.h.in b/build-system/MainProgramConfig.h.in new file mode 100644 index 0000000000000000000000000000000000000000..14bae43409da399306a08fdd0d9a5976fad92551 --- /dev/null +++ b/build-system/MainProgramConfig.h.in @@ -0,0 +1,4 @@ +#define CopyFile_VERSION_MAJOR @CopyFile_VERSION_MAJOR@ +#define CopyFile_VERSION_MINOR @CopyFile_VERSION_MINOR@ +#cmakedefine TRIG_FUNCTIONS +#cmakedefine IS_HOST_WINDOWS \ No newline at end of file diff --git a/build-system/a b/build-system/a new file mode 100644 index 0000000000000000000000000000000000000000..d35bea13740f787e6298feb71b2b07d8ba4f3ff9 --- /dev/null +++ b/build-system/a @@ -0,0 +1 @@ +amongus \ No newline at end of file diff --git a/build-system/b b/build-system/b new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/build-system/copyfile.c b/build-system/copyfile.c index 3a26033b185f129b571940628e736e5a88c13522..ad8dd5bf13c4aaa33d40afbec93e5d87da22cf00 100644 --- a/build-system/copyfile.c +++ b/build-system/copyfile.c @@ -1,11 +1,20 @@ #include <stdio.h> - +#include <string.h> +#include <dlfcn.h> +#include "MainProgramConfig.h" +#include <fcntl.h> +#if !(IS_HOST_WINDOWS) +#include <linux/fs.h> +#include <sys/ioctl.h> +#endif +#include <errno.h> void copy_files() { int dest_fd, src_fd; + printf("lib called\n"); src_fd = open("a", O_RDONLY); dest_fd = open("b", O_WRONLY); /* Needs to exist; not checking this */ -#if 1 +#if !(IS_HOST_WINDOWS) printf("Using FICLONE\n"); if (ioctl(dest_fd, FICLONE, src_fd) < 0) { fprintf(stderr, "error: %s\n", strerror(errno)); diff --git a/build-system/main.cpp b/build-system/main.cpp index b43c749562301c49d8be6794e4391bab99244e19..2f4f7b7c6711439f09816f62196ae9007136a20f 100644 --- a/build-system/main.cpp +++ b/build-system/main.cpp @@ -1,15 +1,24 @@ #include <stdio.h> +#include <dlfcn.h> +#include <math.h> +#include "MainProgramConfig.h" int main(int argc, char **argv) { + void (*cpfileLib)(); /* Note: dlopen does not exist on Windows and the filename will not be .so. * If you are performing the labs on Windows, you need to change this. */ void *ptr = dlopen("libcopyfile.so", RTLD_LAZY); + if (ptr != NULL) { + cpfileLib = (void(*)()) dlsym(ptr,"copy_files"); + cpfileLib(); + } /* TODO: Call copy_files() from the opened shared object */ - { /* Disable this if --without-trig-functions or -DTRIG_FUNCTIONS:BOOL=OFF */ + #ifdef TRIG_FUNCTIONS + /* Disable this if --without-trig-functions or -DTRIG_FUNCTIONS:BOOL=OFF */ double d = cos(1.5); printf("The result of cos (a trigonometric function) is: %f\n", d); - } + #endif }