Skip to content

Commit c095d7d

Browse files
committed
Initial commit
0 parents  commit c095d7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+24217
-0
lines changed

.gitignore

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf

.travis.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
os:
2+
- linux
3+
- osx
4+
language: c
5+
compiler:
6+
- clang
7+
- gcc
8+
sudo: required
9+
dist: trusty
10+
script:
11+
- mkdir build
12+
- cd build
13+
- cmake ..
14+
- make
15+
addons:
16+
coverity_scan:
17+
project:
18+
name: "kala13x/libxutils"
19+
notification_email: sundro.kala@gmail.com
20+
branch_pattern: coverity_scan

CMakeLists.txt

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
2+
3+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
4+
project(libxutils LANGUAGES C)
5+
6+
IF (WIN32)
7+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Od /W3")
8+
ELSE()
9+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall")
10+
ENDIF()
11+
12+
set(THREADS_PREFER_PTHREAD_FLAG ON)
13+
find_package(Threads REQUIRED)
14+
15+
find_package(OpenSSL)
16+
IF(OpenSSL_FOUND)
17+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XUTILS_USE_SSL")
18+
ENDIF()
19+
20+
IF (APPLE)
21+
find_package(RT REQUIRED)
22+
ENDIF()
23+
24+
SET(HEADER_DST "include/xutils")
25+
SET(SOURCE_DIR "./src")
26+
SET(MEDIA_DIR "./media")
27+
include_directories(${SOURCE_DIR} ${MEDIA_DIR})
28+
29+
add_library(xutils STATIC
30+
${SOURCE_DIR}/addr.c
31+
${SOURCE_DIR}/array.c
32+
${SOURCE_DIR}/crypt.c
33+
${SOURCE_DIR}/xtime.c
34+
${SOURCE_DIR}/event.c
35+
${SOURCE_DIR}/list.c
36+
${SOURCE_DIR}/hash.c
37+
${SOURCE_DIR}/xlog.c
38+
${SOURCE_DIR}/xmap.c
39+
${SOURCE_DIR}/xstr.c
40+
${SOURCE_DIR}/xtype.c
41+
${SOURCE_DIR}/xver.c
42+
${SOURCE_DIR}/xbuf.c
43+
${SOURCE_DIR}/xtop.c
44+
${SOURCE_DIR}/xcli.c
45+
${SOURCE_DIR}/errex.c
46+
${SOURCE_DIR}/http.c
47+
${SOURCE_DIR}/sock.c
48+
${SOURCE_DIR}/sync.c
49+
${SOURCE_DIR}/xcpu.c
50+
${SOURCE_DIR}/thread.c
51+
${SOURCE_DIR}/xjson.c
52+
${SOURCE_DIR}/xfs.c
53+
${MEDIA_DIR}/mdtp.c
54+
${MEDIA_DIR}/ntp.c
55+
${MEDIA_DIR}/rtp.c
56+
${MEDIA_DIR}/ts.c
57+
)
58+
59+
install(TARGETS xutils DESTINATION lib)
60+
61+
install(DIRECTORY "${SOURCE_DIR}/"
62+
DESTINATION "${HEADER_DST}"
63+
FILES_MATCHING
64+
PATTERN "*.h"
65+
)
66+
67+
install(DIRECTORY "${MEDIA_DIR}/"
68+
DESTINATION "${HEADER_DST}"
69+
FILES_MATCHING
70+
PATTERN "*.h"
71+
)

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015-2021 Sun Dro <f4tb0y@protonmail.com>
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

