Просмотр исходного кода

implement execute_process function in OS

mikymod 12 лет назад
Родитель
Сommit
bc6c702ea5

+ 1 - 1
engine/CMakeLists.txt

@@ -538,7 +538,7 @@ add_executable(${CROWN_EXECUTABLE_NAME} ${CROWN_MAIN_SRC})
 target_link_libraries(${CROWN_EXECUTABLE_NAME} crown)
 
 if (CROWN_BUILD_TESTS)
-	#add_subdirectory(tests)
+	add_subdirectory(tests)
 endif (CROWN_BUILD_TESTS)
 
 install (TARGETS crown DESTINATION bin)

+ 5 - 0
engine/os/OS.h

@@ -112,6 +112,11 @@ void*			open_library(const char* path);
 void			close_library(void* library);
 void*			lookup_symbol(void* library, const char* name);
 
+//-----------------------------------------------------------------------------
+// Process execution
+//-----------------------------------------------------------------------------
+void			execute_process(const char* program, const char* params);
+
 } // namespace os
 
 //-----------------------------------------------------------------------------

+ 24 - 0
engine/os/linux/LinuxOS.cpp

@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "OS.h"
 #include "StringUtils.h"
+#include "Assert.h"
 #include <cstdio>
 #include <cstdarg>
 #include <sys/stat.h>
@@ -37,6 +38,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <time.h>
 #include <pthread.h>
 #include <dlfcn.h>
+#include <sys/wait.h>
+
 
 namespace crown
 {
@@ -302,5 +305,26 @@ void* lookup_symbol(void* library, const char* name)
 	return symbol;
 }
 
+//-----------------------------------------------------------------------------
+void execute_process(const char* program, const char* params)
+{
+	int32_t ret;
+
+	pid_t pid = fork();
+	CE_ASSERT(pid != -1, "Unable to fork");
+
+	if (pid)
+	{
+		wait(&ret);
+	}
+	else
+	{
+		int32_t res = execlp(program, program, params, NULL);
+		CE_ASSERT(res != -1, "Unable to exec %s with error %d", program, res);
+		exit(EXIT_SUCCESS);
+	}
+}
+
+
 } // namespace os
 } // namespace crown

+ 2 - 2
engine/tests/allocators.cpp

@@ -13,11 +13,11 @@ int main()
 	char* char_buffer = (char*)malloc_allocator.allocate(128);
 	CE_ASSERT(malloc_allocator.allocated_size() >= 128, "Allocated size differs from requested size");
 
-	printf("HeapAllocator::get_allocated_size(): %d\n", malloc_allocator.allocated_size());
+	printf("HeapAllocator::get_allocated_size(): %d\n", (uint32_t)malloc_allocator.allocated_size());
 
 	malloc_allocator.deallocate(char_buffer);
 
-	printf("HeapAllocator::get_allocated_size(): %d\n", malloc_allocator.allocated_size());
+	printf("HeapAllocator::get_allocated_size(): %d\n", (uint32_t)malloc_allocator.allocated_size());
 	//CE_ASSERT(malloc_allocator.get_allocated_size() == 0);
 
 	uint8_t buffer[1024 * 1024];

+ 3 - 3
engine/tests/compressors.cpp

@@ -20,12 +20,12 @@ int main()
  	compressed_string = compressor.compress((void*)uncompressed_string, strlen(uncompressed_string), compr_size);
 	
 	printf("Uncompressed: ");
-	printf("Size: %d - ", strlen(uncompressed_string));
+	printf("Size: %d - ", (uint32_t)strlen(uncompressed_string));
 	printf(uncompressed_string);
 	printf("\n\n");
 
 	printf("Compressed: ");
-	printf("Size: %d - ", compr_size);
+	printf("Size: %d - ", (uint32_t)compr_size);
 	for (size_t i = 0; i < compr_size; i++)
 	{
 		printf("%c", compressed_string[i]);
@@ -35,7 +35,7 @@ int main()
 	result = compressor.uncompress((void*)compressed_string, compr_size, result_size);
 	
 	printf("Uncompressed again: ");
-	printf("Size: %d - ", result_size);
+	printf("Size: %d - ", (uint32_t)result_size);
 	for (size_t i = 0; i < result_size; i++)
 	{
 		printf("%c", result[i]);