├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── CodingStyle.md ├── Contributors.md ├── Doxyfile ├── LICENSE ├── README.md ├── VERSION.txt ├── azure-pipelines.yml ├── docs └── fork.c ├── libunistd-config.cmake ├── libunistd.pro ├── portable ├── App.h ├── AtomicCounter.h ├── AtomicLock.h ├── AtomicLock0.h ├── AtomicMutex.h ├── Breakpoint.h ├── Buffer.h ├── CMakeLists.txt ├── Cfile.h ├── CommandLine.cpp ├── CommandLine.h ├── Counter.h ├── CppTypes.h ├── Db.h ├── FieldMap.h ├── Finder.h ├── FixedQueue.h ├── Folder.h ├── Hash.h ├── Logger.h ├── MemPool.h ├── MsgBuffer.h ├── Network.cpp ├── Network.h ├── QtHelpers.h ├── Random.h ├── RingAllocator.h ├── SharedMemory.h ├── Shutdown.cpp ├── SizeTracker.h ├── SoftLock.h ├── StackTrack.h ├── StdBlob.h ├── StdCopy.h ├── StdDevice.h ├── StdFile.h ├── StdPipe.h ├── SystemCall.h ├── SystemLog.h ├── Text.h ├── UnrealLogger.h ├── VBuffer.h ├── Vec3d.h ├── VerboseCounter.h ├── WormFile.cpp ├── WormFile.h ├── bsd_string.h ├── endian.h ├── homedir.h ├── http │ ├── HtmlPage.h │ ├── Http.cpp │ ├── Http.h │ └── HttpDecoder.h ├── ipc │ ├── BsdMulticast.h │ ├── BsdPacketServer.cpp │ ├── BsdPacketServer.h │ ├── BsdSocket.cpp │ ├── BsdSocket.h │ ├── BsdSocketClient.cpp │ ├── BsdSocketClient.h │ ├── BsdSocketPool.cpp │ ├── BsdSocketPool.h │ ├── BsdSocketServer.cpp │ ├── BsdSocketServer.h │ ├── BsdSocketStartup.cpp │ ├── BsdSocketStartup.h │ ├── BsdSocketTcp.h │ ├── BsdSocketUdp.h │ ├── Packet.h │ ├── PacketBuffer.h │ ├── PacketMarker.h │ ├── PacketQueue.h │ ├── PacketReader.cpp │ ├── PacketReader.h │ ├── PacketSizer.h │ ├── PacketSocket.cpp │ ├── PacketSocket.h │ ├── PacketStats.h │ ├── PacketWriter.h │ ├── PosixQueue.h │ └── UdpPump.h ├── no_copy.h ├── portable.pro ├── print_malloc.h ├── pump │ ├── Pump.cpp │ ├── Pump.h │ └── TimerPump.h ├── strcpy.h ├── thread_semaphore.h └── time │ ├── Timecode.h │ ├── Timespan.h │ ├── Timestamp.cpp │ ├── Timestamp.h │ ├── VariableClock.cpp │ ├── VariableClock.h │ ├── WallClock.h │ └── Watchdog.h ├── qdecoder ├── .gitignore ├── COPYING ├── INSTALL.md ├── Makefile.in ├── README.md ├── VERSION.txt ├── autogen.sh ├── config.guess ├── config.h.in ├── config.sub ├── configure ├── configure.ac ├── doc │ └── html │ │ ├── annotated.html │ │ ├── bc_s.png │ │ ├── bdwn.png │ │ ├── classes.html │ │ ├── closed.png │ │ ├── doxygen.css │ │ ├── doxygen.png │ │ ├── dynsections.js │ │ ├── files.html │ │ ├── ftv2blank.png │ │ ├── ftv2cl.png │ │ ├── ftv2doc.png │ │ ├── ftv2folderclosed.png │ │ ├── ftv2folderopen.png │ │ ├── ftv2lastnode.png │ │ ├── ftv2link.png │ │ ├── ftv2mlastnode.png │ │ ├── ftv2mnode.png │ │ ├── ftv2mo.png │ │ ├── ftv2node.png │ │ ├── ftv2ns.png │ │ ├── ftv2plastnode.png │ │ ├── ftv2pnode.png │ │ ├── ftv2splitbar.png │ │ ├── ftv2vertline.png │ │ ├── functions.html │ │ ├── functions_vars.html │ │ ├── globals.html │ │ ├── globals_func.html │ │ ├── index.html │ │ ├── jquery.js │ │ ├── nav_f.png │ │ ├── nav_g.png │ │ ├── nav_h.png │ │ ├── open.png │ │ ├── qcgireq_8c.html │ │ ├── qcgires_8c.html │ │ ├── qcgisess_8c.html │ │ ├── qdecoder_8h.html │ │ ├── qentry_8c.html │ │ ├── structqentobj__s.html │ │ ├── structqentry__s.html │ │ ├── sync_off.png │ │ ├── sync_on.png │ │ ├── tab_a.png │ │ ├── tab_b.png │ │ ├── tab_h.png │ │ ├── tab_s.png │ │ └── tabs.css ├── examples │ ├── Makefile.in │ ├── cookie.c │ ├── download.c │ ├── index.html │ ├── multivalue.c │ ├── query.c │ ├── session.c │ ├── upload.c │ └── uploadfile.c ├── install-sh ├── qlibc-master.zip ├── src │ ├── CMakeLists.txt │ ├── Makefile.in │ ├── doxygen.conf │ ├── doxygen.css │ ├── doxygen_header.html │ ├── doxygen_layout.xml │ ├── doxygen_tailer.html │ ├── internal.cpp │ ├── internal.h │ ├── qcgireq.cpp │ ├── qcgires.cpp │ ├── qcgisess.cpp │ ├── qdecoder.h │ ├── qdecoder.pc.in │ └── qentry.cpp └── vcpp │ ├── libqdecoder.sln │ ├── libqdecoder.vcxproj │ └── libqdecoder.vcxproj.filters ├── regex ├── CMakeLists.txt ├── regex.cpp └── regex.h ├── sqlite ├── CMakeLists.txt ├── Db.h ├── SqlStatement.cpp ├── SqlStatement.h ├── Statement.h ├── libsqliteQt │ ├── Makefile │ ├── Makefile.Debug │ ├── Makefile.Release │ └── libsqliteQt.pro ├── source │ ├── VERSION_3.25.3.txt │ ├── shell.c │ ├── sqlite3.c │ ├── sqlite3.h │ └── sqlite3ext.h └── vcpp │ ├── ReadMe.txt │ ├── libsqlite.vcxproj │ └── libsqlite.vcxproj.filters ├── test ├── CMakeLists.txt ├── test_PosixQueue │ ├── CMakeLists.txt │ ├── mq_receive │ │ └── main.cpp │ └── mq_send │ │ └── main.cpp ├── test_Pump │ ├── CMakeLists.txt │ └── test_Pump.cpp ├── test_lmdb │ ├── CMakeLists.txt │ ├── ProductData.h │ ├── data.mdb │ ├── lock.mdb │ ├── sample-mdb.c │ ├── test-lmdb-full.cpp │ └── test-lmdb.cpp ├── test_logger │ ├── CMakeLists.txt │ └── main.cpp ├── test_mman │ ├── CMakeLists.txt │ ├── mman_client.cpp │ └── mman_server.cpp ├── test_scandir │ ├── CMakeLists.txt │ ├── opendir.cpp │ └── scandir.cpp ├── test_semaphore │ ├── CMakeLists.txt │ ├── semaphore1.cpp │ ├── semaphore_client.cpp │ ├── semaphore_client2.cpp │ ├── semaphore_server.cpp │ └── semaphore_server2.cpp ├── test_shm │ ├── CMakeLists.txt │ ├── shm_client.cpp │ └── shm_server.cpp ├── test_sqlite │ ├── CMakeLists.txt │ └── main.cpp ├── test_tcp │ └── tcp_server.cpp ├── test_unit │ ├── CMakeLists.txt │ └── main.cpp └── test_wormfile │ ├── CMakeLists.txt │ └── main.cpp ├── unistd ├── CMakeLists.txt ├── arpa │ ├── inet.h │ └── nameser.h ├── cfunc.h ├── clock_gettime.cpp ├── clock_gettime.h ├── dirent.cpp ├── dirent.h ├── dlfcn.h ├── endian.h ├── fnmatch.cpp ├── fnmatch.h ├── fts.c ├── fts.h ├── ftw.h ├── getline.cpp ├── getopt.cpp ├── getopt.h ├── gettimeofday.cpp ├── gettimeofday.h ├── glob.h ├── grp.h ├── iconv.h ├── ifaddrs.h ├── int128 │ ├── BigNumbers │ │ ├── Int128.h │ │ ├── Int128IO.cpp │ │ ├── Int128Net.h │ │ ├── Int128Packer.cpp │ │ ├── Int128Str.cpp │ │ ├── Int128ToString.cpp │ │ ├── Int128x64.asm │ │ └── Int128x86.cpp │ ├── Int128.h │ ├── Int128x64.asm │ ├── Int128x86.cpp │ └── old │ │ ├── Int128.asm │ │ ├── Int128.cpp │ │ ├── Int128.h │ │ └── Uint128.cpp ├── libgen.h ├── libintl.h ├── linux │ ├── limits.h │ └── rtc.h ├── magic.h ├── mem.h ├── more │ └── shm_more.h ├── mqueue.h ├── net │ ├── ethertypes.h │ ├── if.h │ ├── if_arp.h │ └── route.h ├── netdb.c ├── netdb.h ├── netinet │ ├── icmp6.h │ ├── in.h │ ├── in_systm.h │ ├── ip.h │ ├── ip_icmp.h │ ├── tcp.h │ └── udp.h ├── poll.h ├── pthread.cpp ├── pthread.h ├── publib.h ├── pwd.h ├── semaphore.h ├── sigaction.cpp ├── sigaction.h ├── sources.cmake ├── strings.h ├── stub.h ├── sys │ ├── cdefs.h │ ├── epoll.h │ ├── file.cpp │ ├── file.h │ ├── inotify.h │ ├── ioctl.h │ ├── ipc.h │ ├── mman.h │ ├── param.h │ ├── poll.h │ ├── prctl.h │ ├── random.cpp │ ├── random.h │ ├── resource.h │ ├── select.h │ ├── sem.cpp │ ├── sem.h │ ├── shm.h │ ├── socket.h │ ├── socketvar.h │ ├── statvfs.h │ ├── sys_types.h │ ├── syscall.h │ ├── time.h │ ├── vfs.h │ └── wait.h ├── syslog.cpp ├── syslog.h ├── termios.h ├── unistd.cpp ├── unistd.h ├── unistd.pro └── utime.h ├── use-libunistd.cmake ├── uuid ├── CMakeLists.txt ├── COPYING ├── Version-libuuid-1.0.3.txt ├── all-io.h ├── c.h ├── clear.cpp ├── compare.cpp ├── copy.cpp ├── gen_uuid.cpp ├── isnull.cpp ├── pack.cpp ├── parse.cpp ├── randutils.cpp ├── randutils.h ├── test │ ├── CMakeLists.txt │ └── test_uuid.c ├── unpack.cpp ├── unparse.cpp ├── uuid.h ├── uuidP.h ├── uuid_time.cpp └── uuidd.h └── xxhash ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── cmake_unofficial └── CMakeLists.txt ├── xxhash.c ├── xxhash.h ├── xxhash.pro └── xxhsum.c /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pri 2 | *.pro.user 3 | Makefile 4 | Makefile.Release 5 | Makefile.Debug 6 | # Compiled Object files 7 | *.slo 8 | *.lo 9 | *.o 10 | *.obj 11 | 12 | # Precompiled Headers 13 | *.gch 14 | *.pch 15 | 16 | # Compiled Dynamic libraries 17 | *.so 18 | *.dylib 19 | *.dll 20 | 21 | # Fortran module files 22 | *.mod 23 | 24 | # Compiled Static libraries 25 | *.lai 26 | *.la 27 | *.a 28 | *.lib 29 | 30 | # Executables 31 | *.exe 32 | *.out 33 | *.app 34 | 35 | bak 36 | Backup 37 | Release 38 | Debug 39 | build 40 | *.sdf 41 | *.filters 42 | .vs 43 | x64 44 | vscode 45 | staging -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/CMakeList.txt 2 | 3 | cmake_minimum_required (VERSION 3.8) 4 | project(libunistd) 5 | message("<<< Parsing libunistd/CMakeList.txt") 6 | message("--- Building ${PROJECT_NAME} ${CMAKE_SYSTEM_NAME}:${CMAKE_HOST_SYSTEM_PROCESSOR}:${CMAKE_GENERATOR_TOOLSET} ---") 7 | 8 | option(UE4 "Disable _ITERATOR_DEBUG_LEVEL for UE4 compatibility" OFF) 9 | option(WITH_TESTS "Enable this to build the tests / examples as well." OFF) 10 | 11 | set(CMAKE_CXX_STANDARD 23) 12 | set(CMAKE_C_STANDARD 23) 13 | #set(CMAKE_GENERATOR_PLATFORM x64) 14 | 15 | add_definitions(-DTRACE_MSG_FUNCTIONS) 16 | #define _CRT_SECURE_NO_DEPRECATE 17 | #define _CRT_SECURE_NO_WARNINGS 18 | #define _WINSOCK_DEPRECATED_NO_WARNINGS 19 | #define _CRT_NONSTDC_NO_WARNINGS 20 | 21 | if(UE4) 22 | add_definitions(-D_ITERATOR_DEBUG_LEVEL=0) 23 | add_definitions(-D_HAS_ITERATOR_DEBUGGING=0) 24 | endif(UE4) 25 | # cmake -D_HAS_ITERATOR_DEBUGGING=0 -D_ITERATOR_DEBUG_LEVEL=0 -A x64 .. 26 | # _HAS_ITERATOR_DEBUGGING=0;_ITERATOR_DEBUG_LEVEL=0; 27 | 28 | include(libunistd-config.cmake) 29 | 30 | if(WIN32) 31 | include_directories(unistd) 32 | add_subdirectory(unistd) 33 | link_directories(build/win64) 34 | link_libraries(libunistd Ws2_32) 35 | message("Linking libunistd") 36 | endif(WIN32) 37 | 38 | if(NOT WIN32 AND NOT APPLE) 39 | link_libraries(rt pthread dl) 40 | message("Linking rt pthread dl") 41 | endif(NOT WIN32 AND NOT APPLE) 42 | 43 | add_subdirectory(portable) 44 | add_subdirectory(sqlite) 45 | add_subdirectory(uuid) 46 | add_subdirectory(regex) 47 | add_subdirectory(xxhash) 48 | if(WITH_TESTS) 49 | add_subdirectory(test) 50 | endif() 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Robin Rowe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /VERSION.txt: -------------------------------------------------------------------------------- 1 | libunistd v1.3 2022/3/XX 2 | libunistd v1.2 2021/06/21 3 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Starter pipeline 2 | # Start with a minimal pipeline that you can customize to build and deploy your code. 3 | # Add steps that build, run tests, deploy, and more: 4 | # https://aka.ms/yaml 5 | 6 | trigger: 7 | - master 8 | 9 | pool: 10 | vmImage: ubuntu-latest 11 | 12 | steps: 13 | - script: echo Hello, world! 14 | displayName: 'Run a one-line script' 15 | 16 | - script: | 17 | echo Add other tasks to build, test, and deploy your project. 18 | echo See https://aka.ms/yaml 19 | displayName: 'Run a multi-line script' 20 | -------------------------------------------------------------------------------- /docs/fork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | enum {ERROR = -1,CHILD = 0}; 6 | 7 | pid_t pid = fork(); 8 | if(pid==ERROR) 9 | { return FALSE; 10 | } 11 | if(pid!=CHILD) 12 | { return TRUE; 13 | } 14 | // execute child code: 15 | char* args = {"1","2"}; 16 | execv("hello.exe",args) 17 | return TRUE; -------------------------------------------------------------------------------- /libunistd.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | #CONFIG += create_prl 4 | 5 | SUBDIRS = portable xxhash 6 | include(libunistd.pri) 7 | 8 | win32 9 | { SUBDIRS += unistd 10 | } 11 | 12 | message(libunistd SUBDIRS = $$SUBDIRS) 13 | message(libunistd INCLUDEPATH = $$INCLUDEPATH) 14 | message(libunistd LIBS = $$LIBS) 15 | message(libunistd _PRO_FILE_PWD_ = $$_PRO_FILE_PWD_) 16 | message(libunistd OUT_PWD = $$OUT_PWD) 17 | #C:/Code/github/libunistd/portable 18 | 19 | #message(libunistd OUT_DIR = $$OUT_DIR) 20 | #message(DESTDIR = $$DESTDIR) 21 | #message(DESTDIR_TARGET = $$DESTDIR_TARGET) 22 | #QMAKE_POST_LINK = copy $$OUT_PWD\debug\*.lib ..\my-lib 23 | -------------------------------------------------------------------------------- /portable/App.h: -------------------------------------------------------------------------------- 1 | // App.h 2 | // Created by Robin Rowe 2019-07-10 3 | // License Copyright 2019 Robin.Rowe@HeroicRobots.com ***Proprietary*** 4 | 5 | #ifndef App_h 6 | #define App_h 7 | 8 | #include 9 | #include 10 | #include "NamerPump.h" 11 | #include "ReminderPump.h" 12 | 13 | class App 14 | { App(const App&) = delete; 15 | void operator=(const App&) = delete; 16 | NamerPump& namerPump; 17 | static App* app; 18 | static void Stop(int signal) 19 | { (void) signal; 20 | if(!app) 21 | { return; 22 | } 23 | app->namerPump.Stop(); 24 | } 25 | public: 26 | std::ostream& Print(std::ostream& os) const 27 | { return os << "App"; 28 | } 29 | App() 30 | : namerPump(namerPump) 31 | { if(0!=app) 32 | { puts("ERROR: App twice"); 33 | return; 34 | } 35 | app = this; 36 | signal(SIGINT,Stop); 37 | signal(SIGTERM,Stop); 38 | } 39 | ~App() 40 | {} 41 | bool operator!() const 42 | { return true; 43 | } 44 | }; 45 | 46 | inline 47 | std::ostream& operator<<(std::ostream& os,const App& app) 48 | { return app.Print(os); 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /portable/AtomicCounter.h: -------------------------------------------------------------------------------- 1 | // AtomicCounter.h 2 | // 2014/3/17 3 | 4 | #ifndef AtomicCounter_h 5 | #define AtomicCounter_h 6 | 7 | #include 8 | 9 | namespace portable 10 | { 11 | 12 | template 13 | class AtomicCounter 14 | { std::atomic n; 15 | public: 16 | AtomicCounter() 17 | { clear(); 18 | } 19 | void clear() 20 | { n=0; 21 | } 22 | AtomicCounter(T n) 23 | { this->n=n; 24 | } 25 | AtomicCounter& operator=(const T rhs) 26 | { n=rhs; 27 | return *this; 28 | } 29 | T operator++(int) 30 | { return n.fetch_add(1); 31 | } 32 | T operator--(int) 33 | { return n.fetch_sub(1); 34 | } 35 | T operator++() 36 | { const T prev=n.fetch_add(1); 37 | return prev+1; 38 | } 39 | T operator--() 40 | { const T prev=n.fetch_sub(1); 41 | return prev-1; 42 | } 43 | operator T() 44 | { return n; 45 | } 46 | operator T() const 47 | { return n; 48 | } 49 | void Set(T n) 50 | { this->n=n; 51 | } 52 | T Get() const 53 | { return n; 54 | } 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /portable/AtomicLock.h: -------------------------------------------------------------------------------- 1 | // AtomicLock.h 2 | // Robin.Rowe@CinePaint.org 2014/8/22 3 | 4 | #ifndef AtomicLock_h 5 | #define AtomicLock_h 6 | 7 | #include "AtomicCounter.h" 8 | 9 | class AtomicLock 10 | { AtomicCounter i; 11 | public: 12 | AtomicLock() 13 | {} 14 | bool IsLocked() const 15 | { return i==1; 16 | } 17 | bool Lock() 18 | { if(i!=0) 19 | { return false; 20 | } 21 | const int count=++i; 22 | if(count!=1) 23 | { return false; 24 | } 25 | return true; 26 | } 27 | void Unlock() 28 | { i=0; 29 | } }; 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /portable/AtomicLock0.h: -------------------------------------------------------------------------------- 1 | // AtomicLock.h 2 | // 2014/8/4 3 | 4 | #ifndef AtomicLock_h 5 | #define AtomicLock_h 6 | 7 | #include "AtomicCounter.h" 8 | 9 | class AtomicLock 10 | { AtomicCounter& i; 11 | int count; 12 | public: 13 | AtomicLock(AtomicCounter& i) 14 | : i(i) 15 | { count=++i; 16 | } 17 | ~AtomicLock() 18 | { --i; 19 | } 20 | bool operator!() const 21 | { return count!=1; 22 | } }; 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /portable/AtomicMutex.h: -------------------------------------------------------------------------------- 1 | // libportable/AtomicMutex.h 2 | // Robin.Rowe@cinepaint.org 2014/11/20 3 | 4 | #ifndef AtomicMutex_h 5 | #define AtomicMutex_h 6 | 7 | #ifdef UNREAL_ENGINE 8 | #include 9 | #endif 10 | 11 | #include 12 | 13 | #ifdef UNREAL_ENGINE 14 | #include 15 | #endif 16 | 17 | namespace portable 18 | { 19 | 20 | class AtomicMutex 21 | { friend class SoftLock; 22 | std::atomic lock; 23 | public: 24 | AtomicMutex() 25 | { lock=0; 26 | } 27 | bool IsLocked() const 28 | { return 1==lock; 29 | } 30 | bool operator!() const 31 | { return !IsLocked(); 32 | } 33 | bool Lock() 34 | { const int lockCount=lock.fetch_add(1,std::memory_order_relaxed)+1; 35 | const bool isLocked = (1==lockCount); 36 | if(!isLocked) 37 | { Unlock(); 38 | } 39 | return isLocked; 40 | } 41 | int Unlock() 42 | { const int lockCount=lock.fetch_sub(1,std::memory_order_relaxed)-1; 43 | return lockCount; 44 | } 45 | }; 46 | 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /portable/Breakpoint.h: -------------------------------------------------------------------------------- 1 | // portable/Breakpoint.h 2 | // Created by Robin Rowe on 6/30/2015. 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org. All rights reserved. 4 | // 5 | 6 | #if defined(_DEBUG) && defined(_WIN32) 7 | #include 8 | 9 | inline 10 | void Breakpoint() 11 | { DebugBreak(); 12 | } 13 | #else 14 | inline 15 | void Breakpoint() 16 | {} 17 | 18 | /* How to breakpoint a cgi-bin: 19 | 20 | #include " 21 | 22 | int main() 23 | { Breakpoint();//Launches VC++ and stops on bp here 24 | . 25 | . // your stuff... 26 | . 27 | return 0; 28 | } 29 | 30 | */ 31 | 32 | #endif -------------------------------------------------------------------------------- /portable/Buffer.h: -------------------------------------------------------------------------------- 1 | // Buffer.h 2 | // Copyright 2016/1/16 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #ifndef Buffer_h 6 | #define Buffer_h 7 | 8 | #include 9 | 10 | namespace portable 11 | { 12 | 13 | template 14 | class Buffer 15 | { T buffer[bufsize]; 16 | unsigned size; 17 | public: 18 | Buffer() 19 | { size=0; 20 | } 21 | T* get() 22 | { return buffer; 23 | } 24 | const T* get() const 25 | { return buffer; 26 | } 27 | unsigned capacity() const 28 | { return bufsize; 29 | } 30 | unsigned length() const 31 | { return size; 32 | } 33 | bool Append(T* data,unsigned length) 34 | { if (size + length > bufsize) 35 | { return false; 36 | } 37 | memcpy(buffer+size,data,length); 38 | size+=length; 39 | return true; 40 | } 41 | bool Append(T data) 42 | { if (size + sizeof(T) > bufsize) 43 | { return false; 44 | } 45 | buffer[size]=data; 46 | size++; 47 | return true; 48 | } 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /portable/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/portable/CMakeLists.txt 2 | 3 | project(libportable) 4 | message("--- Building library ${PROJECT_NAME} ---") 5 | 6 | set(HEADERS 7 | # Astring.h 8 | AtomicCounter.h 9 | AtomicLock.h 10 | AtomicLock0.h 11 | AtomicMutex.h 12 | Breakpoint.h 13 | ipc/BsdMulticast.h 14 | ipc/BsdPacketServer.h 15 | ipc/BsdSocket.h 16 | ipc/BsdSocketClient.h 17 | ipc/BsdSocketPool.h 18 | ipc/BsdSocketServer.h 19 | ipc/BsdSocketStartup.h 20 | Buffer.h 21 | Cfile.h 22 | CommandLine.h 23 | Counter.h 24 | CppTypes.h 25 | endian.h 26 | Finder.h 27 | Folder.h 28 | homedir.h 29 | http/HtmlPage.h 30 | http/Http.h 31 | http/HttpDecoder.h 32 | Logger.h 33 | MsgBuffer.h 34 | Network.h 35 | ipc/Packet.h 36 | ipc/PacketBuffer.h 37 | ipc/PacketMarker.h 38 | ipc/PacketQueue.h 39 | ipc/PacketReader.h 40 | ipc/PacketSizer.h 41 | ipc/PacketWriter.h 42 | QtHelpers.h 43 | pump/Pump.h 44 | Random.h 45 | SoftLock.h 46 | StdBlob.h 47 | StdCopy.h 48 | StdDevice.h 49 | StdFile.h 50 | StdPipe.h 51 | strcpy.h 52 | SystemCall.h 53 | thread_semaphore.h 54 | time/Timecode.h 55 | pump/TimerPump.h 56 | time/Timespan.h 57 | time/Timestamp.h 58 | UnrealLogger.h 59 | time/VariableClock.h 60 | Vec3d.h 61 | VerboseCounter.h 62 | time/WallClock.h 63 | time/Watchdog.h 64 | WormFile.h 65 | ) 66 | 67 | set(SOURCE 68 | ipc/BsdPacketServer.cpp 69 | ipc/BsdSocket.cpp 70 | ipc/BsdSocketClient.cpp 71 | ipc/BsdSocketPool.cpp 72 | ipc/BsdSocketServer.cpp 73 | ipc/BsdSocketStartup.cpp 74 | CommandLine.cpp 75 | http/Http.cpp 76 | Network.cpp 77 | ipc/PacketReader.cpp 78 | pump/Pump.cpp 79 | time/Timestamp.cpp 80 | time/VariableClock.cpp 81 | WormFile.cpp 82 | ) 83 | 84 | add_library(${PROJECT_NAME} STATIC ${HEADERS} ${SOURCE}) 85 | -------------------------------------------------------------------------------- /portable/Cfile.h: -------------------------------------------------------------------------------- 1 | // Cfile.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef Cfile_h 6 | #define Cfile_h 7 | 8 | #include 9 | 10 | #pragma warning(disable:4996) 11 | 12 | class Cfile 13 | { FILE* fp; 14 | public: 15 | ~Cfile() 16 | { Close(); 17 | } 18 | Cfile() 19 | : fp(nullptr) 20 | {} 21 | bool operator!() const 22 | { return !fp; 23 | } 24 | Cfile(const char* filename,const char* mode) 25 | { Open(filename,mode); 26 | } 27 | bool Open(const char* filename,const char* mode) 28 | { fp=fopen(filename,mode); 29 | return nullptr!=fp; 30 | } 31 | void Close() 32 | { if(fp) 33 | { fclose(fp); 34 | fp=nullptr; 35 | } } 36 | operator FILE*() 37 | { return fp; 38 | } 39 | }; 40 | 41 | #pragma warning(default:4996) 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /portable/CommandLine.cpp: -------------------------------------------------------------------------------- 1 | // CommandLine.cpp 2 | // Libunistd Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #include "CommandLine.h" 6 | 7 | namespace portable 8 | { 9 | 10 | void CommandLine::Set(int argc,const char** argv) 11 | { this->argc = argc; 12 | this->argv = argv; 13 | // skip arg[0] = prog_name 14 | for(int i=1;i 9 | #include 10 | #include 11 | #include 12 | 13 | namespace portable 14 | { 15 | 16 | class CommandLine 17 | { std::map data; 18 | int argc; 19 | const char** argv; 20 | public: 21 | CommandLine() 22 | { argc = 0; 23 | argv = nullptr; 24 | } 25 | CommandLine(int argc,const char** argv) 26 | { Set(argc,argv); 27 | } 28 | void Set(int argc,const char** argv); 29 | void Append(const char* keyval); 30 | const char* Get(const char* key) const 31 | { const auto it = data.find(key); 32 | if(data.end()==it) 33 | { return nullptr; 34 | } 35 | const char* value = it->second.c_str(); 36 | return value; 37 | } 38 | bool Get(const char* key,int& i) const 39 | { const char* value = Get(key); 40 | if(!value) 41 | { return false; 42 | } 43 | i = atoi(value); 44 | return errno != EINVAL; 45 | } 46 | const char* operator[](int i) const 47 | { if(i<0) 48 | { i = argc+i; 49 | } 50 | if(i>=argc) 51 | { return ""; 52 | } 53 | return argv[i]; 54 | } 55 | bool IsKey(const char* key) const 56 | { const auto it = data.find(key); 57 | return data.end()!=it; 58 | } 59 | std::string toString(); 60 | }; 61 | 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /portable/Counter.h: -------------------------------------------------------------------------------- 1 | // Counter.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef Counter_h 6 | #define Counter_h 7 | 8 | #include 9 | 10 | class Counter 11 | { unsigned count; 12 | std::string s; 13 | public: 14 | Counter() 15 | : count(0) 16 | {} 17 | const char* operator ()(const char* msg) 18 | { count++; 19 | s=std::to_string(count); 20 | s.append(": "); 21 | s.append(msg); 22 | return s.c_str(); 23 | } 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /portable/Db.h: -------------------------------------------------------------------------------- 1 | // portable/Db.h 2 | // Robin.Rowe@Cinepaint.org 3 | // 2015/8/3 4 | 5 | #ifndef PortableDb_h 6 | #define PortableDb_h 7 | 8 | namespace portable { 9 | 10 | class Db 11 | { 12 | public: 13 | typedef int (*DbCallback)(void*,int,char**,char**); 14 | virtual ~Db() 15 | { Close(); 16 | } 17 | virtual bool IsExist(const char* dbName) const = 0; 18 | virtual bool IsOpen() const = 0; 19 | virtual bool Open(const char* dbName) = 0; 20 | virtual void Close() 21 | {} 22 | virtual bool Exec(const char* ,DbCallback ) 23 | { return false; 24 | } 25 | bool IsFile(const char* filename) const 26 | { 27 | #ifdef WIN32 28 | struct __stat64 st; 29 | const int err = _stat64(filename, &st); 30 | if(err!=0) 31 | { return false; 32 | } 33 | return true; 34 | #else 35 | struct stat st; 36 | const int err = stat(filename, &st); 37 | if(err!=0) 38 | { return false; 39 | } 40 | return true; 41 | #endif 42 | } 43 | void DropFile(const char* filename) 44 | { remove(filename); 45 | } 46 | }; 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /portable/Folder.h: -------------------------------------------------------------------------------- 1 | // portable/Folder.h 2 | // Copyright 2016/1/16 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #ifndef Folder_h 6 | #define Folder_h 7 | 8 | 9 | #ifdef _WIN32 10 | #include 11 | #endif 12 | 13 | namespace portable 14 | { 15 | 16 | void GetHomePath(std::string& folderPath,bool isForwardSlashes=true) 17 | { 18 | #ifdef _WIN32 19 | TCHAR path[MAX_PATH]; 20 | if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path))) 21 | { folderPath= path; 22 | if(isForwardSlashes) 23 | { std::replace(folderPath.begin(), folderPath.end(), '\\', '/'); 24 | } } 25 | #else 26 | //bug 27 | #endif 28 | } 29 | 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /portable/Hash.h: -------------------------------------------------------------------------------- 1 | 2 | template 3 | T Hash_djb2(const char* s) 4 | { if(!s) 5 | { return 0; 6 | } 7 | const size_t size = strlen(s); 8 | T hash = 5381; 9 | for(size_t = 0;i 10 | #endif 11 | 12 | #include 13 | #include 14 | #ifdef _WIN32 15 | #include 16 | #pragma comment(lib, "Ws2_32.lib") 17 | #endif 18 | 19 | #ifndef __cplusplus 20 | #error 21 | #endif 22 | 23 | namespace portable 24 | { 25 | 26 | template 27 | class MsgBuffer 28 | { char buffer[bufsize]; 29 | void SetPerErrno() 30 | { char* p=strerror(errno); 31 | Append(p); 32 | } 33 | void SetPerLastError() 34 | { 35 | #ifdef _WIN32 36 | const unsigned len = length(); 37 | const DWORD num = FormatMessageA( 38 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 39 | NULL, 40 | WSAGetLastError(), 41 | 0, 42 | buffer+len, 43 | bufsize-len-1, 44 | NULL); 45 | #else 46 | SetPerErrno(); 47 | #endif 48 | } 49 | public: 50 | MsgBuffer() 51 | { Reset(); 52 | } 53 | void Reset() 54 | { buffer[0]=0; 55 | } 56 | operator const char*() const 57 | { return buffer; 58 | } 59 | const char* GetErrnoError() 60 | { SetPerErrno(); 61 | return buffer; 62 | } 63 | const char* GetLastError() 64 | { SetPerLastError(); 65 | return buffer; 66 | } 67 | int GetErrno() 68 | { return errno; 69 | } 70 | int GetSocketErrorCode() 71 | { 72 | #ifdef _WIN32 73 | return WSAGetLastError(); 74 | #else 75 | return GetErrno(); 76 | #endif 77 | } 78 | unsigned length() const 79 | { return (unsigned) strlen(buffer); 80 | } 81 | unsigned capacity() const 82 | { return bufsize-1; 83 | } 84 | void Append(const char* text) 85 | { const unsigned len=length(); 86 | #pragma warning (disable : 4996) 87 | strncpy(buffer+len,text,bufsize-len-1); 88 | #pragma warning (default : 4996) 89 | buffer[bufsize-1]=0; 90 | } 91 | void Set(const char* text) 92 | { Reset(); 93 | Append(text); 94 | } 95 | void SystemLog() const 96 | { puts(buffer); 97 | } 98 | }; 99 | 100 | } 101 | 102 | #ifdef UNREAL_ENGINE 103 | #include 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /portable/QtHelpers.h: -------------------------------------------------------------------------------- 1 | // QtHelpers.h 2 | // Created by Robin Rowe on 11/19/2015. 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org. 4 | // License open source MIT 5 | 6 | #ifndef QtHelpers_h 7 | #define QtHelpers_h 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | inline 14 | bool QtLoadImage(const char* filename,QLabel& image) 15 | { QPixmap qPixmap; 16 | if(!qPixmap.load(filename)) 17 | { qDebug()<<"No image "< 15 | 16 | class MinimalStandardRandom 17 | { static const int a=48271;//16807; 18 | static const int m=2147483647; 19 | static const int q=m/a; 20 | static const int r=m%a; 21 | int seed; 22 | public: 23 | MinimalStandardRandom(int seed=0) 24 | : seed(seed) 25 | { if(!seed) 26 | { time_t seconds; 27 | time(&seconds); 28 | this->seed=(int) seconds; 29 | } } 30 | int NextPositive() // range [1, 2147483646], except 0 31 | { const int hi = seed / q; 32 | const int lo = seed % q; 33 | const int test = a * lo - r * hi; 34 | if(test > 0) 35 | { seed = test; 36 | } 37 | else 38 | { seed = test + m; 39 | } 40 | return seed; 41 | } 42 | int Next() // range +-2147483646 except 0 43 | { const int hi = seed / q; 44 | const int lo = seed % q; 45 | seed = a * lo - r * hi; 46 | return seed; 47 | } 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /portable/RingAllocator.h: -------------------------------------------------------------------------------- 1 | // RingAllocator.h 2 | // Copyright 2018/4/10 Robin.Rowe@CinePaint.org 3 | // License MIT open source 4 | 5 | #ifndef RingAllocator_h 6 | #define RingAllocator_h 7 | 8 | #include 9 | 10 | namespace Atomic 11 | { 12 | // Usage: char buffer[16]; 13 | // Atomic::RingAllocator a(buffer,4); 14 | // char* p = a.Get(12); 15 | // strcpy(p,"Hello World) 16 | // WakeOtherThread(); 17 | // a.Free(p); 18 | 19 | class RingAllocator 20 | { std::atomic p; 21 | char* buffer; 22 | char* bufferEnd; 23 | int bitmask; 24 | public: 25 | RingAllocator(char* buffer,unsigned sizeInBits) 26 | : buffer(buffer) 27 | , p(0) 28 | { bitmask = (1 << sizeInBits) - 1; 29 | bufferEnd = buffer + bitmask; 30 | } 31 | char* Get(unsigned blockSize) 32 | { blockSize += sizeof(int); 33 | int before = p.fetch_add(blockSize,std::memory_order_relaxed); 34 | before &= bitmask; 35 | if(before + blockSize > bitmask) 36 | { // Buffer overflow, 2nd try: 37 | before = p.fetch_add(blockSize,std::memory_order_relaxed); 38 | before &= bitmask; 39 | } 40 | if(before + blockSize > bitmask) 41 | { // Too big 42 | return 0; 43 | } 44 | int* header = (int*) buffer + before; 45 | *header = before; 46 | return buffer + before + sizeof(int); 47 | } 48 | int Free(const char* p) const 49 | { p -= sizeof(int); 50 | if(p < buffer || p >= bufferEnd) 51 | { return 0; 52 | } 53 | int* header = (int*) p; 54 | return *header; 55 | } 56 | }; 57 | 58 | } 59 | 60 | #endif -------------------------------------------------------------------------------- /portable/SharedMemory.h: -------------------------------------------------------------------------------- 1 | 2 | template 3 | class SharedMemory 4 | { int fd; 5 | T* t; 6 | T err; 7 | size_t size; 8 | public: 9 | ~SharedMemory() 10 | { Close(); 11 | } 12 | SharedMemory(const char* name,size_t size) 13 | : fd(0) 14 | , p(0) 15 | , size(0) 16 | { int oflags = O_RDWR | O_CREAT; 17 | fd = shm_open(name,oflags,0644); 18 | if(fd) 19 | { shm_ftruncate(fd,size); 20 | p = (t*) mmap(NULL,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); 21 | } } 22 | SharedMemory(const char* name) 23 | : fd(0) 24 | , p(0) 25 | , size(0) 26 | { int oflags=O_RDWR; 27 | fd = shm_open(name,oflags,0644); 28 | if(fd) 29 | { size = shm_size(fd)/sizeof(t); 30 | p = (t*) mmap(NULL,size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); 31 | } } 32 | T& operator[](size_t i) 33 | { if(i>=size) 34 | { return err; 35 | } 36 | return p[i]; 37 | } 38 | operator t*() 39 | { return p; 40 | } 41 | bool Flush() 42 | { return shm_flush(fd); 43 | } 44 | bool Close() 45 | { return shm_close(fd); 46 | } 47 | size_t Size() const 48 | { return size; 49 | } 50 | }; 51 | -------------------------------------------------------------------------------- /portable/Shutdown.cpp: -------------------------------------------------------------------------------- 1 | // Shutdown.cpp 2 | // Created by Robin Rowe 2019-07-10 3 | // License Copyright 2019 Robin.Rowe@HeroicRobots.com ***Proprietary*** 4 | 5 | #include "Shutdown.h" 6 | using namespace std; 7 | 8 | Shutdown* Shutdown::handler; 9 | 10 | ostream& Shutdown::Print(ostream& os) const 11 | { return os << "Shutdown"; 12 | } 13 | -------------------------------------------------------------------------------- /portable/SizeTracker.h: -------------------------------------------------------------------------------- 1 | // SizeTracker.h 2 | // Copyright 2018/4/10 Robin.Rowe@CinePaint.org 3 | // License MIT open source 4 | 5 | #ifndef SizeTracker_h 6 | #define SizeTracker_h 7 | 8 | #include 9 | 10 | namespace Atomic 11 | { 12 | 13 | class SizeTracker 14 | { std::atomic size; 15 | int bitmask; 16 | public: 17 | SizeTracker(unsigned sizeInBits) 18 | : size(0) 19 | { bitmask = (1 << sizeInBits) - 1; 20 | } 21 | int Add(int qty) 22 | { const int i = size.fetch_add(qty,std::memory_order_relaxed); 23 | return i + qty; 24 | } 25 | int Free(int qty) 26 | { const int i = size.fetch_sub(size,std::memory_order_relaxed); 27 | return i - qty; 28 | } 29 | int GetSize() const 30 | { const int s=size; 31 | return s; 32 | } 33 | int GetMaxSize() const 34 | { return bitmask; 35 | } 36 | int GetFreeSize() const 37 | { return GetMaxSize() - GetSize(); 38 | } 39 | bool IsFull() const 40 | { return GetSize() >= GetMaxSize(); 41 | } 42 | bool IsEmpty() const 43 | { return GetSize() <= 0; 44 | } 45 | }; 46 | 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /portable/SoftLock.h: -------------------------------------------------------------------------------- 1 | // libportable/SoftLock.h 2 | // Robin.Rowe@cinepaint.org 2014/11/20 3 | 4 | #ifndef SoftLock_h 5 | #define SoftLock_h 6 | 7 | #include "AtomicMutex.h" 8 | 9 | namespace portable 10 | { 11 | 12 | class AtomicMutex; 13 | 14 | class SoftLock 15 | { const bool isLocked; 16 | AtomicMutex& atomicMutex; 17 | SoftLock(SoftLock&); 18 | void operator=(SoftLock&); 19 | public: 20 | ~SoftLock() 21 | { if(isLocked) 22 | { atomicMutex.Unlock(); 23 | } } 24 | SoftLock(AtomicMutex& atomicMutex) 25 | : atomicMutex(atomicMutex), 26 | isLocked(atomicMutex.Lock()) 27 | {} 28 | bool IsLocked() const 29 | { return isLocked; 30 | } 31 | bool operator!() const 32 | { return !isLocked; 33 | } 34 | }; 35 | 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /portable/StackTrack.h: -------------------------------------------------------------------------------- 1 | // StackTrank.h 2 | // 2017/6/16 3 | 4 | #ifndef StackTrack_h 5 | #define StackTrack_h 6 | 7 | #include 8 | #if 0 9 | template 10 | class StackTrack 11 | { int count; 12 | const char* name; 13 | const int size; 14 | const T* t; 15 | public: 16 | StackTrack(const StackTrack&) = delete; 17 | StackTrack& operator=(const StackTrack&) = delete; 18 | StackTrack(int size,const char* name) 19 | : name(name) 20 | , size(size) 21 | , t(nullptr) 22 | { count++; 23 | Print(); 24 | } 25 | ~StackTrack() 26 | { count--; 27 | Print(); 28 | } 29 | void Print() 30 | { printf("StackTrack(%s): %i (%u bytes)\n",name,count,count*size); 31 | } 32 | }; 33 | 34 | #define STACK_TRACK(t) stackTrack(sizeof(t),#t) 35 | #else 36 | #define STACK_TRACK(t) {\ 37 | static int count; \ 38 | printf("StackTrack(%s): %i (%i bytes)\n", #t, ++count, int(count*sizeof(t)));\ 39 | } 40 | 41 | #endif 42 | #endif 43 | -------------------------------------------------------------------------------- /portable/StdPipe.h: -------------------------------------------------------------------------------- 1 | // StdPipe.h 2 | // Created by Robin Rowe on 12/5/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | 5 | #ifndef StdPipe_h 6 | #define StdPipe_h 7 | 8 | #include "StdFile.h" 9 | #include 10 | 11 | namespace portable 12 | { 13 | 14 | class StdPipe 15 | : public StdFile 16 | { 17 | public: 18 | ~StdPipe() 19 | { Close(); 20 | } 21 | bool Open(const char* filename) 22 | { fp = popen(filename,"w"); 23 | return 0!=fp; 24 | } 25 | int Close() 26 | { if(!fp) 27 | { return 0; 28 | } 29 | const int retval=pclose(fp); 30 | fp=0; 31 | return retval; 32 | } 33 | }; 34 | 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /portable/UnrealLogger.h: -------------------------------------------------------------------------------- 1 | // UnrealLogger.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // Open source license MIT 4 | 5 | /* Add this to your UE project header: 6 | 7 | DECLARE_LOG_CATEGORY_EXTERN(homStream, Log, All); 8 | 9 | Add to project source file: 10 | 11 | #include 12 | DEFINE_LOG_CATEGORY(your_plugin_name); 13 | UnrealLogger logger("your_plugin_name"); 14 | 15 | */ 16 | 17 | #ifndef UnrealLogger_h 18 | #define UnrealLogger_h 19 | 20 | #ifdef UNREAL_ENGINE 21 | #include 22 | #endif 23 | 24 | //#include 25 | #include 26 | #include 27 | 28 | class UnrealLogger 29 | { FString s; 30 | FName categoryName; 31 | Counter c; 32 | void Puts(const char* filename,int lineNo,const char* msg,ELogVerbosity::Type t) 33 | { s=c(msg); 34 | puts(msg); 35 | FMsg::Logf_Internal(filename, lineNo, categoryName, t, *s); 36 | s.Reset(); 37 | } 38 | void OutputWindow(const char* filename,int lineNo,const char* msg) 39 | {//OutputDebugStringA("My output string."); 40 | //_RPTF2(_CRT_WARN, "In NameOfThisFunc( )," " someVar= %d, otherVar= %d\n", someVar, otherVar ); 41 | //_CRT_WARN, _CRT_ERROR, and _CRT_ASSERT. 42 | #ifdef _DEBUG 43 | _CrtDbgReport( _CRT_WARN,filename,lineNo,msg,NULL); 44 | #endif 45 | } 46 | public: 47 | UnrealLogger(const char* loggerName) 48 | { categoryName = loggerName; 49 | OutputWindow(loggerName,0,"_CrtDbgReport enabled"); 50 | } 51 | void Log(const char* filename,int lineNo,const char* msg) 52 | { OutputWindow(filename,lineNo,msg); 53 | Puts(filename,lineNo,msg,ELogVerbosity::Display); 54 | } 55 | void Error(const char* filename,int lineNo,const char* msg) 56 | { s="LogError: "; 57 | s+=msg; 58 | Puts(filename,lineNo,TCHAR_TO_ANSI(*s),ELogVerbosity::Warning); 59 | s.Reset(); 60 | } 61 | }; 62 | 63 | extern UnrealLogger logger; 64 | 65 | #define LogMsg(msg) logger.Log(__FILE__, __LINE__,msg) 66 | #define LogError(msg) logger.Error(__FILE__, __LINE__,msg) 67 | 68 | 69 | #ifdef UNREAL_ENGINE 70 | #include 71 | #endif 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /portable/VBuffer.h: -------------------------------------------------------------------------------- 1 | // VBuffer.h 2 | // Copyright 2018/7/25 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #ifndef VBuffer_h 6 | #define VBuffer_h 7 | 8 | #include 9 | 10 | namespace portable 11 | { 12 | 13 | class VBuffer 14 | : public std::vector 15 | { 16 | public: 17 | VBuffer() 18 | {} 19 | VBuffer(size_t bufsize) 20 | { resize(bufsize); 21 | } 22 | operator char*() 23 | { return &(*this)[0]; 24 | } 25 | operator const char*() const 26 | { return &(*this)[0]; 27 | } 28 | }; 29 | 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /portable/Vec3d.h: -------------------------------------------------------------------------------- 1 | // portable/Vec3d.h 2 | // Copyright 2016/1/16 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #ifndef Vec3d_h 6 | #define Vec3d_h 7 | 8 | namespace portable 9 | { 10 | 11 | struct Vec3d 12 | { double x; 13 | double y; 14 | double z; 15 | int size() const 16 | { return sizeof(*this) == 3*sizeof(double) ? sizeof(*this) : 0; 17 | } 18 | void Copy(const Vec3d& v) 19 | { x=v.x; 20 | y=v.y; 21 | z=v.z; 22 | } 23 | void Copy(const double* v) 24 | { x=v[0]; 25 | y=v[1]; 26 | z=v[2]; 27 | } 28 | Vec3d() 29 | : x(0.) 30 | , y(0.) 31 | , z(0.) 32 | {} 33 | Vec3d(const Vec3d& v) 34 | { Copy(v); 35 | } 36 | Vec3d& operator=(const Vec3d& v) 37 | { Copy(v); 38 | } 39 | bool operator!=(const Vec3d& v) const 40 | { if(x!=v.x || y!=v.y || z!=v.z) 41 | { return false; 42 | } 43 | return true; 44 | } 45 | }; 46 | 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /portable/VerboseCounter.h: -------------------------------------------------------------------------------- 1 | // VerboseCounter.h 2 | // Created by Robin Rowe on 8/26/2016 3 | // Libunistd Copyright (c) 2016 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef VerboseCounter_h 7 | #define VerboseCounter_h 8 | 9 | namespace portable 10 | { 11 | 12 | class VerboseCounter 13 | { unsigned counter; 14 | unsigned maxMod; 15 | public: 16 | VerboseCounter(unsigned maxMod) 17 | : counter(0) 18 | , maxMod(maxMod) 19 | {} 20 | VerboseCounter& operator++(int) 21 | { counter++; 22 | return *this; 23 | } 24 | operator bool() const 25 | { return !(counter % maxMod); 26 | } 27 | }; 28 | 29 | } 30 | #endif -------------------------------------------------------------------------------- /portable/WormFile.h: -------------------------------------------------------------------------------- 1 | // WormFile.h compressed WORM file using Snappy or Brotli 2 | // Copyright 2017/3/14 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | // File extension: 2017_Q1_mail.wrm 5 | 6 | #ifndef WormFile_h 7 | #define WormFile_h 8 | 9 | #include "StdFile.h" 10 | 11 | namespace portable 12 | { 13 | 14 | class WormFile 15 | { StdFile ioFile; 16 | unsigned offset; 17 | const char* fileSig; 18 | const char* blockSig; 19 | bool WriteFileHeader(); 20 | bool ReadFileHeader(); 21 | bool WriteBlockHeader(unsigned size, unsigned crc = 0); 22 | unsigned ReadBlockHeader(); 23 | public: 24 | enum LastError 25 | { NONE, 26 | FILE_NOT_FOUND, 27 | WRITE_ERROR, 28 | SEEK_ERROR, 29 | READ_ERROR, 30 | INVALID_FORMAT, 31 | BLOCK_ERROR 32 | }; 33 | LastError lastError; 34 | WormFile() 35 | { lastError=NONE; 36 | offset=0; 37 | fileSig="WRM:None"; 38 | blockSig = "WRM:"; 39 | } 40 | bool Open(const char* filename) 41 | { if(!ioFile.Open(filename,"ab+")) 42 | { lastError = FILE_NOT_FOUND; 43 | return false; 44 | } 45 | return true; 46 | } 47 | unsigned Write(const char* data,size_t length);// returns blob offset 48 | unsigned Seek(unsigned offset);// returns blob size 49 | bool Read(char* buffer,size_t len);// uncompressed data 50 | void Close() 51 | { ioFile.Close(); 52 | } 53 | }; 54 | 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /portable/bsd_string.h: -------------------------------------------------------------------------------- 1 | /* bsd/string.h 2 | Copyright 2018/02/01 Robin.Rowe@CinePaint.org 3 | License MIT (http://opensource.org/licenses/mit-license.php) 4 | */ 5 | 6 | #ifndef bsd_string_h 7 | #define bsd_string_h 8 | 9 | #include 10 | 11 | #pragma warning(disable:4996) 12 | inline 13 | size_t strlcpy(char *dst, const char *src, size_t size) 14 | { if(!dst || !src) 15 | { return 0; 16 | } 17 | const char* end = strncpy(dst,src,size); 18 | const size_t length = end - dst; 19 | if(length>=size) 20 | { dst[size-1] = 0; 21 | return size-1; 22 | } 23 | return length; 24 | } 25 | 26 | inline 27 | size_t strlcat(char *dst, const char *src, size_t size) 28 | { if(!dst || !src) 29 | { return 0; 30 | } 31 | const size_t length = strlen(dst); 32 | char* p = dst + length; 33 | return length + strlcpy(p,src,size - length); 34 | } 35 | #pragma warning(default:4996) 36 | 37 | #endif -------------------------------------------------------------------------------- /portable/endian.h: -------------------------------------------------------------------------------- 1 | // endian.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef endian_h 6 | #define endian_h 7 | 8 | class endian 9 | { 10 | public: 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /portable/homedir.h: -------------------------------------------------------------------------------- 1 | // homedir.h 2 | // Copyright 2016 Robin.Rowe@cinepaint.org 3 | // License open source MIT 4 | 5 | #ifndef Homedir_h 6 | #define Homedir_h 7 | 8 | #ifdef _WIN32 9 | 10 | #ifdef UNREAL_ENGINE 11 | #include 12 | #endif 13 | #include 14 | #include 15 | #include 16 | 17 | inline 18 | bool GetHomedir(std::string& path) 19 | { wchar_t wbuffer[MAX_PATH+1]; 20 | if (SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, wbuffer) != S_OK) 21 | { return false; 22 | } 23 | char buffer[MAX_PATH*4+1]; 24 | const int buflen = WideCharToMultiByte(CP_UTF8, 0, wbuffer, lstrlenW(wbuffer), buffer, MAX_PATH*4, NULL, NULL); 25 | if (buflen <= 0) 26 | { return false; 27 | } 28 | buffer[buflen] = 0; 29 | path = buffer; 30 | return true; 31 | } 32 | 33 | #ifdef UNREAL_ENGINE 34 | #include 35 | #endif 36 | 37 | #else 38 | 39 | #include 40 | 41 | inline 42 | bool GetHomedir(std::string& path) 43 | { const char* dir = getenv("HOMEDIR"); 44 | if(!dir) 45 | { return false; 46 | } 47 | path = dir; 48 | return true; 49 | } 50 | 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /portable/http/HttpDecoder.h: -------------------------------------------------------------------------------- 1 | // HttpDecoder.h 2 | // Copyright Robin.Rowe@Cinepaint.org 2015/6/14 3 | // License MIT Open Source 4 | // 5 | #ifndef HttpDecoder_h 6 | #define HttpDecoder_h 7 | 8 | #ifdef ENABLE_FASTCGI 9 | #include "fcgi_stdio.h" 10 | #else 11 | #include 12 | #endif 13 | #include 14 | //#include 15 | #include 16 | 17 | #ifdef ENABLE_FASTCGI 18 | # define FASTCGI_START while(FCGI_Accept() >= 0) { 19 | # define FASTCGI_STOP } 20 | #else 21 | # define FASTCGI_START 22 | # define FASTCGI_STOP 23 | #endif 24 | 25 | class HttpDecoder 26 | { qentry_t* req; 27 | public: 28 | ~HttpDecoder() 29 | { Close(); 30 | } 31 | HttpDecoder() 32 | { req = 0; 33 | } 34 | void Close() 35 | { if(!req) 36 | { return; 37 | } 38 | req->free(req); 39 | req=0; 40 | } 41 | void Open() 42 | { req = qcgireq_parse(NULL,Q_CGI_ALL); 43 | } 44 | const char* GetValue(const char* key) const 45 | { const char* value=(const char *)req->getstr(req,key,false); 46 | return value ? value:""; 47 | } 48 | const char* operator[](const char* key) const 49 | { return GetValue(key); 50 | } 51 | void SetContentType(const char* contentType) 52 | { qcgires_setcontenttype(req, contentType); 53 | } 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /portable/ipc/BsdMulticast.h: -------------------------------------------------------------------------------- 1 | // portable/BsdMulticast.h 2 | // Created by Robin Rowe on 11/27/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef BsdMulticast_h 7 | #define BsdMulticast_h 8 | 9 | #include "../pump/TimerPump.h" 10 | #include "Packet.h" 11 | #include "BsdSocketPool.h" 12 | 13 | namespace portable 14 | { 15 | 16 | class BsdMulticast 17 | : public TimerPump 18 | { Packet* headerPacket; 19 | Packet* framePacket; 20 | BsdSocketPool& socketPool; 21 | protected: 22 | #if 1 23 | virtual void Action() override 24 | { if(framePacket) 25 | { socketPool.DirectMulticast(framePacket); 26 | } 27 | // puts("Unexpected call to pool Action"); 28 | } 29 | #endif 30 | public: 31 | BsdMulticast(BsdSocketPool& socketPool) 32 | : TimerPump("BsdMultiPump") 33 | , headerPacket(nullptr) 34 | , framePacket(nullptr) 35 | , socketPool(socketPool) 36 | { TimerPump::Start(); 37 | } 38 | ~BsdMulticast() 39 | { Close(); 40 | } 41 | void Close() 42 | { socketPool.Close(); 43 | } 44 | void SetIsStreaming(bool isStreaming = true) 45 | { socketPool.SetIsStreaming(isStreaming); 46 | } 47 | void SetHeaderPacket(Packet* packet) 48 | { headerPacket=packet; 49 | } 50 | void SetFramePacket(Packet* packet) 51 | { framePacket=packet; 52 | } 53 | void AddSkipped(unsigned skipped) 54 | { socketPool.stats.AddSkipped(skipped); 55 | } 56 | void PrintStats() 57 | { socketPool.stats.Print(); 58 | } 59 | }; 60 | 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /portable/ipc/BsdPacketServer.cpp: -------------------------------------------------------------------------------- 1 | // portable/BsdPacketServer.cpp 2 | // Created by Robin Rowe on 2016/06/24 3 | // License MIT Open Source 4 | 5 | #include "BsdPacketServer.h" 6 | #include "../Logger.h" 7 | 8 | namespace portable 9 | { 10 | 11 | bool BsdPacketServer::Start(int serverPort,unsigned maxStreams) 12 | { const bool isReceive=false; 13 | if(!Open(serverPort,maxStreams,isReceive)) 14 | { return false; 15 | } 16 | const bool isBlocking=true; 17 | isVerbose = false;//true; //bug - should pass in as param 18 | BsdSocketServer::Start(); 19 | return true; 20 | } 21 | 22 | void BsdPacketServer::LogSocketError(const PacketSocket& bsdSocket) 23 | { std::string msg; 24 | bsdSocket.GetPeerName(msg); 25 | msg+=" SendTo error: "; 26 | msg+=bsdSocket.errorMsg; 27 | error_msg(msg.c_str()); 28 | } 29 | 30 | #if 0 31 | bool BsdPacketServer::Login(SOCKET* slot,SOCKET fd) 32 | { if(!slot) 33 | { puts("No slot"); 34 | return false; 35 | } 36 | for(unsigned i=0;iRun(); 21 | } 22 | protected: 23 | void Run() override; 24 | virtual bool ReadHeader(portable::PacketReader& packet) = 0; 25 | virtual bool ReadFrame(portable::PacketReader& packet,unsigned packetId) = 0; 26 | virtual void SocketReset(const char* msg,portable::PacketReader& packet); 27 | unsigned OnPacket(unsigned bytes,portable::PacketReader& packet) override; 28 | public: 29 | PacketStats stats; 30 | BsdSocketClient(unsigned bufsize) 31 | : bufsize(bufsize) 32 | {} 33 | void Close() override 34 | { Stop(); 35 | if(socketfd) 36 | { closesocket(socketfd); 37 | socketfd=0; 38 | } } 39 | bool Open(const char* serverName,int serverPort) 40 | { if(!PacketSocket::Open(serverName,serverPort)) 41 | { return false; 42 | } 43 | Start(); 44 | return true; 45 | } 46 | void Start() override 47 | { worker=std::thread(Main,this); 48 | worker.detach(); 49 | // puts("Started socket thread"); 50 | } 51 | }; 52 | 53 | } 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /portable/ipc/BsdSocketPool.h: -------------------------------------------------------------------------------- 1 | // portable/BsdSocketPool.h 2 | // Created by Robin Rowe on 11/27/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef BsdSocketPool_h 7 | #define BsdSocketPool_h 8 | 9 | #include "PacketSocket.h" 10 | #include "PacketWriter.h" 11 | #include "PacketStats.h" 12 | 13 | namespace portable 14 | { 15 | 16 | class BsdSocketPool 17 | { bool isStreaming; 18 | std::vector socketfd; 19 | AtomicCounter counter; 20 | void ReleaseSlots(); 21 | bool IsGood(SOCKET sid) const 22 | { if(!sid || -1==sid) 23 | { return false; 24 | } 25 | return true; 26 | } 27 | public: 28 | PacketStats stats; 29 | void Close() 30 | { ReleaseSlots(); 31 | } 32 | void Reset(unsigned size) 33 | { socketfd.resize(size); 34 | socketfd.assign(size,0); 35 | counter=0; 36 | stats.Reset(); 37 | } 38 | unsigned GetCount() const 39 | { return counter; 40 | } 41 | bool IsEmpty() const 42 | { return 0==counter; 43 | } 44 | bool IsStreaming() const 45 | { return isStreaming; 46 | } 47 | void SetIsStreaming(bool isStreaming) 48 | { this->isStreaming = isStreaming; 49 | } 50 | bool SendPacket(Packet* packet,unsigned i) 51 | { PacketSocket bsdSocket(socketfd[i]); 52 | if(bsdSocket.SendTo(*packet)) 53 | { stats.Transmit(packet->GetPacketId()); 54 | return true; 55 | } 56 | ReleaseSlot(i); 57 | return false; 58 | } 59 | bool SetSlot(SOCKET sid); 60 | bool SetZombieSlot(SOCKET sid); 61 | bool ReleaseSlot(SOCKET* sock); 62 | void ReleaseSlot(SOCKET slot); 63 | int DirectMulticast(Packet* framePacket); 64 | }; 65 | 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /portable/ipc/BsdSocketServer.cpp: -------------------------------------------------------------------------------- 1 | // BsdSocketServer.cpp 2 | // Created by Robin Rowe on 11/27/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #include "BsdSocketServer.h" 7 | 8 | namespace portable 9 | { 10 | 11 | SOCKET BsdSocketServer::ListenAccept() 12 | { const int backlog = 1; //point-to-point, not SOMAXCONN; 13 | listen(socketfd,backlog); 14 | sockaddr_in cli_addr; 15 | socklen_t clilen = sizeof(cli_addr); 16 | #ifdef _DEBUG 17 | puts("\nAccepting connections..."); 18 | #endif 19 | SOCKET newsockfd = accept(socketfd, (struct sockaddr *)&cli_addr, &clilen); 20 | if (newsockfd < 0) 21 | { perror("ERROR on accept"); 22 | } 23 | #ifdef _DEBUG 24 | else 25 | { puts("connected"); 26 | } 27 | #endif 28 | return newsockfd; 29 | } 30 | 31 | void BsdSocketServer::ListenRun() 32 | { while(isGo) 33 | { if(socketfd>0) 34 | { SOCKET sock = ListenAccept(); 35 | if(!pool.SetSlot(sock)) 36 | { puts("WARN: no socket slots"); 37 | continue; 38 | } 39 | if(!Login(sock)) 40 | { puts("ERROR: socket connect failed"); 41 | pool.ReleaseSlot(sock); 42 | continue; 43 | } 44 | OnConnect(sock); 45 | } 46 | } 47 | OnStop(); 48 | } 49 | 50 | void BsdSocketServer::PacketRun() 51 | { std::unique_ptr buffer(new char[bufsize]); 52 | PacketReader packet(buffer.get(),bufsize); 53 | unsigned offset=0; 54 | while(isGo) 55 | { const int bytes = RecvFrom(buffer.get(),bufsize,offset); 56 | packet.Reset(); 57 | offset=OnPacket(bytes,packet); 58 | } 59 | OnStop(); 60 | } 61 | 62 | bool BsdSocketServer::Open(int serverPort,int maxStreams,bool isPacketRun) 63 | { this->isPacketRun=isPacketRun; 64 | pool.Reset(maxStreams); 65 | socketfd=OpenSocket(); 66 | if(socketfd == -1) 67 | { puts(errorMsg.GetLastError()); 68 | return false; 69 | } 70 | server_sockaddr.sin_family = AF_INET; 71 | server_sockaddr.sin_port = htons((u_short) serverPort); 72 | server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY); 73 | if(::bind(socketfd, (struct sockaddr*)&server_sockaddr,sizeof(server_sockaddr)) == -1) 74 | { puts(errorMsg.GetLastError()); 75 | return false; 76 | } 77 | SetReuse(socketfd); 78 | isGo=true; 79 | return true; 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /portable/ipc/BsdSocketServer.h: -------------------------------------------------------------------------------- 1 | // portable/BsdSocketServer.h 2 | // Created by Robin Rowe on 11/27/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef BsdSocketServer_h 7 | #define BsdSocketServer_h 8 | 9 | #include "PacketSocket.h" 10 | #include "BsdSocketPool.h" 11 | 12 | namespace portable 13 | { 14 | 15 | class BsdSocketServer 16 | : public PacketSocket 17 | { 18 | protected: 19 | std::thread listenWorker; 20 | BsdSocketPool pool; 21 | const unsigned bufsize; 22 | bool isPacketRun; 23 | SOCKET ListenAccept(); 24 | static void ListenMain(BsdSocketServer* self) 25 | { self->ListenRun(); 26 | } 27 | static void PacketMain(BsdSocketServer* self) 28 | { self->PacketRun(); 29 | } 30 | public: 31 | virtual ~BsdSocketServer() 32 | {} 33 | BsdSocketServer(unsigned bufsize) 34 | : bufsize(bufsize) 35 | , isPacketRun(true) 36 | { SetAsyncMode(); 37 | } 38 | unsigned GetConnectionCount() const 39 | { return pool.GetCount(); 40 | } 41 | bool Open(int serverPort,int maxStreams,bool isPacketRun=true); 42 | void Close() override 43 | { Stop(); 44 | PacketSocket::Close(); 45 | } 46 | virtual bool Login(SOCKET fd) 47 | { (void)fd; 48 | return false;// nobody can login, override function to set true 49 | } 50 | void Start() override 51 | { listenWorker=std::thread(ListenMain,this); 52 | listenWorker.detach(); 53 | if(isPacketRun) 54 | { packetWorker=std::thread(PacketMain,this); 55 | packetWorker.detach(); 56 | } } 57 | virtual void ListenRun(); 58 | virtual void OnConnect(SOCKET sock) const 59 | { (void) sock; 60 | } 61 | virtual void OnDisonnect(SOCKET sock) const 62 | { (void)sock; 63 | } 64 | virtual void PacketRun(); 65 | }; 66 | 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /portable/ipc/BsdSocketStartup.cpp: -------------------------------------------------------------------------------- 1 | // portable/BsdSocketStartup.cpp 2 | // Created by Robin Rowe on 2019/5/31 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifdef _WIN32 7 | 8 | #include "BsdSocketStartup.h" 9 | 10 | bool portable::BsdSocketStartup::isSingleton; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /portable/ipc/BsdSocketStartup.h: -------------------------------------------------------------------------------- 1 | // portable/BsdSocketStartup.h 2 | // Created by Robin Rowe on 11/27/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef BsdSocketStartup_h 7 | #define BsdSocketStartup_h 8 | 9 | #ifdef _WIN32 10 | 11 | #ifdef UNREAL_ENGINE 12 | #include 13 | #endif 14 | #include 15 | #ifdef UNREAL_ENGINE 16 | #include 17 | #endif 18 | 19 | namespace portable 20 | { 21 | 22 | class BsdSocketStartup 23 | { static bool isSingleton; 24 | public: 25 | BsdSocketStartup() 26 | { if(!isSingleton) 27 | { WSADATA data; 28 | const WORD version_requested = MAKEWORD(2, 0); 29 | WSAStartup(version_requested, &data); 30 | isSingleton = true; 31 | } } 32 | ~BsdSocketStartup() 33 | { if(isSingleton) 34 | { WSACleanup(); 35 | isSingleton = false; 36 | } } 37 | }; 38 | 39 | } 40 | #else 41 | namespace portable 42 | { 43 | 44 | class BsdSocketStartup 45 | { 46 | public: 47 | BsdSocketStartup() 48 | {} 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /portable/ipc/BsdSocketTcp.h: -------------------------------------------------------------------------------- 1 | // portable/BsdSocketTcp.h 2 | // Created by Robin Rowe on 2018/4/4 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef BsdSocketTcp_h 7 | #define BsdSocketTcp_h 8 | 9 | #include "BsdSocket.h" 10 | 11 | namespace portable 12 | { 13 | 14 | class BsdSocketTcp 15 | : public BsdSocket 16 | {public: 17 | virtual int OpenSocket() 18 | { return (int)socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 19 | } 20 | bool operator!() const 21 | { return !IsGood(); 22 | } 23 | }; 24 | 25 | } 26 | 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /portable/ipc/BsdSocketUdp.h: -------------------------------------------------------------------------------- 1 | // portable/BsdSocketUdp.h 2 | // Created by Robin Rowe on 2018/4/4 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef BsdSocketUdp_h 7 | #define BsdSocketUdp_h 8 | 9 | #include 10 | #include "BsdSocket.h" 11 | 12 | namespace portable 13 | { 14 | 15 | class BsdSocketUdp 16 | : public BsdSocket 17 | { 18 | public: 19 | std::vector v; 20 | BsdSocketUdp(size_t bufsize) 21 | : v(bufsize) 22 | { Clear(); 23 | } 24 | virtual int OpenSocket() 25 | { return (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 26 | } 27 | bool operator!() const 28 | { return !IsOpen(); 29 | } 30 | void Clear() 31 | { if(!v.size()) 32 | { return; 33 | } 34 | v[0] = 0; 35 | v[v.size()-1] = 0; 36 | } 37 | bool Receive() 38 | { int bufsize = (int) v.size(); 39 | bytesRead = RecvFrom(&v[0],bufsize,0); 40 | if(bytesRead<=0) 41 | { v[0] = 0; 42 | return false; 43 | } 44 | if(bytesRead >= bufsize) 45 | { bufsize--; 46 | v[bufsize] = 0; 47 | return true; 48 | } 49 | v[bytesRead] = 0; 50 | return true; 51 | } 52 | const char* c_str() const 53 | { return &v[0]; 54 | } 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /portable/ipc/PacketBuffer.h: -------------------------------------------------------------------------------- 1 | // portable/PacketBuffer.h 2 | // Copyright 2016/1/16 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #ifndef PacketBuffer_h 6 | #define PacketBuffer_h 7 | 8 | #include "Packet.h" 9 | 10 | namespace portable 11 | { 12 | 13 | template 14 | class PacketBuffer 15 | { char buffer[bufsize]; 16 | public: 17 | operator PacketSizer() 18 | { return PacketSizer(buffer,bufsize); 19 | } 20 | }; 21 | 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /portable/ipc/PacketMarker.h: -------------------------------------------------------------------------------- 1 | // portable/PacketMarker.h 2 | // Copyright 2016/1/16 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #ifndef PacketMarker_h 6 | #define PacketMarker_h 7 | 8 | #include "PacketWriter.h" 9 | #include "PacketReader.h" 10 | 11 | namespace portable 12 | { 13 | 14 | template 15 | class PacketMarker 16 | { char *data; 17 | public: 18 | PacketMarker(PacketWriter& packet) 19 | : data(packet.GetEndPtr()) 20 | { packet.Skip(sizeof(T)); 21 | } 22 | void SetValue(const T& value) 23 | { memcpy(data,&value,sizeof(T)); 24 | } 25 | unsigned GetSize() const 26 | { return sizeof(T); 27 | } 28 | }; 29 | 30 | class PacketDelta 31 | { PacketWriter& packet; 32 | PacketMarker marker; 33 | unsigned offset; 34 | public: 35 | PacketDelta(PacketWriter& packet) 36 | : packet(packet) 37 | , marker(packet) 38 | { offset = packet.GetPacketSize(); 39 | } 40 | void SetValue() 41 | { const unsigned delta = packet.GetPacketSize() - offset; 42 | marker.SetValue(delta); 43 | } 44 | }; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /portable/ipc/PacketQueue.h: -------------------------------------------------------------------------------- 1 | // portable/PacketQueue.h 2 | // Copyright 2016/1/16 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #ifndef PacketQueue_h 6 | #define PacketQueue_h 7 | 8 | #include "PacketWriter.h" 9 | 10 | namespace portable 11 | { 12 | 13 | template 14 | class PacketQueue 15 | { static const size_t depth = 3; 16 | char buffer[bufsize*depth]; 17 | PacketWriter packetWriter0; 18 | PacketWriter packetWriter1; 19 | PacketWriter packetWriter2; 20 | PacketWriter* baked; 21 | PacketWriter* dirty; 22 | PacketWriter* fresh; 23 | public: 24 | PacketQueue() 25 | : packetWriter0(buffer,bufsize) 26 | , packetWriter1(buffer+bufsize,bufsize) 27 | , packetWriter2(buffer+2*bufsize,bufsize) 28 | { const unsigned size = sizeof(buffer); 29 | memset(buffer,0,size); 30 | baked = &packetWriter0; 31 | dirty = &packetWriter1; 32 | fresh = &packetWriter2; 33 | } 34 | void Advance() 35 | { PacketWriter* oldBaked = baked; 36 | baked = dirty;//must be first 37 | dirty = fresh; 38 | fresh = oldBaked;//must be last 39 | dirty->Reset(); 40 | } 41 | PacketWriter& GetDirty() 42 | { return *dirty; 43 | } 44 | PacketWriter& GetBaked() 45 | { return *baked; 46 | } 47 | }; 48 | 49 | } 50 | #endif -------------------------------------------------------------------------------- /portable/ipc/PacketReader.cpp: -------------------------------------------------------------------------------- 1 | // portable/PacketReader.cpp 2 | // Libunistd Copyright 2016/1/16 Robin.Rowe@cinepaint.org 3 | // License open source MIT/BSD 4 | 5 | #include "PacketReader.h" 6 | 7 | namespace portable 8 | { 9 | 10 | template<> 11 | PacketReader& operator>>(PacketReader& packet,std::string& data) 12 | { const bool ok = packet.Read(data); 13 | // std::cout<<"read string" << std::endl; 14 | return packet; 15 | } 16 | 17 | bool PacketReader::Read(std::string& s) 18 | { const char* cs =""; 19 | unsigned stringLength = 0; 20 | if(!Read(cs,stringLength)) 21 | { return false; 22 | } 23 | s = cs; 24 | return true; 25 | } 26 | 27 | bool PacketReader::Read(const char*& s,unsigned& stringLength) 28 | { stringLength = 0; 29 | if(IsInvalid()) 30 | { return false; 31 | } 32 | s = readPtr; 33 | stringLength = 0; 34 | while(readPtr 7 | #include 8 | #include 9 | 10 | inline 11 | void debug_print(const char* op,void* p,const char* filename,int lineno,size_t size) 12 | { 13 | #ifdef _WIN32 14 | char sep = '\\'; 15 | #else 16 | char sep = '/'; 17 | #endif 18 | const char* ptr = strrchr(filename,sep); 19 | if(sep) 20 | { filename = ptr+1; 21 | } 22 | printf("%s: %p %s:%i %zu bytes\n",op,p,filename,lineno,size); 23 | } 24 | 25 | inline 26 | void *debug_malloc(size_t size,const char* filename,int line) 27 | { void* p = malloc(size); 28 | debug_print("+malloc",p,filename,line,size); 29 | return p; 30 | } 31 | 32 | inline 33 | void debug_free(void *p,const char* filename,int line) 34 | { debug_print("-free",p,filename,line,0); 35 | free(p); 36 | } 37 | 38 | inline 39 | void *debug_calloc(size_t nmemb, size_t size,const char* filename,int line) 40 | { void* p = calloc(nmemb,size); 41 | debug_print("+calloc",p,filename,line,nmemb*size); 42 | return p; 43 | } 44 | 45 | inline 46 | void *debug_realloc(void *ptr, size_t size,const char* filename,int line) 47 | { debug_print("-free",ptr,filename,line,0); 48 | void* p = realloc(ptr,size); 49 | debug_print("+realloc",p,filename,line,size); 50 | return p; 51 | } 52 | 53 | #define malloc(size) debug_malloc(size,__FILE__,__LINE__) 54 | #define calloc(n,size) debug_calloc(n,size,__FILE__,__LINE__) 55 | #define realloc(p,size) debug_realloc(p,size,__FILE__,__LINE__) 56 | #define free(p) debug_free(p,__FILE__,__LINE__) 57 | 58 | /* 59 | void SetDebugHeap() 60 | {// Get current flag 61 | int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); 62 | // Turn on leak-checking bit. 63 | tmpFlag |= _CRTDBG_LEAK_CHECK_DF; 64 | tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF; 65 | tmpFlag |= _CRTDBG_DELAY_FREE_MEM_DF; 66 | tmpFlag |= _CRTDBG_ALLOC_MEM_DF; 67 | // Turn off CRT block checking bit. 68 | // tmpFlag &= ~_CRTDBG_CHECK_CRT_DF; 69 | // Set flag to the new value. 70 | _CrtSetDbgFlag( tmpFlag ); 71 | _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); 72 | } 73 | */ 74 | #endif -------------------------------------------------------------------------------- /portable/pump/Pump.cpp: -------------------------------------------------------------------------------- 1 | // libportable/Pump.cpp 2 | // Created by Robin Rowe on 4/19/2015. 3 | // License MIT Open Source 4 | // 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "Pump.h" 11 | #include "../bsd_string.h" 12 | #include "../SystemLog.h" 13 | using namespace std; 14 | 15 | namespace portable 16 | { 17 | 18 | vector Pump::pumps; 19 | 20 | Pump::Pump(const char* pumpName) 21 | : pumpName(pumpName) 22 | , isGo(false) 23 | , isWake(false) 24 | { if(!pumps.size()) 25 | { signal(SIGINT,Signal); 26 | signal(SIGTERM,Signal); 27 | trace_msg("Pump hooked SIGINT"); 28 | } 29 | pumps.push_back(this); 30 | } 31 | 32 | void Pump::Run() 33 | { if(!Init()) 34 | { return; 35 | } 36 | while(isGo) 37 | { if(Receive()) 38 | { Action(); 39 | } } 40 | Shutdown(); 41 | } 42 | 43 | bool Pump::Start(bool isJoin) 44 | { if(isGo) 45 | { return false; 46 | } 47 | isGo=true; 48 | worker = std::thread(Main,this); 49 | PrintTask(pumpName,pumpName); 50 | if(isJoin) 51 | { worker.join(); 52 | } 53 | else 54 | { worker.detach(); 55 | } 56 | return true; 57 | } 58 | 59 | // CAUTION! Pump::Signal(int signal) to be called from SIGINT, must be signal-safe: 60 | // http://man7.org/linux/man-pages/man7/signal-safety.7.html 61 | 62 | void Pump::Signal(int signal) 63 | { if(SIGINT == signal) 64 | { signal_safe_puts("SIGINT interrupt\n"); 65 | } 66 | else 67 | { signal_safe_puts("Signal interrupt\n"); 68 | } 69 | enum {size = 40}; 70 | char s[size]; // Note: not std::string because inside interrupt routine! 71 | for(Pump* pump:pumps) 72 | { strlcpy(s,"Stop ",size); 73 | strlcat(s,pump->pumpName,size); 74 | strlcat(s,"\n",size); 75 | signal_safe_puts(s); 76 | pump->Stop(); 77 | } 78 | pumps.clear(); 79 | using namespace std::chrono_literals; 80 | std::this_thread::sleep_for(2s); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /portable/pump/Pump.h: -------------------------------------------------------------------------------- 1 | // libportable/TimerPump.h 2 | // Created by Robin Rowe on 4/19/2015. 3 | // License MIT Open Source 4 | // 5 | 6 | #ifndef Pump_h 7 | #define Pump_h 8 | 9 | // You may get _Pad compile error if a dependant class is not defined. 10 | // If you embed unique_ptr anywhere in your objects, you may get this error. 11 | /* Also try this: 12 | #pragma warning(push) 13 | #pragma warning(disable:4265) 14 | #include 15 | #pragma warning(pop) 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "../SystemCall.h" 24 | 25 | namespace portable 26 | { 27 | 28 | class Pump 29 | {protected: 30 | typedef std::unique_lock Lock; 31 | std::mutex mut; 32 | std::condition_variable cv; 33 | std::thread worker; 34 | volatile bool isGo; 35 | volatile bool isWake; 36 | const char* pumpName;// Expects static string, not copied! 37 | static std::vector pumps; 38 | static void Main(Pump* self) 39 | { self->Run(); 40 | } 41 | virtual void Wait(Lock& lock) 42 | { cv.wait(lock); 43 | } 44 | virtual bool Receive() 45 | { Lock lock(mut); 46 | Wait(lock); 47 | if(!isWake || !isGo) 48 | { // spurious thread wake or Stop() 49 | return false; 50 | } 51 | isWake=false; 52 | return true; 53 | } 54 | virtual void Action() 55 | {} 56 | virtual bool Init() 57 | { return true; 58 | } 59 | void Run(); 60 | bool Start(bool isJoin = false); 61 | public: 62 | Pump(const char* pumpName); 63 | virtual ~Pump() 64 | { Stop(); 65 | Stop(); 66 | } 67 | bool StartJoin() 68 | { return Start(true); 69 | } 70 | bool StartDetach() 71 | { return Start(false); 72 | } 73 | // CAUTION! Stop() may be called from SIGINT, must be signal-safe: 74 | // http://man7.org/linux/man-pages/man7/signal-safety.7.html 75 | virtual bool Stop() 76 | { isGo=false; 77 | Wake(); 78 | return true; 79 | } 80 | void Wake() 81 | { isWake = true; 82 | cv.notify_one(); 83 | #if 0 84 | while(isWake)) 85 | { std::this_thread::sleep_for(std::chrono_literals::50ms); 86 | } 87 | #endif 88 | } 89 | virtual void Shutdown() 90 | { printf("Shutdown %s\n",pumpName); 91 | } 92 | static void Signal(int signal); 93 | }; 94 | 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /portable/pump/TimerPump.h: -------------------------------------------------------------------------------- 1 | // libportable/TimerPump.h 2 | // Created by Robin Rowe on 4/19/2015. 3 | // License MIT Open Source 4 | // 5 | 6 | #ifndef TimerPump_h 7 | #define TimerPump_h 8 | 9 | #include "Pump.h" 10 | 11 | namespace portable 12 | { 13 | 14 | class TimerPump 15 | : public Pump 16 | {protected: 17 | typedef std::chrono::milliseconds milliseconds; 18 | milliseconds wakeDelay; 19 | bool isTimeout; 20 | void Wait(Lock& lock) override 21 | { isTimeout = false; 22 | if(wakeDelay.count()) 23 | { isTimeout = std::cv_status::timeout==cv.wait_for(lock,milliseconds(wakeDelay)); 24 | return; 25 | } 26 | cv.wait(lock); 27 | } 28 | public: 29 | TimerPump(const char* pumpName) 30 | : Pump(pumpName) 31 | , wakeDelay(0) 32 | , isTimeout(false) 33 | {} 34 | bool Start(int millis=0,bool isJoin = false) 35 | { SetTimeout(millis); 36 | return Pump::Start(isJoin); 37 | } 38 | void SetTimeout(int millis) 39 | { wakeDelay = milliseconds(millis); 40 | } 41 | long long GetTimeout() const 42 | { return wakeDelay.count(); 43 | } 44 | }; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /portable/strcpy.h: -------------------------------------------------------------------------------- 1 | // strcpy.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef strcpy_h 6 | #define strcpy_h 7 | 8 | #include 9 | #include 10 | 11 | inline 12 | void strcpy(std::string& s, const char* s2) 13 | { s=s2; 14 | } 15 | 16 | inline 17 | void strcpy(std::string& s, std::string& s2) 18 | { s=s2; 19 | } 20 | 21 | inline 22 | void strcpy(std::string& s, const std::string& s2) 23 | { s=s2; 24 | } 25 | 26 | inline 27 | const char* strstr(const std::string& s, const char* cs) 28 | { return strstr(s.c_str(),cs); 29 | } 30 | 31 | inline 32 | const char* strstr(const std::string& s, const std::string& s2) 33 | { return strstr(s.c_str(),s2.c_str()); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /portable/thread_semaphore.h: -------------------------------------------------------------------------------- 1 | // thread_semaphore.h 2 | // 2013/10/31 3 | 4 | #ifndef thread_semaphore_h 5 | #define thread_semaphore_h 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | //#include 14 | 15 | //typedef boost::mutex mutex; 16 | typedef boost::lock_guard lock_guard; 17 | 18 | #ifdef USE_IPC_SEMAPHORE 19 | typedef boost::interprocess::interprocess_semaphore semaphore; 20 | #else 21 | 22 | class thread_semaphore 23 | { boost::mutex protect; 24 | boost::condition_variable cond; 25 | typedef boost::unique_lock Lock; 26 | public: 27 | thread_semaphore() 28 | {} 29 | void Wait(long long microSeconds) 30 | { if(0>=microSeconds) 31 | { return; 32 | } 33 | Lock lock(protect); 34 | boost::system_time timeout = boost::get_system_time() + boost::posix_time::milliseconds(microSeconds); 35 | if(!cond.timed_wait(lock,timeout)) 36 | { // false if timeout 37 | return; 38 | } 39 | } 40 | void Wait() 41 | { Lock lock(protect); 42 | cond.wait(lock); 43 | } 44 | void Signal() 45 | { cond.notify_one(); 46 | } 47 | }; 48 | 49 | class thread_lock 50 | { typedef boost::lock_guard Lock; 51 | boost::mutex protect; 52 | Lock lock; 53 | public: 54 | thread_lock() 55 | : lock(protect) 56 | {} 57 | }; 58 | 59 | #if 0 60 | 61 | class thread_mutex 62 | { 63 | public: 64 | bool Lock() 65 | { try 66 | { lock(); 67 | } 68 | catch(...) 69 | { return false; 70 | } 71 | return true; 72 | } 73 | bool Unlock() 74 | { try 75 | { unlock(); 76 | } 77 | catch(...) 78 | { return false; 79 | } 80 | return true; 81 | } 82 | }; 83 | #endif 84 | 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /portable/time/Timecode.h: -------------------------------------------------------------------------------- 1 | // Timecode.h 2 | // 2016/06/17 3 | 4 | #ifndef Timecode_h 5 | #define Timecode_h 6 | 7 | union Timecode // char[4] h:m:s:f, range 0-255 each 8 | { struct at 9 | { unsigned char reel; 10 | unsigned char minutes; 11 | unsigned char seconds; 12 | unsigned char frame; 13 | }; 14 | unsigned int intVal; 15 | Timecode() 16 | : intVal(0) 17 | {} 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /portable/time/Timespan.h: -------------------------------------------------------------------------------- 1 | // Timespan.h 2 | // Libunistd Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef Timespan_h 6 | #define Timespan_h 7 | 8 | #include 9 | #include 10 | 11 | namespace portable 12 | { 13 | 14 | class Timespan 15 | { double longestDuration; 16 | double shortestDuration; 17 | unsigned tickCount; 18 | std::chrono::steady_clock::time_point start; 19 | public: 20 | Timespan() 21 | { Reset(); 22 | } 23 | void Reset(const char* msg = nullptr) 24 | { tickCount = 0; 25 | longestDuration = 0.; 26 | shortestDuration = -1.; 27 | start = std::chrono::steady_clock::now(); 28 | if(msg) 29 | { printf("%s: resetting from %fs at tick %u\n",msg,longestDuration/1000,tickCount); 30 | } } 31 | void Snap(const char* msg = nullptr) 32 | { tickCount++; 33 | auto end = std::chrono::steady_clock::now(); 34 | std::chrono::duration interval = end - start; 35 | if(interval.count()>longestDuration) 36 | { if(msg) 37 | { printf("%s: increasing from %fs to %fs at tick %u\n",msg,longestDuration/1000,interval.count()/1000,tickCount); 38 | } 39 | longestDuration = interval.count(); 40 | } 41 | if(-1. == shortestDuration || interval.count() 10 | #include 11 | #else 12 | #include 13 | #include 14 | #endif 15 | #include 16 | 17 | namespace portable 18 | { 19 | 20 | class VariableClock 21 | { static double speed; 22 | static timeval dayStart; 23 | static timespec clockStart; 24 | public: 25 | VariableClock() 26 | { SetSpeed(1.); 27 | } 28 | static bool IsNormaltime() 29 | { if(speed<=0.) 30 | { return true;// negative time ignored 31 | } 32 | if(speed<1.) 33 | { return false;// fractional speed 34 | } 35 | if(speed>1.) 36 | { return false;// high speed 37 | } 38 | return true;// 1X speed 39 | } 40 | static void SetSpeed(double speed=1.) 41 | { ::gettimeofday(&dayStart,nullptr); 42 | ::clock_gettime(CLOCK_MONOTONIC,&clockStart); 43 | VariableClock::speed = speed; 44 | } 45 | static int gettimeofday(struct timeval* tv, struct timezone* tz) 46 | { if(IsNormaltime()) 47 | { return ::gettimeofday(tv,tz); 48 | } 49 | timeval delta; 50 | ::gettimeofday(&delta,tz); 51 | delta.tv_sec-=dayStart.tv_sec; 52 | delta.tv_sec=static_cast(double(delta.tv_sec)*speed); 53 | delta.tv_usec-=dayStart.tv_usec; 54 | delta.tv_usec=static_cast(double(delta.tv_usec)*speed); 55 | tv->tv_sec=dayStart.tv_sec+delta.tv_sec; 56 | tv->tv_usec=dayStart.tv_usec+delta.tv_sec; 57 | return 0; 58 | } 59 | static int clock_gettime(clockid_t clk_id, struct timespec *tp) 60 | { if(IsNormaltime()) 61 | { return ::clock_gettime(clk_id,tp); 62 | } 63 | timespec delta; 64 | ::clock_gettime(clk_id,&delta); 65 | delta.tv_sec-=clockStart.tv_sec; 66 | delta.tv_sec=static_cast(double(delta.tv_sec)*speed); 67 | delta.tv_nsec-=clockStart.tv_nsec; 68 | delta.tv_nsec=static_cast(double(delta.tv_nsec)*speed); 69 | tp->tv_sec=clockStart.tv_sec+delta.tv_sec; 70 | tp->tv_nsec=clockStart.tv_nsec+delta.tv_nsec; 71 | return 0; 72 | } }; 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /portable/time/WallClock.h: -------------------------------------------------------------------------------- 1 | // WallClock.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef WallClock_h 6 | #define WallClock_h 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | class WallClock 13 | { std::chrono::system_clock::time_point start; 14 | std::chrono::system_clock::time_point lastWakeUp; 15 | public: 16 | WallClock() 17 | { Start(); 18 | } 19 | void Start() 20 | { start = std::chrono::system_clock::now(); 21 | lastWakeUp = start; 22 | } 23 | long long BumpIntervalMilliseconds(long long interval) 24 | { std::chrono::milliseconds delay(interval); 25 | lastWakeUp += delay; 26 | std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 27 | std::chrono::system_clock::duration pause = lastWakeUp - now; 28 | if(pause.count()<0) 29 | { return 0; 30 | } 31 | return std::chrono::duration_cast(pause).count(); 32 | } 33 | }; 34 | 35 | /* 36 | const chrono::seconds seconds = chrono::duration_cast(duration); 37 | m_microseconds = (uint32_t)(chrono::duration_cast(duration - seconds).count() & UINT32_MAX); 38 | time_t timet = (time_t)(seconds.count() & UINT32_MAX); 39 | localtime_s(&m_tm, &timet); 40 | */ 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /portable/time/Watchdog.h: -------------------------------------------------------------------------------- 1 | // Watchdog.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef Watchdog_h 6 | #define Watchdog_h 7 | 8 | #include 9 | #include 10 | #include 11 | #include "SystemCall.h" 12 | 13 | namespace portable 14 | { 15 | 16 | class Watchdog 17 | { typedef std::unique_lock Lock; 18 | typedef std::chrono::milliseconds milliseconds; 19 | milliseconds delay; 20 | bool isGo; 21 | std::mutex m; 22 | std::condition_variable cv; 23 | void Run() 24 | { while(isGo && delay.count()) 25 | { Lock lock(m); 26 | const bool isTimeout=std::cv_status::timeout==cv.wait_for(lock,delay); 27 | if(isGo) 28 | { Action(isTimeout); 29 | } } } 30 | static void Main(Watchdog* self) 31 | { self->Run(); 32 | } 33 | public: 34 | Watchdog() 35 | : delay(0) 36 | , isGo(false) 37 | {} 38 | void Start(unsigned delay,const char* description= "") 39 | { isGo =true; 40 | this->delay = milliseconds(delay); 41 | std::thread worker(Main,this); 42 | PrintTask("Watchdog",description); 43 | worker.detach(); 44 | } 45 | virtual ~Watchdog() 46 | { isGo=false; 47 | } 48 | void Wake() 49 | { cv.notify_one(); 50 | } 51 | void Stop() 52 | { isGo=false; 53 | Wake(); 54 | } 55 | virtual void Action(bool isTimeout)=0; 56 | }; 57 | 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /qdecoder/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | config.h 3 | config.h.in~ 4 | config.log 5 | config.status 6 | qdecoder.pc 7 | *.o 8 | *.a 9 | *.so* 10 | -------------------------------------------------------------------------------- /qdecoder/COPYING: -------------------------------------------------------------------------------- 1 | qDecoder License 2 | ================ 3 | 4 | ============================================================================== 5 | qDecoder - http://www.qdecoder.org 6 | 7 | Copyright (c) 2000-2012 Seungyoung Kim. 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright notice, 14 | this list of conditions and the following disclaimer. 15 | 2. Redistributions in binary form must reproduce the above copyright notice, 16 | this list of conditions and the following disclaimer in the documentation 17 | and/or other materials provided with the distribution. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | ============================================================================== 31 | (end of COPYRIGHT) 32 | -------------------------------------------------------------------------------- /qdecoder/INSTALL.md: -------------------------------------------------------------------------------- 1 | Installing qDecoder 2 | =================== 3 | 4 | ## Get qDecoder Package 5 | 6 | The latest version of qDecoder can be found at https://github.com/wolkykim/qdecoder 7 | 8 | ## Configure 9 | 10 | Configure compile option by executing included "configure" script. 11 | 12 | ``` 13 | $ ./configure 14 | ``` 15 | 16 | qDecoder can be FastCGI enabled at the compile time, use --enable-fastcgi option and put the directory path where the "fcgi_stdio.h" is located. 17 | 18 | ``` 19 | $ ./configure --enable-fastcgi=/usr/local/include 20 | ``` 21 | 22 | By default qDecoder will be install on /usr/local/{include,lib}, so use --prefix option if you want to change the installation path. 23 | 24 | ``` 25 | $ ./configure --prefix=/usr/local/qdecoder 26 | ``` 27 | 28 | To see detailed configure options, use --help option. 29 | 30 | ``` 31 | $ ./configure --help 32 | ``` 33 | 34 | ## Compile 35 | 36 | Type make to compile the source codes. 37 | 38 | ``` 39 | $ make 40 | ``` 41 | 42 | ## Install 43 | 44 | This command will install qDecoder on your system. By default, the directory prefix is "/usr/local" so it will be install on /usr/local/include and /usr/local/lib. 45 | 46 | ``` 47 | $ make install 48 | ``` 49 | 50 | This will only install header files and library(archive; static and dynamic) files. 51 | The Examples and Documentations will not be installed, so make a copy of it by yourself if you want to keep it. 52 | 53 | ## Uninstall 54 | 55 | qDecoder can be completely removed from the system. 56 | 57 | ``` 58 | $ make uninstall 59 | ``` 60 | 61 | ## Test 62 | 63 | Sample sources and API document are provided with the package in the "examples" and "doc" directories. 64 | 65 | The examples also can be compiled by typing "make" command in the "examples" directory. 66 | And "index.html" file is provided for your tests. 67 | 68 | Analyzing the example codes is probably best starting point. 69 | But be aware that the examples were written as simple as it can be just to give you straight-forward ideas, so please refer included API document for more details. 70 | -------------------------------------------------------------------------------- /qdecoder/VERSION.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/VERSION.txt -------------------------------------------------------------------------------- /qdecoder/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | autoreconf -fi; 4 | rm -Rf autom4te*.cache; 5 | 6 | ./configure $* 7 | -------------------------------------------------------------------------------- /qdecoder/doc/html/bc_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/bc_s.png -------------------------------------------------------------------------------- /qdecoder/doc/html/bdwn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/bdwn.png -------------------------------------------------------------------------------- /qdecoder/doc/html/closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/closed.png -------------------------------------------------------------------------------- /qdecoder/doc/html/doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/doxygen.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2blank.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2cl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2cl.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2doc.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2folderclosed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2folderclosed.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2folderopen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2folderopen.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2lastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2lastnode.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2link.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2mlastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2mlastnode.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2mnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2mnode.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2mo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2mo.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2node.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2node.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2ns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2ns.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2plastnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2plastnode.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2pnode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2pnode.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2splitbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2splitbar.png -------------------------------------------------------------------------------- /qdecoder/doc/html/ftv2vertline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/ftv2vertline.png -------------------------------------------------------------------------------- /qdecoder/doc/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Main Page 12 | 13 | 14 | 15 | 16 |

