Skip to content

Commit 2b0e910

Browse files
author
Rodney Price
committed
first
0 parents  commit 2b0e910

11 files changed

+876
-0
lines changed

CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required (VERSION 3.5.1)
2+
project (XPLDIR)
3+
set(CMAKE_BUILD_TYPE Debug)
4+
5+
include_directories(
6+
include
7+
${CMAKE_CURRENT_BINARY_DIR}/include # To find xpldir.h
8+
)
9+
10+
include(cmake/deps.cmake)
11+
include(cmake/platform.cmake)
12+
13+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/xpldir.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/xpldir.h)
14+
15+
include_directories(include)
16+
17+
18+
add_subdirectory(src)
19+
20+
install(
21+
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/
22+
DESTINATION /usr/include
23+
24+
PATTERN "*" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ
25+
)

cmake/deps.cmake

Whitespace-only changes.

cmake/linux.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
find_library(MEMMGR memmgr libmemmgr HINT /usr/lib/ NO_DEFAULT_PATH)
2+
3+
#TODO write detection utility
4+
set(HAVE_UNIX_SOCKETS 1)
5+
6+
set (RESOLV_LIBS resolv)

cmake/platform.cmake

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
######### OS Detection ##############
2+
if (CMAKE_SYSTEM_NAME MATCHES Linux)
3+
set (LINUX 1)
4+
set (UNIX 1)
5+
6+
find_program(LSB_RELEASE_EXEC lsb_release)
7+
execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
8+
OUTPUT_VARIABLE LINUX_DISTRIBUTION
9+
OUTPUT_STRIP_TRAILING_WHITESPACE)
10+
message( "Creating make files for " ${CMAKE_SYSTEM_NAME} " distribution " ${LINUX_DISTRIBUTION} )
11+
endif (CMAKE_SYSTEM_NAME MATCHES Linux)
12+
13+
if (CMAKE_SYSTEM_NAME MATCHES Windows)
14+
set (WIN32 1)
15+
set (WINDOWS 1)
16+
set (_WIN32 )
17+
set (_CRT_SECURE_NO_DEPRECATE 1)
18+
19+
macro(get_WIN32_WINNT version)
20+
if (WIN32 AND CMAKE_SYSTEM_VERSION)
21+
set(ver ${CMAKE_SYSTEM_VERSION})
22+
string(REPLACE "." "" ver ${ver})
23+
string(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
24+
25+
set(${version} "0x${ver}")
26+
endif()
27+
endmacro()
28+
29+
get_WIN32_WINNT( WINDOWS_VERSION )
30+
31+
message( "Creating make files for " ${CMAKE_SYSTEM_NAME} " distribution " ${WINDOWS_VERSION} )
32+
endif (CMAKE_SYSTEM_NAME MATCHES Windows)
33+
34+
35+
# OS specific options
36+
if (LINUX)
37+
include(${CMAKE_CURRENT_LIST_DIR}/linux.cmake)
38+
endif()
39+
40+
if (WINDOWS)
41+
include(${CMAKE_CURRENT_LIST_DIR}/windows.cmake)
42+
endif()

cmake/windows.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#TODO create a detection utility
2+
set(HAVE_WIN_SOCKETS 1)
3+
4+
set (RESOLV_LIBS ws2_32 iphlpapi)

include/xpldir.h.in

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#ifndef XPLDIR_H
2+
#define XPLDIR_H
3+
4+
#cmakedefine HAVE_VALGRIND_H 1
5+
#cmakedefine HAVE_MMAN_H 1
6+
7+
/*
8+
Platform defines
9+
10+
The use of these should be limited as much as possible. Specific tests for
11+
features of the platform are prefered.
12+
*/
13+
#ifndef LINUX
14+
#cmakedefine LINUX 1
15+
#endif
16+
17+
#ifndef WIN32
18+
#cmakedefine WIN32 1
19+
#endif
20+
#ifndef WINDOWS
21+
#cmakedefine WINDOWS 1
22+
23+
#endif
24+
25+
26+
#ifndef MACOSX
27+
#cmakedefine MACOSX 1
28+
#endif
29+
#ifndef DARWIN
30+
#cmakedefine DARWIN 1
31+
#endif
32+
#ifndef APPLE
33+
#cmakedefine APPLE 1
34+
#endif
35+
36+
#cmakedefine DEBUG 1
37+
38+
39+
40+
/* File and Directory Functions */
41+
42+
#if defined(LINUX) || defined(MACOSX)
43+
44+
#include <sys/stat.h>
45+
#include <sys/types.h>
46+
#include <dirent.h>
47+
48+
/* Limits */
49+
#if defined (PATH_MAX)
50+
# define XPL_MAX_PATH PATH_MAX
51+
#elif defined (MAX_PATH)
52+
# define XPL_MAX_PATH MAX_PATH
53+
#elif defined (_PC_PATH_MAX)
54+
# define XPL_MAX_PATH sysconf(_PC_PATH_MAX)
55+
#elif defined (_MAX_PATH)
56+
# define XPL_MAX_PATH _MAX_PATH
57+
#else
58+
# error "XPL_MAX_PATH is not implemented on this platform"
59+
#endif
60+
61+
62+
typedef struct _XplDir {
63+
unsigned long d_attr;
64+
unsigned long d_size;
65+
unsigned char *d_name;
66+
unsigned long d_cdatetime;
67+
DIR *dirp;
68+
struct dirent *direntp;
69+
unsigned char Path[XPL_MAX_PATH];
70+
} XplDir;
71+
72+
#ifdef __cplusplus
73+
extern "C"{
74+
#endif
75+
76+
int XplMakeDir(const char *path);
77+
78+
#ifdef __cplusplus
79+
}
80+
#endif
81+
82+
#elif defined(WIN32)
83+
84+
#include <direct.h>
85+
#include <io.h>
86+
87+
typedef struct _XplDir {
88+
unsigned long d_attr;
89+
unsigned long d_size;
90+
unsigned char *d_name;
91+
unsigned long d_cdatetime;
92+
long dirp;
93+
struct _finddata_t FindData;
94+
unsigned char Path[_MAX_PATH+1];
95+
} XplDir;
96+
97+
#define XplMakeDir(path) mkdir(path)
98+
99+
#endif
100+
101+
typedef struct _XplDirMatch {
102+
struct _XplDirMatch *next;
103+
struct _XplDirMatch *base;
104+
105+
unsigned long d_attr;
106+
unsigned long d_size;
107+
unsigned long d_cdatetime;
108+
109+
unsigned char *d_name;
110+
111+
struct {
112+
void *data;
113+
void *lock;
114+
} client;
115+
} XplDirMatch;
116+
117+
#ifdef __cplusplus
118+
extern "C" {
119+
#endif
120+
121+
EXPORT XplDir *XplOpenDir(const char *dirname);
122+
EXPORT XplDir *XplReadDir(XplDir *dirp);
123+
EXPORT int XplCloseDir(XplDir *dirp);
124+
EXPORT int XplIsSubDir(XplDir *dirp);
125+
126+
EXPORT XplDirMatch *XplOpenDirMatch(const char *pattern);
127+
EXPORT XplDirMatch *XplReadDirMatch(XplDirMatch *dirp);
128+
EXPORT XplDirMatch *XplResetDirMatch(XplDirMatch *dirp);
129+
EXPORT int XplCloseDirMatch(XplDirMatch *dirp);
130+
EXPORT void XplMakePath(const char *path);
131+
EXPORT int XplStat( const char *path, struct stat *st );
132+
133+
134+
#if defined(WIN32)
135+
#define XplGetCurrentDir _getcwd
136+
#else
137+
#define XplGetCurrentDir getcwd
138+
#endif
139+
140+
typedef struct
141+
{
142+
struct stat st;
143+
char d_name[256];
144+
}XDirEnt;
145+
146+
typedef struct
147+
{
148+
void *dirp;
149+
void (*XFree)(void *);
150+
XDirEnt entry;
151+
char *pattern;
152+
char name[];
153+
}XDir;
154+
155+
EXPORT XDir *XOpenDir( const char *path, void *(*XAlloc)(size_t), void (*XFree)(void *) );
156+
EXPORT XDirEnt *XReadDir( XDir *dir );
157+
EXPORT int XCloseDir( XDir *dir );
158+
159+
#endif // XPLDIR_H

src/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
add_library(xpldir SHARED
2+
dir.c
3+
)
4+
5+
6+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ALL_CFLAGS} ${PTHREAD_CFLAGS} ${OPENSSL_CFLAGS}")
7+
8+
find_library(MEMMGR_LIBRARY
9+
NAMES libmemmgr memmgr
10+
)
11+
12+
target_link_libraries(xpldir
13+
memmgr${BIT}
14+
)
15+
16+
install(TARGETS xpldir DESTINATION /usr/lib)

src/cmake/deps.cmake

Whitespace-only changes.

src/cmake/linux.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
find_library(MEMMGR memmgr libmemmgr HINT /usr/lib/ NO_DEFAULT_PATH)

src/cmake/platform.cmake

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# OS specific options
2+
if (LINUX)
3+
include(${CMAKE_CURRENT_LIST_DIR}/linux.cmake)
4+
endif()
5+
6+
if (WINDOWS)
7+
include(${CMAKE_CURRENT_LIST_DIR}/windows.cmake)
8+
endif()

0 commit comments

Comments
 (0)