libmem icon indicating copy to clipboard operation
libmem copied to clipboard

Break down OS-specific functions into separate files

Open rdbo opened this issue 2 years ago • 2 comments

Example:

src/
  win/
    handle.c
  bsd/
    ptrace.c
  linux/
    ptrace.c
  unix/
    ptrace.c

Unix will compile for both Linux and BSD. Linux will compile for Linux (android also, bc android uses Linux)

rdbo avatar Nov 24 '23 09:11 rdbo

Since we are using iteration of files to build them, i think this is good aproach to order and manage them.

Other alternatives;

  1. File prefixes
bsd_
win_
lin_
un_
  1. definitions from CMakeLists.txt

CMakeLists.txt

if(WIN32)
    add_definitions(-DLM_BUILD_TYPE_WIN=1)
endif()

Code:

#ifdef LM_BUILD_TYPE_WIN
// windows code
#endif 

illegal-instruction-co avatar Nov 28 '23 18:11 illegal-instruction-co

@illegal-instruction-co

For (2); Currently those definitions are in the C header files, but they can be passed to CMake also IIRC: Right now it looks like this:

#if LM_OS == LM_OS_WIN
// ...
#endif

But there is an option that forces the operating system (and there are options also for architecture, and everything, really):

#if defined(LM_FORCE_OS_WIN)
#	define LM_OS LM_OS_WIN
#elif defined(LM_FORCE_OS_LINUX)
#	define LM_OS LM_OS_LINUX
#elif defined(LM_FORCE_OS_BSD)
#	define LM_OS LM_OS_BSD
#elif defined(LM_FORCE_OS_ANDROID)
#	define LM_OS LM_OS_ANDROID
#endif

rdbo avatar Nov 28 '23 20:11 rdbo