qDecoder API Reference

17 | 18 | 25 | 26 |
27 |
28 |
qDecoder Documentation
29 |
30 |
31 |
32 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /qdecoder/doc/html/nav_f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/nav_f.png -------------------------------------------------------------------------------- /qdecoder/doc/html/nav_g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/nav_g.png -------------------------------------------------------------------------------- /qdecoder/doc/html/nav_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/nav_h.png -------------------------------------------------------------------------------- /qdecoder/doc/html/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/open.png -------------------------------------------------------------------------------- /qdecoder/doc/html/sync_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/sync_off.png -------------------------------------------------------------------------------- /qdecoder/doc/html/sync_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/sync_on.png -------------------------------------------------------------------------------- /qdecoder/doc/html/tab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/tab_a.png -------------------------------------------------------------------------------- /qdecoder/doc/html/tab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/tab_b.png -------------------------------------------------------------------------------- /qdecoder/doc/html/tab_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/tab_h.png -------------------------------------------------------------------------------- /qdecoder/doc/html/tab_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/doc/html/tab_s.png -------------------------------------------------------------------------------- /qdecoder/doc/html/tabs.css: -------------------------------------------------------------------------------- 1 | .tabs, .tabs2, .tabs3 { 2 | background-image: url('tab_b.png'); 3 | width: 100%; 4 | z-index: 101; 5 | font-size: 13px; 6 | font-family: 'Lucida Grande',Geneva,Helvetica,Arial,sans-serif; 7 | } 8 | 9 | .tabs2 { 10 | font-size: 10px; 11 | } 12 | .tabs3 { 13 | font-size: 9px; 14 | } 15 | 16 | .tablist { 17 | margin: 0; 18 | padding: 0; 19 | display: table; 20 | } 21 | 22 | .tablist li { 23 | float: left; 24 | display: table-cell; 25 | background-image: url('tab_b.png'); 26 | line-height: 36px; 27 | list-style: none; 28 | } 29 | 30 | .tablist a { 31 | display: block; 32 | padding: 0 20px; 33 | font-weight: bold; 34 | background-image:url('tab_s.png'); 35 | background-repeat:no-repeat; 36 | background-position:right; 37 | color: #283A5D; 38 | text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); 39 | text-decoration: none; 40 | outline: none; 41 | } 42 | 43 | .tabs3 .tablist a { 44 | padding: 0 10px; 45 | } 46 | 47 | .tablist a:hover { 48 | background-image: url('tab_h.png'); 49 | background-repeat:repeat-x; 50 | color: #fff; 51 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 52 | text-decoration: none; 53 | } 54 | 55 | .tablist li.current a { 56 | background-image: url('tab_a.png'); 57 | background-repeat:repeat-x; 58 | color: #fff; 59 | text-shadow: 0px 1px 1px rgba(0, 0, 0, 1.0); 60 | } 61 | -------------------------------------------------------------------------------- /qdecoder/examples/download.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * qDecoder - http://www.qdecoder.org 3 | * 4 | * Copyright (c) 2000-2012 Seungyoung Kim. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | ******************************************************************************/ 28 | 29 | #ifdef ENABLE_FASTCGI 30 | #include "fcgi_stdio.h" 31 | #else 32 | #include 33 | #endif 34 | #include 35 | #include 36 | #include "qdecoder.h" 37 | 38 | int main(void) 39 | { 40 | #ifdef ENABLE_FASTCGI 41 | while(FCGI_Accept() >= 0) { 42 | #endif 43 | qentry_t *req = qcgireq_parse(NULL, 0); 44 | qcgires_download(req, "download.c", "text/plain"); 45 | #ifdef ENABLE_FASTCGI 46 | } 47 | #endif 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /qdecoder/qlibc-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/qdecoder/qlibc-master.zip -------------------------------------------------------------------------------- /qdecoder/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libqdecoder 2 | # Copyright Robin.Rowe@cinepaint.org 2015/7/19 3 | # License MIT or BSD 4 | 5 | cmake_minimum_required(VERSION 2.8) 6 | project(CMake_qdecoder) 7 | 8 | #version number 9 | set(CMake_qdecoder_VERSION_MAJOR 1) 10 | set(CMake_qdecoder_VERSION_MINOR 0) 11 | set(CMake_qdecoder_VERSION_PATCH 0) 12 | 13 | file(GLOB qdecoder_SRC 14 | "*.h" 15 | "*.cpp" 16 | ) 17 | 18 | add_library( qdecoder STATIC ${qdecoder_SRC} ) 19 | 20 | -------------------------------------------------------------------------------- /qdecoder/src/doxygen_header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | $title 13 | 14 | 15 | 16 | 17 | 18 |

qDecoder API Reference

19 | -------------------------------------------------------------------------------- /qdecoder/src/doxygen_tailer.html: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /qdecoder/src/qdecoder.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: qDecoder 7 | Description: CGI library for C/C++ 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -lqdecoder 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /qdecoder/vcpp/libqdecoder.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libqdecoder", "libqdecoder.vcxproj", "{B20FDEF1-806F-4F82-9A0C-1D1DBFCBB773}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B20FDEF1-806F-4F82-9A0C-1D1DBFCBB773}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {B20FDEF1-806F-4F82-9A0C-1D1DBFCBB773}.Debug|Win32.Build.0 = Debug|Win32 16 | {B20FDEF1-806F-4F82-9A0C-1D1DBFCBB773}.Release|Win32.ActiveCfg = Release|Win32 17 | {B20FDEF1-806F-4F82-9A0C-1D1DBFCBB773}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /qdecoder/vcpp/libqdecoder.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /regex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/lmdb/CMakeLists.txt 2 | 3 | project(libregex) 4 | message("--- Building library ${PROJECT_NAME} ---") 5 | 6 | set(SOURCES 7 | regex.h 8 | regex.cpp 9 | ) 10 | 11 | add_library(${PROJECT_NAME} ${SOURCES}) 12 | 13 | -------------------------------------------------------------------------------- /sqlite/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/sqlite/CMakeLists.txt 2 | 3 | project(libsqlite) 4 | message("--- Building library ${PROJECT_NAME} ---") 5 | 6 | set(SOURCES 7 | source/sqlite3.h 8 | source/sqlite3ext.h 9 | source/sqlite3.c 10 | ) 11 | 12 | add_library(${PROJECT_NAME} STATIC ${SOURCES}) 13 | add_executable(sqlite ${SOURCES} source/shell.c) 14 | -------------------------------------------------------------------------------- /sqlite/libsqliteQt/libsqliteQt.pro: -------------------------------------------------------------------------------- 1 | 2 | TEMPLATE = lib 3 | 4 | TARGET = libsqlite 5 | VERSION = 1.0 6 | 7 | QT -= gui 8 | CONFIG += static c++11 console 9 | 10 | PWD_UP = $$dirname(PWD) 11 | INCLUDEPATH += $$PWD_UP 12 | HEADERS = $$PWD_UP/*.h 13 | SOURCES = $$PWD_UP/*.c $$PWD_UP/*.cpp 14 | 15 | DESTDIR = $$PWD_UP/lib 16 | 17 | -------------------------------------------------------------------------------- /sqlite/source/VERSION_3.25.3.txt: -------------------------------------------------------------------------------- 1 | https://www.sqlite.org/2018/sqlite-amalgamation-3250300.zip 2 | -------------------------------------------------------------------------------- /sqlite/vcpp/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | STATIC LIBRARY : libsqlite Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this libsqlite library project for you. 6 | 7 | No source files were created as part of your project. 8 | 9 | 10 | libsqlite.vcxproj 11 | This is the main project file for VC++ projects generated using an Application Wizard. 12 | It contains information about the version of Visual C++ that generated the file, and 13 | information about the platforms, configurations, and project features selected with the 14 | Application Wizard. 15 | 16 | libsqlite.vcxproj.filters 17 | This is the filters file for VC++ projects generated using an Application Wizard. 18 | It contains information about the association between the files in your project 19 | and the filters. This association is used in the IDE to show grouping of files with 20 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 21 | "Source Files" filter). 22 | 23 | ///////////////////////////////////////////////////////////////////////////// 24 | Other notes: 25 | 26 | AppWizard uses "TODO:" comments to indicate parts of the source code you 27 | should add to or customize. 28 | 29 | ///////////////////////////////////////////////////////////////////////////// 30 | -------------------------------------------------------------------------------- /sqlite/vcpp/libsqlite.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/CMakeList.txt 2 | 3 | if(WIN32) 4 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../unistd") 5 | link_libraries(libunistd) 6 | endif(WIN32) 7 | 8 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..") 9 | 10 | add_subdirectory(test_PosixQueue) 11 | add_subdirectory(test_unit) 12 | add_subdirectory(test_wormfile) 13 | add_subdirectory(test_scandir) 14 | add_subdirectory(test_lmdb) 15 | add_subdirectory(test_sqlite) 16 | add_subdirectory(test_mman) 17 | add_subdirectory(test_semaphore) 18 | add_subdirectory(test_logger) 19 | add_subdirectory(test_Pump) 20 | -------------------------------------------------------------------------------- /test/test_PosixQueue/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/test_PosixQueue/CMakeList.txt 2 | 3 | add_executable(test_mq_receive mq_receive/main.cpp) 4 | target_link_libraries(test_mq_receive libportable) 5 | 6 | add_executable(test_mq_send mq_send/main.cpp) 7 | target_link_libraries(test_mq_send libportable) -------------------------------------------------------------------------------- /test/test_PosixQueue/mq_receive/main.cpp: -------------------------------------------------------------------------------- 1 | // mq_receive.cpp 2 | // Copyright 2016 Robin.Rowe@Cinepaint.org 3 | // License open source MIT 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | const char* QUEUE_NAME="/test_queue"; 16 | const unsigned MAX_SIZE=1024; 17 | const char* MSG_STOP="quit"; 18 | 19 | int main() 20 | { char buffer[MAX_SIZE + 1]; 21 | bool isGo=true; 22 | mq_attr attr; 23 | attr.mq_flags = 0; 24 | attr.mq_maxmsg = 10; 25 | attr.mq_msgsize = MAX_SIZE; 26 | attr.mq_curmsgs = 0; 27 | cout << "opening message queue "<< QUEUE_NAME << endl; 28 | mqd_t mq = mq_open(QUEUE_NAME, O_CREAT | O_RDONLY, 0644, &attr); 29 | if(mq<0) 30 | { perror("mq_open"); 31 | return 1; 32 | } 33 | while(isGo) 34 | { ssize_t bytes_read = mq_receive(mq, buffer, MAX_SIZE, NULL); 35 | if(bytes_read < 0) 36 | { perror("mq_read"); 37 | return 2; 38 | } 39 | buffer[bytes_read-1] = 0; 40 | cout << "received: " << buffer << endl; 41 | if (!strcmp(buffer, MSG_STOP)) 42 | { isGo=false; 43 | } } 44 | mq_close(mq); 45 | mq_unlink(QUEUE_NAME); 46 | return 0; 47 | } -------------------------------------------------------------------------------- /test/test_PosixQueue/mq_send/main.cpp: -------------------------------------------------------------------------------- 1 | // mq_send.cpp 2 | // Copyright 2016 Robin.Rowe@Cinepaint.org 3 | // License open source MIT 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | const char* QUEUE_NAME="/test_queue"; 15 | const unsigned MAX_SIZE=1024; 16 | const char* MSG_STOP="quit"; 17 | 18 | int main() 19 | { char buffer[MAX_SIZE]; 20 | mqd_t mq = mq_open(QUEUE_NAME, O_WRONLY, 0644); 21 | if(mq<0) 22 | { perror("mq_open"); 23 | return 1; 24 | } 25 | buffer[0]=0; 26 | cout << "Send to server (enter \"quit\" to stop it):\n"; 27 | while(strncmp(buffer, MSG_STOP, strlen(MSG_STOP))) 28 | { cout<< "> "; 29 | cin.getline(buffer,MAX_SIZE); 30 | int ok = mq_send(mq, buffer, strlen(buffer)+1, 0); 31 | if(ok<0) 32 | { perror("mq_send"); 33 | return 2; 34 | } } 35 | mq_close(mq); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /test/test_Pump/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/Pump/CMakeList.txt 2 | 3 | add_executable(test_Pump test_Pump.cpp) 4 | target_link_libraries(test_Pump libportable) -------------------------------------------------------------------------------- /test/test_Pump/test_Pump.cpp: -------------------------------------------------------------------------------- 1 | // test_Pump.cpp 2 | // Created by Robin Rowe 2019-10-18 3 | // License MIT open source 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main(int argc,char* argv[]) 10 | { cout << "Testing Pump" << endl; 11 | portable::Pump pump("TestPump"); 12 | pump.StartJoin(); 13 | cout << "Shutdown main" << endl; 14 | return 0; 15 | } 16 | 17 | /* 18 | Testing Pump 19 | Trace: Pump hooked SIGINT (portable::Pump::Pump@25) 20 | SIGINT interrupt 21 | Shutdown TestPump 22 | Shutdown main 23 | */ -------------------------------------------------------------------------------- /test/test_lmdb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # lmdb/CMakeLists.txt 2 | 3 | set(NAME test_lmdb) 4 | set(INCDIR 5 | ${CMAKE_CURRENT_SOURCE_DIR}/../../lmdb/liblmdb 6 | ${CMAKE_CURRENT_SOURCE_DIR}/../.. 7 | ) 8 | #message("INCDIR = " ${INCDIR}) 9 | 10 | add_executable(test_lmdb_c sample-mdb.c) 11 | target_include_directories(test_lmdb_c PUBLIC ${INCDIR}) 12 | target_link_libraries(test_lmdb_c liblmdb) 13 | 14 | add_executable(${NAME} test-lmdb.cpp ProductData.h) 15 | target_include_directories(${NAME} PUBLIC ${INCDIR}) 16 | target_link_libraries(${NAME} liblmdb) -------------------------------------------------------------------------------- /test/test_lmdb/ProductData.h: -------------------------------------------------------------------------------- 1 | // ProductData.h 2 | // Created by Robin Rowe on 12/21/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // OpenLDAP Public License 5 | 6 | #ifndef ProductData_h 7 | #define ProductData_h 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | struct ProductData 16 | : public lmdb::Item 17 | { int id; 18 | std::string product; 19 | std::string description; 20 | std::string buffer; 21 | ProductData() 22 | : id(0) 23 | {} 24 | virtual void Set() override 25 | { key.ToMval(&id,sizeof(id)); 26 | buffer = product; 27 | buffer += delimiter; 28 | buffer += description; 29 | buffer += delimiter; 30 | value.ToMval(buffer); 31 | } 32 | virtual bool Retrieve() override 33 | { key.ResetOffset(); 34 | if(!key.FromMval(&id,sizeof(id))) 35 | { return false; 36 | } 37 | value.ResetOffset(); 38 | if(!value.FromMval(product,delimiter)) 39 | { return false; 40 | } 41 | if(!value.FromMval(description,delimiter)) 42 | { return false; 43 | } 44 | return true; 45 | } 46 | virtual std::ostream& Print(std::ostream& os) const override 47 | { return os << id << ", " << product << ", " << description; 48 | } 49 | }; 50 | //Buffer((void*) name.c_str(),name.size()+1); 51 | #endif -------------------------------------------------------------------------------- /test/test_lmdb/data.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/test/test_lmdb/data.mdb -------------------------------------------------------------------------------- /test/test_lmdb/lock.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/test/test_lmdb/lock.mdb -------------------------------------------------------------------------------- /test/test_lmdb/test-lmdb.cpp: -------------------------------------------------------------------------------- 1 | // test-lmdb.cpp 2 | // Created by Robin Rowe on 12/21/2015 3 | // Copyright (c) 2015 Robin.Rowe@CinePaint.org 4 | // OpenLDAP Public License 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "ProductData.h" 14 | using namespace std; 15 | 16 | enum STATUS 17 | { ok, 18 | open_failed, 19 | lock_failed, 20 | write_failed, 21 | cursor_failed 22 | }; 23 | 24 | int main(int argc,char * argv[]) 25 | { lmdb::LightningDb db; 26 | // const char* filename = "/Code/github/libunistd/build/test/lmdb/data.mdb"; 27 | const char* filename = "./test-lmdb"; 28 | #if 1 29 | db.Drop(filename); 30 | #endif 31 | if(!db.Open(filename,MDB_CREATE)) 32 | { return open_failed; 33 | } 34 | lmdb::Transaction tr(db); 35 | if(!tr) 36 | { return lock_failed; 37 | } 38 | { 39 | ProductData data; 40 | data.id = 41; 41 | data.product = "Widget"; 42 | data.description = "Generic"; 43 | cout << "Put: " << data << endl; 44 | if(!tr.Put(data)) 45 | { return write_failed; 46 | } 47 | data.id = 32; 48 | data.product = "Gadget"; 49 | data.description = "Special"; 50 | cout << "Put: " << data << endl; 51 | if(!tr.Put(data)) 52 | { return write_failed; 53 | } 54 | tr.Commit(); 55 | } 56 | { lmdb::Cursor cursor(db,tr,0); 57 | if(!cursor) 58 | { return cursor_failed; 59 | } 60 | ProductData data; 61 | bool ok = cursor.GetFirst(data); 62 | while(ok) 63 | { cout << "Cursor: " << data << endl; 64 | if(32==data.id) 65 | { cursor.Drop(); 66 | cout << "Dropped id #" << 32 << endl; 67 | } 68 | ok = cursor.Get(data); 69 | } } 70 | puts("Done"); 71 | db.Close(); 72 | return 0; 73 | } 74 | 75 | /* Output: 76 | 77 | LMDB: ok 78 | LMDB: drop db failed 79 | LMDB: Transaction ok 80 | LMDB: open 81 | LMDB: Transaction ok 82 | Put: 41, Widget, Generic 83 | LMDB: put ok 84 | Put: 32, Gadget, Special 85 | LMDB: put ok 86 | LMDB: Transaction ok 87 | LMDB: Cursor ok 88 | LMDB: Cursor get ok 89 | Cursor: 32, Gadget, Special 90 | LMDB: Cursor drop ok 91 | Dropped id #32 92 | LMDB: Cursor get ok 93 | Cursor: 41, Widget, Generic 94 | LMDB: Cursor get not found 95 | Done 96 | 97 | */ 98 | 99 | -------------------------------------------------------------------------------- /test/test_logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/test_logger/CMakeList.txt 2 | 3 | add_definitions(-DTRACE_MSG_FUNCTIONS) 4 | 5 | add_executable(test_logger main.cpp) 6 | 7 | -------------------------------------------------------------------------------- /test/test_logger/main.cpp: -------------------------------------------------------------------------------- 1 | // test/test_logger/main.cpp: 2 | // robin.rowe@cinepaint.org 2019/10/16 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | using namespace portable; 8 | 9 | #define P(name) cout << "** " << #name << " ** " 10 | 11 | int main() 12 | { 13 | #ifdef OLD_SYSLOG 14 | P(SysLogMsg); 15 | SysLogMsg("msg",__FUNCTION__); 16 | #ifdef TEST_DEBUG_BREAK 17 | P(SysLogError); 18 | SysLogError("msg","function"); 19 | #endif 20 | P(LogMsg); 21 | LogMsg("msg"); 22 | P(LogError); 23 | LogError("msg"); 24 | P(SYSLOG); 25 | SYSLOG("msg"); 26 | #ifdef TEST_DEBUG_BREAK 27 | P(SYSERR); 28 | SYSERR("msg"); 29 | #endif 30 | P(SystemLog); 31 | SystemLog(__FILE__,__LINE__,"msg"); 32 | P(StatusMsg); 33 | StatusMsg("msg"); 34 | #endif 35 | P(tty_msg); 36 | tty_msg("tag","msg"); 37 | P(status_msg); 38 | status_msg("msg"); 39 | P(warning_msg); 40 | warning_msg("msg"); 41 | P(trace_msg); 42 | trace_msg("msg"); 43 | P(error_msg); 44 | error_msg("msg"); 45 | P(return_msg); 46 | enum { RETURN_NAME }; 47 | return_msg(RETURN_NAME); 48 | return 0; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /test/test_mman/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/test_mman/CMakeList.txt 2 | 3 | add_executable(test_mman_server mman_server.cpp) 4 | add_executable(test_mman_client mman_client.cpp) 5 | -------------------------------------------------------------------------------- /test/test_mman/mman_client.cpp: -------------------------------------------------------------------------------- 1 | // mman_client.cpp 2 | // 2018/10/28 Robin.Rowe@CinePaint.org 3 | // Inspired by http://users.cs.cf.ac.uk/Dave.Marshall/C/node27.html 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "../../unistd/more/shm_more.h" 15 | 16 | int main(int argc, char **argv) 17 | { int oflags=O_RDWR; 18 | const char *name = "/mmanjunk"; 19 | int fd = shm_open(name, oflags, 0644 ); 20 | printf("Shared Mem Descriptor: fd=%d\n", fd); 21 | assert (fd>0); 22 | size_t length = shm_size(fd); 23 | char* p = (char *) mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 24 | printf("Shared Mem Address: %p [0..%zu]\n", p, length-1); 25 | assert (p); 26 | printf("%s",p); 27 | // change 1st byte 28 | p[0] = 'H' ; 29 | printf("%s",p); 30 | shm_flush(fd); 31 | shm_close(fd); 32 | return 0; 33 | } 34 | 35 | /* Shared Mem Descriptor: fd=1 36 | Shared Mem Address: 0000021930530000 [0..2047] 37 | hello world!! 38 | Hello world!! 39 | */ -------------------------------------------------------------------------------- /test/test_mman/mman_server.cpp: -------------------------------------------------------------------------------- 1 | // mman_server.cpp 2 | // 2018/10/28 Robin.Rowe@CinePaint.org 3 | // Inspired by http://users.cs.cf.ac.uk/Dave.Marshall/C/node27.html 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "../../unistd/more/shm_more.h" 14 | 15 | int main(int argc, char **argv) 16 | { int oflags=O_RDWR; 17 | oflags = O_RDWR | O_CREAT; 18 | off_t length = 2 * 1024; 19 | const char *name = "/mmanjunk"; 20 | int fd = shm_open(name, oflags, 0644 ); 21 | shm_ftruncate(fd, length); 22 | fprintf(stderr,"Shared Mem Descriptor: fd=%d\n", fd); 23 | assert (fd>0); 24 | u_char *ptr = (u_char *) mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 25 | fprintf(stderr, "Shared Memory Address: %p [0..%lu]\n", ptr, length-1); 26 | fprintf(stderr, "Shared Memory Path: /dev/shm/%s\n", name ); 27 | assert (ptr); 28 | const char *msg = "hello world!!\n"; 29 | #pragma warning(disable : 4996) 30 | strcpy((char*)ptr,msg); 31 | #pragma warning(default : 4996) 32 | shm_close(fd); 33 | return 0; 34 | } 35 | 36 | /* 37 | Shared Mem Descriptor: fd=1 38 | Shared Memory Address: 000002DD34910000 [0..2047] 39 | Shared Memory Path: /dev/shm//mmanjunk 40 | 41 | */ -------------------------------------------------------------------------------- /test/test_scandir/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # test_scandir/CMakeLists.txt 2 | 3 | add_executable(test_scandir scandir.cpp) 4 | add_executable(test_opendir opendir.cpp) 5 | #get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME) 6 | -------------------------------------------------------------------------------- /test/test_scandir/opendir.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { const char* path ="./*"; 6 | DIR* dir = opendir(path); 7 | if(!dir) 8 | { printf("ERROR: opendir"); 9 | return 1; 10 | } 11 | struct dirent* entry = 0; 12 | while(entry = readdir(dir)) 13 | { if (!entry) 14 | { printf("ERROR: readdir"); 15 | return 2; 16 | } 17 | printf("Filename: %s\t\t Location in Directory Stream: %ld\n", 18 | entry->d_name,telldir(dir)); 19 | } 20 | closedir(dir); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /test/test_scandir/scandir.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { const char* path ="./*"; 7 | struct dirent **namelist; 8 | int n = scandir(path, &namelist, NULL, alphasort); 9 | if (n < 0) 10 | { perror("scandir"); 11 | return 1; 12 | } 13 | for(int i=0;id_name); 15 | free(namelist[i]); 16 | } 17 | free(namelist); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /test/test_semaphore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/test_semaphore/CMakeList.txt 2 | 3 | add_executable(test_semaphore_server semaphore_server.cpp) 4 | add_executable(test_semaphore_client semaphore_client.cpp) 5 | -------------------------------------------------------------------------------- /test/test_semaphore/semaphore_client.cpp: -------------------------------------------------------------------------------- 1 | //sem_client.c 2 | // Inspired by https://gist.github.com/aspyct/3118858 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char *argv[]) 11 | { key_t sem_key = 1234; 12 | int sem_id = semget(sem_key, 0, 0); 13 | if(sem_id < 0) 14 | { perror("Could not obtain semaphore"); 15 | return 1; 16 | } 17 | sembuf sop; 18 | for(int i = 0; i < 5; ++i) 19 | { sop.sem_num = 0; 20 | sop.sem_op = -1; 21 | sop.sem_flg = SEM_UNDO; 22 | printf("Client #%d waiting\n", getpid()); 23 | semop(sem_id, &sop, 1); 24 | printf("Client #%d acquired. Sleeping\n", getpid()); 25 | sleep(1); 26 | printf("Client #%d releasing\n", getpid()); 27 | sop.sem_op = 1; 28 | semop(sem_id, &sop, 1); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /test/test_semaphore/semaphore_server.cpp: -------------------------------------------------------------------------------- 1 | // sem_server.c 2 | // Inspired by https://gist.github.com/aspyct/3118858 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | int main(int argc, char *argv[]) 16 | { sembuf sop; 17 | key_t sem_key = 1234; //ftok("./sem_server.c", 42); 18 | // Create the semaphore 19 | int sem_id = semget(sem_key, 1, IPC_CREAT | IPC_EXCL | 0600); 20 | if(semctl(sem_id, 0, SETVAL, 0) < 0) 21 | { perror("Could not set value of semaphore"); 22 | return 1; 23 | } 24 | puts("Now create some clients"); 25 | sleep(5); 26 | printf("Increasing sem count\n"); 27 | sop.sem_num = 0; 28 | sop.sem_op = 1; 29 | sop.sem_flg = 0; 30 | if(semop(sem_id, &sop, 1)) 31 | { perror("Could not increment semaphore"); 32 | return 2; 33 | } 34 | sleep(30); 35 | if(semctl(sem_id, 0, IPC_RMID) < 0) 36 | { perror("Could not delete semaphore"); 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /test/test_shm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/test_shm/CMakeList.txt 2 | 3 | add_executable(test_shm_server shm_server.cpp) 4 | target_link_libraries(test_shm_server libunistd) 5 | add_executable(test_shm_client shm_server.cpp) 6 | target_link_libraries(test_shm_client libunistd) -------------------------------------------------------------------------------- /test/test_shm/shm_client.cpp: -------------------------------------------------------------------------------- 1 | shm_client.c 2 | /* 3 | * shm-client - client program to demonstrate shared memory. 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define SHMSZ 27 11 | 12 | main() 13 | { 14 | int shmid; 15 | key_t key; 16 | char *shm, *s; 17 | 18 | /* 19 | * We need to get the segment named 20 | * "5678", created by the server. 21 | */ 22 | key = 5678; 23 | 24 | /* 25 | * Locate the segment. 26 | */ 27 | if ((shmid = shmget(key, SHMSZ, 0666)) < 0) { 28 | perror("shmget"); 29 | exit(1); 30 | } 31 | 32 | /* 33 | * Now we attach the segment to our data space. 34 | */ 35 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { 36 | perror("shmat"); 37 | exit(1); 38 | } 39 | 40 | /* 41 | * Now read what the server put in the memory. 42 | */ 43 | for (s = shm; *s != NULL; s++) 44 | putchar(*s); 45 | putchar('\n'); 46 | 47 | /* 48 | * Finally, change the first character of the 49 | * segment to '*', indicating we have read 50 | * the segment. 51 | */ 52 | *shm = '*'; 53 | 54 | exit(0); 55 | } 56 | -------------------------------------------------------------------------------- /test/test_shm/shm_server.cpp: -------------------------------------------------------------------------------- 1 | // shm_server.cpp 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define SHMSZ 27 8 | 9 | main() 10 | { 11 | char c; 12 | int shmid; 13 | key_t key; 14 | char *shm, *s; 15 | 16 | /* 17 | * We'll name our shared memory segment 18 | * "5678". 19 | */ 20 | key = 5678; 21 | 22 | /* 23 | * Create the segment. 24 | */ 25 | if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { 26 | perror("shmget"); 27 | exit(1); 28 | } 29 | 30 | /* 31 | * Now we attach the segment to our data space. 32 | */ 33 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { 34 | perror("shmat"); 35 | exit(1); 36 | } 37 | 38 | /* 39 | * Now put some things into the memory for the 40 | * other process to read. 41 | */ 42 | s = shm; 43 | 44 | for (c = 'a'; c <= 'z'; c++) 45 | *s++ = c; 46 | *s = NULL; 47 | 48 | /* 49 | * Finally, we wait until the other process 50 | * changes the first character of our memory 51 | * to '*', indicating that it has read what 52 | * we put there. 53 | */ 54 | while (*shm != '*') 55 | sleep(1); 56 | 57 | exit(0); 58 | } 59 | -------------------------------------------------------------------------------- /test/test_sqlite/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/test_sqlite/CMakeList.txt 2 | 3 | include_directories("..") 4 | add_executable(test_sqlite main.cpp) 5 | link_directories(${LIBSQLITE_LIB_DIRS}/sqlite) 6 | target_link_libraries(test_sqlite libsqlite) 7 | -------------------------------------------------------------------------------- /test/test_tcp/tcp_server.cpp: -------------------------------------------------------------------------------- 1 | // tcp_server.cpp 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | int main() 13 | { const int networkPort = 8000; 14 | cout << "Starting server on port " << networkPort << endl; 15 | std::unique_ptr packetServer = make_unique("1.0"); 16 | const bool ok = packetServer->Start(networkPort, max_streams); 17 | 18 | 19 | portable::PacketWriter& packet(packetServer->headerPacket); 20 | portable::SoftLock softlock(packet.ownership); 21 | if (!softlock) 22 | { 23 | cout << "ERROR: Couldn't lock header packet" << endl; 24 | return; 25 | } 26 | const unsigned packetId = 0; 27 | packet << packetId; 28 | 29 | portable::PacketWriter& packet = packetServer->framePacket.GetDirty(); 30 | -------------------------------------------------------------------------------- /test/test_unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/test_unit/CMakeList.txt 2 | 3 | add_executable(test_unit main.cpp) 4 | 5 | -------------------------------------------------------------------------------- /test/test_unit/main.cpp: -------------------------------------------------------------------------------- 1 | // test/UnitTest/main.cpp: 2 | // robin.rowe@cinepaint.org 2017/3/31 3 | 4 | //#include 5 | //#include 6 | //#include 7 | //#include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | 50 | int main() 51 | { return 0; 52 | } -------------------------------------------------------------------------------- /test/test_wormfile/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/test/WormFile/CMakeList.txt 2 | 3 | add_executable(test_WormFile main.cpp) 4 | target_link_libraries(test_WormFile libportable) -------------------------------------------------------------------------------- /test/test_wormfile/main.cpp: -------------------------------------------------------------------------------- 1 | // WormFile test main 2 | // Robin Rowe 2017/3/21 3 | 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int main() 10 | { portable::WormFile wormFile; 11 | const char* filename = "test.wrm"; 12 | if(!wormFile.Open(filename)) 13 | { cout << "Can't open "< buffer(length); 33 | if(!wormFile.Read(&buffer[0],length)) 34 | { cout << "Can't read "<< filename << endl; 35 | return 5; 36 | } 37 | if(strcmp(data,&buffer[0])) 38 | { cout <<"Blob data mismatch" << endl; 39 | return 6; 40 | } 41 | cout << "SUCCESS!" << endl; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /unistd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/unistd/CMakeLists.txt 2 | # Copyright 2016 Robin.Rowe@cinepaint.org 3 | # License MIT open source 4 | 5 | if(_M_X64) 6 | enable_language(ASM_MASM) 7 | set(INT128_SRC Int128x64.asm) 8 | else(_M_X64) 9 | set(INT128_SRC int128/Int128x86.cpp) 10 | endif(_M_X64) 11 | 12 | file(STRINGS sources.cmake SOURCES) 13 | add_library(libunistd 14 | ${SOURCES} 15 | int128/Int128.h 16 | ${INT128_SRC} 17 | ) 18 | 19 | target_include_directories(libunistd PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 20 | target_link_libraries(libunistd LINK_PUBLIC shlwapi) 21 | target_link_libraries(libunistd LINK_PUBLIC libportable) 22 | -------------------------------------------------------------------------------- /unistd/arpa/inet.h: -------------------------------------------------------------------------------- 1 | // arpa/inet.h 2 | // Copyright 2016 Robin.Rowe\@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef arpa_inet_h 6 | #define arpa_inet_h 7 | 8 | #include "../unistd.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #else 13 | #define inline __inline 14 | #endif 15 | 16 | typedef unsigned in_addr_t; 17 | 18 | inline 19 | in_addr_t uni_inet_addr(const char* ip) 20 | { in_addr_t out; 21 | if(inet_pton(AF_INET,ip,&out)<=0) 22 | { return INADDR_NONE; 23 | } 24 | return out; 25 | } 26 | 27 | #define inet_addr uni_inet_addr 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /unistd/arpa/nameser.h: -------------------------------------------------------------------------------- 1 | // arpa/nameser.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef arpa_nameser_h 6 | #define arpa_nameser_h 7 | 8 | #include 9 | 10 | #define HFIXEDSZ 12 11 | 12 | #define NS_IN6ADDRSZ 16 13 | #define NS_INADDRSZ 4 14 | #define NS_INT16SZ 2 15 | #define NS_MAXDNAME 1025 16 | 17 | #define T_A 1 18 | #define T_PTR 12 19 | #define T_TXT 16 20 | #define T_AAAA 28 21 | 22 | #define ns_o_query 0 23 | 24 | #define ns_r_noerror 0 25 | #define ns_r_formerr 1 26 | #define ns_r_servfail 2 27 | #define ns_r_nxdomain 3 28 | #define ns_r_notimpl 4 29 | #define ns_r_refused 5 30 | 31 | typedef void ns_rr; 32 | 33 | #define ns_rr_type(rr) 0 34 | #define ns_rr_ttl(rr) 0 35 | #define ns_rr_rdlen(rr) 0 36 | #define ns_rr_rdata(rr) 0 37 | 38 | typedef void ns_msg; 39 | 40 | #define ns_msg_id(handle) 0 41 | #define ns_msg_count(handle, section) 0 42 | #define ns_msg_getflag(handle, flag) 0 43 | 44 | typedef struct 45 | { int id; 46 | } HEADER; 47 | 48 | #define ns_initparse(a, b, c) (-1) 49 | #define ns_parserr(a, b, c, d) (-1) 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /unistd/cfunc.h: -------------------------------------------------------------------------------- 1 | // cfunc.h 2 | // Copyright 2022 CinePaint MIT Open Source 3 | // 15 July 2022 Robin.Rowe@CinePaint.org 4 | 5 | #ifndef cfunc_h 6 | #define cfunc_h 7 | 8 | #ifdef __cplusplus 9 | #define CFUNC extern "C" 10 | #else 11 | #define CFUNC extern 12 | #ifndef inline 13 | #define inline __inline 14 | #endif 15 | #endif 16 | 17 | #endif -------------------------------------------------------------------------------- /unistd/clock_gettime.h: -------------------------------------------------------------------------------- 1 | // clock_gettime.h 2 | // Copyright 2022 CinePaint MIT Open Source 3 | // 13 July 2022 Robin.Rowe@CinePaint.org 4 | 5 | #ifndef clock_gettime_h 6 | #define clock_gettime_h 7 | 8 | #include "cfunc.h" 9 | 10 | typedef int clockid_t; 11 | typedef long long useconds_t; 12 | 13 | enum 14 | { CLOCK_REALTIME, 15 | CLOCK_MONOTONIC, 16 | CLOCK_PROCESS_CPUTIME_ID, 17 | CLOCK_THREAD_CPUTIME_ID 18 | }; 19 | 20 | CFUNC int clock_getres(clockid_t clk_id, struct timespec *res); 21 | CFUNC int clock_gettime(clockid_t clk_id, struct timespec *tp); 22 | CFUNC int clock_settime(clockid_t clk_id, const struct timespec *tp); 23 | CFUNC int sleep(useconds_t delay); 24 | CFUNC int usleep(useconds_t delay); 25 | CFUNC int nanosleep(const struct timespec *req, struct timespec *rem); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /unistd/dirent.h: -------------------------------------------------------------------------------- 1 | // dirent.h 2 | // Created by Robin Rowe on 2016/8/30 3 | // Copyright (c) 2016 Robin.Rowe@CinePaint.org 4 | // License open source MIT 5 | 6 | #ifndef dirent_h 7 | #define dirent_h 8 | 9 | #include 10 | #include 11 | #include "unistd.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | enum 18 | { DT_BLK, // This is a block device. 19 | DT_CHR, // This is a character device. 20 | DT_DIR, // This is a directory. 21 | DT_FIFO, // This is a named pipe (FIFO). 22 | DT_LNK, // This is a symbolic link. 23 | DT_REG, // This is a regular file. 24 | DT_SOCK, // This is a UNIX domain socket. 25 | DT_UNKNOWN // The file type could not be determined. 26 | }; 27 | 28 | typedef struct dirent 29 | { long d_ino; 30 | unsigned short d_reclen; 31 | unsigned short d_namlen; 32 | unsigned char d_type; 33 | char* d_name; 34 | } dirent; 35 | 36 | typedef ptrdiff_t handle_type; /* C99's intptr_t not sufficiently portable */ 37 | 38 | struct DIR 39 | { 40 | #ifdef GLIB_STYLE 41 | handle_type handle; /* -1 for failed rewind */ 42 | struct _finddata_t info; 43 | struct dirent result; /* d_name null iff first time */ 44 | char *name; /* null-terminated char string */ 45 | #else 46 | int dummy; 47 | #endif 48 | }; 49 | 50 | typedef int scandir_f(const struct dirent* d); 51 | typedef int scandir_alphasort(const struct dirent** a,const struct dirent** b); 52 | int alphasort(const struct dirent** a,const struct dirent** b); 53 | int versionsort(const struct dirent** a,const struct dirent** b); 54 | 55 | typedef struct DIR DIR; 56 | struct DIR* opendir(const char* path); 57 | struct dirent* readdir(struct DIR* dir); 58 | int readdir_r(struct DIR* dir,struct dirent* entry, struct dirent** result); 59 | int closedir(struct DIR* dir); 60 | void rewinddir(struct DIR* dir); 61 | long telldir(struct DIR* dir); 62 | void seekdir(struct DIR* dir,long tell); 63 | int scandir(const char* buf,struct dirent*** namelist,scandir_f sf,scandir_alphasort af); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /unistd/dlfcn.h: -------------------------------------------------------------------------------- 1 | // dlfcn.h 9/20/04 2 | // Copyright 2004 Robin.Rowe@MovieEditor.com 3 | // License OSI MIT 4 | 5 | #ifndef DLFCN_H 6 | #define DLFCN_H 7 | 8 | #include "unistd.h" 9 | 10 | #if 0 11 | #define dlopen(mLibName,unused) LoadLibrary(mLibName) 12 | #define dlsym(mHandle,funcname) GetProcAddress((HMODULE)(mHandle),funcname) 13 | #define dlclose(mHandle) FreeLibrary((HMODULE)(mHandle)) 14 | inline 15 | char* dlerror() 16 | { return 0; 17 | } 18 | #endif 19 | 20 | enum 21 | { RTLD_LAZY, 22 | RTLD_NOW, 23 | RTLD_GLOBAL, 24 | RTLD_LOCAL, 25 | RTLD_NODELETE, 26 | RTLD_NOLOAD, 27 | RTLD_DEEPBIND 28 | }; 29 | 30 | inline 31 | void* dlopen(const char* filename, int flag) 32 | { return LoadLibraryA(filename); 33 | } 34 | 35 | inline 36 | const char* dlerror(void) 37 | { enum { len = 60 }; 38 | static char msg[len]; 39 | msg[0] = 0; 40 | const int wsaError = GetLastError(); 41 | const DWORD num = FormatMessageA( 42 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 43 | NULL, 44 | wsaError, 45 | 0,//MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 46 | (LPSTR)&msg, 47 | len - 1, 48 | NULL); 49 | msg[len - 1] = 0; 50 | return msg; 51 | } 52 | 53 | inline 54 | void* dlsym(void* handle, const char* function) 55 | { return GetProcAddress((HMODULE) handle, function); 56 | } 57 | 58 | inline 59 | int dlclose(void* handle) 60 | { const int success = 0; 61 | const int fail = -1; 62 | if(!FreeLibrary((HMODULE)(handle))) 63 | { return fail; 64 | } 65 | return success; 66 | } 67 | 68 | #endif 69 | 70 | 71 | -------------------------------------------------------------------------------- /unistd/endian.h: -------------------------------------------------------------------------------- 1 | // endian.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef endian_h 6 | #define endian_h 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #else 14 | #define inline __inline 15 | #endif 16 | 17 | inline 18 | uint16_t htobe16(uint16_t host_16bits) 19 | { return _byteswap_ushort(host_16bits); 20 | } 21 | 22 | inline 23 | uint16_t htole16(uint16_t host_16bits) 24 | { return host_16bits; 25 | } 26 | 27 | inline 28 | uint16_t be16toh(uint16_t big_endian_16bits) 29 | { return _byteswap_ushort(big_endian_16bits); 30 | } 31 | 32 | inline 33 | uint16_t le16toh(uint16_t little_endian_16bits) 34 | { return little_endian_16bits; 35 | } 36 | 37 | inline 38 | uint32_t htobe32(uint32_t host_32bits) 39 | { return _byteswap_ulong(host_32bits); 40 | } 41 | 42 | inline 43 | uint32_t htole32(uint32_t host_32bits) 44 | { return host_32bits; 45 | } 46 | 47 | inline 48 | uint32_t be32toh(uint32_t big_endian_32bits) 49 | { return _byteswap_ulong(big_endian_32bits); 50 | } 51 | 52 | inline 53 | uint32_t le32toh(uint32_t little_endian_32bits) 54 | { return little_endian_32bits; 55 | } 56 | 57 | inline 58 | uint64_t htobe64(uint64_t host_64bits) 59 | { return _byteswap_uint64(host_64bits); 60 | } 61 | 62 | inline 63 | uint64_t htole64(uint64_t host_64bits) 64 | { return host_64bits; 65 | } 66 | 67 | inline 68 | uint64_t be64toh(uint64_t big_endian_64bits) 69 | { return _byteswap_uint64(big_endian_64bits); 70 | } 71 | 72 | inline 73 | uint64_t le64toh(uint64_t little_endian_64bits) 74 | { return little_endian_64bits; 75 | } 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /unistd/fnmatch.cpp: -------------------------------------------------------------------------------- 1 | // fnmatch.cpp 2 | // Copyright (c) 2022/10/19 Tomer Lev 3 | // License open source MIT 4 | 5 | #include 6 | #include "fnmatch.h" 7 | 8 | int fnmatch(const char *pattern, const char *string, int flags) 9 | { BOOL match = PathMatchSpecA(string, pattern); // flags are not supported in Windows 10 | return match ? 0 : FNM_NOMATCH; 11 | } 12 | -------------------------------------------------------------------------------- /unistd/fnmatch.h: -------------------------------------------------------------------------------- 1 | #ifndef fnmatch_h 2 | #define fnmatch_h 3 | 4 | #include "cfunc.h" 5 | 6 | #define FNM_NOMATCH 1 7 | 8 | CFUNC int fnmatch(const char *pattern, const char *string, int flags); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /unistd/fts.c: -------------------------------------------------------------------------------- 1 | // fts.c 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #include "fts.h" 6 | #include 7 | 8 | #include "stub.h" 9 | 10 | FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **)) 11 | { STUB_0(fts_open); 12 | } 13 | 14 | FTSENT *fts_read(FTS *ftsp) 15 | { STUB_0(fts_read); 16 | } 17 | 18 | int fts_close(FTS *ftsp) 19 | { STUB_NEG(fts_close); 20 | } 21 | -------------------------------------------------------------------------------- /unistd/fts.h: -------------------------------------------------------------------------------- 1 | // fts.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef fts_h 6 | #define fts_h 7 | 8 | #include "cfunc.h" 9 | 10 | #define FTS_F 0 11 | #define FTS_NOCHDIR 0 12 | 13 | typedef struct 14 | { int unused; 15 | } FTS; 16 | 17 | typedef struct 18 | { unsigned short fts_info; 19 | char * fts_path; 20 | } FTSENT; 21 | 22 | CFUNC FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **)); 23 | CFUNC FTSENT *fts_read(FTS *ftsp); 24 | CFUNC int fts_close(FTS *ftsp); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /unistd/ftw.h: -------------------------------------------------------------------------------- 1 | // ftw.h 2 | // Copyright 2022 CinePaint MIT Open Source 3 | // 13 July 2022 4 | 5 | #ifndef ftw_h 6 | #define ftw_h 7 | 8 | #include 9 | #include "stub.h" 10 | 11 | inline 12 | int nftw(const char *dirpath, 13 | int (*fn)(const char *fpath, 14 | const struct stat *sb, 15 | int typeflag, struct FTW *ftwbuf), 16 | int nopenfd, int flags) 17 | { STUB_NEG(nftw); 18 | } 19 | 20 | inline 21 | int ftw(const char *dirpath, 22 | int (*fn)(const char *fpath, 23 | const struct stat *sb, 24 | int typeflag), 25 | int nopenfd) 26 | { STUB_NEG(ftw); 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /unistd/getline.cpp: -------------------------------------------------------------------------------- 1 | // getline.c 2 | // Created by Robin Rowe 2024-10-05 3 | // Open Source MIT 4 | 5 | #include 6 | #include 7 | #include "unistd.h" 8 | 9 | #define BUFSIZE 256 10 | 11 | ssize_t getline(char** buf, size_t* bufsiz, FILE* fp) 12 | { return getdelim(buf, bufsiz, '\n', fp); 13 | } 14 | 15 | ssize_t getdelim(char** buf, size_t* bufsiz, int delimiter, FILE* fp) 16 | { if (!*buf || !*bufsiz ) 17 | { *bufsiz = BUFSIZE; 18 | *buf = (char*) malloc(*bufsiz); 19 | if(!buf) 20 | { return -1; 21 | } } 22 | char* ptr = *buf; 23 | char* eptr = *buf + *bufsiz; 24 | for(;;) 25 | { const int c = fgetc(fp); 26 | if (c == -1) 27 | { if (feof(fp)) 28 | { return ptr == *buf ? -1 : ptr - *buf; 29 | } 30 | return -1; 31 | } 32 | *ptr++ = c; 33 | if (c == delimiter) 34 | { *ptr = '\0'; 35 | return ptr - *buf; 36 | } 37 | if (ptr + 2 >= eptr) 38 | { char* nbuf; 39 | size_t nbufsiz = *bufsiz * 2; 40 | ssize_t d = ptr - *buf; 41 | nbuf = (char*) realloc(*buf, nbufsiz); 42 | if (!nbuf) 43 | { return -1; 44 | } 45 | *buf = nbuf; 46 | *bufsiz = nbufsiz; 47 | eptr = nbuf + nbufsiz; 48 | ptr = nbuf + d; 49 | } 50 | } 51 | return -1; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /unistd/getopt.h: -------------------------------------------------------------------------------- 1 | // getopt.h 2 | // Copyright 2022 CinePaint MIT Open Source 3 | // 13 July 2022 4 | 5 | #ifndef getopt_h 6 | #define getopt_h 7 | 8 | #include "cfunc.h" 9 | 10 | CFUNC int getopt(int argc, char *const argv[], 11 | const char *optstring); 12 | 13 | CFUNC const char *optarg; 14 | CFUNC int optind, opterr, optopt; 15 | enum getopt_argument_requirement { no_argument = 0, required_argument = 1, optional_argument = 2 }; 16 | 17 | struct option { 18 | const char *name; 19 | int has_arg; 20 | int *flag; 21 | int val; 22 | }; 23 | 24 | CFUNC int getopt_long(int argc, char *const argv[], 25 | const char *optstring, 26 | const struct option *longopts, int *longindex); 27 | 28 | CFUNC int getopt_long_only(int argc, char *const argv[], 29 | const char *optstring, 30 | const struct option *longopts, int *longindex); 31 | 32 | #endif -------------------------------------------------------------------------------- /unistd/gettimeofday.cpp: -------------------------------------------------------------------------------- 1 | // gettimeofday.cpp 2 | // Copyright 2016/06/20 robin.rowe@cinepaint.org 3 | // License open source MIT 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | extern "C" char* strptime(const char* s,const char* f,struct tm* tm) 12 | { // std::get_time is defined such that its format parameters are the exact same as strptime 13 | std::istringstream input(s); 14 | input.imbue(std::locale(setlocale(LC_ALL, nullptr))); 15 | input >> std::get_time(tm, f); 16 | if (input.fail()) { 17 | return nullptr; 18 | } 19 | s += (intptr_t) input.tellg(); 20 | return (char*)(s); 21 | } 22 | 23 | extern "C" int gettimeofday(struct timeval* tv, struct timezone* tz) 24 | { (void)tz; 25 | FILETIME ft; 26 | ULARGE_INTEGER t; 27 | ULONGLONG x; 28 | ULONGLONG m=1000000; 29 | GetSystemTimeAsFileTime(&ft); 30 | t.LowPart=ft.dwLowDateTime; 31 | t.HighPart=ft.dwHighDateTime; 32 | x=t.QuadPart/m; 33 | tv->tv_sec=(long) x; 34 | x=t.QuadPart%m; 35 | tv->tv_usec=(long) x; 36 | return 0; 37 | } 38 | 39 | int settimeofday(const struct timeval *tv, const struct timezone *tz) 40 | { (void)tv; 41 | (void)tz; 42 | STUB_NEG(settimeofday); 43 | } 44 | 45 | #if 0 46 | #include 47 | 48 | int gettimeofday(struct timeval* tp, struct timezone* tzp) 49 | { namespace sc = std::chrono; 50 | sc::system_clock::duration d = sc::system_clock::now().time_since_epoch(); 51 | sc::seconds s = sc::duration_cast(d); 52 | tp->tv_sec = s.count(); 53 | tp->tv_usec = sc::duration_cast(d - s).count(); 54 | return 0; 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /unistd/gettimeofday.h: -------------------------------------------------------------------------------- 1 | // gettimeofday.h: Windows emulation of common time functions 2 | // Libunistd Copyright Nov 10, 2002, Robin.Rowe@CinePaint.org 3 | // License MIT (http://opensource.org/licenses/mit-license.php) 4 | 5 | #ifndef gettimeofday_h 6 | #define gettimeofday_h 7 | 8 | #include "stub.h" 9 | #include "cfunc.h" 10 | 11 | CFUNC int gettimeofday(struct timeval* tv, struct timezone* tz); 12 | CFUNC int settimeofday(const struct timeval *tv, const struct timezone *tz); 13 | 14 | #endif -------------------------------------------------------------------------------- /unistd/glob.h: -------------------------------------------------------------------------------- 1 | // glob.h 2 | // Copyright 2021 Robin.Rowe@cinepaint.org 3 | // License MIT open source 4 | 5 | #ifndef glob_h 6 | #define glob_h 7 | 8 | //#include "unistd.h" 9 | #include "stub.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #else 14 | #define inline __inline 15 | #endif 16 | 17 | enum 18 | { GLOB_ERR, 19 | GLOB_MARK, 20 | GLOB_NOSORT, 21 | GLOB_DOOFFS, 22 | GLOB_NOCHECK, 23 | GLOB_APPEND, 24 | GLOB_NOESCAPE 25 | }; 26 | 27 | typedef struct 28 | { size_t gl_pathc; /* Count of paths matched so far */ 29 | char** gl_pathv; /* List of matched pathnames. */ 30 | size_t gl_offs; /* Slots to reserve in gl_pathv. */ 31 | } glob_t; 32 | 33 | inline 34 | int glob(const char* restrict pattern, int flags, 35 | int (*errfunc)(const char* epath, int eerrno), 36 | glob_t* restrict pglob) 37 | { STUB_NEG(glob); 38 | } 39 | 40 | inline 41 | void globfree(glob_t* pglob) 42 | { STUB(globfree); 43 | } 44 | 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /unistd/grp.h: -------------------------------------------------------------------------------- 1 | // rsr 2018/3/25 2 | 3 | #ifndef GRP_H 4 | #define GRP_H 5 | 6 | #include "stub.h" 7 | 8 | struct group { 9 | char *gr_name; /* group name */ 10 | char *gr_passwd; /* group password */ 11 | gid_t gr_gid; /* group ID */ 12 | char **gr_mem; /* group members */ 13 | }; 14 | 15 | inline 16 | struct group *getgrnam(const char *name) 17 | { (void) name; 18 | STUB_0(getgrnam); 19 | } 20 | 21 | inline 22 | struct group *getgrgid(gid_t gid) 23 | { (void) gid; 24 | STUB_0(getgrgid); 25 | } 26 | 27 | inline 28 | int getgrnam_r(const char *name, struct group *grp,char *buf, size_t buflen, struct group **result) 29 | { (void)name; 30 | (void)grp; 31 | (void)buf; 32 | (void)buflen; 33 | (void)result; 34 | STUB_NEG(getgrnam_r); 35 | } 36 | 37 | inline 38 | int getgrgid_r(gid_t gid, struct group *grp,char *buf, size_t buflen, struct group **result) 39 | { (void)gid; 40 | (void)grp; 41 | (void)buf; 42 | (void)buflen; 43 | (void)result; 44 | STUB_NEG(getgrgid_r); 45 | } 46 | 47 | inline 48 | int initgroups(const char *user, gid_t group) 49 | { (void)user; 50 | (void)group; 51 | STUB_NEG(initgroups); 52 | } 53 | 54 | inline 55 | struct group *getgrent() 56 | { STUB_0(getgrent); 57 | } 58 | 59 | inline 60 | void setgrent() 61 | { STUB(setgrent); 62 | } 63 | 64 | inline 65 | void endgrent() 66 | { STUB(endgrent); 67 | } 68 | 69 | inline 70 | int getgroups(int size, gid_t list[]) 71 | { STUB_0(getgroups); 72 | } 73 | 74 | inline 75 | int setgroups(size_t size, const gid_t* list) 76 | { STUB_0(setgroups); 77 | } 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /unistd/iconv.h: -------------------------------------------------------------------------------- 1 | // iconv.h 2 | // Copyright 2024 Robin.Rowe@cinepaint.org 3 | // License MIT open source 4 | 5 | #ifndef iconv_h 6 | #define iconv_h 7 | 8 | #include "cfunc.h" 9 | #include "stub.h" 10 | 11 | typedef int* iconv_t; 12 | 13 | CFUNC inline 14 | iconv_t iconv_open(const char* tocode, const char* fromcode) 15 | { STUB_0(iconv_open); 16 | } 17 | 18 | CFUNC inline 19 | size_t iconv(iconv_t cd, const char** inbuf, size_t* inbytesleft,char** outbuf, size_t* outbytesleft) 20 | { STUB_0(globfree); 21 | } 22 | 23 | CFUNC int iconv_close(iconv_t cd) 24 | { STUB_NEG(globfree); 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /unistd/ifaddrs.h: -------------------------------------------------------------------------------- 1 | // ifaddrs.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | // Creates a linked list of structures describing the network interfaces of the local system 5 | 6 | #ifndef ifaddrs_h 7 | #define ifaddrs_h 8 | 9 | #include "stub.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #else 14 | #define inline __inline 15 | #endif 16 | 17 | #define ifa_broadaddr ifa_ifu.ifu_broadaddr 18 | #define ifa_dstaddr ifa_ifu.ifu_dstaddr 19 | 20 | struct ifaddrs 21 | { struct ifaddrs *ifa_next; 22 | char* ifa_name; 23 | unsigned int ifa_flags; 24 | struct sockaddr* ifa_addr; 25 | struct sockaddr* ifa_netmask; 26 | union 27 | { struct sockaddr* ifu_broadaddr; 28 | struct sockaddr* ifu_dstaddr; 29 | } ifa_ifu; 30 | void* ifa_data; 31 | }; 32 | 33 | inline 34 | int getifaddrs(struct ifaddrs **ifap) 35 | { STUB_NEG(getifaddrs); 36 | } 37 | 38 | inline 39 | void freeifaddrs(struct ifaddrs *ifa) 40 | { STUB(freeifaddrs); 41 | } 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /unistd/int128/BigNumbers/Int128Net.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Int128.h" 5 | 6 | #if __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ 7 | 8 | inline _uint128 htonlll(_uint128 hostlong) { 9 | return _uint128(htonll(LO64(hostlong)),htonll(HI64(hostlong))); 10 | } 11 | 12 | inline _uint128 ntohlll(_uint128 netlong) { 13 | return _uint128(ntohll(LO64(netlong)),ntohll(HI64(netlong))); 14 | } 15 | 16 | #else 17 | 18 | #define htonlll(hostlong) hostlong 19 | #define ntohlll(netlong ) netlong 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /unistd/int128/BigNumbers/Int128Packer.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | 4 | // --------------------------------- _int128 -------------------------- 5 | Packer &operator<<(Packer &p, const _int128 &n) { 6 | if(isInt64(n)) { 7 | p << (INT64&)n; 8 | } else { 9 | const _uint128 nl = htonlll(n); 10 | p.addElement(Packer::E_INT128, &nl, sizeof(nl)); 11 | } 12 | return p; 13 | } 14 | 15 | Packer &operator>>(Packer &p, _int128 &n) { 16 | switch(p.peekType()) { 17 | case Packer::E_CHAR : 18 | case Packer::E_SHORT : 19 | case Packer::E_RESERVED : 20 | case Packer::E_LONG : 21 | case Packer::E_LONG_LONG: 22 | { INT64 tmp; 23 | p >> tmp; 24 | n = tmp; 25 | } 26 | break; 27 | case Packer::E_INT128 : 28 | { _uint128 nl; 29 | p.getElement(Packer::E_INT128, &nl, sizeof(nl)); 30 | n = ntohlll(nl); 31 | } 32 | break; 33 | default: 34 | throwException(_T("%s:Invalid type:%d. Expected E_CHAR/SHORT/LONG/LONG_LONG/INT128"), __TFUNCTION__, p.peekType()); 35 | } 36 | return p; 37 | } 38 | 39 | // --------------------------------- _uint128 -------------------------- 40 | Packer &operator<<(Packer &p, const _uint128 &n) { 41 | if(isUint64(n)) { 42 | p << (UINT64&)n; 43 | } else { 44 | const _uint128 nl = htonlll(n); 45 | p.addElement(Packer::E_INT128, &nl, sizeof(nl)); 46 | } 47 | return p; 48 | } 49 | 50 | Packer &operator>>(Packer &p, _uint128 &n) { 51 | switch(p.peekType()) { 52 | case Packer::E_CHAR : 53 | case Packer::E_SHORT : 54 | case Packer::E_RESERVED : 55 | case Packer::E_LONG : 56 | case Packer::E_LONG_LONG: 57 | { UINT64 tmp; 58 | p >> tmp; 59 | n = tmp; 60 | } 61 | break; 62 | case Packer::E_INT128 : 63 | { _uint128 nl; 64 | p.getElement(Packer::E_INT128, &nl, sizeof(nl)); 65 | n = ntohlll(nl); 66 | } 67 | break; 68 | default: 69 | throwException(_T("%s:Invalid type:%d. Expected E_CHAR/SHORT/LONG/LONG_LONG/INT128"), __TFUNCTION__, p.peekType()); 70 | } 71 | return p; 72 | } 73 | -------------------------------------------------------------------------------- /unistd/int128/BigNumbers/Int128ToString.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | 4 | String toString(const _int128 &n, StreamSize precision, StreamSize width, FormatFlags flags) { 5 | tostrstream stream; 6 | stream.width( width ); 7 | stream.precision(precision); 8 | stream.flags( flags ); 9 | stream << n; 10 | return stream.str().c_str(); 11 | } 12 | 13 | String toString(const _uint128 &n, StreamSize precision, StreamSize width, FormatFlags flags) { 14 | tostrstream stream; 15 | stream.width( width ); 16 | stream.precision(precision); 17 | stream.flags( flags ); 18 | stream << n; 19 | return stream.str().c_str(); 20 | } 21 | -------------------------------------------------------------------------------- /unistd/libgen.h: -------------------------------------------------------------------------------- 1 | /* libgen.h: replaces *nix header of same name 2 | // Windows emulation of common *nix functions 3 | // Copyright 2015/6/10 Robin.Rowe@MovieEditor.com 4 | // License MIT (http://opensource.org/licenses/mit-license.php) 5 | */ 6 | 7 | #ifndef libgen_h 8 | #define libgen_h 9 | 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #else 15 | //#define inline __inline 16 | #endif 17 | 18 | inline 19 | const char* dirname(char *path) 20 | { return "error"; 21 | } 22 | 23 | inline 24 | const char* GetLastChar(const char* path, char sep) 25 | { const char* p=strchr(path,sep); 26 | const char* prev=p; 27 | while(p) 28 | { prev=p; 29 | p=strchr(p+1,sep); 30 | } 31 | return prev; 32 | } 33 | 34 | inline 35 | const char* basename(char *path) 36 | { const char* last=GetLastChar(path,'/'); 37 | if(!last) 38 | { last=GetLastChar(path,'\\'); 39 | } 40 | if(!last) 41 | { return path; 42 | } 43 | return last+1; 44 | } 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif -------------------------------------------------------------------------------- /unistd/libintl.h: -------------------------------------------------------------------------------- 1 | // libintl.h 2 | 3 | #ifndef libintl_h 4 | #define libintl_h 5 | 6 | #include "stub.h" 7 | 8 | #ifndef __cplusplus 9 | #define inline __inline 10 | #endif 11 | 12 | #if 0 13 | #define PACKAGE IntlGetPackage() 14 | 15 | inline 16 | const char* IntlGetPackage() 17 | { return "English"; 18 | } 19 | #endif 20 | inline 21 | const char* bindtextdomain(const char* package, const char* localdir) 22 | { STUB_BLANK(bindtextdomain); 23 | } 24 | 25 | inline 26 | char* textdomain(const char* package) 27 | { 28 | #if 0 29 | STUB_0(textdomain); 30 | #else 31 | return ""; 32 | #endif 33 | } 34 | 35 | inline 36 | char const* gettext(char const* text) 37 | { return text; 38 | } 39 | 40 | #define gettext_noop(String) (String) 41 | 42 | #define dgettext(Domain,Message) (char *) (Message) 43 | #define dcgettext(Domain,Message,Type) (char *) (Message) 44 | #define bindtextdomain(Domain,Directory) (Domain) 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /unistd/linux/limits.h: -------------------------------------------------------------------------------- 1 | // linux/limits.harderr 2 | 3 | #ifndef linux_limits_h 4 | #define linux_limits_h 5 | 6 | #include 7 | 8 | #define NR_OPEN 1024 9 | #define NGROUPS_MAX 65536 10 | #define ARG_MAX 131072 11 | #define LINK_MAX 127 12 | #define MAX_CANON 255 13 | #define MAX_INPUT 255 14 | #define NAME_MAX _MAX_FNAME 15 | #define PATH_MAX _MAX_PATH 16 | #define PIPE_BUF 4096 17 | #define XATTR_NAME_MAX 255 18 | #define XATTR_SIZE_MAX 65536 19 | #define XATTR_LIST_MAX 65536 20 | #define RTSIG_MAX 32 21 | 22 | #endif -------------------------------------------------------------------------------- /unistd/linux/rtc.h: -------------------------------------------------------------------------------- 1 | // rtc.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef rtc_h 6 | #define rtc_h 7 | 8 | #include "sys/ioctl.h" 9 | #include "stub.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #else 14 | #define inline __inline 15 | #endif 16 | 17 | // The following ioctl(2) requests are defined on file descriptors connected to RTC devices: RTC_RD_TIME 18 | // Returns this RTC's time in the following structure: 19 | 20 | struct rtc_time 21 | { int tm_sec; 22 | int tm_min; 23 | int tm_hour; 24 | int tm_mday; 25 | int tm_mon; 26 | int tm_year; 27 | int tm_wday; /* unused */ 28 | int tm_yday; /* unused */ 29 | int tm_isdst; /* unused */ 30 | }; 31 | 32 | enum 33 | { RTC_SET_TIME, 34 | RTC_ALM_READ, 35 | RTC_ALM_SET, 36 | RTC_IRQP_READ, 37 | RTC_IRQP_SET, 38 | RTC_AIE_ON, 39 | RTC_AIE_OFF, 40 | RTC_UIE_ON, 41 | RTC_UIE_OFF, 42 | RTC_PIE_ON, 43 | RTC_PIE_OFF, 44 | RTC_EPOCH_READ, 45 | RTC_EPOCH_SET, 46 | RTC_WKALM_RD, 47 | RTC_WKALM_SET 48 | }; 49 | 50 | struct rtc_wkalrm 51 | { unsigned char enabled; 52 | unsigned char pending; 53 | struct rtc_time time; 54 | }; 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /unistd/magic.h: -------------------------------------------------------------------------------- 1 | // magic.h 2 | // Libunistd Copyright 2017 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef magic_h 6 | #define magic_h 7 | 8 | typedef int magic_t; 9 | static const unsigned MAGIC_MIME; 10 | 11 | inline 12 | magic_t magic_open(int flags) 13 | { (void) flags; 14 | return 0; 15 | } 16 | 17 | inline 18 | void magic_close(magic_t cookie) 19 | { (void) cookie; 20 | } 21 | 22 | inline 23 | const char* magic_file(magic_t cookie, const char *filename) 24 | { (void) cookie; 25 | const char* mimeType = strrchr(filename,'.'); 26 | if(!mimeType) 27 | { return ""; 28 | } 29 | return mimeType+1; 30 | } 31 | 32 | inline 33 | int magic_load(magic_t cookie, const char *filename) 34 | { (void) cookie; 35 | (void) filename; 36 | return 0; 37 | } 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /unistd/mem.h: -------------------------------------------------------------------------------- 1 | #ifndef mem_h 2 | #define mem_h 3 | 4 | #include "cfunc.h" 5 | 6 | CFUNC void* memmem(const void* haystack, size_t haystack_len, const void* needle, size_t needle_len) 7 | { if (haystack == 0) 8 | { return 0; 9 | } 10 | if (haystack_len == 0) 11 | { return 0; 12 | } 13 | if (needle == 0) 14 | { return 0; 15 | } 16 | if (needle_len == 0) 17 | { return 0; 18 | } 19 | for (const char* h = haystack; 20 | haystack_len >= needle_len; 21 | ++h, --haystack_len) 22 | { if (!memcmp(h, needle, needle_len)) 23 | { return (void*)h; 24 | } 25 | } 26 | return 0; 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /unistd/more/shm_more.h: -------------------------------------------------------------------------------- 1 | // unistd/more/shm_more.h 2 | // 2018/10/28 Robin.Rowe@CinePaint.org 3 | 4 | #ifndef shm_more_h 5 | #define shm_more_h 6 | 7 | #ifndef _WIN32 8 | 9 | #include 10 | #include 11 | 12 | #define shm_close close 13 | #define shm_ftruncate ftruncate 14 | #define shm_flush(fd) 15 | 16 | int shm_size(int fd) 17 | { struct stat sb; 18 | fstat(fd, &sb); 19 | off_t length = sb.st_size; 20 | return int(length); 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /unistd/net/ethertypes.h: -------------------------------------------------------------------------------- 1 | // net/ethertypes.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef net_ethertypes_h 6 | #define net_ethertypes_h 7 | 8 | #define ETHERTYPE_IP 0x0800 9 | #define ETHERTYPE_ARP 0x0806 10 | #define ETHERTYPE_REVARP 0x8035 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /unistd/net/if_arp.h: -------------------------------------------------------------------------------- 1 | // net/if_arp.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef net_if_arp_h 6 | #define net_if_arp_h 7 | 8 | #include 9 | 10 | #define ARPHRD_ETHER 1 11 | 12 | // Modification: Memory packing is needed for cross-platform buffer evaluation. 13 | #pragma pack(push, 1) 14 | struct arphdr 15 | { uint16_t ar_hrd; 16 | uint16_t ar_pro; 17 | uint8_t ar_hln; 18 | uint8_t ar_pln; 19 | uint16_t ar_op; 20 | }; 21 | #pragma pack(pop) 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /unistd/net/route.h: -------------------------------------------------------------------------------- 1 | // net/route.h -------------------------------------------------------------------------------- /unistd/netdb.c: -------------------------------------------------------------------------------- 1 | // netdb.c 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #include "netdb.h" 6 | #include 7 | 8 | #pragma warning(disable:4996) 9 | 10 | struct hostent *gethostbyname2(const char *name, int af) 11 | { // Winsock's gethostbyname() only returns AF_INET addresses. 12 | if ( af != AF_INET ) 13 | { return 0; 14 | } 15 | return gethostbyname(name); 16 | } 17 | -------------------------------------------------------------------------------- /unistd/netdb.h: -------------------------------------------------------------------------------- 1 | // netdb.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef netdb_h 6 | #define netdb_h 7 | 8 | #include 9 | #include "cfunc.h" 10 | 11 | CFUNC struct hostent *gethostbyname2(const char *name, int af); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /unistd/netinet/icmp6.h: -------------------------------------------------------------------------------- 1 | // netinet/icmp6.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef netinet_icmp6_h 6 | #define netinet_icmp6_h 7 | 8 | #include 9 | 10 | #define ICMP6_DST_UNREACH 1 11 | #define ICMP6_PACKET_TOO_BIG 2 12 | #define ICMP6_TIME_EXCEEDED 3 13 | #define ICMP6_PARAM_PROB 4 14 | 15 | #define ICMP6_ECHO_REQUEST 128 16 | #define ICMP6_ECHO_REPLY 129 17 | 18 | #define MLD_LISTENER_QUERY 130 19 | #define MLD_LISTENER_REPORT 131 20 | #define MLD_LISTENER_REDUCTION 132 21 | 22 | #define ND_ROUTER_SOLICIT 133 23 | #define ND_ROUTER_ADVERT 134 24 | #define ND_NEIGHBOR_SOLICIT 135 25 | #define ND_NEIGHBOR_ADVERT 136 26 | #define ND_REDIRECT 137 27 | 28 | #define ICMP6_ROUTER_RENUMBERING 138 29 | 30 | // Modification: Memory packing is needed for cross-platform buffer evaluation. 31 | #pragma pack(push, 1) 32 | struct icmp6_hdr 33 | { uint8_t icmp6_type; 34 | uint8_t icmp6_code; 35 | uint16_t icmp6_cksum; 36 | union 37 | { uint32_t icmp6_un_data32[1]; 38 | uint16_t icmp6_un_data16[2]; 39 | uint8_t icmp6_un_data8[4]; 40 | } icmp6_dataun; 41 | }; 42 | #pragma pack(pop) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /unistd/netinet/in.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/unistd/netinet/in.h -------------------------------------------------------------------------------- /unistd/netinet/in_systm.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/unistd/netinet/in_systm.h -------------------------------------------------------------------------------- /unistd/netinet/ip.h: -------------------------------------------------------------------------------- 1 | // ip.h 2 | // Libunistd Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef ip_h 6 | #define ip_h 7 | 8 | #ifdef _WIN32 9 | #include "../unistd.h" 10 | #else 11 | #include 12 | #endif 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #else 20 | #define inline __inline 21 | #endif 22 | 23 | // Modification: Memory packing is needed for cross-platform buffer evaluation. 24 | #pragma pack(push, 1) 25 | struct ip 26 | { // Use uint8_t instead of unsigned for ip_hl and ip_v so they 27 | // occupy one byte instead of four on Windows. (MSVC allocates 28 | // space sufficient for the bit field's type rather than its 29 | // width. This corresponds to GCC's -mms-bitfields option, 30 | // which is enabled by default on Windows. On other platforms, 31 | // GCC allocates space sufficient for the bit field's width 32 | // regardless of its type.) 33 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 34 | uint8_t ip_hl : 4; 35 | uint8_t ip_v : 4; 36 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 37 | uint8_t ip_v : 4; /* header length */ 38 | uint8_t ip_hl : 4; /* version */ 39 | #else 40 | #error Unknown byte order. 41 | #endif 42 | uint8_t ip_tos; /* type of service */ 43 | uint16_t ip_len; /* total length */ 44 | uint16_t ip_id; /* identification */ 45 | uint16_t ip_off; /* fragment offset field */ 46 | #define IP_RF 0x8000 /* reserved fragment flag */ 47 | #define IP_DF 0x4000 /* dont fragment flag */ 48 | #define IP_MF 0x2000 /* more fragments flag */ 49 | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 50 | uint8_t ip_ttl; /* time to live */ 51 | uint8_t ip_p; /* protocol */ 52 | uint16_t ip_sum; /* checksum */ 53 | struct in_addr ip_src, ip_dst; /* source and dest address */ 54 | }; 55 | #pragma pack(pop) 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /unistd/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | // netinet/tcp.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef netinet_tcp_h 6 | #define netinet_tcp_h 7 | 8 | #include 9 | 10 | #define TCPOPT_EOL 0 11 | #define TCPOPT_NOP 1 12 | #define TCPOPT_MAXSEG 2 13 | #define TCPOPT_WINDOW 3 14 | #define TCPOPT_SACK_PERMITTED 4 15 | #define TCPOPT_TIMESTAMP 8 16 | 17 | #define TH_FIN 0x01 18 | #define TH_SYN 0x02 19 | #define TH_RST 0x04 20 | #define TH_PUSH 0x08 21 | #define TH_ACK 0x10 22 | #define TH_URG 0x20 23 | 24 | // Modification: Memory packing is needed for cross-platform buffer evaluation. 25 | #pragma pack(push, 1) 26 | struct tcphdr 27 | { uint16_t th_sport; 28 | uint16_t th_dport; 29 | uint32_t th_seq; 30 | uint32_t th_ack; 31 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 32 | uint8_t th_x2:4; 33 | uint8_t th_off:4; 34 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 35 | uint8_t th_off:4; 36 | uint8_t th_x2:4; 37 | #else 38 | #error Unknown byte order. 39 | #endif 40 | uint8_t th_flags; 41 | uint16_t th_win; 42 | uint16_t th_sum; 43 | uint16_t th_urp; 44 | }; 45 | #pragma pack(pop) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /unistd/netinet/udp.h: -------------------------------------------------------------------------------- 1 | // netinet/udp.h 2 | // Copyright (c) 2022/10/19 Noah Treuhaft 3 | // License open source MIT 4 | 5 | #ifndef netinet_udp_h 6 | #define netinet_udp_h 7 | 8 | #include 9 | 10 | // Modification: Memory packing is needed for cross-platform buffer evaluation. 11 | #pragma pack(push, 1) 12 | struct udphdr 13 | { uint16_t uh_sport; 14 | uint16_t uh_dport; 15 | uint16_t uh_ulen; 16 | uint16_t uh_sum; 17 | }; 18 | #pragma pack(pop) 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /unistd/poll.h: -------------------------------------------------------------------------------- 1 | // poll.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef poll_h 6 | #define poll_h 7 | 8 | #include "unistd.h" 9 | #include "stub.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #else 14 | #define inline __inline 15 | #endif 16 | 17 | typedef int nfds_t; 18 | 19 | inline 20 | int poll(struct pollfd *fds, nfds_t nfds, int mille_timeout) 21 | { struct timeval timeout; 22 | timeout.tv_sec=mille_timeout/1000; 23 | timeout.tv_usec=1000000*mille_timeout%1000; 24 | // std::vector fd(2*nfds); 25 | struct fd_set* fd=(fd_set*) malloc(2*nfds*sizeof(fd_set)); 26 | if(!fd) 27 | { return -1; 28 | } 29 | u_int* const readerCount=&fd[0].fd_count; 30 | *readerCount=0; 31 | SOCKET* fdReader=fd[0].fd_array; 32 | int writer=nfds; 33 | u_int* const writerCount=&fd[nfds].fd_count; 34 | *writerCount=0; 35 | SOCKET* fdWriter=fd[nfds].fd_array; 36 | for(int i=0;i 9 | #include 10 | #include 11 | 12 | #define QUIT(f) puts("Failed: " #f); exit(-1) 13 | 14 | inline 15 | void *xmalloc(size_t bytes) 16 | { void* p = malloc(bytes); 17 | if(!p) 18 | { QUIT(xmalloc); 19 | } 20 | return p; 21 | } 22 | 23 | inline 24 | void *xrealloc(void *ptr, size_t bytes) 25 | { void* p = realloc(ptr,bytes); 26 | if(!p) 27 | { QUIT(xrealloc); 28 | } 29 | return p; 30 | } 31 | 32 | inline 33 | void xfree(void *ptr) 34 | { free(ptr); 35 | } 36 | 37 | inline 38 | char *xstrdup(const char *s) 39 | { if(!s) 40 | { QUIT(xstrdup); 41 | } 42 | void* p = _strdup(s); 43 | if(!p) 44 | { QUIT(xstrdup); 45 | } 46 | return (char*) p; 47 | } 48 | 49 | inline 50 | void *memdup(const void *mem, size_t bytes) 51 | { void* p = malloc(bytes); 52 | if(!p) 53 | { return 0; 54 | } 55 | memcpy(p,mem,bytes); 56 | return p; 57 | } 58 | 59 | inline 60 | void *xmemdup(const void *mem, size_t bytes) 61 | { void* p = malloc(bytes); 62 | if(!p) 63 | { QUIT(xmemdup); 64 | } 65 | memcpy(p,mem,bytes); 66 | return p; 67 | } 68 | 69 | inline 70 | void* xcalloc (size_t nelem, size_t elsize) 71 | { void* p = calloc(nelem,elsize); 72 | if(!p) 73 | { QUIT(xrealloc); 74 | } 75 | return p; 76 | } 77 | 78 | #define xsnprintf _snprintf 79 | 80 | #undef QUIT 81 | 82 | #endif -------------------------------------------------------------------------------- /unistd/pwd.h: -------------------------------------------------------------------------------- 1 | // rsr 9/6/05 2 | 3 | #ifndef PWD_H 4 | #define PWD_H 5 | 6 | #include "stub.h" 7 | #include "unistd.h" 8 | 9 | struct passwd { 10 | char *pw_name; /* username */ 11 | char *pw_passwd; /* user password */ 12 | uid_t pw_uid; /* user ID */ 13 | gid_t pw_gid; /* group ID */ 14 | char *pw_gecos; /* user information */ 15 | char *pw_dir; /* home directory */ 16 | char *pw_shell; /* shell program */ 17 | }; 18 | 19 | inline 20 | struct passwd *getpwnam(const char *name) 21 | { (void) name; 22 | STUB_0(getpwnam); 23 | } 24 | 25 | inline 26 | struct passwd *getpwuid(uid_t uid) 27 | { (void) uid; 28 | STUB_0(getpwuid); 29 | } 30 | 31 | inline 32 | int getpwnam_r(const char *name, struct passwd *pwd,char *buf, size_t buflen, struct passwd **result) 33 | { (void) name; 34 | (void) pwd; 35 | (void) buf; 36 | (void) buflen; 37 | (void) result; 38 | STUB_0(getpwnam_r); 39 | } 40 | 41 | inline 42 | int getpwuid_r(uid_t uid, struct passwd *pwd,char *buf, size_t buflen, struct passwd **result) 43 | { (void) uid; 44 | (void) pwd; 45 | (void) buf; 46 | (void) buflen; 47 | (void) result; 48 | STUB_0(getpwuid_r); 49 | } 50 | 51 | inline 52 | struct passwd *getpwent() 53 | { STUB_0(getpwent); 54 | } 55 | 56 | inline 57 | void setpwent() 58 | { STUB(setpwent); 59 | } 60 | 61 | inline 62 | void endpwent() 63 | { STUB(endpwent); 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /unistd/sources.cmake: -------------------------------------------------------------------------------- 1 | CMakeLists.txt 2 | sources.cmake 3 | cfunc.h 4 | clock_gettime.h 5 | dirent.h 6 | dlfcn.h 7 | endian.h 8 | fnmatch.h 9 | fts.h 10 | ftw.h 11 | getopt.h 12 | gettimeofday.h 13 | glob.h 14 | grp.h 15 | iconv.h 16 | ifaddrs.h 17 | libgen.h 18 | libintl.h 19 | magic.h 20 | mem.h 21 | mqueue.h 22 | netdb.h 23 | poll.h 24 | pthread.h 25 | publib.h 26 | pwd.h 27 | semaphore.h 28 | sigaction.h 29 | strings.h 30 | syslog.h 31 | termios.h 32 | unistd.h 33 | utime.h 34 | clock_gettime.cpp 35 | dirent.cpp 36 | fnmatch.cpp 37 | fts.c 38 | getline.cpp 39 | getopt.cpp 40 | gettimeofday.cpp 41 | netdb.c 42 | pthread.cpp 43 | sigaction.cpp 44 | stub.h 45 | syslog.cpp 46 | unistd.cpp 47 | arpa/inet.h 48 | arpa/nameser.h 49 | linux/limits.h 50 | linux/rtc.h 51 | more/shm_more.h 52 | net/ethertypes.h 53 | net/if.h 54 | net/if_arp.h 55 | net/route.h 56 | netinet/icmp6.h 57 | netinet/in.h 58 | netinet/in_systm.h 59 | netinet/ip.h 60 | netinet/ip_icmp.h 61 | netinet/tcp.h 62 | netinet/udp.h 63 | sys/cdefs.h 64 | sys/inotify.h 65 | sys/mman.h 66 | sys/random.cpp 67 | sys/sem.cpp 68 | sys/socketvar.h 69 | sys/time.h 70 | sys/epoll.h 71 | sys/ioctl.h 72 | sys/param.h 73 | sys/random.h 74 | sys/sem.h 75 | sys/statvfs.h 76 | sys/vfs.h 77 | sys/file.cpp 78 | sys/poll.h 79 | sys/resource.h 80 | sys/shm.h 81 | sys/sys_types.h 82 | sys/wait.h 83 | sys/file.h 84 | sys/ipc.h 85 | sys/prctl.h 86 | sys/select.h 87 | sys/socket.h 88 | sys/syscall.h 89 | -------------------------------------------------------------------------------- /unistd/strings.h: -------------------------------------------------------------------------------- 1 | // strings.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef strings_h 6 | #define strings_h 7 | 8 | #include 9 | #include "stub.h" 10 | #include "cfunc.h" 11 | 12 | inline 13 | int ffs(int i) 14 | { STUB_NEG(ffs); 15 | } 16 | 17 | inline 18 | int ffsl(long int i) 19 | { STUB_NEG(ffsl); 20 | } 21 | 22 | inline 23 | int ffsll(long long int i) 24 | { STUB_NEG(ffsll); 25 | } 26 | 27 | inline 28 | int strcasecmp(const char *s1, const char *s2) 29 | { return stricmp(s1,s2); 30 | } 31 | 32 | inline 33 | int strncasecmp(const char *s1, const char *s2, size_t n) 34 | { return strnicmp(s1,s2,n); 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /unistd/stub.h: -------------------------------------------------------------------------------- 1 | // stub.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef stub_h 6 | #define stub_h 7 | 8 | #include 9 | #include 10 | #include "cfunc.h" 11 | 12 | CFUNC inline 13 | void StubBug(const char* msg) 14 | { printf("WARNING: Missing %s\n",msg); 15 | } 16 | 17 | #define STUB(functionName) StubBug("Bug! " #functionName) 18 | #define STUB_0(functionName) StubBug("Bug! " #functionName); return 0 19 | #define STUB_NEG(functionName) StubBug("Bug! " #functionName); return -1 20 | #define STUB_RETVAL(functionName,retval) StubBug("Bug! " #functionName); return retval 21 | #define STUB_BLANK(functionName) StubBug("Bug! " #functionName); return "" 22 | #define STUB_MSG(functionName,msg) StubBug("Bug! " #functionName msg) 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /unistd/sys/cdefs.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/unistd/sys/cdefs.h -------------------------------------------------------------------------------- /unistd/sys/epoll.h: -------------------------------------------------------------------------------- 1 | // sys/epoll.h 2 | // Libunistd Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_ioctl_h 6 | #define sys_ioctl_h 7 | 8 | #include "../stub.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #else 13 | #define inline __inline 14 | #endif 15 | 16 | inline 17 | int epoll_create(int size) 18 | STUB0(epoll_create) 19 | 20 | inline 21 | int epoll_create1(int flags) 22 | STUB0(epoll_create1) 23 | 24 | typedef union epoll_data 25 | { void *ptr; 26 | int fd; 27 | uint32_t u32; 28 | uint64_t u64; 29 | } epoll_data_t; 30 | 31 | struct epoll_event 32 | { uint32_t events; 33 | epoll_data_t data; 34 | }; 35 | 36 | enum 37 | { EPOLL_CTL_ADD, 38 | EPOLL_CTL_MOD, 39 | EPOLL_CTL_DEL 40 | }; 41 | 42 | enum 43 | { EPOLLIN, 44 | EPOLLOUT, 45 | EPOLLRDHUP, 46 | EPOLLPRI, 47 | EPOLLERR, 48 | EPOLLHUP, 49 | EPOLLET, 50 | EPOLLONESHOT, 51 | EPOLLWAKEUP, 52 | EPOLLEXCLUSIVE 53 | }; 54 | 55 | inline 56 | int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) 57 | STUB0(epoll_ctl) 58 | 59 | int epoll_wait(int epfd, struct epoll_event *events,int maxevents, int timeout) 60 | STUB0(epoll_wait) 61 | 62 | int epoll_pwait(int epfd, struct epoll_event *events,int maxevents, int timeout,const sigset_t *sigmask) 63 | STUB0(epoll_pwait) 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /unistd/sys/file.h: -------------------------------------------------------------------------------- 1 | // sys/file.h 2 | // Copyright (c) 2022/10/19 Tomer Lev 3 | // License open source MIT 4 | 5 | #ifndef sys_file_h 6 | #define sys_file_h 7 | 8 | #include "../cfunc.h" 9 | 10 | #define LOCK_SH 1 11 | #define LOCK_EX 2 12 | #define LOCK_NB 4 13 | #define LOCK_UN 8 14 | 15 | CFUNC int flock(int fd, int operation); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /unistd/sys/inotify.h: -------------------------------------------------------------------------------- 1 | // sys/inotify.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_inotify_h 6 | #define sys_inotify_h 7 | 8 | #include 9 | #include "../stub.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #else 14 | #define inline __inline 15 | #endif 16 | 17 | enum 18 | { IN_NONBLOCK, 19 | IN_CLOEXEC, 20 | IN_ACCESS, 21 | IN_ATTRIB, 22 | IN_CLOSE_WRITE, 23 | IN_CLOSE_NOWRITE, 24 | IN_CREATE, 25 | IN_DELETE, 26 | IN_DELETE_SELF, 27 | IN_MODIFY, 28 | IN_MOVE_SELF, 29 | IN_MOVED_FROM, 30 | IN_MOVED_TO, 31 | IN_OPEN, 32 | IN_MOVE 33 | }; 34 | 35 | struct inotify_event 36 | { int wd; /* Watch descriptor */ 37 | uint32_t mask; /* Mask describing event */ 38 | uint32_t cookie; /* Unique cookie associating related events (for rename(2)) */ 39 | uint32_t len; /* Size of name field */ 40 | char name[1]; /* Optional null-terminated name */ 41 | }; 42 | 43 | inline 44 | int inotify_init(void) 45 | { STUB_NEG(inotify_init); 46 | } 47 | 48 | inline 49 | int inotify_init1(int flags) 50 | { STUB_NEG(inotify_init1); 51 | } 52 | 53 | inline 54 | int inotify_add_watch(int fd, const char *pathname, uint32_t mask) 55 | { STUB_NEG(inotify_add_watch); 56 | } 57 | 58 | inline 59 | int inotify_rm_watch(int fd, int wd) 60 | { STUB_NEG(inotify_rm_watch); 61 | } 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /unistd/sys/ioctl.h: -------------------------------------------------------------------------------- 1 | // sys/ioctl.h 2 | // Libunistd Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_ioctl_h 6 | #define sys_ioctl_h 7 | 8 | #include "../stub.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #else 13 | #define inline __inline 14 | #endif 15 | 16 | inline 17 | int ioctl(int fd, unsigned long request, ...) 18 | { STUB_NEG(ioctl); 19 | } 20 | 21 | // include net/if.h if you need struct ifreq 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /unistd/sys/ipc.h: -------------------------------------------------------------------------------- 1 | // sys/ipc.h 2 | 3 | #ifndef sys_ipc_h 4 | #define sys_ipc_h 5 | 6 | #include 7 | #include 8 | #include 9 | #include "../stub.h" 10 | 11 | struct ipc_perm 12 | { uid_t uid; 13 | gid_t gid; 14 | uid_t cuid; 15 | gid_t cgid; 16 | mode_t mode; 17 | }; 18 | 19 | enum 20 | { IPC_CREAT, 21 | IPC_EXCL, 22 | IPC_NOWAIT, 23 | IPC_PRIVATE, 24 | IPC_RMID, 25 | IPC_SET, 26 | IPC_STAT 27 | }; 28 | 29 | inline 30 | key_t ftok(const char *pathname, int proj_id) 31 | { STUB_NEG(ftok); 32 | } 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /unistd/sys/mman.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/unistd/sys/mman.h -------------------------------------------------------------------------------- /unistd/sys/poll.h: -------------------------------------------------------------------------------- 1 | // sys/poll.h 2 | // Copyright Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_poll_h 6 | #define sys_poll_h 7 | 8 | #if _MSC_VER <= 1900 9 | #include 10 | 11 | typedef WSAPOLLFD pollfd; 12 | typedef unsigned long nfds_t; 13 | 14 | inline 15 | int poll(struct pollfd *fds, nfds_t nfds, int timeout) 16 | { return WSAPoll(fds,nfds,timeout); 17 | } 18 | 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /unistd/sys/prctl.h: -------------------------------------------------------------------------------- 1 | // sys/prctl.h 2 | // Copyright 2016 Robin.Rowe@cinepaint.org 3 | // License MIT open source 4 | 5 | #ifndef prctl_h 6 | #define prctl_h 7 | 8 | #include "stub.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #else 13 | #define inline __inline 14 | #endif 15 | 16 | inline 17 | int prctl(int option, unsigned long arg2, unsigned long arg3,unsigned long arg4, unsigned long arg5) 18 | { STUB_NEG(prctl); 19 | } 20 | 21 | enum 22 | { PR_CAP_AMBIENT, 23 | PR_CAP_AMBIENT_RAISE, 24 | PR_CAP_AMBIENT_LOWER, 25 | PR_CAP_AMBIENT_IS_SET, 26 | PR_CAP_AMBIENT_CLEAR_ALL, 27 | PR_CAPBSET_READ, 28 | PR_CAPBSET_DROP, 29 | PR_SET_CHILD_SUBREAPER, 30 | PR_GET_CHILD_SUBREAPER, 31 | PR_SET_DUMPABLE, 32 | PR_GET_DUMPABLE, 33 | PR_SET_ENDIAN, 34 | PR_GET_ENDIAN, 35 | PR_SET_FPEMU, 36 | PR_GET_FPEMU, 37 | PR_SET_FPEXC, 38 | PR_GET_FPEXC, 39 | PR_SET_KEEPCAPS, 40 | PR_GET_KEEPCAPS, 41 | PR_MCE_KILL, 42 | PR_MCE_KILL_GET, 43 | PR_SET_MM, 44 | PR_SET_MM_START_CODE, 45 | PR_SET_MM_END_CODE, 46 | PR_SET_MM_START_DATA, 47 | PR_SET_MM_END_DATA, 48 | PR_SET_MM_START_STACK, 49 | PR_SET_MM_START_BRK, 50 | PR_SET_MM_BRK, 51 | PR_SET_MM_ARG_START, 52 | PR_SET_MM_ARG_END, 53 | PR_SET_MM_ENV_START, 54 | PR_SET_MM_ENV_END, 55 | PR_SET_MM_AUXV, 56 | PR_SET_MM_EXE_FILE, 57 | PR_SET_NAME, 58 | PR_GET_NAME, 59 | PR_SET_NO_NEW_PRIVS, 60 | PR_GET_NO_NEW_PRIVS, 61 | PR_SET_PDEATHSIG, 62 | PR_GET_PDEATHSIG, 63 | PR_SET_PTRACER, 64 | PR_SET_SECCOMP, 65 | PR_GET_SECCOMP, 66 | PR_SET_SECUREBITS, 67 | PR_GET_SECUREBITS, 68 | PR_SET_THP_DISABLE, 69 | PR_TASK_PERF_EVENTS_DISABLE, 70 | PR_TASK_PERF_EVENTS_ENABLE, 71 | PR_GET_THP_DISABLE, 72 | PR_GET_TID_ADDRESS, 73 | PR_SET_TIMERSLACK, 74 | PR_GET_TIMERSLACK, 75 | PR_SET_TIMING, 76 | PR_GET_TIMING, 77 | PR_SET_TSC, 78 | PR_GET_TSC, 79 | PR_SET_UNALIGN, 80 | PR_GET_UNALIGN 81 | }; 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /unistd/sys/random.cpp: -------------------------------------------------------------------------------- 1 | // sys/random.cpp 2 | // Copyright (c) 2022/10/19 Tomer Lev 3 | // License open source MIT 4 | 5 | #define _CRT_RAND_S 6 | #include 7 | #include 8 | 9 | #include "random.h" 10 | 11 | int getrandom(void *buf, size_t buflen, unsigned int flags) 12 | { size_t count = buflen / sizeof(unsigned int); 13 | unsigned int* result = reinterpret_cast(buf); 14 | for (size_t i = 0; i < count; ++i) 15 | { if (0 != rand_s(&result[i])) 16 | { return static_cast(i * sizeof(unsigned int)); 17 | } 18 | } 19 | size_t remainder = buflen % sizeof(unsigned int); 20 | if (remainder > 0) 21 | { unsigned int val = 0; 22 | unsigned char* remainderBuf = reinterpret_cast(buf) + buflen - remainder; 23 | if (0 != rand_s(&val)) 24 | { return static_cast(count * sizeof(unsigned int)); 25 | } 26 | memcpy_s(remainderBuf, remainder, &val, remainder); 27 | } 28 | return static_cast(buflen); 29 | } 30 | -------------------------------------------------------------------------------- /unistd/sys/random.h: -------------------------------------------------------------------------------- 1 | #ifndef sys_random_h 2 | #define sys_random_h 3 | 4 | #define HAVE_GETRANDOM 5 | 6 | int getrandom(void *buf, size_t buflen, unsigned int flags); 7 | 8 | #endif -------------------------------------------------------------------------------- /unistd/sys/select.h: -------------------------------------------------------------------------------- 1 | // sys/select.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_select_h 6 | #define sys_select_h 7 | 8 | #include "../unistd.h" 9 | 10 | /* Open Groups says timeval should be this... 11 | 12 | struct timeval { 13 | time_t tv_sec // Seconds. 14 | suseconds_t tv_usec // Microseconds. 15 | }; 16 | 17 | However, Winsock2.h has this... 18 | 19 | struct timeval { 20 | long tv_sec; // seconds 21 | long tv_usec; // and microseconds 22 | }; 23 | 24 | The time_t and suseconds_t types shall be defined as described in . 25 | The sigset_t type shall be defined as described in . 26 | The timespec structure shall be defined as described in . 27 | 28 | 29 | 30 | inline 31 | void FD_CLR(int fd, fd_set *fdset) 32 | STUB(FD_CLR) 33 | 34 | inline 35 | int FD_ISSET(int fd, fd_set *fdset) 36 | STUB0(FD_ISSET) 37 | 38 | inline 39 | void FD_SET(int fd, fd_set *fdset) 40 | STUB(FD_SET) 41 | 42 | inline 43 | void FD_ZERO(fd_set *fdset) 44 | STUB(FD_ZERO) 45 | 46 | //FD_SETSIZE 47 | 48 | inline 49 | int pselect(int, fd_set *restrict, fd_set *restrict, fd_set *restrict,const struct timespec *restrict, const sigset_t *restrict) 50 | STUB0(pselect) 51 | 52 | inline 53 | int select(int, fd_set *restrict, fd_set *restrict, fd_set *restrict,struct timeval *restrict) 54 | STUB0(select) 55 | */ 56 | #endif 57 | -------------------------------------------------------------------------------- /unistd/sys/sem.h: -------------------------------------------------------------------------------- 1 | // sys/sem.h 2 | // 2018/10/29 Robin.Rowe@Cinepaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_sem_h 6 | #define sys_sem_h 7 | 8 | #include 9 | #include 10 | #include 11 | #include "../stub.h" 12 | #include "../cfunc.h" 13 | 14 | #ifndef SEMS_MAX_COUNT 15 | #define SEMS_MAX_COUNT 255 16 | #endif 17 | #define SEMMSL 128 18 | 19 | struct semid_ds 20 | { ipc_perm sem_perm; /* Ownership and permissions */ 21 | time_t sem_otime; /* Last semop time */ 22 | time_t sem_ctime; /* Last change time */ 23 | unsigned long sem_nsems; /* No. of semaphores in set */ 24 | }; 25 | 26 | enum 27 | { SEM_UNDO, 28 | GETNCNT, 29 | GETPID, 30 | GETVAL, 31 | GETALL, 32 | GETZCNT, 33 | SETVAL, 34 | SETALL, 35 | }; 36 | 37 | struct semaphore 38 | { unsigned short int semval;// semaphore value 39 | pid_t sempid; //process ID of last operation 40 | unsigned short int semncnt; //number of processes waiting for semval to become greater than current value 41 | unsigned short int semzcnt; //number of processes waiting for semval to become 0 42 | }; 43 | 44 | struct sembuf 45 | { unsigned short int sem_num; // semaphore number 46 | short int sem_op; // semaphore operation 47 | short int sem_flg; // operation flags 48 | }; 49 | 50 | /* 51 | The argument nsems can be 0 (a don't care) when a semaphore set is 52 | not being created. Otherwise, nsems must be greater than 0 and less 53 | than or equal to the maximum number of semaphores per semaphore set 54 | (SEMMSL). 55 | */ 56 | 57 | CFUNC int semget(key_t key, int nsems, int semflg); 58 | CFUNC int semop(int semid, struct sembuf *sops, size_t nsops); 59 | 60 | inline 61 | int semtimedop(int semid, struct sembuf *sops, size_t nsops,const struct timespec *timeout) 62 | { STUB_NEG(semtimedop); 63 | } 64 | 65 | inline 66 | int semctl(int, int, int, ...) 67 | { STUB_NEG(semctl); 68 | } 69 | 70 | #endif -------------------------------------------------------------------------------- /unistd/sys/shm.h: -------------------------------------------------------------------------------- 1 | // sys/shm.h 2 | // Robin Rowe 2020/3/7 3 | 4 | #ifndef sys_shm_h 5 | #define sys_shm_h 6 | 7 | #include 8 | #include 9 | #include 10 | #include "../stub.h" 11 | 12 | typedef int shmatt_t; 13 | 14 | struct shmid_ds 15 | { struct ipc_perm shm_perm; /* Ownership and permissions */ 16 | size_t shm_segsz; /* Size of segment (bytes) */ 17 | time_t shm_atime; /* Last attach time */ 18 | time_t shm_dtime; /* Last detach time */ 19 | time_t shm_ctime; /* Last change time */ 20 | pid_t shm_cpid; /* PID of creator */ 21 | pid_t shm_lpid; /* PID of last shmat(2)/shmdt(2) */ 22 | shmatt_t shm_nattch; /* No. of current attaches */ 23 | }; 24 | 25 | inline 26 | int shmget(key_t key, size_t size, int shmflg) 27 | { STUB_NEG(shmget); 28 | } 29 | 30 | inline 31 | int shmctl(int shmid, int cmd, struct shmid_ds *buf) 32 | { STUB_NEG(shmctl); 33 | } 34 | 35 | inline 36 | void *shmat(int shmid, const void *shmaddr, int shmflg) 37 | { STUB_0(shmat); 38 | } 39 | 40 | inline 41 | int shmdt(const void *shmaddr) 42 | { STUB_NEG(shmdt); 43 | } 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /unistd/sys/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef socket_h 2 | #define socket_h 3 | 4 | #define WIN32_LEAN_AND_MEAN 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "stub.h" 11 | #include "cfunc.h" 12 | 13 | typedef uint32_t sa_family_t; 14 | 15 | // The iovec structure shall be defined as described in . 16 | 17 | struct iovec 18 | { int junk; 19 | }; 20 | 21 | struct msghdr 22 | { void* msg_name; 23 | socklen_t msg_namelen; 24 | struct iovec* msg_iov; 25 | int msg_iovlen; 26 | void* msg_control; 27 | socklen_t msg_controllen; 28 | int msg_flags; 29 | }; 30 | 31 | typedef int caddr_t; 32 | 33 | // The ioctlsocket function and the WSAIoctl function handle socket functions that were performed by IOCTL and fcntl in BSD 34 | 35 | /* FYI, how to do TCP_KEEPCNT in linux/windows: 36 | #ifndef _WIN32 37 | int count = 10; 38 | int optlen = sizeof( int ); 39 | //Set the time before a keepalive is sent to 60 seconds 40 | setsockopt( sockFD, SOL_TCP, TCP_KEEPIDLE, &idle, optlen ); 41 | //Set the time between keepalive packets to 5 seconds 42 | setsockopt( sockFD, SOL_TCP, TCP_KEEPINTVL, &intvl, optlen ); 43 | //Set the number of packets before connection is closed to 5 44 | setsockopt( sockFD, SOL_TCP, TCP_KEEPCNT, &count, optlen ); 45 | #endif 46 | #ifdef _WIN32 47 | //WinSock structure for KeepAlive timing settings 48 | struct tcp_keepalive settings; 49 | settings.onoff = 1; 50 | settings.keepalivetime = idle * 1000; 51 | settings.keepaliveinterval = intvl * 1000; 52 | 53 | //Random, useless pointers for WinSock call 54 | DWORD bytesReturned; 55 | WSAOVERLAPPED overlapped; 56 | overlapped.hEvent = NULL; 57 | //Set KeepAlive settings -- I HATE WINSOCK 58 | WSAIoctl( 59 | sockFD, 60 | SIO_KEEPALIVE_VALS, 61 | &settings, 62 | sizeof( struct tcp_keepalive ), 63 | NULL, 64 | 0, 65 | &bytesReturned, 66 | &overlapped, 67 | NULL 68 | ); 69 | #endif 70 | */ 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /unistd/sys/socketvar.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/unistd/sys/socketvar.h -------------------------------------------------------------------------------- /unistd/sys/statvfs.h: -------------------------------------------------------------------------------- 1 | // sys/statvfs.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_statvfs_h 6 | #define sys_statvfs_h 7 | 8 | #include 9 | #include "stub.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #else 14 | #define inline __inline 15 | #endif 16 | 17 | struct statvfs 18 | { unsigned long f_bsize; /* Filesystem block size */ 19 | unsigned long f_frsize; /* Fragment size */ 20 | fsblkcnt_t f_blocks; /* Size of fs in f_frsize units */ 21 | fsblkcnt_t f_bfree; /* Number of free blocks */ 22 | fsblkcnt_t f_bavail; /* Number of free blocks for unprivileged users */ 23 | fsfilcnt_t f_files; /* Number of inodes */ 24 | fsfilcnt_t f_ffree; /* Number of free inodes */ 25 | fsfilcnt_t f_favail; /* Number of free inodes for unprivileged users */ 26 | unsigned long f_fsid; /* Filesystem ID */ 27 | unsigned long f_flag; /* Mount flags */ 28 | unsigned long f_namemax; /* Maximum filename length */ 29 | }; 30 | 31 | enum 32 | { ST_MANDLOCK, // Mandatory locking is permitted on the filesystem (see fcntl(2)). 33 | ST_NOATIME, // Do not update access times; see mount(2). 34 | ST_NODEV, // Disallow access to device special files on this filesystem. 35 | ST_NODIRATIME, // Do not update directory access times; see mount(2). 36 | ST_NOEXEC, // Execution of programs is disallowed on this filesystem. 37 | ST_NOSUID, // The set-user-ID and set-group-ID bits are ignored by exec(3) for executable files on this filesystem 38 | ST_RDONLY, // This filesystem is mounted read-only. 39 | ST_RELATIME, // Update atime relative to mtime/ctime; see mount(2). 40 | ST_SYNCHRONOUS, // Writes are synched to the filesystem immediately (see the description of O_SYNC in open(2)). 41 | }; 42 | 43 | // On success, zero is returned. On error, -1 is returned, and errno is set appropriately. 44 | #if 0 45 | int statvfs(const char *path, struct statvfs *buf) 46 | { STUB0(statvfs); 47 | } 48 | 49 | int fstatvfs(int fd, struct statvfs *buf) 50 | { STUB0(fstatvfs); 51 | } 52 | #endif 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /unistd/sys/syscall.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robinrowe/libunistd/8ab9bd613b15302e767003ff1841acfad5d8ac97/unistd/sys/syscall.h -------------------------------------------------------------------------------- /unistd/sys/time.h: -------------------------------------------------------------------------------- 1 | // sys/time.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_time_h 6 | #define sys_time_h 7 | 8 | #include "../unistd.h" 9 | #include 10 | #include "stub.h" 11 | 12 | #ifdef __cplusplus 13 | #include 14 | 15 | extern "C" { 16 | #else 17 | //#define inline __inline 18 | #define nullptr 0 19 | #endif 20 | 21 | struct itimerval 22 | { struct timeval it_interval; /* Interval for periodic timer */ 23 | struct timeval it_value; /* Time until next expiration */ 24 | }; 25 | #if 0 26 | typedef int suseconds_t; 27 | 28 | struct timeval 29 | { time_t tv_sec; /* seconds */ 30 | suseconds_t tv_usec; /* microseconds */ 31 | }; 32 | #endif 33 | 34 | inline 35 | int getitimer(int which, struct itimerval *curr_value) 36 | { (void)which; 37 | (void)curr_value; 38 | STUB_NEG(getitimer); 39 | } 40 | 41 | inline 42 | int setitimer(int which, const struct itimerval *new_value,struct itimerval *old_value) 43 | { (void)which; 44 | (void)new_value; 45 | (void)old_value; 46 | STUB_NEG(setitimer); 47 | } 48 | 49 | enum 50 | { ITIMER_REAL, 51 | ITIMER_VIRTUAL, 52 | ITIMER_PROF 53 | }; 54 | 55 | #if 0 56 | typedef struct _SYSTEMTIME { 57 | WORD wYear; 58 | WORD wMonth; 59 | WORD wDayOfWeek; 60 | WORD wDay; 61 | WORD wHour; 62 | WORD wMinute; 63 | WORD wSecond; 64 | WORD wMilliseconds; 65 | } SYSTEMTIME, *PSYSTEMTIME; 66 | #endif 67 | 68 | inline 69 | struct tm *gmtime_r(const time_t* t, struct tm* result) 70 | { const errno_t err = gmtime_s(result, t); 71 | return err ? nullptr:result; 72 | } 73 | 74 | inline 75 | char *asctime_r(const struct tm *tm, char *result) 76 | { const unsigned bufsize = 26;//minimum 77 | const errno_t err = asctime_s(result,bufsize,tm); 78 | return err ? nullptr:result; 79 | } 80 | 81 | inline 82 | char *ctime_r(const time_t *t, char *result) 83 | { const unsigned bufsize = 26;//minimum 84 | const errno_t err = ctime_s(result,bufsize,t); 85 | return err ? nullptr:result; 86 | } 87 | 88 | inline 89 | struct tm *localtime_r(const time_t *t, struct tm *result) 90 | { const errno_t err = localtime_s(result,t); 91 | return err ? nullptr:result; 92 | } 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /unistd/sys/vfs.h: -------------------------------------------------------------------------------- 1 | // sys/vfs.h 2 | // Libunistd Copyright 2017 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_vfs_h 6 | #define sys_vfs_h 7 | 8 | #include 9 | #include "../stub.h" 10 | 11 | inline 12 | int statfs(const char *path, struct statfs *buf) 13 | { STUB_NEG(statfs); 14 | } 15 | 16 | inline 17 | int fstatfs(int fd, struct statfs *buf) 18 | { STUB_NEG(fstatfs); 19 | } 20 | 21 | typedef short __fsword_t; 22 | typedef int fsblkcnt_t; 23 | typedef int fsfilcnt_t; 24 | typedef int fsid_t; 25 | 26 | struct statfs 27 | { __fsword_t f_type; /* Type of filesystem */ 28 | __fsword_t f_bsize; /* Optimal transfer block size */ 29 | fsblkcnt_t f_blocks; /* Total data blocks in filesystem */ 30 | fsblkcnt_t f_bfree; /* Free blocks in filesystem */ 31 | fsblkcnt_t f_bavail; /* Free blocks available to 32 | unprivileged user */ 33 | fsfilcnt_t f_files; /* Total file nodes in filesystem */ 34 | fsfilcnt_t f_ffree; /* Free file nodes in filesystem */ 35 | fsid_t f_fsid; /* Filesystem ID */ 36 | __fsword_t f_namelen; /* Maximum length of filenames */ 37 | __fsword_t f_frsize; /* Fragment size (since Linux 2.6) */ 38 | __fsword_t f_flags; /* Mount flags of filesystem (since Linux 2.6.36) */ 39 | __fsword_t f_spare[1]; /* Padding bytes reserved for future use */ 40 | }; 41 | 42 | #endif 43 | 44 | -------------------------------------------------------------------------------- /unistd/sys/wait.h: -------------------------------------------------------------------------------- 1 | // sys/wait.h 2 | // Copyright 2016 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef sys_wait_h 6 | #define sys_wait_h 7 | 8 | #include "sys/sys_types.h" 9 | #include "stub.h" 10 | #include "sigaction.h" 11 | 12 | #define WIFEXITED(wstatus) 1 13 | #define WEXITSTATUS(wstatus) 0 14 | 15 | inline 16 | pid_t wait(int *status) 17 | { STUB_NEG(wait); 18 | } 19 | 20 | inline 21 | pid_t waitpid(pid_t pid, int *status, int options) 22 | { STUB_NEG(waitpid); 23 | } 24 | 25 | typedef int idtype_t; 26 | typedef int id_t; 27 | 28 | inline 29 | int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) 30 | { STUB_NEG(waitid); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /unistd/syslog.h: -------------------------------------------------------------------------------- 1 | // syslog.h 2 | // Copyright 2019/10/8 Robin.Rowe@CinePaint.org 3 | // License open source MIT 4 | 5 | #ifndef syslog_h 6 | #define syslog_h 7 | 8 | struct Syslog_data; 9 | 10 | //extern Syslog_data Syslog_data; 11 | 12 | // option: 13 | enum 14 | { LOG_CONS = 1, 15 | LOG_NDELAY = 2, 16 | LOG_NOWAIT = 4, 17 | LOG_ODELAY = 8, 18 | LOG_PERROR = 16, 19 | LOG_PID = 32 20 | }; 21 | 22 | // facility: 23 | enum 24 | { LOG_AUTH = 1, 25 | LOG_AUTHPRIV = 2, 26 | LOG_CRON = 4, 27 | LOG_DAEMON = 8, 28 | LOG_FTP = 16, 29 | LOG_KERN = 32, 30 | LOG_LOCAL0 = 64, 31 | LOG_LOCAL1 = 128, 32 | LOG_LOCAL2 = 256, 33 | LOG_LOCAL3 = 512, 34 | LOG_LOCAL4 = 1024, 35 | LOG_LOCAL5 = 2*1024, 36 | LOG_LOCAL6 = 4*1024, 37 | LOG_LOCAL7 = 8*1024, 38 | LOG_LPR = 16*1024, 39 | LOG_MAIL = 32*1024, 40 | LOG_NEWS = 64*1024, 41 | LOG_SYSLOG = 128*1024, 42 | LOG_USER = 256*1024, 43 | LOG_UUCP = 512*1024 44 | }; 45 | 46 | // level: 47 | enum 48 | { LOG_EMERG, 49 | LOG_ALERT, 50 | LOG_CRIT, 51 | LOG_ERR, 52 | LOG_WARNING, 53 | LOG_NOTICE, 54 | LOG_INFO, 55 | LOG_DEBUG 56 | }; 57 | 58 | void openlog(const char *programname, int option, int facility); 59 | void syslog(int priority, const char *format, ...); 60 | void closelog(); 61 | int setlogmask(int mask); 62 | void vsyslog(int priority, const char* format, va_list argp); 63 | 64 | inline 65 | int LOG_UPTO(const int maxMask) 66 | { const int mask = ((1<<((maxMask)+1))-1); 67 | return mask; 68 | } 69 | 70 | /* 71 | 72 | #include 73 | 74 | setlogmask (LOG_UPTO (LOG_NOTICE)); 75 | openlog ("exampleprog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); 76 | syslog (LOG_NOTICE, "Program started by User %d", getuid ()); 77 | syslog (LOG_INFO, "A tree falls in a forest"); 78 | closelog (); 79 | 80 | openlog("programname", 0, LOG_USER); --> /var/log/messages 81 | openlog("programname", 0, LOG_LOCAL0); --> /var/log/programname 82 | 83 | */ 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /unistd/unistd.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += staticlib 3 | 4 | include(../libunistd.pri) 5 | 6 | HEADERS = \ 7 | chrono.h \ 8 | dirent.h \ 9 | dlfcn.h \ 10 | endian.h \ 11 | gettimeofday.h \ 12 | grp.h \ 13 | ifaddrs.h \ 14 | libgen.h \ 15 | libintl.h \ 16 | magic.h \ 17 | mqueue.h \ 18 | netdb.h \ 19 | poll.h \ 20 | pthread.h \ 21 | pwd.h \ 22 | semaphore.h \ 23 | strings.h \ 24 | termios.h \ 25 | uni_signal.h \ 26 | unistd.h \ 27 | arpa/inet.h \ 28 | linux/rtc.h \ 29 | net/if.h \ 30 | net/route.h \ 31 | netinet/in.h \ 32 | netinet/ip.h \ 33 | netinet/ip_icmp.h \ 34 | sys/epoll.h \ 35 | sys/file.h \ 36 | sys/inotify.h \ 37 | sys/ioctl.h \ 38 | sys/mman.h \ 39 | sys/poll.h \ 40 | sys/prctl.h \ 41 | sys/resource.h \ 42 | sys/select.h \ 43 | sys/socket.h \ 44 | sys/socketvar.h \ 45 | sys/statvfs.h \ 46 | sys/sys_types.h \ 47 | sys/syscall.h \ 48 | sys/time.h \ 49 | sys/vfs.h \ 50 | sys/wait.h 51 | 52 | SOURCES = \ 53 | dirent.cpp \ 54 | gettimeofday.cpp \ 55 | uni_signal.cpp 56 | -------------------------------------------------------------------------------- /unistd/utime.h: -------------------------------------------------------------------------------- 1 | #include -------------------------------------------------------------------------------- /uuid/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/libuuid/CMakeLists.txt 2 | 3 | project(libuuid) 4 | message("--- Building library ${PROJECT_NAME} ---") 5 | 6 | if(WIN32) 7 | include_directories( 8 | "${CMAKE_CURRENT_SOURCE_DIR}/../unistd" 9 | ) 10 | endif(WIN32) 11 | 12 | add_definitions( 13 | -DHAVE_UNISTD_H 14 | -DHAVE_ERR 15 | -DHAVE_ERRX 16 | -DHAVE_WARN 17 | -DHAVE_WARNX 18 | -DHAVE_STDLIB_H 19 | -DHAVE_USLEEP 20 | -DHAVE_SYS_TIME_H 21 | ) 22 | 23 | set(HEADERS 24 | uuid.h 25 | all-io.h 26 | c.h 27 | randutils.h 28 | uuidd.h 29 | uuidP.h 30 | ) 31 | 32 | set(SOURCES 33 | clear.cpp 34 | compare.cpp 35 | copy.cpp 36 | gen_uuid.cpp 37 | isnull.cpp 38 | pack.cpp 39 | parse.cpp 40 | unpack.cpp 41 | unparse.cpp 42 | uuid_time.cpp 43 | randutils.cpp 44 | ) 45 | 46 | add_library(${PROJECT_NAME} STATIC ${SOURCES}) 47 | if(WITH_TESTS) 48 | add_subdirectory(test) 49 | endif() -------------------------------------------------------------------------------- /uuid/COPYING: -------------------------------------------------------------------------------- 1 | This library is free software; you can redistribute it and/or 2 | modify it under the terms of the Modified BSD License. 3 | 4 | The complete text of the license is available at the 5 | Documentation/licenses/COPYING.BSD-3 file. 6 | -------------------------------------------------------------------------------- /uuid/Version-libuuid-1.0.3.txt: -------------------------------------------------------------------------------- 1 | libuuid-1.0.3 -------------------------------------------------------------------------------- /uuid/all-io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * No copyright is claimed. This code is in the public domain; do with 3 | * it what you wish. 4 | * 5 | * Written by Karel Zak 6 | * Petr Uzel 7 | */ 8 | 9 | #ifndef UTIL_LINUX_ALL_IO_H 10 | #define UTIL_LINUX_ALL_IO_H 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "c.h" 17 | 18 | static inline int write_all(int fd, const void *buf, size_t count) 19 | { 20 | while (count) { 21 | ssize_t tmp; 22 | 23 | errno = 0; 24 | #pragma warning(disable : 4996) 25 | tmp = write(fd, buf,(unsigned int) count); 26 | if (tmp > 0) { 27 | count -= tmp; 28 | if (count) 29 | buf = (void *) ((char *) buf + tmp); 30 | } else if (errno != EINTR && errno != EAGAIN) 31 | return -1; 32 | if (errno == EAGAIN) /* Try later, *sigh* */ 33 | usleep(10000); 34 | } 35 | return 0; 36 | } 37 | 38 | static inline int fwrite_all(const void *ptr, size_t size, 39 | size_t nmemb, FILE *stream) 40 | { 41 | while (nmemb) { 42 | size_t tmp; 43 | 44 | errno = 0; 45 | tmp = fwrite(ptr, size, nmemb, stream); 46 | if (tmp > 0) { 47 | nmemb -= tmp; 48 | if (nmemb) 49 | ptr = (void *) ((char *) ptr + (tmp * size)); 50 | } else if (errno != EINTR && errno != EAGAIN) 51 | return -1; 52 | if (errno == EAGAIN) /* Try later, *sigh* */ 53 | usleep(10000); 54 | } 55 | return 0; 56 | } 57 | 58 | static inline ssize_t read_all(int fd, char *buf, size_t count) 59 | { 60 | ssize_t ret; 61 | ssize_t c = 0; 62 | int tries = 0; 63 | 64 | memset(buf, 0, count); 65 | while (count > 0) { 66 | ret = read(fd, buf, (unsigned int) count); 67 | #pragma warning(default : 4996) 68 | if (ret <= 0) { 69 | if ((errno == EAGAIN || errno == EINTR || ret == 0) && 70 | (tries++ < 5)) 71 | continue; 72 | return c ? c : -1; 73 | } 74 | if (ret > 0) 75 | tries = 0; 76 | count -= ret; 77 | buf += ret; 78 | c += ret; 79 | } 80 | return c; 81 | } 82 | 83 | 84 | #endif /* UTIL_LINUX_ALL_IO_H */ 85 | -------------------------------------------------------------------------------- /uuid/clear.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * clear.c -- Clear a UUID 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "string.h" 36 | 37 | #include "uuidP.h" 38 | 39 | void uuid_clear(uuid_t uu) 40 | { 41 | memset(uu, 0, 16); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /uuid/copy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * copy.c --- copy UUIDs 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "uuidP.h" 36 | 37 | void uuid_copy(uuid_t dst, const uuid_t src) 38 | { 39 | unsigned char *cp1; 40 | const unsigned char *cp2; 41 | int i; 42 | 43 | for (i=0, cp1 = dst, cp2 = src; i < 16; i++) 44 | *cp1++ = *cp2++; 45 | } 46 | -------------------------------------------------------------------------------- /uuid/isnull.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * isnull.c --- Check whether or not the UUID is null 3 | * 4 | * Copyright (C) 1996, 1997 Theodore Ts'o. 5 | * 6 | * %Begin-Header% 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, and the entire permission notice in its entirety, 12 | * including the disclaimer of warranties. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote 17 | * products derived from this software without specific prior 18 | * written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 23 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 27 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 31 | * DAMAGE. 32 | * %End-Header% 33 | */ 34 | 35 | #include "uuidP.h" 36 | 37 | /* Returns 1 if the uuid is the NULL uuid */ 38 | int uuid_is_null(const uuid_t uu) 39 | { 40 | const unsigned char *cp; 41 | int i; 42 | 43 | for (i=0, cp = uu; i < 16; i++) 44 | if (*cp++) 45 | return 0; 46 | return 1; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /uuid/randutils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_LINUX_RANDUTILS 2 | #define UTIL_LINUX_RANDUTILS 3 | 4 | #ifdef HAVE_SRANDOM 5 | #define srand(x) srandom(x) 6 | #define rand() random() 7 | #endif 8 | 9 | extern int random_get_fd(void); 10 | extern void random_get_bytes(void *buf, size_t nbytes); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /uuid/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libuuid/test/CMakeLists.txt 2 | 3 | if(WIN32) 4 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../unistd") 5 | endif(WIN32) 6 | 7 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..") 8 | 9 | #message("CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR}") 10 | 11 | add_executable(test_uuid test_uuid.c) 12 | target_link_libraries(test_uuid libuuid) 13 | -------------------------------------------------------------------------------- /xxhash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # libunistd/xxhash/CMakeLists.txt 2 | 3 | project(libxxhash) 4 | message("--- Building library ${PROJECT_NAME} ---") 5 | 6 | set(SOURCES 7 | xxhash.h 8 | xxhash.c 9 | xxhsum.c 10 | ) 11 | 12 | add_library(${PROJECT_NAME} STATIC ${SOURCES}) 13 | -------------------------------------------------------------------------------- /xxhash/LICENSE: -------------------------------------------------------------------------------- 1 | xxHash Library 2 | Copyright (c) 2012-2014, Yann Collet 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 19 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 22 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /xxhash/cmake_unofficial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | cmake_policy(VERSION 2.6) 3 | 4 | project(xxhash) 5 | 6 | set(XXHASH_LIB_VERSION "0.42.0") 7 | set(XXHASH_LIB_SOVERSION "0") 8 | 9 | add_library(xxhash SHARED ../xxhash.c) 10 | set_target_properties(xxhash PROPERTIES COMPILE_DEFINITIONS "XXHASH_EXPORT" 11 | VERSION "${XXHASH_LIB_VERSION}" 12 | SOVERSION "${XXHASH_LIB_SOVERSION}") 13 | set(install_libs xxhash) 14 | 15 | set(BUILD_STATIC_LIBS ON CACHE BOOL "Set to ON to build static libraries") 16 | if(BUILD_STATIC_LIBS) 17 | add_library(xxhashstatic ../xxhash.c) 18 | set_target_properties(xxhashstatic PROPERTIES OUTPUT_NAME xxhash) 19 | LIST(APPEND install_libs xxhashstatic) 20 | endif(BUILD_STATIC_LIBS) 21 | 22 | 23 | INSTALL(FILES ../xxhash.h DESTINATION include) 24 | INSTALL(TARGETS ${install_libs} DESTINATION lib) 25 | -------------------------------------------------------------------------------- /xxhash/xxhash.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = lib 2 | CONFIG += staticlib 3 | HEADERS = xxhash.h 4 | 5 | SOURCES = xxhsum.c xxhash.c 6 | --------------------------------------------------------------------------------