Makefile

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
####################################
2+
# Automatically generated by SMake #
3+
# https://github.com/kala13x/smake #
4+
####################################
5+
6+
CFLAGS = -g -O2 -Wall -D_XUTILS_USE_SSL -I./src -I./media
7+
LIBS = -lpthread -lssl -lcrypto
8+
NAME = libxutils.a
9+
ODIR = ./obj
10+
OBJ = o
11+
12+
OBJS = errex.$(OBJ) \
13+
event.$(OBJ) \
14+
hash.$(OBJ) \
15+
http.$(OBJ) \
16+
list.$(OBJ) \
17+
sync.$(OBJ) \
18+
thread.$(OBJ) \
19+
xcpu.$(OBJ) \
20+
xlog.$(OBJ) \
21+
xmap.$(OBJ) \
22+
xtime.$(OBJ) \
23+
xtype.$(OBJ) \
24+
xver.$(OBJ) \
25+
sock.$(OBJ) \
26+
xtop.$(OBJ) \
27+
xcli.$(OBJ) \
28+
addr.$(OBJ) \
29+
xfs.$(OBJ) \
30+
xjson.$(OBJ) \
31+
xaes.$(OBJ) \
32+
array.$(OBJ) \
33+
crypt.$(OBJ) \
34+
xbuf.$(OBJ) \
35+
xstr.$(OBJ) \
36+
mdtp.$(OBJ) \
37+
ntp.$(OBJ) \
38+
rtp.$(OBJ) \
39+
ts.$(OBJ) \
40+
xapi.$(OBJ)
41+
42+
OBJECTS = $(patsubst %,$(ODIR)/%,$(OBJS))
43+
INSTALL_INC = /usr/local/include/xutils
44+
INSTALL_BIN = /usr/local/lib
45+
VPATH = ./src:./media
46+
47+
.c.$(OBJ):
48+
@test -d $(ODIR) || mkdir -p $(ODIR)
49+
$(CC) $(CFLAGS) -c -o $(ODIR)/$@ $< $(LIBS)
50+
51+
$(NAME):$(OBJS)
52+
$(AR) rcs -o $(ODIR)/$(NAME) $(OBJECTS)
53+
54+
.PHONY: install
55+
install:
56+
@test -d $(INSTALL_BIN) || mkdir -p $(INSTALL_BIN)
57+
@install -m 0755 $(ODIR)/$(NAME) $(INSTALL_BIN)/
58+
@test -d $(INSTALL_INC) || mkdir -p $(INSTALL_INC)
59+
@cp -r ./src/*.h $(INSTALL_INC)/
60+
@cp -r ./media/*.h $(INSTALL_INC)/
61+
62+
.PHONY: clean
63+
clean:
64+
$(RM) $(ODIR)/$(NAME) $(OBJECTS)

README

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
xUtils C Library release 2.x (c) Sun Dro <f4tb0y@protonmail.com>
2+
3+
This directory contains the sources of the xUtils C Library. See
4+
the file "src/xver.h" to check out what release version you have.
5+
6+
The xUtils C Library is the general purpose, cross-platform library for all
7+
Linux / Unix and Windows operating systems. It provides the implementations
8+
of various functionality to make some routines easier for all the programs
9+
written in C and C-compatible languages such as C++, Rust, and Objective C.
10+
11+
The xUtils C Library is free software. you can redistribute it and / or
12+
modify it under the terms of The MIT License (See LICENSE file for more
13+
information).

build.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
LIB_CRYPTO=/usr/lib64/libcrypto.so
4+
LIB_SSL=/usr/lib64/libssl.so
5+
6+
if [ -f "LIB_CRYPTO" ] && [ -f "LIB_SSL" ]; then
7+
export XUTILS_USE_SSL=y
8+
fi
9+
10+
./clean.sh
11+
12+
CPU_COUNT=`cat /proc/cpuinfo | grep processor -c`
13+
MAKE_TOOL=0
14+
15+
if [ ! -z "$1" ]; then
16+
MAKE_TOOL=$1
17+
fi
18+
19+
if [ $MAKE_TOOL == 0 ]; then
20+
echo "Specify build tool (cmake / smake)"
21+
echo "example: $0 smake"
22+
exit 1
23+
fi
24+
25+
# Generate Makefile and build library
26+
$MAKE_TOOL . && make -j $CPU_COUNT
27+
28+
if [ ! -z "$2" ]; then
29+
if [ $2 == "--examples" ]; then
30+
cd examples
31+
make -j $CPU_COUNT
32+
cd ..
33+
elif [ $2 == "--install" ]; then
34+
sudo make install
35+
cd examples
36+
make -j $CPU_COUNT
37+
sudo make install
38+
fi
39+
fi
40+
41+
exit 0

clean.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
cd examples
4+
make clean
5+
cd ..
6+
7+
make clean
8+
9+
if [ -d ./obj ]; then
10+
rm -rf ./obj
11+
fi
12+
13+
if [ -d ./build ]; then
14+
rm -rf ./build
15+
fi
16+
17+
if [ -d ./CMakeFiles ]; then
18+
rm -rf ./CMakeFiles
19+
fi
20+
21+
if [ -f ./CMakeCache.txt ]; then
22+
rm -f ./CMakeCache.txt
23+
fi
24+
25+
if [ -f ./cmake_install.cmake ]; then
26+
rm -f ./cmake_install.cmake
27+
fi
28+
29+
if [ -f ./install_manifest.txt ]; then
30+
rm -f ./install_manifest.txt
31+
fi

cmake/FindRT.cmake

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# FindRT.cmake - Try to find the RT library
2+
# Once done this will define
3+
#
4+
# RT_FOUND - System has rt
5+
# RT_INCLUDE_DIR - The rt include directory
6+
# RT_LIBRARIES - The libraries needed to use rt
7+
# RT_DEFINITIONS - Compiler switches required for using rt
8+
#
9+
# Also creates an import target called RT::RT
10+
11+
find_path (RT_INCLUDE_DIR NAMES time.h
12+
PATHS
13+
/usr
14+
/usr/local
15+
/opt
16+
PATH_SUFFIXES
17+
)
18+
19+
find_library(RT_LIBRARIES NAMES rt
20+
PATHS
21+
/usr
22+
/usr/local
23+
/opt
24+
)
25+
26+
include(FindPackageHandleStandardArgs)
27+
28+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(rt DEFAULT_MSG RT_LIBRARIES RT_INCLUDE_DIR)
29+
30+
mark_as_advanced(RT_INCLUDE_DIR RT_LIBRARIES)
31+
32+
if (NOT TARGET RT::RT)
33+
add_library(RT::RT INTERFACE IMPORTED)
34+
35+
set_target_properties(RT::RT PROPERTIES
36+
INTERFACE_INCLUDE_DIRECTORIES ${RT_INCLUDE_DIR}
37+
INTERFACE_LINK_LIBRARIES ${RT_LIBRARIES}
38+
)
39+
endif()

0 commit comments

Comments
 (0)