├── README.md ├── docs ├── jemalloc改造.md └── qkc-arch.jpg ├── include ├── alloca.h ├── arpa │ └── inet.h ├── assert.h ├── atomic.h ├── bits │ ├── confname.h │ ├── in.h │ ├── select.h │ ├── siginfo.h │ ├── sockaddr.h │ ├── socket.h │ ├── termios.h │ ├── waitflags.h │ └── wordsize.h ├── builtin.h ├── byteswap.h ├── ctype.h ├── dirent.h ├── dlfcn.h ├── endian.h ├── errno.h ├── fcntl.h ├── float.h ├── getopt.h ├── grp.h ├── iconv.h ├── ifaddrs.h ├── inttypes.h ├── limits.h ├── locale.h ├── math.h ├── net │ ├── ethernet.h │ └── if.h ├── netdb.h ├── netinet │ ├── in.h │ ├── tcp.h │ └── udp.h ├── netpacket │ └── packet.h ├── poll.h ├── pthread.h ├── pwd.h ├── quark_compile.h ├── sched.h ├── semaphore.h ├── signal.h ├── stdarg.h ├── stdbool.h ├── stddef.h ├── stdint.h ├── stdio.h ├── stdlib.h ├── string.h ├── strings.h ├── sys │ ├── epoll.h │ ├── inotify.h │ ├── ioctl.h │ ├── ipc.h │ ├── mman.h │ ├── param.h │ ├── poll.h │ ├── prctl.h │ ├── resource.h │ ├── select.h │ ├── sem.h │ ├── sendfile.h │ ├── shm.h │ ├── signal.h │ ├── socket.h │ ├── stat.h │ ├── syscall.h │ ├── sysinfo.h │ ├── syslog.h │ ├── time.h │ ├── timeb.h │ ├── times.h │ ├── types.h │ ├── uio.h │ ├── un.h │ ├── unistd.h │ └── wait.h ├── syscall.h ├── syslog.h ├── termios.h ├── time.h ├── unistd.h ├── utime.h ├── wait.h ├── wimpl │ ├── IOCPMgr.h │ ├── MMapMgr.h │ ├── PThreadCond.h │ ├── PThreadMutex.h │ └── PThreadRWLocker.h ├── wintf │ └── wipc.h ├── wobjs │ ├── AddrMgr.h │ ├── AdvAPI32Loader.h │ ├── AtomicCounter.h │ ├── BitOP.h │ ├── Condition.h │ ├── CrtLinker.h │ ├── CrtLoader.h │ ├── DateTime.h │ ├── DllInit.h │ ├── DllLoader.h │ ├── ErrorMap.h │ ├── FileSystem.h │ ├── FileSystemDevNull.h │ ├── FileSystemProc.h │ ├── GlobalLocker.h │ ├── Hash.h │ ├── INotifyMgr.h │ ├── IOCPMgr.h │ ├── LargePageMap.h │ ├── MemMgr.h │ ├── MemoryInfo.h │ ├── Mutex.h │ ├── ObjMgr.h │ ├── Object.h │ ├── ProcessMemoryInfo.h │ ├── RBTree.h │ ├── RList.h │ ├── RWLocker.h │ ├── RXTree.h │ ├── RingBuffer.h │ ├── SemaphoreW.h │ ├── SockOpt.h │ ├── SpinLocker.h │ ├── StrUtil.h │ ├── SysInfo.h │ ├── Thread.h │ ├── ThreadLocal.h │ └── UserEnvLoader.h └── wstub │ ├── advapi32.h │ ├── intrin.h │ ├── iphlpapi.h │ ├── ntstatus.h │ ├── userenv.h │ ├── winbase.h │ ├── windef.h │ ├── windows.h │ ├── winerror.h │ ├── winnt.h │ └── winsock2.h ├── qkc ├── advapi32_imp.cpp ├── arpa_inet.cpp ├── assert.cpp ├── atomic.cpp ├── builtin.cpp ├── byteswap.cpp ├── ctype.cpp ├── dirent.cpp ├── dlfcn.cpp ├── fcntl.cpp ├── getopt.cpp ├── grp.cpp ├── iconv.cpp ├── ifaddrs.cpp ├── internal │ ├── ffile.cpp │ ├── ffile.h │ ├── fpipe.cpp │ ├── fpipe.h │ ├── fsocket.cpp │ ├── fsocket.h │ ├── pipe_mgr.cpp │ └── pipe_mgr.h ├── iphlpapi_imp.cpp ├── kernel32.txt ├── math.cpp ├── msvcr90.txt ├── net_if.cpp ├── netdb.cpp ├── netinet_in.cpp ├── ntdll.txt ├── pthread.cpp ├── pwd.cpp ├── qkc.vcproj ├── qkc.vcxproj ├── qkc.vcxproj.filters ├── qkc_init.cpp ├── sched.cpp ├── semaphore.cpp ├── signal.cpp ├── stdio.cpp ├── stdlib.cpp ├── string.cpp ├── sys_epoll.cpp ├── sys_inotify.cpp ├── sys_ioctl.cpp ├── sys_ipc.cpp ├── sys_mman.cpp ├── sys_poll.cpp ├── sys_resource.cpp ├── sys_select.cpp ├── sys_sem.cpp ├── sys_sendfile.cpp ├── sys_shm.cpp ├── sys_socket.cpp ├── sys_stat.cpp ├── sys_sysinfo.cpp ├── sys_syslog.cpp ├── sys_time.cpp ├── sys_times.cpp ├── sys_uio.cpp ├── syscall.cpp ├── termios.cpp ├── time.cpp ├── ucrt │ ├── ucrt_errno.cpp │ └── ucrt_stdio.cpp ├── unistd.cpp ├── userenv_imp.cpp ├── utime.cpp ├── wait.cpp ├── wimpl │ ├── IOCPMgr.cpp │ ├── MMapMgr.cpp │ ├── PThreadCond.cpp │ ├── PThreadMutex.cpp │ └── PThreadRWLocker.cpp ├── winsock2_imp.cpp ├── wintf │ └── wipc.cpp └── wobjs │ ├── AddrMgr.cpp │ ├── AdvAPI32Loader.cpp │ ├── AtomicCounter.cpp │ ├── Condition.cpp │ ├── CrtLoader.cpp │ ├── DateTime.cpp │ ├── DllInit.cpp │ ├── DllLoader.cpp │ ├── ErrorMap.cpp │ ├── FileSystem.cpp │ ├── FileSystemDevNull.cpp │ ├── FileSystemProc.cpp │ ├── GlobalLocker.cpp │ ├── Hash.cpp │ ├── INotifyMgr.cpp │ ├── IOCPMgr.cpp │ ├── LargePageMap.cpp │ ├── MemMgr.cpp │ ├── MemoryInfo.cpp │ ├── Mutex.cpp │ ├── ObjMgr.cpp │ ├── Object.cpp │ ├── ProcessMemoryInfo.cpp │ ├── RBTree.cpp │ ├── RList.cpp │ ├── RWLocker.cpp │ ├── RXTree.cpp │ ├── RingBuffer.cpp │ ├── SemaphoreW.cpp │ ├── SockOpt.cpp │ ├── SpinLocker.cpp │ ├── StrUtil.cpp │ ├── SysInfo.cpp │ ├── Thread.cpp │ ├── ThreadLocal.cpp │ ├── UserEnvLoader.cpp │ ├── proc.txt │ ├── proc_cpuinfo.txt │ ├── proc_pid_stat.txt │ ├── proc_stat.txt │ └── ws2_32.txt ├── qkn ├── iphlpapi_imp.cpp ├── qkn.vcproj ├── qkn.vcxproj ├── qkn.vcxproj.filters ├── qkn_init.cpp └── winsock2_imp.cpp ├── qkw ├── advapi32.txt ├── advapi32_imp.cpp ├── qkw.vcproj ├── qkw.vcxproj ├── qkw.vcxproj.filters ├── qkw_init.cpp ├── userenv.txt └── userenv_imp.cpp ├── quark-vs2008.sln ├── quark-vs2017.sln └── test ├── main.cpp ├── support ├── Makefile ├── README ├── README-testing.c ├── capture_subprocess.h ├── check.c ├── check.h ├── check_addrinfo.c ├── check_dns_packet.c ├── check_hostent.c ├── check_netent.c ├── check_nss.h ├── delayed_exit.c ├── format_nss.h ├── ignore_stderr.c ├── namespace.h ├── next_to_fault.c ├── next_to_fault.h ├── oom_error.c ├── resolv_test.c ├── resolv_test.h ├── run_diff.h ├── set_fortify_handler.c ├── support-xfstat.c ├── support-xstat.c ├── support.h ├── support_become_root.c ├── support_can_chroot.c ├── support_capture_subprocess.c ├── support_capture_subprocess_check.c ├── support_chroot.c ├── support_enter_mount_namespace.c ├── support_enter_network_namespace.c ├── support_format_address_family.c ├── support_format_addrinfo.c ├── support_format_dns_packet.c ├── support_format_herrno.c ├── support_format_hostent.c ├── support_format_netent.c ├── support_isolate_in_subprocess.c ├── support_record_failure.c ├── support_run_diff.c ├── support_shared_allocate.c ├── support_test_compare_failure.c ├── support_test_main.c ├── support_test_verify_impl.c ├── support_write_file_string.c ├── temp_file-internal.h ├── temp_file.c ├── temp_file.h ├── test-driver.c ├── test-driver.h ├── tst-support-namespace.c ├── tst-support_capture_subprocess.c ├── tst-support_format_dns_packet.c ├── tst-support_record_failure-2.sh ├── tst-support_record_failure.c ├── tst-test_compare.c ├── tst-xreadlink.c ├── write_message.c ├── xaccept.c ├── xaccept4.c ├── xasprintf.c ├── xbind.c ├── xcalloc.c ├── xchroot.c ├── xclose.c ├── xconnect.c ├── xdlfcn.c ├── xdlfcn.h ├── xdup2.c ├── xfclose.c ├── xfopen.c ├── xfork.c ├── xftruncate.c ├── xgetsockname.c ├── xlisten.c ├── xlseek.c ├── xmalloc.c ├── xmemstream.c ├── xmemstream.h ├── xmkdir.c ├── xmmap.c ├── xmprotect.c ├── xmunmap.c ├── xopen.c ├── xpipe.c ├── xpoll.c ├── xpthread_attr_destroy.c ├── xpthread_attr_init.c ├── xpthread_attr_setdetachstate.c ├── xpthread_attr_setguardsize.c ├── xpthread_attr_setstacksize.c ├── xpthread_barrier_destroy.c ├── xpthread_barrier_init.c ├── xpthread_barrier_wait.c ├── xpthread_cancel.c ├── xpthread_check_return.c ├── xpthread_cond_wait.c ├── xpthread_create.c ├── xpthread_detach.c ├── xpthread_join.c ├── xpthread_mutex_consistent.c ├── xpthread_mutex_destroy.c ├── xpthread_mutex_init.c ├── xpthread_mutex_lock.c ├── xpthread_mutex_unlock.c ├── xpthread_mutexattr_destroy.c ├── xpthread_mutexattr_init.c ├── xpthread_mutexattr_setprotocol.c ├── xpthread_mutexattr_setpshared.c ├── xpthread_mutexattr_setrobust.c ├── xpthread_mutexattr_settype.c ├── xpthread_once.c ├── xpthread_rwlock_init.c ├── xpthread_rwlock_rdlock.c ├── xpthread_rwlock_unlock.c ├── xpthread_rwlock_wrlock.c ├── xpthread_rwlockattr_init.c ├── xpthread_rwlockattr_setkind_np.c ├── xpthread_sigmask.c ├── xpthread_spin_lock.c ├── xpthread_spin_unlock.c ├── xraise.c ├── xreadlink.c ├── xrealloc.c ├── xrecvfrom.c ├── xsendto.c ├── xsetsockopt.c ├── xsigaction.c ├── xsignal.c ├── xsignal.h ├── xsocket.c ├── xsocket.h ├── xstdio.h ├── xstrdup.c ├── xstrndup.c ├── xsysconf.c ├── xthread.h ├── xunistd.h ├── xunlink.c ├── xwaitpid.c └── xwrite.c ├── test.h ├── test.vcproj ├── test.vcxproj ├── test.vcxproj.filters └── time ├── time_testcase.h ├── tst-ftime.c ├── tst-ftime_l.c ├── tst-getdate.c ├── tst-mktime.cpp ├── tst-mktime2.c ├── tst-mktime3.c ├── tst-posixtz.c ├── tst-strftime.c ├── tst-strptime-whitespace.c ├── tst-strptime.c ├── tst-strptime2.c ├── tst-strptime3.c ├── tst-tzname.c └── tst_wcsftime.c /docs/jemalloc改造.md: -------------------------------------------------------------------------------- 1 | 2 | 1、size_t和wchar_t在c语言下,vs2008不支持,需要独立定义 3 | 4 | 2、stdbool.h默认没有,需要加入 5 | 6 | 3、sizeof不能求匿名结构的大小 7 | 8 | 4、gcc的内建函数__builtin_xxx和__atomic_xxx类似模板,支持任意类型,在vs2008下,实现比较麻烦。 9 | 10 | 5、C的标准在vs2008下,支持不完整,如果改成cpp文件会好点。 11 | 12 | 6、gcc的内置宏 \_\_func\_\_ 对影城 \_\_FUNCTION\_\_ 13 | 14 | 7、内置\_\_builtin\_unreachable没有对应的函数 15 | 16 | 8、\_\_attribute\_\_位置在后,而且没有完全的对应的,需要改代码。 17 | -------------------------------------------------------------------------------- /docs/qkc-arch.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/docs/qkc-arch.jpg -------------------------------------------------------------------------------- /include/alloca.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_ALLOCA_H 3 | #define __QKC_ALLOCA_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | QUARK_LINKAGE void *_alloca (size_t size) ; 11 | 12 | #ifdef __GNUC__ 13 | # define alloca(size) __builtin_alloca (size) 14 | #else 15 | # define alloca(size) _alloca (size) 16 | #endif /* GCC. */ 17 | 18 | __END_DECLS 19 | 20 | #endif /**__QKC_ALLOCA_H*/ 21 | 22 | -------------------------------------------------------------------------------- /include/arpa/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_ARPA_INET_H 2 | #define __QKC_ARPA_INET_H 1 3 | 4 | #include 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | QKCAPI in_addr_t inet_addr (const char * cp) ; 10 | QKCAPI char *inet_ntoa (struct in_addr in) ; 11 | 12 | __END_DECLS 13 | 14 | #endif /** __QKC_ARPA_INET_H */ 15 | -------------------------------------------------------------------------------- /include/assert.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_ASSERT_H 3 | #define __QUARK_ASSERT_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | 10 | QKCAPI void __assert_fail(const char *assertion, const char *file, unsigned int line, const char *func); 11 | 12 | 13 | __END_DECLS 14 | 15 | #if defined(DEBUG) 16 | 17 | #define assert(expr) \ 18 | ((expr) \ 19 | ? __ASSERT_VOID_CAST (0) \ 20 | : __assert_fail (#expr, __FILE__, __LINE__, __FUNCTION__)) 21 | #else 22 | # define assert(expr) 23 | #endif 24 | 25 | 26 | #endif /** __QUARK_ASSERT_H */ 27 | -------------------------------------------------------------------------------- /include/atomic.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/atomic.h -------------------------------------------------------------------------------- /include/bits/select.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_BITS_SELECT_H 3 | #define __QKC_BITS_SELECT_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | 11 | # define __FD_ZERO(set) \ 12 | do { \ 13 | unsigned int __i; \ 14 | fd_set *__arr = (set); \ 15 | for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) \ 16 | __FDS_BITS (__arr)[__i] = 0; \ 17 | } while (0) 18 | 19 | 20 | #define __FD_SET(d, set) ((void) (__FDS_BITS (set)[__FD_ELT (d)] |= __FD_MASK (d))) 21 | #define __FD_CLR(d, set) ((void) (__FDS_BITS (set)[__FD_ELT (d)] &= ~__FD_MASK (d))) 22 | #define __FD_ISSET(d, set) ((__FDS_BITS (set)[__FD_ELT (d)] & __FD_MASK (d)) != 0) 23 | 24 | __END_DECLS 25 | 26 | #endif /** __QKC_BITS_SELECT_H */ 27 | -------------------------------------------------------------------------------- /include/bits/sockaddr.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_BITS_SOCKADDR_H 3 | #define __QUARK_BITS_SOCKADDR_H 1 4 | 5 | 6 | typedef unsigned short int sa_family_t; 7 | 8 | #define __SOCKADDR_COMMON(sa_prefix) sa_family_t sa_prefix##family 9 | 10 | #define __SOCKADDR_COMMON_SIZE (sizeof (unsigned short int)) 11 | 12 | #endif /** __QUARK_BITS_SOCKADDR_H */ 13 | -------------------------------------------------------------------------------- /include/bits/waitflags.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_BITS_WAITFLAGS_H 3 | #define __QKC_BITS_WAITFLAGS_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | 10 | /* Bits in the third argument to `waitpid'. */ 11 | #define WNOHANG 1 /* Don't block waiting. */ 12 | #define WUNTRACED 2 /* Report status of stopped children. */ 13 | 14 | /* Bits in the fourth argument to `waitid'. */ 15 | #define WSTOPPED 2 /* Report stopped child (same as WUNTRACED). */ 16 | #define WEXITED 4 /* Report dead child. */ 17 | #define WCONTINUED 8 /* Report continued child. */ 18 | #define WNOWAIT 0x01000000 /* Don't reap, just poll status. */ 19 | 20 | #define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads 21 | in this group */ 22 | #define __WALL 0x40000000 /* Wait for any child. */ 23 | #define __WCLONE 0x80000000 /* Wait for cloned process. */ 24 | 25 | __END_DECLS 26 | 27 | #endif /** __QKC_BITS_WAITFLAGS_H */ 28 | -------------------------------------------------------------------------------- /include/bits/wordsize.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_BITS_WORDSIZE_H 3 | #define __QUARK_BITS_WORDSIZE_H 1 4 | 5 | 6 | #if defined(_WIN32) || defined(WIN32) 7 | #define __WORDSIZE 32 8 | #endif 9 | 10 | #if defined(_WIN64) || defined(WIN64) 11 | #if defined(__WORDSIZE) 12 | #undef __WORDSIZE 13 | #endif 14 | 15 | #define __WORDSIZE 64 16 | #endif 17 | 18 | #endif /** __QUARK_BITS_WORDSIZE_H */ 19 | -------------------------------------------------------------------------------- /include/builtin.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/builtin.h -------------------------------------------------------------------------------- /include/byteswap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_BYTESWAP_H 3 | #define __QKC_BYTESWAP_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | QKCAPI uint16_t bswap_16 (uint16_t x) ; 11 | QKCAPI uint32_t bswap_32 (uint32_t x) ; 12 | QKCAPI uint64_t bswap_64 (uint64_t x) ; 13 | 14 | __END_DECLS 15 | 16 | #endif /* __QKC_BYTESWAP_H */ 17 | -------------------------------------------------------------------------------- /include/ctype.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_CTYPE_H 3 | #define __QKC_CTYPE_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | QUARK_LINKAGE int isalnum (int c) ; 10 | QUARK_LINKAGE int isalpha (int c) ; 11 | QUARK_LINKAGE int iscntrl (int c) ; 12 | QUARK_LINKAGE int isdigit (int c) ; 13 | QUARK_LINKAGE int islower (int c) ; 14 | 15 | QUARK_LINKAGE int isgraph (int c) ; 16 | QUARK_LINKAGE int isprint (int c) ; 17 | QUARK_LINKAGE int ispunct (int c) ; 18 | QUARK_LINKAGE int isspace (int c) ; 19 | QUARK_LINKAGE int isupper (int c) ; 20 | 21 | QUARK_LINKAGE int isxdigit (int c) ; 22 | QKCAPI int isblank (int c) ; 23 | 24 | 25 | QUARK_LINKAGE int tolower (int c) ; 26 | QUARK_LINKAGE int toupper (int c) ; 27 | 28 | QKCAPI int isctype (int c , int mask); 29 | 30 | __END_DECLS 31 | 32 | #endif /** __QKC_CTYPE_H */ 33 | -------------------------------------------------------------------------------- /include/dirent.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/dirent.h -------------------------------------------------------------------------------- /include/dlfcn.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/dlfcn.h -------------------------------------------------------------------------------- /include/endian.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_ENDIAN_H 2 | #define __QKC_ENDIAN_H 1 3 | 4 | #include 5 | 6 | __BEGIN_DECLS 7 | 8 | static inline bool is_little_endian() 9 | { 10 | static bool __little_endian__ = true ; 11 | static bool __endian_inited__ = false ; 12 | 13 | if(__endian_inited__ == false) 14 | { 15 | int val = 1 ; 16 | __little_endian__ = ((*((char *)&val)) == 1) ; 17 | __endian_inited__ = true ; 18 | } 19 | 20 | return __little_endian__ ; 21 | } 22 | 23 | __END_DECLS 24 | 25 | #endif /** __QKC_ENDIAN_H */ -------------------------------------------------------------------------------- /include/fcntl.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/fcntl.h -------------------------------------------------------------------------------- /include/getopt.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_GETOPT_H 3 | #define __QKC_GETOPT_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | extern char *optarg; 10 | extern int optind; 11 | extern int opterr; 12 | extern int optopt; 13 | 14 | QKCAPI int getopt (int argc , char *const *argv, const char *shortopts) ; 15 | 16 | __END_DECLS 17 | 18 | 19 | #endif /* __QKC_GETOPT_H */ 20 | -------------------------------------------------------------------------------- /include/grp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_GRP_H 3 | #define __QKC_GRP_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | 11 | struct group 12 | { 13 | char *gr_name; /* Group name. */ 14 | char *gr_passwd; /* Password. */ 15 | gid_t gr_gid; /* Group ID. */ 16 | char **gr_mem; /* Member list. */ 17 | }; 18 | 19 | QKCAPI void setgrent (void); 20 | 21 | QKCAPI struct group *getgrgid (gid_t gid); 22 | 23 | QKCAPI struct group *getgrnam (const char *name); 24 | 25 | QKCAPI int setgroups (size_t n, const gid_t *groups) ; 26 | 27 | QKCAPI int initgroups (const char *user, gid_t group); 28 | 29 | __END_DECLS 30 | 31 | #endif /** __QKC_GRP_H */ 32 | -------------------------------------------------------------------------------- /include/iconv.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/iconv.h -------------------------------------------------------------------------------- /include/ifaddrs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_IFADDRS_H 3 | #define __QKC_IFADDRS_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | struct ifaddrs 11 | { 12 | struct ifaddrs *ifa_next; 13 | 14 | char *ifa_name; 15 | unsigned int ifa_flags; 16 | 17 | struct sockaddr *ifa_addr; 18 | struct sockaddr *ifa_netmask; 19 | union 20 | { 21 | struct sockaddr *ifu_broadaddr; 22 | struct sockaddr *ifu_dstaddr; 23 | } ifa_ifu; 24 | # ifndef ifa_broadaddr 25 | # define ifa_broadaddr ifa_ifu.ifu_broadaddr 26 | # endif 27 | # ifndef ifa_dstaddr 28 | # define ifa_dstaddr ifa_ifu.ifu_dstaddr 29 | # endif 30 | 31 | void *ifa_data; 32 | }; 33 | 34 | QKCAPI int getifaddrs (struct ifaddrs **ifap) ; 35 | QKCAPI void freeifaddrs (struct ifaddrs * ifa) ; 36 | 37 | __END_DECLS 38 | 39 | #endif /** __QKC_IFADDRS_H */ 40 | -------------------------------------------------------------------------------- /include/locale.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_LOCALE_H 2 | #define __QKC_LOCALE_H 1 3 | 4 | #include 5 | 6 | 7 | __BEGIN_DECLS 8 | 9 | 10 | __END_DECLS 11 | 12 | #endif /** __QKC_LOCALE_H */ 13 | -------------------------------------------------------------------------------- /include/math.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_MATH_H 3 | #define __QKC_MATH_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | QUARK_LINKAGE int abs(int x); 10 | QUARK_LINKAGE long labs(long x); 11 | 12 | QUARK_LINKAGE double acos(double x); 13 | QUARK_LINKAGE double asin(double x); 14 | QUARK_LINKAGE double atan(double x); 15 | QUARK_LINKAGE double atan2(double y, double x); 16 | 17 | QUARK_LINKAGE double cos(double x); 18 | QUARK_LINKAGE double cosh(double x); 19 | QUARK_LINKAGE double exp(double x); 20 | QUARK_LINKAGE double fabs(double x); 21 | QUARK_LINKAGE double fmod(double x, double y); 22 | QUARK_LINKAGE double log(double x); 23 | QUARK_LINKAGE double log10(double x); 24 | QUARK_LINKAGE double pow(double x, double y); 25 | QUARK_LINKAGE double sin(double x); 26 | QUARK_LINKAGE double sinh(double x); 27 | QUARK_LINKAGE double tan(double x); 28 | QUARK_LINKAGE double tanh(double x); 29 | QUARK_LINKAGE double sqrt(double x); 30 | QUARK_LINKAGE double atof(const char *str); 31 | QUARK_LINKAGE double ceil(double x); 32 | QUARK_LINKAGE double floor(double x); 33 | QUARK_LINKAGE double frexp(double x, int * y); 34 | 35 | QKCAPI double round(double x) ; 36 | 37 | __END_DECLS 38 | 39 | #endif /**__QKC_MATH_H*/ 40 | 41 | -------------------------------------------------------------------------------- /include/netdb.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __QKC_NETDB_H 4 | #define __QKC_NETDB_H 1 5 | 6 | #include 7 | #include 8 | 9 | __BEGIN_DECLS 10 | 11 | struct addrinfo 12 | { 13 | int ai_flags; /* Input flags. */ 14 | int ai_family; /* Protocol family for socket. */ 15 | int ai_socktype; /* Socket type. */ 16 | int ai_protocol; /* Protocol for socket. */ 17 | socklen_t ai_addrlen; /* Length of socket address. */ 18 | struct sockaddr *ai_addr; /* Socket address for socket. */ 19 | char *ai_canonname; /* Canonical name for service location. */ 20 | struct addrinfo *ai_next; /* Pointer to next in list. */ 21 | }; 22 | 23 | QKCAPI int getaddrinfo (const char *name,const char *service,const struct addrinfo *req,struct addrinfo **pai); 24 | 25 | QKCAPI void freeaddrinfo (struct addrinfo * ai) ; 26 | 27 | QKCAPI int getnameinfo (const struct sockaddr *sa,socklen_t salen, char *host, socklen_t hostlen, 28 | char *serv, socklen_t servlen, int flags); 29 | 30 | __END_DECLS 31 | 32 | #endif /** __QKC_NETDB_H */ 33 | -------------------------------------------------------------------------------- /include/netinet/udp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_NETINET_UDP_H 3 | #define __QKC_NETINET_UDP_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | #define SOL_UDP 17 /* sockopt level for UDP */ 11 | 12 | __END_DECLS 13 | 14 | #endif /** __QKC_NETINET_UDP_H */ 15 | -------------------------------------------------------------------------------- /include/netpacket/packet.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_NETPACKET_PACKET_H 3 | #define __QKC_NETPACKET_PACKET_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | struct sockaddr_ll 10 | { 11 | unsigned short int sll_family; 12 | unsigned short int sll_protocol; 13 | int sll_ifindex; 14 | unsigned short int sll_hatype; 15 | unsigned char sll_pkttype; 16 | unsigned char sll_halen; 17 | unsigned char sll_addr[8]; 18 | }; 19 | 20 | /* Packet types. */ 21 | 22 | #define PACKET_HOST 0 /* To us. */ 23 | #define PACKET_BROADCAST 1 /* To all. */ 24 | #define PACKET_MULTICAST 2 /* To group. */ 25 | #define PACKET_OTHERHOST 3 /* To someone else. */ 26 | #define PACKET_OUTGOING 4 /* Originated by us . */ 27 | #define PACKET_LOOPBACK 5 28 | #define PACKET_FASTROUTE 6 29 | 30 | /* Packet socket options. */ 31 | 32 | #define PACKET_ADD_MEMBERSHIP 1 33 | #define PACKET_DROP_MEMBERSHIP 2 34 | #define PACKET_RECV_OUTPUT 3 35 | #define PACKET_RX_RING 5 36 | #define PACKET_STATISTICS 6 37 | 38 | struct packet_mreq 39 | { 40 | int mr_ifindex; 41 | unsigned short int mr_type; 42 | unsigned short int mr_alen; 43 | unsigned char mr_address[8]; 44 | }; 45 | 46 | #define PACKET_MR_MULTICAST 0 47 | #define PACKET_MR_PROMISC 1 48 | #define PACKET_MR_ALLMULTI 2 49 | 50 | __END_DECLS 51 | 52 | #endif /** __QKC_NETPACKET_PACKET_H */ 53 | -------------------------------------------------------------------------------- /include/poll.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/pthread.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/pthread.h -------------------------------------------------------------------------------- /include/pwd.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_PWD_H 3 | #define __QKC_PWD_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | 11 | struct passwd 12 | { 13 | char *pw_name; /* Username. */ 14 | char *pw_passwd; /* Password. */ 15 | uid_t pw_uid; /* User ID. */ 16 | gid_t pw_gid; /* Group ID. */ 17 | char *pw_gecos; /* Real name. */ 18 | char *pw_dir; /* Home directory. */ 19 | char *pw_shell; /* Shell program. */ 20 | }; 21 | 22 | 23 | QKCAPI void setpwent (void); 24 | 25 | QKCAPI void endpwent (void); 26 | 27 | QKCAPI struct passwd *getpwent (void); 28 | 29 | QKCAPI struct passwd *getpwuid (uid_t uid); 30 | 31 | QKCAPI struct passwd *getpwnam (const char * name); 32 | 33 | QKCAPI int getpw (uid_t uid, char *buffer); 34 | 35 | QKCAPI int getpwuid_r(uid_t uid,struct passwd * resultbuf, 36 | char * buffer, size_t buflen,struct passwd **_result); 37 | 38 | 39 | __END_DECLS 40 | 41 | #endif /** __QKC_PWD_H */ -------------------------------------------------------------------------------- /include/quark_compile.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/quark_compile.h -------------------------------------------------------------------------------- /include/sched.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/sched.h -------------------------------------------------------------------------------- /include/semaphore.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/semaphore.h -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_STDARG_H 3 | #define __QKC_STDARG_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | #ifndef _VA_LIST_DEFINED 10 | typedef char * va_list; 11 | #define _VA_LIST_DEFINED 12 | #endif /* _VA_LIST_DEFINED */ 13 | 14 | #ifdef __cplusplus 15 | #define _ADDRESSOF(v) ( &reinterpret_cast(v) ) 16 | #else 17 | #define _ADDRESSOF(v) ( &(v) ) 18 | #endif 19 | 20 | #define _SLOTSIZEOF(t) (sizeof(t)) 21 | #define _APALIGN(t,ap) (__alignof(t)) 22 | 23 | #if defined (_M_IX86) 24 | 25 | #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) ) 26 | 27 | #define _crt_va_start(ap,v) ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) ) 28 | #define _crt_va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) ) 29 | #define _crt_va_end(ap) ( ap = (va_list)0 ) 30 | 31 | #elif defined (_M_AMD64) 32 | extern void __cdecl __va_start(va_list *, ...) ; 33 | 34 | #define _crt_va_start(ap, x) ( __va_start(&ap, x) ) 35 | #define _crt_va_arg(ap, t) \ 36 | ( ( sizeof(t) > sizeof(__int64) || ( sizeof(t) & (sizeof(t) - 1) ) != 0 ) \ 37 | ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \ 38 | : *(t *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) ) 39 | #define _crt_va_end(ap) ( ap = (va_list)0 ) 40 | #endif 41 | 42 | #define va_start _crt_va_start 43 | #define va_arg _crt_va_arg 44 | #define va_end _crt_va_end 45 | 46 | __END_DECLS 47 | 48 | #endif /* __QKC_STDARG_H */ 49 | -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_STDBOOL_H 3 | #define __QKC_STDBOOL_H 1 4 | 5 | #include 6 | 7 | #ifndef __cplusplus 8 | 9 | typedef int bool ; 10 | 11 | #define false 0 12 | #define true 1 13 | 14 | #endif 15 | 16 | #endif /* __QKC_STDBOOL_H */ 17 | 18 | 19 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_STDDEF_H 3 | #define __QKC_STDDEF_H 1 4 | 5 | 6 | #ifdef container_of 7 | #undef container_of 8 | #endif 9 | 10 | #define container_of(ptr, type, member) ((type *) ((char *) (ptr) - offsetof(type, member))) 11 | 12 | 13 | #ifdef offsetof 14 | #undef offsetof 15 | #endif 16 | 17 | #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) 18 | 19 | 20 | #endif /** __QKC_STDDEF_H */ 21 | -------------------------------------------------------------------------------- /include/stdlib.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/stdlib.h -------------------------------------------------------------------------------- /include/strings.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/strings.h -------------------------------------------------------------------------------- /include/sys/ipc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/sys/ipc.h -------------------------------------------------------------------------------- /include/sys/mman.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/sys/mman.h -------------------------------------------------------------------------------- /include/sys/poll.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_SYS_POLL_H 3 | #define __QKC_SYS_POLL_H 1 4 | 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | #define POLLIN 0x001 /* There is data to read. */ 10 | #define POLLPRI 0x002 /* There is urgent data to read. */ 11 | #define POLLOUT 0x004 /* Writing now will not block. */ 12 | 13 | #define POLLRDNORM 0x040 /* Normal data may be read. */ 14 | #define POLLRDBAND 0x080 /* Priority data may be read. */ 15 | #define POLLWRNORM 0x100 /* Writing now will not block. */ 16 | #define POLLWRBAND 0x200 /* Priority data may be written. */ 17 | #define POLLMSG 0x400 18 | #define POLLREMOVE 0x1000 19 | #define POLLRDHUP 0x2000 20 | #define POLLERR 0x008 /* Error condition. */ 21 | #define POLLHUP 0x010 /* Hung up. */ 22 | #define POLLNVAL 0x020 /* Invalid polling request. */ 23 | 24 | 25 | typedef unsigned long int nfds_t; 26 | 27 | struct pollfd 28 | { 29 | int fd; /* File descriptor to poll. */ 30 | short int events; /* Types of events poller cares about. */ 31 | short int revents; /* Types of events that actually occurred. */ 32 | }; 33 | 34 | 35 | QKCAPI int poll (struct pollfd * fds, nfds_t nfds, int timeout); 36 | 37 | __END_DECLS 38 | 39 | #endif /** __QKC_SYS_POLL_H */ 40 | -------------------------------------------------------------------------------- /include/sys/prctl.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_SYS_PRCTL_H 2 | #define __QKC_SYS_PRCTL_H 1 3 | 4 | #include 5 | 6 | 7 | __BEGIN_DECLS 8 | 9 | 10 | __END_DECLS 11 | 12 | 13 | #endif /** __QKC_SYS_PRCTL_H */ 14 | -------------------------------------------------------------------------------- /include/sys/select.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_SYS_SELECT_H 3 | #define __QKC_SYS_SELECT_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | typedef long int __fd_mask; 11 | 12 | #define __FD_SETSIZE 1024 13 | #define __NFDBITS (8 * (int) sizeof (__fd_mask)) 14 | #define __FD_ELT(d) ((d) / __NFDBITS) 15 | #define __FD_MASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS)) 16 | 17 | typedef struct 18 | { 19 | __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS]; 20 | # define __FDS_BITS(set) ((set)->__fds_bits) 21 | } fd_set; 22 | 23 | #define FD_SETSIZE __FD_SETSIZE 24 | 25 | typedef __fd_mask fd_mask; 26 | # define NFDBITS __NFDBITS 27 | 28 | 29 | #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp) 30 | #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp) 31 | #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp) 32 | #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp) 33 | 34 | 35 | QKCAPI int select (int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval *timeout); 36 | 37 | __END_DECLS 38 | 39 | #endif /** __QKC_SYS_SELECT_H */ 40 | -------------------------------------------------------------------------------- /include/sys/sendfile.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_SYS_SENDFILE_H 2 | #define __QKC_SYS_SENDFILE_H 1 3 | 4 | #include 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | QKCAPI ssize_t sendfile(int out_fd , int in_fd , off_t * offset , size_t count) ; 10 | 11 | QKCAPI ssize_t sendfile64(int out_fd , int in_fd , off64_t * offset , size_t count) ; 12 | 13 | __END_DECLS 14 | 15 | 16 | #endif /** __QKC_SYS_SENDFILE_H */ 17 | -------------------------------------------------------------------------------- /include/sys/shm.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/sys/shm.h -------------------------------------------------------------------------------- /include/sys/signal.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /include/sys/sysinfo.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_SYS_SYSINFO_H 3 | #define __QKC_SYS_SYSINFO_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | struct sysinfo { 11 | long uptime; /* Seconds since boot */ 12 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ 13 | unsigned long totalram; /* Total usable main memory size */ 14 | unsigned long freeram; /* Available memory size */ 15 | unsigned long sharedram; /* Amount of shared memory */ 16 | unsigned long bufferram; /* Memory used by buffers */ 17 | unsigned long totalswap; /* Total swap space size */ 18 | unsigned long freeswap; /* swap space still available */ 19 | unsigned short procs; /* Number of current processes */ 20 | unsigned long totalhigh; /* Total high memory size */ 21 | unsigned long freehigh; /* Available high memory size */ 22 | unsigned int mem_unit; /* Memory unit size in bytes */ 23 | char __f[10]; /* Pads structure to 64 bytes */ 24 | }; 25 | 26 | QKCAPI int sysinfo (struct sysinfo * info) ; 27 | QKCAPI int get_nprocs_conf (void) ; 28 | QKCAPI int get_nprocs (void) ; 29 | QKCAPI long int get_phys_pages (void) ; 30 | QKCAPI long int get_avphys_pages (void) ; 31 | 32 | __END_DECLS 33 | 34 | #endif /** __QKC_SYS_SYSINFO_H */ 35 | -------------------------------------------------------------------------------- /include/sys/time.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_SYS_TIME_H 3 | #define __QKC_SYS_TIME_H 1 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | //#define CLOCKS_PER_SEC 1000000l 11 | 12 | /* Identifier for system-wide realtime clock. */ 13 | #define CLOCK_REALTIME 0 14 | /* Monotonic system-wide clock. */ 15 | #define CLOCK_MONOTONIC 1 16 | /* High-resolution timer from the CPU. */ 17 | #define CLOCK_PROCESS_CPUTIME_ID 2 18 | /* Thread-specific CPU-time clock. */ 19 | #define CLOCK_THREAD_CPUTIME_ID 3 20 | 21 | /* Flag to indicate time is absolute. */ 22 | #define TIMER_ABSTIME 1 23 | 24 | __BEGIN_DECLS 25 | 26 | QKCAPI int gettimeofday (struct timeval * tv , void * tz) ; 27 | 28 | QKCAPI int utimes (const char * file, const struct timeval tvp[2]) ; 29 | 30 | 31 | __END_DECLS 32 | 33 | #endif /** __QKC_SYS_TIME_H */ 34 | -------------------------------------------------------------------------------- /include/sys/timeb.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_SYS_TIMEB_H 3 | #define __QKC_SYS_TIMEB_H 1 4 | 5 | #include 6 | 7 | #endif /**__QKC_SYS_TIMEB_H*/ 8 | 9 | -------------------------------------------------------------------------------- /include/sys/times.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/sys/times.h -------------------------------------------------------------------------------- /include/sys/types.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_SYS_TYPES_H 3 | #define __QKC_SYS_TYPES_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | 11 | typedef long int long_t ; 12 | typedef unsigned long int ulong_t ; 13 | 14 | typedef int64_t quad_t ; 15 | typedef uint64_t uquad_t ; 16 | 17 | typedef uint32_t uid_t ; 18 | typedef uint32_t gid_t ; 19 | typedef ulong_t dev_t ; 20 | typedef ulong_t ino_t ; 21 | typedef uquad_t ino64_t ; 22 | typedef uint32_t mode_t; 23 | typedef long_t off_t ; 24 | typedef quad_t off64_t ; 25 | typedef quad_t fpos_t ; 26 | typedef int32_t pid_t ; 27 | typedef quad_t clock_t ; 28 | typedef long_t ssize_t ; 29 | typedef uint32_t useconds_t ; 30 | typedef long_t suseconds_t ; 31 | typedef int64_t time_t ; 32 | typedef int32_t key_t ; 33 | typedef int32_t clockid_t ; 34 | typedef uint32_t socklen_t ; 35 | typedef ulong_t nlink_t ; 36 | 37 | 38 | __END_DECLS 39 | 40 | #endif /** __QKC_SYS_TYPES_H */ 41 | -------------------------------------------------------------------------------- /include/sys/uio.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/sys/uio.h -------------------------------------------------------------------------------- /include/sys/un.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_SYS_UN_H 2 | #define __QKC_SYS_UN_H 1 3 | 4 | #include 5 | 6 | __BEGIN_DECLS 7 | 8 | typedef unsigned short int sa_family_t; 9 | 10 | struct sockaddr_un 11 | { 12 | sa_family_t sun_family ; 13 | char sun_path[108]; /* Path name. */ 14 | }; 15 | 16 | __END_DECLS 17 | 18 | #endif /** __QKC_SYS_UN_H */ 19 | -------------------------------------------------------------------------------- /include/sys/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_SYS_UNISTD_H 2 | #define __QKC_SYS_UNISTD_H 1 3 | 4 | #include 5 | 6 | #include 7 | 8 | 9 | #endif /** __QKC_SYS_UNISTD_H */ 10 | -------------------------------------------------------------------------------- /include/sys/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_SYS_WAIT_H 2 | #define __QKC_SYS_WAIT_H 1 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | # define __WAIT_INT(status) (status) 11 | # define __WAIT_STATUS int * 12 | # define __WAIT_STATUS_DEFN int * 13 | 14 | #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) 15 | #define __WTERMSIG(status) ((status) & 0x7f) 16 | #define __WSTOPSIG(status) __WEXITSTATUS(status) 17 | #define __WIFEXITED(status) (__WTERMSIG(status) == 0) 18 | #define __WIFSIGNALED(status) (((signed char) (((status) & 0x7f) + 1) >> 1) > 0) 19 | #define __WIFSTOPPED(status) (((status) & 0xff) == 0x7f) 20 | #define __WCOREDUMP(status) ((status) & __WCOREFLAG) 21 | 22 | #define __W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 23 | #define __W_STOPCODE(sig) ((sig) << 8 | 0x7f) 24 | #define __W_CONTINUED 0xffff 25 | #define __WCOREFLAG 0x80 26 | 27 | # define WEXITSTATUS(status) __WEXITSTATUS(__WAIT_INT(status)) 28 | # define WTERMSIG(status) __WTERMSIG(__WAIT_INT(status)) 29 | # define WSTOPSIG(status) __WSTOPSIG(__WAIT_INT(status)) 30 | # define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status)) 31 | # define WIFSIGNALED(status) __WIFSIGNALED(__WAIT_INT(status)) 32 | # define WIFSTOPPED(status) __WIFSTOPPED(__WAIT_INT(status)) 33 | 34 | QKCAPI pid_t wait (__WAIT_STATUS stat_loc); 35 | QKCAPI pid_t waitpid (pid_t pid, int * stat_loc, int options); 36 | 37 | __END_DECLS 38 | 39 | #endif /** __QKC_SYS_WAIT_H */ 40 | 41 | -------------------------------------------------------------------------------- /include/syscall.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/syscall.h -------------------------------------------------------------------------------- /include/syslog.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_SYSLOG_H 2 | #define __QKC_SYSLOG_H 1 3 | 4 | #include 5 | #include 6 | 7 | #endif /** __QKC_SYS_SYSLOG_H*/ 8 | -------------------------------------------------------------------------------- /include/termios.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef __QKC_TERMIOS_H 4 | #define __QKC_TERMIOS_H 1 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | __BEGIN_DECLS 11 | 12 | QKCAPI int tcgetattr (int fd, struct termios * termios_p) ; 13 | 14 | QKCAPI int tcsetattr (int fd, int optional_actions, const struct termios * termios_p) ; 15 | 16 | QKCAPI void cfmakeraw (struct termios *termios_p) ; 17 | 18 | QKCAPI int tcsendbreak (int fd, int duration) ; 19 | 20 | QKCAPI int tcdrain (int fd); 21 | 22 | QKCAPI int tcflush (int fd, int queue_selector) ; 23 | 24 | QKCAPI int tcflow (int fd, int action) ; 25 | 26 | QKCAPI pid_t tcgetsid (int fd) ; 27 | 28 | __END_DECLS 29 | 30 | #endif /** __QKC_TERMIOS_H */ 31 | -------------------------------------------------------------------------------- /include/unistd.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/unistd.h -------------------------------------------------------------------------------- /include/utime.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_UTIME_H 3 | #define __QKC_UTIME_H 1 4 | 5 | #include 6 | #include 7 | 8 | __BEGIN_DECLS 9 | 10 | struct utimbuf 11 | { 12 | time_t actime; /* Access time. */ 13 | time_t modtime; /* Modification time. */ 14 | }; 15 | 16 | QKCAPI int utime (const char * file, const struct utimbuf * file_times); 17 | 18 | __END_DECLS 19 | 20 | #endif /** __QKC_UTIME_H */ 21 | -------------------------------------------------------------------------------- /include/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef __QKC_WAIT_H 2 | #define __QKC_WAIT_H 1 3 | 4 | #include 5 | 6 | #endif /** __QKC_WAIT_H */ 7 | 8 | -------------------------------------------------------------------------------- /include/wimpl/IOCPMgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wimpl/IOCPMgr.h -------------------------------------------------------------------------------- /include/wimpl/MMapMgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wimpl/MMapMgr.h -------------------------------------------------------------------------------- /include/wimpl/PThreadCond.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wimpl/PThreadCond.h -------------------------------------------------------------------------------- /include/wimpl/PThreadMutex.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wimpl/PThreadMutex.h -------------------------------------------------------------------------------- /include/wimpl/PThreadRWLocker.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wimpl/PThreadRWLocker.h -------------------------------------------------------------------------------- /include/wintf/wipc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wintf/wipc.h -------------------------------------------------------------------------------- /include/wobjs/AddrMgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/AddrMgr.h -------------------------------------------------------------------------------- /include/wobjs/AdvAPI32Loader.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_ADVAPI32_LOADER_H 3 | #define __QUARK_WOBJS_ADVAPI32_LOADER_H 1 4 | 5 | #include 6 | #include 7 | #include "wobjs/DllLoader.h" 8 | 9 | namespace qkc { 10 | 11 | class QKCAPI AdvAPI32Loader : public DllLoader { 12 | public: 13 | AdvAPI32Loader(); 14 | virtual ~AdvAPI32Loader(); 15 | 16 | virtual bool Init(); 17 | virtual void Final(); 18 | 19 | typedef BOOL(WINAPI*LPFN_GETUSERNAMEW)(LPWSTR buffer, LPDWORD size); 20 | typedef BOOL(WINAPI*LPFN_OPENPROCESSTOKEN)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle); 21 | 22 | int GetUserName(char * name , int size); 23 | bool GetProcessToken(HANDLE& token); 24 | 25 | static const char * kDllName; 26 | static AdvAPI32Loader Singleton; 27 | 28 | private: 29 | LPFN_GETUSERNAMEW lpfnGetUserName_; 30 | LPFN_OPENPROCESSTOKEN lpfnOpenProcessToken_; 31 | }; 32 | 33 | } 34 | 35 | #endif /** __QUARK_WOBJS_ADVAPI32_LOADER_H */ 36 | -------------------------------------------------------------------------------- /include/wobjs/AtomicCounter.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_ATOMIC_COUNTER_H 3 | #define __QUARK_WOBJS_ATOMIC_COUNTER_H 1 4 | 5 | #include 6 | #include 7 | 8 | namespace qkc { 9 | 10 | class QKCAPI AtomicCounter{ 11 | public: 12 | AtomicCounter(); 13 | virtual ~AtomicCounter(); 14 | 15 | LONG Increment(); 16 | LONG Decrement(); 17 | LONG Value() const; 18 | 19 | private: 20 | AtomicCounter(const AtomicCounter& counter); 21 | AtomicCounter& operator=(const AtomicCounter& counter); 22 | mutable volatile LONG value_; 23 | }; 24 | } 25 | 26 | #endif /** __QUARK_WOBJS_ATOMIC_COUNTER_H */ 27 | -------------------------------------------------------------------------------- /include/wobjs/BitOP.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_BIT_OP_H 3 | #define __QUARK_WOBJS_BIT_OP_H 1 4 | 5 | #include 6 | #include 7 | 8 | namespace qkc { 9 | 10 | static inline bool BitOPIn(uint32_t val, uint32_t mask) { return ((val & mask) == mask); } 11 | static inline void BitOPSet(uint32_t& val, uint32_t mask) { val |= mask; } 12 | static inline uint32_t BitOPGet(uint32_t val, uint32_t mask) { return (val &= mask); } 13 | static inline void BitOPClear(uint32_t& val, uint32_t mask) { val &= ~mask; } 14 | static inline void BitOPReverse(uint32_t val, uint32_t mask) { val ^= mask; } 15 | 16 | } 17 | 18 | #endif /** __QUARK_WOBJS_BIT_OP_H */ 19 | -------------------------------------------------------------------------------- /include/wobjs/Condition.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_CONDITION_H 3 | #define __QUARK_WOBJS_CONDITION_H 1 4 | 5 | #include 6 | #include 7 | #include "wobjs/Object.h" 8 | #include "wobjs/Mutex.h" 9 | #include "wobjs/SemaphoreW.h" 10 | 11 | namespace qkc { 12 | 13 | class QKCAPI Condition : public Object { 14 | public: 15 | Condition(); 16 | virtual ~Condition(); 17 | 18 | int Notify(); 19 | int Broadcast(); 20 | int Wait(Mutex& locker); 21 | int TimedWait(Mutex& locker , int timeout); 22 | protected: 23 | void SetInfo(); 24 | private: 25 | Condition(const Condition& locker); 26 | Condition& operator=(const Condition& locker); 27 | Mutex guard_; 28 | Semaphore sema_; 29 | }; 30 | } 31 | 32 | #endif /** __QUARK_WOBJS_CONDITION_H */ 33 | -------------------------------------------------------------------------------- /include/wobjs/CrtLinker.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/CrtLinker.h -------------------------------------------------------------------------------- /include/wobjs/CrtLoader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/CrtLoader.h -------------------------------------------------------------------------------- /include/wobjs/DateTime.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/DateTime.h -------------------------------------------------------------------------------- /include/wobjs/DllInit.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_DLL_INIT_H 3 | #define __QUARK_WOBJS_DLL_INIT_H 1 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace qkc { 10 | 11 | QKCAPI uintptr_t GetThisDllHandle(); 12 | QKCAPI void SetThisDllHandle(uintptr_t handle); 13 | 14 | 15 | } 16 | 17 | #endif /** __QUARK_WOBJS_DLL_INIT_H */ 18 | -------------------------------------------------------------------------------- /include/wobjs/DllLoader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/DllLoader.h -------------------------------------------------------------------------------- /include/wobjs/ErrorMap.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_ERROR_MAP_H 3 | #define __QUARK_WOBJS_ERROR_MAP_H 1 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | __BEGIN_DECLS 11 | 12 | QKCAPI int oserr_map(DWORD oserr); 13 | 14 | __END_DECLS 15 | 16 | #endif /** __QUARK_WOBJS_ERROR_MAP_H */ 17 | -------------------------------------------------------------------------------- /include/wobjs/FileSystem.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/FileSystem.h -------------------------------------------------------------------------------- /include/wobjs/FileSystemDevNull.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_FILE_SYSTEM_DEV_NULL_H 3 | #define __QUARK_WOBJS_FILE_SYSTEM_DEV_NULL_H 1 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "wobjs/FileSystem.h" 13 | 14 | namespace qkc { 15 | 16 | class QKCAPI FileSystemDevNull : public FileSystem { 17 | public: 18 | FileSystemDevNull(); 19 | virtual ~FileSystemDevNull(); 20 | 21 | virtual int Create(const char * file, mode_t mode); 22 | virtual int Open(const char * path, int oflag, ...); 23 | virtual void Close(int fd); 24 | virtual int FCntl(int fd, int cmd, ...); 25 | 26 | virtual ssize_t Write(int fd, const void * buf, size_t bytes); 27 | virtual ssize_t Read(int fd, void * buf, size_t bytes); 28 | virtual int Dup(int fd); 29 | virtual int Dup2(int fd1, int fd2); 30 | virtual int LSeek(int fd, off_t offset, int whence); 31 | virtual int FStat(int fd, struct stat * stat); 32 | 33 | static const char * kName; 34 | }; 35 | 36 | } 37 | 38 | #endif /** __QUARK_WOBJS_FILE_SYSTEM_DEV_NULL_H */ 39 | -------------------------------------------------------------------------------- /include/wobjs/GlobalLocker.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/GlobalLocker.h -------------------------------------------------------------------------------- /include/wobjs/Hash.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_HASH_H 3 | #define __QUARK_WOBJS_HASH_H 1 4 | 5 | #include 6 | #include 7 | 8 | namespace qkc { 9 | 10 | QKCAPI uint32_t HashTime33(const char * str, int size, uint32_t hash); 11 | 12 | } 13 | 14 | #endif /** __QUARK_WOBJS_HASH_H */ 15 | -------------------------------------------------------------------------------- /include/wobjs/INotifyMgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/INotifyMgr.h -------------------------------------------------------------------------------- /include/wobjs/IOCPMgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/IOCPMgr.h -------------------------------------------------------------------------------- /include/wobjs/LargePageMap.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/LargePageMap.h -------------------------------------------------------------------------------- /include/wobjs/MemMgr.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_MEM_MGR_H 3 | #define __QUARK_WOBJS_MEM_MGR_H 1 4 | 5 | #include 6 | 7 | namespace qkc { 8 | 9 | class QKCAPI MemMgr { 10 | public: 11 | MemMgr(); 12 | virtual ~MemMgr(); 13 | 14 | virtual void * Alloc(size_t size , bool zeroed = false); 15 | virtual void Free(void * addr); 16 | 17 | static MemMgr * Default(); 18 | static void Default(MemMgr * mgr); 19 | 20 | static MemMgr Singleton; 21 | }; 22 | 23 | QKCAPI void * MemAlloc(size_t size, bool zeroed = false); 24 | QKCAPI void MemFree(void * addr); 25 | } 26 | 27 | #endif /** __QUARK_WOBJS_MEM_MGR_H */ 28 | -------------------------------------------------------------------------------- /include/wobjs/Mutex.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_MUTEX_H 3 | #define __QUARK_WOBJS_MUTEX_H 1 4 | 5 | #include 6 | #include 7 | #include "wobjs/Object.h" 8 | 9 | namespace qkc { 10 | 11 | class QKCAPI Mutex : public Object { 12 | public: 13 | Mutex(); 14 | virtual ~Mutex(); 15 | 16 | int Lock(); 17 | int TryLock(); 18 | int TimedLock(int msec); 19 | int Unlock(); 20 | 21 | class QKCAPI ScopedLock { 22 | public: 23 | ScopedLock(Mutex& locker) : locker_(locker) { locker_.Lock(); } 24 | ~ScopedLock() { locker_.Unlock(); } 25 | private: 26 | ScopedLock(const ScopedLock& locker); 27 | ScopedLock& operator=(const ScopedLock&); 28 | 29 | Mutex& locker_; 30 | }; 31 | 32 | protected: 33 | void SetInfo(); 34 | private: 35 | Mutex(const Mutex& locker); 36 | Mutex& operator=(const Mutex& locker); 37 | HANDLE handle_; 38 | }; 39 | } 40 | 41 | #endif /** __QUARK_WOBJS_MUTEX_H */ 42 | -------------------------------------------------------------------------------- /include/wobjs/ObjMgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/ObjMgr.h -------------------------------------------------------------------------------- /include/wobjs/Object.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/Object.h -------------------------------------------------------------------------------- /include/wobjs/ProcessMemoryInfo.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_PROCESS_MEMORY_INFO_H 3 | #define __QUARK_WOBJS_PROCESS_MEMORY_INFO_H 1 4 | 5 | #include 6 | #include 7 | 8 | namespace qkc { 9 | 10 | class QKCAPI ProcessMemoryInfo { 11 | public : 12 | ProcessMemoryInfo(); 13 | ~ProcessMemoryInfo(); 14 | 15 | size_t PageFaultCount; 16 | size_t PeakWorkingSetSize; 17 | size_t WorkingSetSize; 18 | size_t QuotaPeakPagedPoolUsage; 19 | size_t QuotaPagedPoolUsage; 20 | size_t QuotaPeakNonPagedPoolUsage; 21 | size_t QuotaNonPagedPoolUsage; 22 | size_t PagefileUsage; 23 | size_t PeakPagefileUsage; 24 | 25 | bool Load(); 26 | }; 27 | 28 | } 29 | 30 | #endif /** __QUARK_WOBJS_PROCESS_MEMORY_INFO_H */ 31 | -------------------------------------------------------------------------------- /include/wobjs/RBTree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/RBTree.h -------------------------------------------------------------------------------- /include/wobjs/RList.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QKC_WOBJS_RLIST_H 3 | #define __QKC_WOBJS_RLIST_H 1 4 | 5 | #include 6 | #include 7 | 8 | namespace qkc { 9 | 10 | class QKCAPI RLNode { 11 | public: 12 | RLNode(); 13 | void Init(); 14 | bool Empty() const; 15 | void Remove(); 16 | RLNode * Prev; 17 | RLNode * Next; 18 | }; 19 | 20 | class QKCAPI RList : public RLNode { 21 | public: 22 | RList() {} 23 | 24 | void Add(RLNode * entry); 25 | void Del(RLNode * entry); 26 | }; 27 | } 28 | 29 | #endif /** __QKC_WOBJS_RLIST_H */ 30 | -------------------------------------------------------------------------------- /include/wobjs/RWLocker.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_RWLOCKER_H 3 | #define __QUARK_WOBJS_RWLOCKER_H 1 4 | 5 | #include 6 | #include 7 | #include "wobjs/Object.h" 8 | 9 | namespace qkc { 10 | 11 | class QKCAPI RWLocker : public Object{ 12 | public: 13 | RWLocker(); 14 | virtual ~RWLocker(); 15 | 16 | void Lock(); 17 | void Unlock(); 18 | void LockShared() const; 19 | void UnlockShared() const; 20 | 21 | class QKCAPI ScopedLock { 22 | public: 23 | ScopedLock(RWLocker& locker) : locker_(locker) { locker_.Lock(); } 24 | ~ScopedLock() { locker_.Unlock(); } 25 | private: 26 | ScopedLock(const ScopedLock& locker); 27 | ScopedLock& operator=(const ScopedLock&) { return *this; } 28 | 29 | RWLocker& locker_; 30 | }; 31 | 32 | class QKCAPI ScopedSharedLock { 33 | public: 34 | ScopedSharedLock(RWLocker& locker) : locker_(locker) { locker_.LockShared(); } 35 | ~ScopedSharedLock() { locker_.UnlockShared(); } 36 | private: 37 | ScopedSharedLock(const ScopedSharedLock& locker); 38 | ScopedSharedLock& operator=(const ScopedSharedLock&) { return *this; } 39 | 40 | RWLocker& locker_; 41 | }; 42 | 43 | protected: 44 | void SetInfo(); 45 | private: 46 | RWLocker(const RWLocker& locker); 47 | RWLocker& operator=(const RWLocker& locker) { return (*this); } 48 | mutable SRWLOCK locker_; 49 | }; 50 | } 51 | 52 | #endif /** __QUARK_WOBJS_RWLOCKER_H */ 53 | -------------------------------------------------------------------------------- /include/wobjs/RXTree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/RXTree.h -------------------------------------------------------------------------------- /include/wobjs/RingBuffer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_RING_BUFFER_H 3 | #define __QUARK_WOBJS_RING_BUFFER_H 1 4 | 5 | #include 6 | #include "wobjs/MemMgr.h" 7 | 8 | namespace qkc { 9 | 10 | class QKCAPI RingBuffer { 11 | public: 12 | RingBuffer(MemMgr * mmgr = NULL); 13 | virtual ~RingBuffer(); 14 | 15 | bool Init(size_t size); 16 | void Final(); 17 | 18 | size_t WriteStream(const void * buf, size_t size); 19 | bool ReferStream(char *& buf, size_t& size); 20 | bool MoveSize(size_t size); 21 | 22 | size_t WriteMessage(const void * buf, size_t size); 23 | bool ReferMessage(char *&buf, size_t& size); 24 | private: 25 | MemMgr * mmgr_; 26 | char * buffer_; 27 | size_t size_; 28 | size_t head_; 29 | size_t tail_; 30 | }; 31 | } 32 | 33 | #endif /** __QUARK_WOBJS_RING_BUFFER_H */ 34 | -------------------------------------------------------------------------------- /include/wobjs/SemaphoreW.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_SEMAPHORE_H 3 | #define __QUARK_WOBJS_SEMAPHORE_H 1 4 | 5 | #include 6 | #include 7 | #include "wobjs/Object.h" 8 | 9 | namespace qkc { 10 | 11 | class QKCAPI Semaphore : public Object { 12 | public: 13 | Semaphore(); 14 | Semaphore(int value); 15 | virtual ~Semaphore(); 16 | 17 | void SetInfo(); 18 | 19 | int Post(int count = 1); 20 | int Wait(); 21 | int TimedWait(int timeout); 22 | int Value() const; 23 | private: 24 | Semaphore(const Semaphore& locker); 25 | Semaphore& operator=(const Semaphore& locker); 26 | HANDLE handle_; 27 | LONG value_; 28 | }; 29 | } 30 | 31 | #endif /** __QUARK_WOBJS_SEMAPHORE_H */ 32 | -------------------------------------------------------------------------------- /include/wobjs/SockOpt.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_SOCK_OPT_H 3 | #define __QUARK_WOBJS_SOCK_OPT_H 1 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | namespace qkc { 12 | 13 | class QKCAPI SockOpt { 14 | public: 15 | SockOpt(SOCKET& s) : s_(s) {} 16 | 17 | 18 | bool KeepAlive(bool &optval); 19 | bool KeepAlive(bool optval); 20 | 21 | bool RecvBufferSize(int& optval); 22 | bool RecvBufferSize(int optval); 23 | 24 | bool SendBufferSize(int& optval); 25 | bool SendBufferSize(int optval); 26 | 27 | bool RecvTimeout(DWORD& optval); 28 | bool RecvTimeout(DWORD optval); 29 | 30 | bool SendTimeout(DWORD& optval); 31 | bool SendTimeout(DWORD optval); 32 | 33 | bool NoDelay(bool& optval); 34 | bool NoDelay(bool optval); 35 | 36 | bool ReadableSize(DWORD& size); 37 | bool NonBlock(bool enable); 38 | 39 | private: 40 | SOCKET& s_; 41 | }; 42 | 43 | } 44 | 45 | #endif /** __QUARK_WOBJS_SOCK_OPT_H */ 46 | -------------------------------------------------------------------------------- /include/wobjs/SpinLocker.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/SpinLocker.h -------------------------------------------------------------------------------- /include/wobjs/StrUtil.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/StrUtil.h -------------------------------------------------------------------------------- /include/wobjs/SysInfo.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_SYS_INFO_H 3 | #define __QUARK_WOBJS_SYS_INFO_H 1 4 | 5 | #include 6 | #include 7 | 8 | namespace qkc { 9 | class QKCAPI SysInfo { 10 | public: 11 | SysInfo(); 12 | ~SysInfo(); 13 | 14 | bool Init(); 15 | 16 | inline uint32_t PageSize() const { return page_size_; } 17 | inline uintptr_t ActiveProcessorMask() const { return active_processor_mask_; } 18 | inline uint32_t NumberOfProcessors() const { return number_of_processors_; } 19 | inline uint32_t AllocationGranularity() const { return allocation_granularity_; } 20 | 21 | static SysInfo& Singleton(); 22 | private: 23 | uint32_t page_size_; 24 | uintptr_t active_processor_mask_; 25 | uint32_t number_of_processors_; 26 | uint32_t allocation_granularity_; 27 | 28 | bool inited_; 29 | }; 30 | } 31 | 32 | #endif /** __QUARK_WOBJS_SYS_INFO_H */ 33 | -------------------------------------------------------------------------------- /include/wobjs/Thread.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wobjs/Thread.h -------------------------------------------------------------------------------- /include/wobjs/UserEnvLoader.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WOBJS_USER_ENV_LOADER_H 3 | #define __QUARK_WOBJS_USER_ENV_LOADER_H 1 4 | 5 | #include 6 | #include 7 | #include "wobjs/DllLoader.h" 8 | 9 | namespace qkc { 10 | 11 | class QKCAPI UserEnvLoader : public DllLoader { 12 | public: 13 | UserEnvLoader(); 14 | virtual ~UserEnvLoader(); 15 | 16 | virtual bool Init(); 17 | virtual void Final(); 18 | 19 | typedef BOOL(WINAPI *LPFN_GETUSERPROFILEDIRECTORW)(HANDLE token, LPWSTR profile, LPDWORD size); 20 | int GetUserDirector(char * dir, int size); 21 | 22 | static const char * kDllName; 23 | static UserEnvLoader Singleton; 24 | 25 | private: 26 | LPFN_GETUSERPROFILEDIRECTORW lpfnGetUserProfileDirectorW_; 27 | }; 28 | 29 | } 30 | 31 | #endif /** __QUARK_WOBJS_USER_ENV_LOADER_H */ 32 | -------------------------------------------------------------------------------- /include/wstub/advapi32.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WSTUB_ADVAPI32_H 3 | #define __QUARK_WSTUB_ADVAPI32_H 1 4 | 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef BOOL (WINAPI *LPFN_GETUSERNAMEW)(LPWSTR buffer ,LPDWORD size); 13 | int _imp_get_username(char * name , int size) ; 14 | 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif /** __QUARK_WSTUB_ADVAPI32_H */ 21 | -------------------------------------------------------------------------------- /include/wstub/userenv.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WSTUB_USERENV_H 3 | #define __QUARK_WSTUB_USERENV_H 1 4 | 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef BOOL (WINAPI *LPFN_GETUSERPROFILEDIRECTORW)(HANDLE token ,LPWSTR profile,LPDWORD size); 13 | int _imp_get_user_directory(char * dir , int size) ; 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /** __QUARK_WSTUB_USERENV_H */ 20 | -------------------------------------------------------------------------------- /include/wstub/windows.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_WSTUB_WINDOWS_H 3 | #define __QUARK_WSTUB_WINDOWS_H 1 4 | 5 | 6 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_IX86) 7 | #define _X86_ 8 | #endif 9 | 10 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_AMD64) 11 | #define _AMD64_ 12 | #endif 13 | 14 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_M68K) 15 | #define _68K_ 16 | #endif 17 | 18 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_IA64_) && !defined(_AMD64_) && defined(_M_MPPC) 19 | #define _MPPC_ 20 | #endif 21 | 22 | #if !defined(_68K_) && !defined(_MPPC_) && !defined(_X86_) && !defined(_M_IX86) && !defined(_AMD64_) && defined(_M_IA64) 23 | #if !defined(_IA64_) 24 | #define _IA64_ 25 | #endif // !_IA64_ 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #endif /** __QUARK_WSTUB_WINDOWS_H */ 33 | 34 | 35 | -------------------------------------------------------------------------------- /include/wstub/winnt.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wstub/winnt.h -------------------------------------------------------------------------------- /include/wstub/winsock2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/include/wstub/winsock2.h -------------------------------------------------------------------------------- /qkc/arpa_inet.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | in_addr_t inet_addr (const char * cp) 6 | { 7 | return _imp_inet_addr(cp) ; 8 | } 9 | 10 | char * inet_ntoa (struct in_addr in) 11 | { 12 | IN_ADDR wi ; 13 | wi.s_addr = in.s_addr ; 14 | return _imp_inet_ntoa(wi) ; 15 | } 16 | -------------------------------------------------------------------------------- /qkc/assert.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) 9 | { 10 | char str[2048] = {'\0'} ; 11 | size_t slen = ::sprintf("Assertion '%s' file '%s' line %d function %s .\n" , assertion , file , line , function) ; 12 | ::write(STDERR_FILENO , str , slen + 1); 13 | 14 | abort (); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /qkc/byteswap.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | uint16_t bswap_16 (uint16_t x) 5 | { 6 | uint16_t j; 7 | j = (x << 8) ; 8 | j += (x >> 8) ; 9 | return j; 10 | } 11 | 12 | uint32_t bswap_32 (uint32_t x) 13 | { 14 | uint32_t j; 15 | j = (x << 24); 16 | j += (x << 8) & 0x00FF0000; 17 | j += (x >> 8) & 0x0000FF00; 18 | j += (x >> 24); 19 | return j; 20 | } 21 | 22 | uint64_t bswap_64 (uint64_t x) 23 | { 24 | uint64_t j; 25 | j = (x << 56); 26 | j += (x << 40)&0x00FF000000000000; 27 | j += (x << 24)&0x0000FF0000000000; 28 | j += (x << 8)&0x000000FF00000000; 29 | j += (x >> 8)&0x00000000FF000000; 30 | j += (x >> 24)&0x0000000000FF0000; 31 | j += (x >> 40)&0x000000000000FF00; 32 | j += (x >> 56); 33 | return j; 34 | } 35 | -------------------------------------------------------------------------------- /qkc/ctype.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wobjs/CrtLinker.h" 4 | 5 | 6 | int isblank (int c) 7 | { 8 | if(c == ' ' || c == '\t') 9 | return 1; 10 | else 11 | return 0 ; 12 | } 13 | 14 | 15 | int isctype (int c , int mask) 16 | { 17 | return _isctype(c , mask) ; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /qkc/dlfcn.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "wobjs/DllInit.h" 5 | 6 | void *dlopen (const char * file, int mode) 7 | { 8 | return ::LoadLibrary(file) ; 9 | } 10 | 11 | int dlclose (void * handle) 12 | { 13 | if(::FreeLibrary((HMODULE)handle) == TRUE) 14 | return 0 ; 15 | else 16 | return -1 ; 17 | } 18 | 19 | void *dlsym_default(const char * name) 20 | { 21 | HMODULE handle = (HMODULE)qkc::GetThisDllHandle() ; 22 | if(handle == NULL) 23 | return NULL ; 24 | 25 | return ::GetProcAddress(handle , name) ; 26 | } 27 | 28 | void *dlsym_special(void * handle , const char * name) 29 | { 30 | return ::GetProcAddress((HMODULE)handle , name) ; 31 | } 32 | 33 | void *dlsym (void * handle , const char * name) 34 | { 35 | if(handle == RTLD_DEFAULT || handle == RTLD_NEXT) 36 | return dlsym_default(name) ; 37 | else 38 | return dlsym_special(handle , name) ; 39 | } 40 | 41 | char *dlerror (void) 42 | { 43 | static char __dlerror__[] = "dlfcn failed" ; 44 | if(GetLastError() != 0) 45 | return __dlerror__ ; 46 | else 47 | return NULL ; 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /qkc/fcntl.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/fcntl.cpp -------------------------------------------------------------------------------- /qkc/getopt.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int opterr = 1; /* if error message should be printed */ 5 | int optind = 1; /* index into parent argv vector */ 6 | int optopt = '?'; /* character checked for validity */ 7 | int optreset; /* reset getopt */ 8 | char *optarg; /* argument associated with option */ 9 | 10 | int getopt (int argc , char *const *argv, const char *shortopts) 11 | { 12 | return 0 ; 13 | } 14 | -------------------------------------------------------------------------------- /qkc/grp.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | void setgrent (void) 5 | { 6 | // 7 | } 8 | 9 | struct group *getgrgid (gid_t gid) 10 | { 11 | return NULL ; 12 | } 13 | 14 | struct group *getgrnam (const char *name) 15 | { 16 | return NULL ; 17 | } 18 | 19 | int setgroups (size_t n, const gid_t *groups) 20 | { 21 | return -1 ; 22 | } 23 | 24 | int initgroups (const char *user, gid_t group) 25 | { 26 | return 0 ; 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /qkc/iconv.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | iconv_t iconv_open (const char * to , const char * from) 6 | { 7 | return NULL ; 8 | } 9 | 10 | size_t iconv (iconv_t cd , char ** inbuf , size_t * inleft, char ** outbuf, size_t * outleft) 11 | { 12 | return 0 ; 13 | } 14 | 15 | int iconv_close (iconv_t cd) 16 | { 17 | return 0 ; 18 | } 19 | -------------------------------------------------------------------------------- /qkc/ifaddrs.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/ifaddrs.cpp -------------------------------------------------------------------------------- /qkc/internal/ffile.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/internal/ffile.cpp -------------------------------------------------------------------------------- /qkc/internal/ffile.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/internal/ffile.h -------------------------------------------------------------------------------- /qkc/internal/fpipe.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/internal/fpipe.cpp -------------------------------------------------------------------------------- /qkc/internal/fsocket.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/internal/fsocket.cpp -------------------------------------------------------------------------------- /qkc/internal/fsocket.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/internal/fsocket.h -------------------------------------------------------------------------------- /qkc/internal/pipe_mgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/internal/pipe_mgr.h -------------------------------------------------------------------------------- /qkc/netdb.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int getaddrinfo (const char *name,const char *service,const struct addrinfo *req,struct addrinfo **pai) 5 | { 6 | return 0 ; 7 | } 8 | 9 | void freeaddrinfo (struct addrinfo * ai) 10 | { 11 | // 12 | } 13 | 14 | int getnameinfo (const struct sockaddr *sa,socklen_t salen, char *host, socklen_t hostlen, 15 | char *serv, socklen_t servlen, int flags) 16 | { 17 | return 0 ; 18 | } 19 | -------------------------------------------------------------------------------- /qkc/netinet_in.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | const struct in6_addr in6addr_any = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }; 7 | const struct in6_addr in6addr_loopback = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }; 8 | 9 | 10 | uint32_t ntohl (uint32_t netlong) 11 | { 12 | if(is_little_endian() == true) 13 | return bswap_32(netlong) ; 14 | else 15 | return netlong ; 16 | } 17 | 18 | uint16_t ntohs (uint16_t netshort) 19 | { 20 | if(is_little_endian() == true) 21 | return bswap_16(netshort) ; 22 | else 23 | return netshort ; 24 | } 25 | 26 | 27 | uint32_t htonl (uint32_t hostlong) 28 | { 29 | if(is_little_endian() == true) 30 | return bswap_32(hostlong) ; 31 | else 32 | return hostlong ; 33 | } 34 | 35 | uint16_t htons (uint16_t hostshort) 36 | { 37 | if(is_little_endian() == true) 38 | return bswap_16(hostshort) ; 39 | else 40 | return hostshort ; 41 | } 42 | -------------------------------------------------------------------------------- /qkc/qkc.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/qkc.vcproj -------------------------------------------------------------------------------- /qkc/qkc_init.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/qkc_init.cpp -------------------------------------------------------------------------------- /qkc/semaphore.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int sem_init(sem_t * sem , int pshared, unsigned int value) 5 | { 6 | return -1 ; 7 | } 8 | 9 | int sem_destroy(sem_t *sem) 10 | { 11 | return -1 ; 12 | } 13 | 14 | sem_t * sem_open(const char * name , int oflag , mode_t mode , uint32_t value) 15 | { 16 | return NULL ; 17 | } 18 | 19 | int sem_close(sem_t *sem) 20 | { 21 | return -1 ; 22 | } 23 | 24 | int sem_unlink(const char * name) 25 | { 26 | return -1 ; 27 | } 28 | 29 | int sem_wait(sem_t *sem) 30 | { 31 | return -1 ; 32 | } 33 | 34 | int sem_timedwait(sem_t *sem , const struct timespec * abstime) 35 | { 36 | return -1 ; 37 | } 38 | 39 | int sem_trywait(sem_t *sem) 40 | { 41 | return -1 ; 42 | } 43 | 44 | int sem_post(sem_t *sem) 45 | { 46 | return -1 ; 47 | } 48 | 49 | int sem_getvalue(sem_t *sem , int * sval) 50 | { 51 | return -1 ; 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /qkc/stdio.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wobjs/CrtLinker.h" 4 | 5 | 6 | char *tmpnam_r (char *s) 7 | { 8 | return tmpnam_s(s) ; 9 | } 10 | 11 | int fcloseall (void) 12 | { 13 | return _fcloseall() ; 14 | } 15 | 16 | FILE *fdopen (int fd , const char *modes) 17 | { 18 | return _fdopen(fd , modes) ; 19 | } 20 | 21 | int getw (FILE *stream) 22 | { 23 | return _getw(stream) ; 24 | } 25 | 26 | int putw (int w , FILE *stream) 27 | { 28 | return _putw(w , stream) ; 29 | } 30 | 31 | int fseeko (FILE *stream , off_t off , int whence) 32 | { 33 | return _fseeki64(stream , off , whence) ; 34 | } 35 | 36 | off_t ftello (FILE *stream) 37 | { 38 | return _ftelli64(stream) ; 39 | } 40 | 41 | 42 | void flockfile (FILE *stream) 43 | { 44 | _lock_file(stream) ; 45 | } 46 | 47 | void funlockfile (FILE *stream) 48 | { 49 | _unlock_file(stream) ; 50 | } 51 | 52 | #if _MSC_VER < 1912 53 | int snprintf (char * s , size_t maxlen , const char * format , ...) 54 | { 55 | va_list arg ; 56 | int done = 0 ; 57 | 58 | va_start(arg , format) ; 59 | done = _vsnprintf(s , maxlen , format , arg) ; 60 | va_end(arg) ; 61 | return done ; 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /qkc/string.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wobjs/CrtLinker.h" 4 | 5 | 6 | 7 | char *strtok_r (char * s, const char * delim, char ** save_ptr) 8 | { 9 | return strtok_s(s , delim , save_ptr) ; 10 | } 11 | 12 | 13 | char *strerror_r (int errnum , char * buf, size_t buflen) 14 | { 15 | if(strerror_s(buf , buflen , errnum) == 0) 16 | return buf ; 17 | else 18 | return NULL ; 19 | } -------------------------------------------------------------------------------- /qkc/sys_epoll.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/sys_epoll.cpp -------------------------------------------------------------------------------- /qkc/sys_inotify.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include "wobjs/INotifyMgr.h" 6 | #include "wobjs/ObjMgr.h" 7 | 8 | int inotify_init (void) 9 | { 10 | qkc::INotifyMgr * mgr = new qkc::INotifyMgr(); 11 | int index = mgr->Init(); 12 | if (index < 0) 13 | delete mgr; 14 | 15 | return index; 16 | } 17 | 18 | int inotify_add_watch (int fd, const char *name, uint32_t mask) 19 | { 20 | qkc::Object * obj = qkc::ObjMgr::Singleton().Get(fd); 21 | if (obj == NULL || obj->OType() != qkc::Object::kFileWatcher) 22 | return -1; 23 | 24 | qkc::INotifyMgr * mgr = (qkc::INotifyMgr *)obj; 25 | return mgr->Add(name, mask); 26 | } 27 | 28 | int inotify_rm_watch (int fd, uint32_t wd) 29 | { 30 | qkc::Object * obj = qkc::ObjMgr::Singleton().Get(fd); 31 | if (obj == NULL || obj->OType() != qkc::Object::kFileWatcher) 32 | return -1; 33 | 34 | qkc::INotifyMgr * mgr = (qkc::INotifyMgr *)obj; 35 | return mgr->Del(wd); 36 | } 37 | -------------------------------------------------------------------------------- /qkc/sys_ioctl.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int ioctl(int fd , unsigned long request , ...) 5 | { 6 | return 0 ; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /qkc/sys_ipc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | key_t ftok (const char *pathname , int proj_id) 7 | { 8 | struct stat sbuf ; 9 | if(::stat(pathname , &sbuf) != 0) 10 | return -1 ; 11 | 12 | uint32_t dev = sbuf.st_dev ; 13 | uint32_t ino = sbuf.st_ino ; 14 | uint32_t id = (uint32_t)proj_id ; 15 | 16 | key_t key = (id << 24) | ((dev & 0XFF) << 16) | (ino & 0XFFFF) ; 17 | return key ; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /qkc/sys_mman.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/sys_mman.cpp -------------------------------------------------------------------------------- /qkc/sys_poll.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int poll (struct pollfd * fds, nfds_t nfds, int timeout) 5 | { 6 | return -1 ; 7 | } 8 | -------------------------------------------------------------------------------- /qkc/sys_select.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int select (int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval *timeout) 5 | { 6 | return -1 ; 7 | } 8 | -------------------------------------------------------------------------------- /qkc/sys_sem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/sys_sem.cpp -------------------------------------------------------------------------------- /qkc/sys_socket.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/sys_socket.cpp -------------------------------------------------------------------------------- /qkc/sys_syslog.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void closelog(void) 4 | { 5 | 6 | } 7 | 8 | void openlog(const char *ident , int option, int facility) 9 | { 10 | 11 | } 12 | 13 | int setlogmask(int mask) 14 | { 15 | return 0 ; 16 | } 17 | 18 | void syslog(int pri, const char *fmt , ...) 19 | { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /qkc/sys_time.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/sys_time.cpp -------------------------------------------------------------------------------- /qkc/sys_times.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #define NSPERSEC 10000000LL 7 | static clock_t __stdcall __to_clock_t (PFILETIME src) 8 | { 9 | uint64_t total = src->dwHighDateTime ; 10 | total = (total << 32) + src->dwLowDateTime ; 11 | total /= NSPERSEC / CLOCKS_PER_SEC; 12 | return (clock_t)total; 13 | } 14 | 15 | clock_t times (struct tms * buffer) 16 | { 17 | clock_t tc = (clock_t) -1; 18 | 19 | FILETIME idle_time , kernel_time , user_time ; 20 | if(::GetSystemTimes(&idle_time , &kernel_time , &user_time) == FALSE) 21 | return tc ; 22 | 23 | buffer->tms_stime = __to_clock_t (&kernel_time); 24 | buffer->tms_utime = __to_clock_t (&user_time); 25 | buffer->tms_cstime = 0 ; 26 | buffer->tms_cutime = 0 ; 27 | 28 | return tc; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /qkc/sys_uio.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | ssize_t readv(int fd , const struct iovec * iovec , int count) 5 | { 6 | return 0 ; 7 | } 8 | 9 | ssize_t writev(int fd , const struct iovec * iovec , int count) 10 | { 11 | return 0 ; 12 | } 13 | 14 | ssize_t preadv (int fd, const struct iovec * iovec, int count, off_t offset) 15 | { 16 | return 0 ; 17 | } 18 | 19 | ssize_t pwritev (int fd, const struct iovec * iovec, int count, off_t offset) 20 | { 21 | return 0 ; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /qkc/termios.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | int tcgetattr (int fd, struct termios * termios_p) 6 | { 7 | return -1 ; 8 | } 9 | 10 | int tcsetattr (int fd, int optional_actions, const struct termios * termios_p) 11 | { 12 | return -1 ; 13 | } 14 | 15 | void cfmakeraw (struct termios *termios_p) 16 | { 17 | // 18 | } 19 | 20 | int tcsendbreak (int fd, int duration) 21 | { 22 | return -1 ; 23 | } 24 | 25 | int tcdrain (int fd) 26 | { 27 | return -1 ; 28 | } 29 | 30 | int tcflush (int fd, int queue_selector) 31 | { 32 | return -1 ; 33 | } 34 | 35 | int tcflow (int fd, int action) 36 | { 37 | return -1 ; 38 | } 39 | 40 | pid_t tcgetsid (int fd) 41 | { 42 | return -1 ; 43 | } 44 | -------------------------------------------------------------------------------- /qkc/unistd.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/unistd.cpp -------------------------------------------------------------------------------- /qkc/utime.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wobjs/CrtLinker.h" 4 | 5 | int utime (const char * file, const struct utimbuf * file_times) 6 | { 7 | struct utimbuf ftimes ; 8 | if(file_times == NULL) 9 | { 10 | ftimes.actime = 0 ; 11 | ftimes.modtime = 0 ; 12 | } 13 | else 14 | { 15 | ftimes.actime = file_times->actime ; 16 | ftimes.modtime = file_times->modtime ; 17 | } 18 | 19 | return ::_utime64(file , &ftimes) ; 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /qkc/wait.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wait.cpp -------------------------------------------------------------------------------- /qkc/wimpl/IOCPMgr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wimpl/IOCPMgr.cpp -------------------------------------------------------------------------------- /qkc/wimpl/MMapMgr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wimpl/MMapMgr.cpp -------------------------------------------------------------------------------- /qkc/wintf/wipc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wintf/wipc.cpp -------------------------------------------------------------------------------- /qkc/wobjs/AddrMgr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/AddrMgr.cpp -------------------------------------------------------------------------------- /qkc/wobjs/AtomicCounter.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/AtomicCounter.h" 3 | 4 | namespace qkc { 5 | 6 | 7 | AtomicCounter::AtomicCounter() 8 | { 9 | value_ = 0; 10 | } 11 | 12 | AtomicCounter::~AtomicCounter() 13 | { 14 | // 15 | } 16 | 17 | LONG AtomicCounter::Increment() 18 | { 19 | return ::InterlockedIncrement(&value_); 20 | } 21 | 22 | LONG AtomicCounter::Decrement() 23 | { 24 | return ::InterlockedDecrement(&value_); 25 | } 26 | 27 | LONG AtomicCounter::Value() const 28 | { 29 | return ::InterlockedCompareExchange(&value_, 0, value_); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /qkc/wobjs/Condition.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/Condition.h" 3 | 4 | namespace qkc { 5 | 6 | 7 | Condition::Condition() 8 | { 9 | // 10 | } 11 | 12 | void Condition::SetInfo() 13 | { 14 | OType(Object::kCondition); 15 | } 16 | 17 | Condition:: ~Condition() 18 | { 19 | // 20 | } 21 | 22 | int Condition::Notify() 23 | { 24 | Mutex::ScopedLock locker(guard_); 25 | return sema_.Post(); 26 | } 27 | 28 | int Condition::Broadcast() 29 | { 30 | Mutex::ScopedLock locker(guard_); 31 | int count = sema_.Value(); 32 | return sema_.Post(count); 33 | } 34 | 35 | int Condition::Wait(Mutex& locker) 36 | { 37 | int result = 0; 38 | locker.Unlock(); 39 | result = sema_.Wait(); 40 | locker.Lock(); 41 | return result; 42 | } 43 | 44 | int Condition::TimedWait(Mutex& locker, int timeout) 45 | { 46 | int result = 0; 47 | locker.Unlock(); 48 | result = sema_.TimedWait(timeout); 49 | locker.Lock(); 50 | return result; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qkc/wobjs/CrtLoader.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/CrtLoader.h" 3 | 4 | 5 | namespace qkc { 6 | 7 | CrtLoader::CrtLoader() 8 | { 9 | // 10 | } 11 | 12 | CrtLoader::~CrtLoader() 13 | { 14 | // 15 | } 16 | 17 | bool CrtLoader::Init() 18 | { 19 | return false; 20 | } 21 | 22 | void CrtLoader::Final() 23 | { 24 | // 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /qkc/wobjs/DateTime.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/DateTime.cpp -------------------------------------------------------------------------------- /qkc/wobjs/DllInit.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/DllInit.cpp -------------------------------------------------------------------------------- /qkc/wobjs/DllLoader.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/DllLoader.h" 3 | #include "wobjs/GlobalLocker.h" 4 | 5 | namespace qkc { 6 | DllLoader::DllLoader() 7 | { 8 | handle_ = NULL; 9 | OType(Object::kModule); 10 | } 11 | 12 | DllLoader::~DllLoader() 13 | { 14 | Final(); 15 | if (handle_ != NULL && handle_ != INVALID_HANDLE_VALUE) 16 | { 17 | Close(); 18 | } 19 | } 20 | 21 | bool DllLoader::Init() 22 | { 23 | return false; 24 | } 25 | 26 | void DllLoader::Final() 27 | { 28 | // 29 | } 30 | 31 | bool DllLoader::Open(const char * name) 32 | { 33 | handle_ = ::LoadLibrary(name); 34 | return (handle_ != NULL); 35 | } 36 | 37 | void DllLoader::Close() 38 | { 39 | if (handle_ != NULL) 40 | { 41 | FreeLibrary(handle_); 42 | handle_ = NULL; 43 | } 44 | } 45 | 46 | FARPROC DllLoader::GetAddress(const char * name) 47 | { 48 | return ::GetProcAddress(handle_, name); 49 | } 50 | 51 | bool DllLoader::ConfirmLoad() 52 | { 53 | if (loaded_ == false) 54 | { 55 | guard_.Lock(); 56 | if (loaded_ == false) 57 | loaded_ = Init(); 58 | guard_.Unlock(); 59 | } 60 | 61 | return loaded_; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /qkc/wobjs/ErrorMap.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/ErrorMap.cpp -------------------------------------------------------------------------------- /qkc/wobjs/FileSystem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/FileSystem.cpp -------------------------------------------------------------------------------- /qkc/wobjs/FileSystemProc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/FileSystemProc.cpp -------------------------------------------------------------------------------- /qkc/wobjs/GlobalLocker.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/GlobalLocker.h" 3 | 4 | namespace qkc { 5 | 6 | GlobalLocker::GlobalLocker() 7 | { 8 | // 9 | } 10 | 11 | GlobalLocker::~GlobalLocker() 12 | { 13 | // 14 | } 15 | 16 | GlobalLocker GlobalLocker::kLocker; 17 | } 18 | -------------------------------------------------------------------------------- /qkc/wobjs/Hash.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/Hash.h" 3 | 4 | namespace qkc { 5 | 6 | uint32_t HashTime33(const char * str, int size, uint32_t hash) 7 | { 8 | const uint8_t * p = (const uint8_t *)str; 9 | if (size < 0) 10 | { 11 | int i = 0; 12 | for (; (*p) != '\0'; ++p) 13 | hash = (hash << 5) + hash + (*p); 14 | } 15 | else 16 | { 17 | for (int i = size; i >= 0; --i, ++p) 18 | { 19 | hash = (hash << 5) + hash + (*p); 20 | } 21 | } 22 | 23 | return hash; 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /qkc/wobjs/IOCPMgr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/IOCPMgr.cpp -------------------------------------------------------------------------------- /qkc/wobjs/LargePageMap.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/LargePageMap.cpp -------------------------------------------------------------------------------- /qkc/wobjs/MemMgr.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "wobjs/MemMgr.h" 4 | #include "wobjs/GlobalLocker.h" 5 | 6 | namespace qkc { 7 | 8 | 9 | MemMgr::MemMgr() 10 | { 11 | // 12 | } 13 | 14 | MemMgr::~MemMgr() 15 | { 16 | // 17 | } 18 | 19 | void * MemMgr::Alloc(size_t size, bool zeroed) 20 | { 21 | DWORD flags = 0; 22 | if (zeroed == true) 23 | flags = 0x00000008; //HEAP_ZERO_MEMORY; 24 | return ::HeapAlloc(::GetProcessHeap(), flags, size); 25 | } 26 | 27 | void MemMgr::Free(void * addr) 28 | { 29 | if(addr != NULL) 30 | ::HeapFree(::GetProcessHeap(), 0, addr); 31 | } 32 | 33 | MemMgr MemMgr::Singleton; 34 | static MemMgr * __default_mem_mgr__ = &MemMgr::Singleton; 35 | 36 | MemMgr * MemMgr::Default() 37 | { 38 | return __default_mem_mgr__; 39 | } 40 | 41 | void MemMgr::Default(MemMgr * mgr) 42 | { 43 | GlobalLocker::kLocker.Lock(); 44 | if (mgr == NULL) 45 | __default_mem_mgr__ = &MemMgr::Singleton; 46 | else 47 | __default_mem_mgr__ = mgr; 48 | GlobalLocker::kLocker.Unlock(); 49 | } 50 | 51 | void * MemAlloc(size_t size, bool zeroed) 52 | { 53 | return __default_mem_mgr__->Alloc(size , zeroed); 54 | } 55 | 56 | void MemFree(void * addr) 57 | { 58 | __default_mem_mgr__->Free(addr); 59 | } 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /qkc/wobjs/Mutex.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/Mutex.h" 3 | 4 | namespace qkc { 5 | 6 | Mutex::Mutex() 7 | { 8 | handle_ = ::CreateMutexA(NULL, FALSE, NULL); 9 | } 10 | 11 | void Mutex::SetInfo() 12 | { 13 | OType(Object::kMutex); 14 | } 15 | 16 | Mutex::~Mutex() 17 | { 18 | if (handle_ != NULL) 19 | { 20 | ::CloseHandle(handle_); 21 | handle_ = NULL; 22 | } 23 | } 24 | 25 | int Mutex::Lock() 26 | { 27 | if (::WaitForSingleObject(handle_, INFINITE) != WAIT_OBJECT_0) 28 | return -1; 29 | else 30 | return 0; 31 | } 32 | 33 | int Mutex::TryLock() 34 | { 35 | if (::WaitForSingleObject(handle_, 0) != WAIT_OBJECT_0) 36 | return -1; 37 | else 38 | return 0; 39 | 40 | } 41 | 42 | int Mutex::TimedLock(int msec) 43 | { 44 | if (msec < 0) 45 | return Lock(); 46 | else if (msec == 0) 47 | return TryLock(); 48 | 49 | } 50 | 51 | int Mutex::Unlock() 52 | { 53 | if (::ReleaseMutex(handle_) == TRUE) 54 | return 0; 55 | else 56 | return -1; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /qkc/wobjs/ObjMgr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/ObjMgr.cpp -------------------------------------------------------------------------------- /qkc/wobjs/RBTree.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/RBTree.cpp -------------------------------------------------------------------------------- /qkc/wobjs/RList.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/RList.h" 3 | 4 | 5 | namespace qkc { 6 | 7 | RLNode::RLNode() 8 | { 9 | Init(); 10 | } 11 | 12 | void RLNode::Init() 13 | { 14 | Prev = Next = this; 15 | } 16 | 17 | bool RLNode::Empty() const 18 | { 19 | return ((Prev == this) && (Next == this)); 20 | } 21 | 22 | void RLNode::Remove() 23 | { 24 | RLNode * prev = Prev; 25 | RLNode * next = Next; 26 | 27 | prev->Next = next; 28 | next->Prev = prev; 29 | 30 | Init(); 31 | } 32 | 33 | void RList::Add(RLNode * entry) 34 | { 35 | RLNode * last = Prev; 36 | last->Next = entry; 37 | entry->Prev = last; 38 | entry->Next = this; 39 | Prev = entry; 40 | } 41 | 42 | void RList::Del(RLNode * entry) 43 | { 44 | RLNode * prev = entry->Prev; 45 | RLNode * next = entry->Next; 46 | 47 | prev->Next = next; 48 | next->Prev = prev; 49 | 50 | entry->Init(); 51 | } 52 | 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /qkc/wobjs/RWLocker.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/RWLocker.h" 3 | 4 | namespace qkc { 5 | 6 | RWLocker::RWLocker() 7 | { 8 | locker_ = SRWLOCK_INIT; 9 | } 10 | RWLocker::~RWLocker() 11 | { 12 | // 13 | } 14 | 15 | void RWLocker::SetInfo() 16 | { 17 | OType(Object::kRWLocker); 18 | } 19 | 20 | void RWLocker::Lock() 21 | { 22 | ::AcquireSRWLockExclusive(&locker_); 23 | } 24 | 25 | void RWLocker::Unlock() 26 | { 27 | ::ReleaseSRWLockExclusive(&locker_); 28 | } 29 | 30 | void RWLocker::LockShared() const 31 | { 32 | ::AcquireSRWLockShared(&locker_); 33 | } 34 | 35 | void RWLocker::UnlockShared() const 36 | { 37 | ::ReleaseSRWLockShared(&locker_); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /qkc/wobjs/RXTree.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/RXTree.cpp -------------------------------------------------------------------------------- /qkc/wobjs/RingBuffer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/RingBuffer.cpp -------------------------------------------------------------------------------- /qkc/wobjs/SemaphoreW.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/SemaphoreW.h" 3 | #include 4 | 5 | namespace qkc { 6 | 7 | Semaphore::Semaphore() 8 | { 9 | value_ = 1; 10 | handle_ = ::CreateSemaphore(NULL , value_ , 65536 , NULL); 11 | } 12 | 13 | Semaphore::Semaphore(int value) 14 | { 15 | value_ = value; 16 | handle_ = ::CreateSemaphore(NULL, value, 65536, NULL); 17 | } 18 | 19 | Semaphore::~Semaphore() 20 | { 21 | value_ = 0; 22 | if (handle_ != NULL) 23 | { 24 | ::CloseHandle(handle_); 25 | handle_ = NULL; 26 | } 27 | } 28 | 29 | void Semaphore::SetInfo() 30 | { 31 | OType(Object::kSemaphore); 32 | } 33 | 34 | int Semaphore::Post(int count) 35 | { 36 | if (::ReleaseSemaphore(handle_, (LONG)count, &value_) == TRUE) 37 | return 0; 38 | else 39 | return -1; 40 | } 41 | 42 | int Semaphore::Wait() 43 | { 44 | if (::WaitForSingleObject(handle_, INFINITE) == WAIT_OBJECT_0) 45 | return 0; 46 | else 47 | return -1; 48 | } 49 | 50 | int Semaphore::TimedWait(int timeout) 51 | { 52 | if (::WaitForSingleObject(handle_, timeout) == WAIT_OBJECT_0) 53 | return 0; 54 | 55 | DWORD errcode = ::GetLastError(); 56 | if (errcode == WAIT_TIMEOUT) 57 | errno = ETIMEDOUT; 58 | return -1; 59 | } 60 | 61 | int Semaphore::Value() const 62 | { 63 | return (int)::InterlockedCompareExchange((volatile LONG *)&value_, 0, 0); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /qkc/wobjs/SpinLocker.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/SpinLocker.h" 3 | #include 4 | 5 | namespace qkc { 6 | 7 | SpinLocker::SpinLocker() 8 | { 9 | token_ = 0; 10 | allow_ = 1; 11 | owner_ = 0; 12 | } 13 | 14 | void SpinLocker::SetInfo() 15 | { 16 | OType(Object::kSpinLocker); 17 | } 18 | 19 | SpinLocker::~SpinLocker() 20 | { 21 | allow_ = token_; 22 | owner_ = 0; 23 | } 24 | 25 | int SpinLocker::Lock() 26 | { 27 | LONG token = ::InterlockedIncrement(&token_); 28 | uint32_t counter = 0; 29 | while (allow_ < token) 30 | { 31 | ++counter; 32 | if (counter >= 256) 33 | { 34 | counter = 0; 35 | ::SwitchToThread(); 36 | } 37 | } 38 | 39 | if (allow_ != token) 40 | return -1; 41 | 42 | allow_ = token; 43 | owner_ = ::GetCurrentThreadId(); 44 | ::MemoryBarrier(); 45 | return 0; 46 | } 47 | 48 | int SpinLocker::TryLock() 49 | { 50 | LONG token = token_; 51 | if (allow_ == token + 1) 52 | { 53 | if (::InterlockedCompareExchange(&token_, token + 1, token) == token + 1) 54 | { 55 | owner_ = ::GetCurrentThreadId(); 56 | ::MemoryBarrier(); 57 | return 0; 58 | } 59 | } 60 | 61 | return -1; 62 | 63 | } 64 | 65 | int SpinLocker::Unlock() 66 | { 67 | owner_ = 0; 68 | allow_++; 69 | ::MemoryBarrier(); 70 | return 0; 71 | } 72 | 73 | } 74 | 75 | -------------------------------------------------------------------------------- /qkc/wobjs/StrUtil.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/StrUtil.cpp -------------------------------------------------------------------------------- /qkc/wobjs/SysInfo.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "wobjs/SysInfo.h" 3 | #include 4 | 5 | namespace qkc { 6 | 7 | SysInfo::SysInfo() 8 | { 9 | inited_ = false; 10 | } 11 | 12 | SysInfo::~SysInfo() 13 | { 14 | // 15 | } 16 | 17 | bool SysInfo::Init() 18 | { 19 | if (inited_ == true) 20 | return true; 21 | 22 | SYSTEM_INFO sysinfo; 23 | ::GetSystemInfo(&sysinfo); 24 | 25 | page_size_ = sysinfo.dwPageSize; 26 | active_processor_mask_ = sysinfo.dwActiveProcessorMask; 27 | number_of_processors_ = sysinfo.dwNumberOfProcessors; 28 | allocation_granularity_ = sysinfo.dwAllocationGranularity; 29 | 30 | inited_ = true; 31 | return true; 32 | } 33 | 34 | SysInfo& SysInfo::Singleton() 35 | { 36 | static SysInfo __sysinfo_singleton__; 37 | 38 | __sysinfo_singleton__.Init() ; 39 | return __sysinfo_singleton__; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /qkc/wobjs/Thread.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkc/wobjs/Thread.cpp -------------------------------------------------------------------------------- /qkn/qkn.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkn/qkn.vcproj -------------------------------------------------------------------------------- /qkn/qkn_init.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | -------------------------------------------------------------------------------- /qkw/qkw.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/qkw/qkw.vcproj -------------------------------------------------------------------------------- /qkw/qkw_init.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | -------------------------------------------------------------------------------- /qkw/userenv.txt: -------------------------------------------------------------------------------- 1 | CreateEnvironmentBlock 2 | CreateProfile 3 | DeleteProfileA 4 | DeleteProfileW 5 | DestroyEnvironmentBlock 6 | DllCanUnloadNow 7 | DllGetClassObject 8 | DllGetContractDescription 9 | DllRegisterServer 10 | DllUnregisterServer 11 | EnterCriticalPolicySection 12 | ExpandEnvironmentStringsForUserA 13 | ExpandEnvironmentStringsForUserW 14 | ForceSyncFgPolicy 15 | FreeGPOListA 16 | FreeGPOListW 17 | GetAllUsersProfileDirectoryA 18 | GetAllUsersProfileDirectoryW 19 | GetAppliedGPOListA 20 | GetAppliedGPOListW 21 | GetDefaultUserProfileDirectoryA 22 | GetDefaultUserProfileDirectoryW 23 | GetGPOListA 24 | GetGPOListW 25 | GetNextFgPolicyRefreshInfo 26 | GetPreviousFgPolicyRefreshInfo 27 | GetProfilesDirectoryA 28 | GetProfilesDirectoryW 29 | GetProfileType 30 | GetUserProfileDirectoryA 31 | GetUserProfileDirectoryW 32 | LeaveCriticalPolicySection 33 | LoadUserProfileA 34 | LoadUserProfileW 35 | ProcessGroupPolicyCompleted 36 | ProcessGroupPolicyCompletedEx 37 | RefreshPolicy 38 | RefreshPolicyEx 39 | RegisterGPNotification 40 | RsopAccessCheckByType 41 | RsopFileAccessCheck 42 | RsopLoggingEnabled 43 | RsopResetPolicySettingStatus 44 | RsopSetPolicySettingStatus 45 | UnloadUserProfile 46 | UnregisterGPNotification 47 | WaitForMachinePolicyForegroundProcessing 48 | WaitForUserPolicyForegroundProcessing 49 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include "test.h" 7 | 8 | int main(int argc , char * argv[]) 9 | { 10 | int idx = 0 ; 11 | while(true) 12 | { 13 | test_case_t *ts = __test_cases__ + idx ; 14 | if(ts->func == NULL) 15 | break ; 16 | ++idx ; 17 | 18 | 19 | ::printf("**************begin to test %s************** \n" , ts->name) ; 20 | int result = ts->func() ; 21 | if(result != 0) 22 | { 23 | printf("************** failed to test %s , result = %d ***\n" , ts->name , result) ; 24 | break ; 25 | } 26 | ::printf("**************succeed to test %s************** \n" , ts->name) ; 27 | } 28 | return 0 ; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /test/support/README: -------------------------------------------------------------------------------- 1 | This subdirectory contains infrastructure which is not put into 2 | installed libraries, but may be linked into programs (installed or 3 | not) and tests. 4 | 5 | # Error-checking wrappers 6 | 7 | These wrappers test for error return codes an terminate the process on 8 | error. They are declared in these header files: 9 | 10 | * support.h 11 | * xsignal.h 12 | * xthread.h 13 | 14 | In general, new wrappers should be added to support.h if possible. 15 | However, support.h must remain fully compatible with C90 and therefore 16 | cannot include headers which use identifers not reserved in C90. If 17 | the wrappers need additional types, additional headers such as 18 | signal.h need to be introduced. 19 | 20 | # Test framework 21 | 22 | The test framework provides a main program for tests, including a 23 | timeout for hanging tests. See README-testing.c for a minimal 24 | example, and test-driver.c for details how to use it. The following 25 | header files provide related declarations: 26 | 27 | * check.h 28 | * temp_file.h 29 | * test-driver.h 30 | -------------------------------------------------------------------------------- /test/support/README-testing.c: -------------------------------------------------------------------------------- 1 | /* This file contains an example test case which shows minimal use of 2 | the test framework. Additional testing hooks are described in 3 | . */ 4 | 5 | /* This function will be called from the test driver. */ 6 | static int 7 | do_test (void) 8 | { 9 | if (3 == 5) 10 | /* Indicate failure. */ 11 | return 1; 12 | else 13 | /* Indicate success. */ 14 | return 0; 15 | } 16 | 17 | /* This file references do_test above and contains the definition of 18 | the main function. */ 19 | #include 20 | -------------------------------------------------------------------------------- /test/support/ignore_stderr.c: -------------------------------------------------------------------------------- 1 | /* Avoid all the buffer overflow messages on stderr. 2 | Copyright (C) 2015-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | void 27 | ignore_stderr (void) 28 | { 29 | int fd = open (_PATH_DEVNULL, O_WRONLY); 30 | if (fd == -1) 31 | close (STDERR_FILENO); 32 | else 33 | { 34 | dup2 (fd, STDERR_FILENO); 35 | close (fd); 36 | } 37 | setenv ("LIBC_FATAL_STDERR_", "1", 1); 38 | } 39 | -------------------------------------------------------------------------------- /test/support/oom_error.c: -------------------------------------------------------------------------------- 1 | /* Reporting out-of-memory errors. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | void 25 | oom_error (const char *function, size_t size) 26 | { 27 | printf ("%s: unable to allocate %zu bytes: %m\n", function, size); 28 | exit (1); 29 | } 30 | -------------------------------------------------------------------------------- /test/support/run_diff.h: -------------------------------------------------------------------------------- 1 | /* Invoke the system diff tool to compare two strings. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #ifndef SUPPORT_RUN_DIFF_H 20 | #define SUPPORT_RUN_DIFF_H 21 | 22 | /* Compare the two NUL-terminated strings LEFT and RIGHT using the 23 | diff tool. Label the sides of the diff with LEFT_LABEL and 24 | RIGHT_LABEL, respectively. 25 | 26 | This function assumes that LEFT and RIGHT are different 27 | strings. */ 28 | void support_run_diff (const char *left_label, const char *left, 29 | const char *right_label, const char *right); 30 | 31 | #endif /* SUPPORT_RUN_DIFF_H */ 32 | -------------------------------------------------------------------------------- /test/support/set_fortify_handler.c: -------------------------------------------------------------------------------- 1 | /* Set signal handler for use in fortify tests. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | void 24 | set_fortify_handler (void (*handler) (int sig)) 25 | { 26 | struct sigaction sa; 27 | 28 | sa.sa_handler = handler; 29 | sa.sa_flags = 0; 30 | sigemptyset (&sa.sa_mask); 31 | 32 | sigaction (SIGABRT, &sa, NULL); 33 | ignore_stderr (); 34 | } 35 | -------------------------------------------------------------------------------- /test/support/support-xfstat.c: -------------------------------------------------------------------------------- 1 | /* fstat64 with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | xfstat (int fd, struct stat64 *result) 25 | { 26 | if (fstat64 (fd, result) != 0) 27 | FAIL_EXIT1 ("fstat64 (%d): %m", fd); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/support-xstat.c: -------------------------------------------------------------------------------- 1 | /* stat64 with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | /* NB: Non-standard file name to avoid sysdeps override for xstat. */ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | xstat (const char *path, struct stat64 *result) 27 | { 28 | if (stat64 (path, result) != 0) 29 | FAIL_EXIT1 ("stat64 (\"%s\"): %m", path); 30 | } 31 | -------------------------------------------------------------------------------- /test/support/support_format_address_family.c: -------------------------------------------------------------------------------- 1 | /* Convert an address family to a string. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | char * 24 | support_format_address_family (int family) 25 | { 26 | switch (family) 27 | { 28 | case AF_INET: 29 | return xstrdup ("INET"); 30 | case AF_INET6: 31 | return xstrdup ("INET6"); 32 | default: 33 | return xasprintf ("", family); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/support/support_format_herrno.c: -------------------------------------------------------------------------------- 1 | /* Convert a h_errno error code to a string. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | char * 24 | support_format_herrno (int code) 25 | { 26 | const char *errstr; 27 | switch (code) 28 | { 29 | case HOST_NOT_FOUND: 30 | errstr = "HOST_NOT_FOUND"; 31 | break; 32 | case NO_ADDRESS: 33 | errstr = "NO_ADDRESS"; 34 | break; 35 | case NO_RECOVERY: 36 | errstr = "NO_RECOVERY"; 37 | break; 38 | case TRY_AGAIN: 39 | errstr = "TRY_AGAIN"; 40 | break; 41 | default: 42 | return xasprintf ("\n", code); 43 | } 44 | return xstrdup (errstr); 45 | } 46 | -------------------------------------------------------------------------------- /test/support/support_isolate_in_subprocess.c: -------------------------------------------------------------------------------- 1 | /* Run a function in a subprocess. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | void 23 | support_isolate_in_subprocess (void (*callback) (void *), void *closure) 24 | { 25 | pid_t pid = xfork (); 26 | if (pid == 0) 27 | { 28 | /* Child process. */ 29 | callback (closure); 30 | _exit (0); 31 | } 32 | 33 | /* Parent process. */ 34 | int status; 35 | xwaitpid (pid, &status, 0); 36 | if (status != 0) 37 | FAIL_EXIT1 ("child process exited with status %d", status); 38 | } 39 | -------------------------------------------------------------------------------- /test/support/support_test_verify_impl.c: -------------------------------------------------------------------------------- 1 | /* Implementation of the TEST_VERIFY and TEST_VERIFY_EXIT macros. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | support_test_verify_impl (const char *file, int line, const char *expr) 27 | { 28 | int saved_errno = errno; 29 | support_record_failure (); 30 | printf ("error: %s:%d: not true: %s\n", file, line, expr); 31 | errno = saved_errno; 32 | } 33 | 34 | void 35 | support_test_verify_exit_impl (int status, const char *file, int line, 36 | const char *expr) 37 | { 38 | support_test_verify_impl (file, line, expr); 39 | exit (status); 40 | } 41 | -------------------------------------------------------------------------------- /test/support/temp_file-internal.h: -------------------------------------------------------------------------------- 1 | /* Internal weak declarations for temporary file handling. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #ifndef SUPPORT_TEMP_FILE_INTERNAL_H 20 | #define SUPPORT_TEMP_FILE_INTERNAL_H 21 | 22 | /* These functions are called by the test driver if they are 23 | defined. Tests should not call them directly. */ 24 | 25 | #include 26 | 27 | void support_set_test_dir (const char *name) __attribute__ ((weak)); 28 | void support_delete_temp_files (void) __attribute__ ((weak)); 29 | void support_print_temp_files (FILE *) __attribute__ ((weak)); 30 | 31 | #endif /* SUPPORT_TEMP_FILE_INTERNAL_H */ 32 | -------------------------------------------------------------------------------- /test/support/write_message.c: -------------------------------------------------------------------------------- 1 | /* Write a message to standard output. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | write_message (const char *message) 27 | { 28 | int saved_errno = errno; 29 | ssize_t unused __attribute__ ((unused)); 30 | unused = write (STDOUT_FILENO, message, strlen (message)); 31 | errno = saved_errno; 32 | } 33 | -------------------------------------------------------------------------------- /test/support/xaccept.c: -------------------------------------------------------------------------------- 1 | /* accept with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | int 26 | xaccept (int fd, struct sockaddr *sa, socklen_t *salen) 27 | { 28 | int clientfd = accept (fd, sa, salen); 29 | if (clientfd < 0) 30 | FAIL_EXIT1 ("accept (%d): %m", fd); 31 | return clientfd; 32 | } 33 | -------------------------------------------------------------------------------- /test/support/xaccept4.c: -------------------------------------------------------------------------------- 1 | /* accept4 with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | int 26 | xaccept4 (int fd, struct sockaddr *sa, socklen_t *salen, int flags) 27 | { 28 | int clientfd = accept4 (fd, sa, salen, flags); 29 | if (clientfd < 0) 30 | FAIL_EXIT1 ("accept4 (%d, 0x%x): %m", fd, flags); 31 | return clientfd; 32 | } 33 | -------------------------------------------------------------------------------- /test/support/xasprintf.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for asprintf. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | char * 27 | xasprintf (const char *format, ...) 28 | { 29 | va_list ap; 30 | va_start (ap, format); 31 | char *result; 32 | if (vasprintf (&result, format, ap) < 0) 33 | FAIL_EXIT1 ("asprintf: %m"); 34 | va_end (ap); 35 | return result; 36 | } 37 | -------------------------------------------------------------------------------- /test/support/xbind.c: -------------------------------------------------------------------------------- 1 | /* bind with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | xbind (int fd, const struct sockaddr *sa, socklen_t sa_len) 27 | { 28 | if (bind (fd, sa, sa_len) != 0) 29 | FAIL_EXIT1 ("bind (%d), family %d: %m", fd, sa->sa_family); 30 | } 31 | -------------------------------------------------------------------------------- /test/support/xcalloc.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for calloc. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void * 26 | xcalloc (size_t n, size_t s) 27 | { 28 | void *p; 29 | 30 | p = calloc (n, s); 31 | if (p == NULL) 32 | oom_error ("calloc", n * s); 33 | return p; 34 | } 35 | -------------------------------------------------------------------------------- /test/support/xchroot.c: -------------------------------------------------------------------------------- 1 | /* chroot with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | xchroot (const char *path) 25 | { 26 | if (chroot (path) != 0) 27 | FAIL_EXIT1 ("chroot (\"%s\"): %m", path); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xclose.c: -------------------------------------------------------------------------------- 1 | /* close with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | xclose (int fd) 25 | { 26 | if (close (fd) < 0 && errno != EINTR) 27 | FAIL_EXIT1 ("close of descriptor %d failed: %m", fd); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xconnect.c: -------------------------------------------------------------------------------- 1 | /* connect with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | xconnect (int fd, const struct sockaddr *sa, socklen_t sa_len) 27 | { 28 | if (connect (fd, sa, sa_len) != 0) 29 | FAIL_EXIT1 ("connect (%d), family %d: %m", fd, sa->sa_family); 30 | } 31 | -------------------------------------------------------------------------------- /test/support/xdlfcn.h: -------------------------------------------------------------------------------- 1 | /* Support functionality for using dlopen/dlclose/dlsym. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #ifndef SUPPORT_DLOPEN_H 20 | #define SUPPORT_DLOPEN_H 21 | 22 | #include 23 | 24 | __BEGIN_DECLS 25 | 26 | /* Each of these terminates process on failure with relevant error message. */ 27 | void *xdlopen (const char *filename, int flags); 28 | void *xdlsym (void *handle, const char *symbol); 29 | void xdlclose (void *handle); 30 | 31 | 32 | __END_DECLS 33 | 34 | #endif /* SUPPORT_DLOPEN_H */ 35 | -------------------------------------------------------------------------------- /test/support/xdup2.c: -------------------------------------------------------------------------------- 1 | /* dup2 with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | void 24 | xdup2 (int from, int to) 25 | { 26 | if (dup2 (from, to) < 0) 27 | FAIL_EXIT1 ("dup2 (%d, %d): %m", from, to); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xfclose.c: -------------------------------------------------------------------------------- 1 | /* fclose with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | void 25 | xfclose (FILE *fp) 26 | { 27 | if (ferror (fp)) 28 | FAIL_EXIT1 ("stdio stream closed with pending errors"); 29 | if (fflush (fp) != 0) 30 | FAIL_EXIT1 ("fflush: %m"); 31 | if (fclose (fp) != 0) 32 | FAIL_EXIT1 ("fclose: %m"); 33 | } 34 | -------------------------------------------------------------------------------- /test/support/xfopen.c: -------------------------------------------------------------------------------- 1 | /* fopen with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | FILE * 25 | xfopen (const char *path, const char *mode) 26 | { 27 | FILE *fp = fopen (path, mode); 28 | if (fp == NULL) 29 | FAIL_EXIT1 ("could not open %s (mode \"%s\"): %m", path, mode); 30 | return fp; 31 | } 32 | -------------------------------------------------------------------------------- /test/support/xfork.c: -------------------------------------------------------------------------------- 1 | /* fork with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | pid_t 26 | xfork (void) 27 | { 28 | pid_t result = fork (); 29 | if (result < 0) 30 | FAIL_EXIT1 ("fork: %m"); 31 | return result; 32 | } 33 | -------------------------------------------------------------------------------- /test/support/xftruncate.c: -------------------------------------------------------------------------------- 1 | /* ftruncate with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | void 23 | xftruncate (int fd, long long length) 24 | { 25 | if (ftruncate64 (fd, length) != 0) 26 | FAIL_EXIT1 ("ftruncate64 (%d, %lld): %m", fd, length); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xgetsockname.c: -------------------------------------------------------------------------------- 1 | /* getsockname with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | xgetsockname (int fd, struct sockaddr *sa, socklen_t *plen) 27 | { 28 | if (getsockname (fd, sa, plen) != 0) 29 | FAIL_EXIT1 ("setsockopt (%d): %m", fd); 30 | } 31 | -------------------------------------------------------------------------------- /test/support/xlisten.c: -------------------------------------------------------------------------------- 1 | /* listen with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | xlisten (int fd, int backlog) 27 | { 28 | if (listen (fd, backlog) != 0) 29 | FAIL_EXIT1 ("listen (%d, %d): %m", fd, backlog); 30 | } 31 | -------------------------------------------------------------------------------- /test/support/xlseek.c: -------------------------------------------------------------------------------- 1 | /* lseek with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | long long 23 | xlseek (int fd, long long offset, int whence) 24 | { 25 | long long result = lseek64 (fd, offset, whence); 26 | if (result < 0) 27 | FAIL_EXIT1 ("lseek64 (%d, %lld, %d): %m", fd, offset, whence); 28 | return result; 29 | } 30 | -------------------------------------------------------------------------------- /test/support/xmalloc.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for malloc. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void * 26 | xmalloc (size_t n) 27 | { 28 | void *p; 29 | 30 | p = malloc (n); 31 | if (p == NULL) 32 | oom_error ("malloc", n); 33 | return p; 34 | } 35 | -------------------------------------------------------------------------------- /test/support/xmemstream.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrappers for memstream functions. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | void 27 | xopen_memstream (struct xmemstream *stream) 28 | { 29 | int old_errno = errno; 30 | *stream = (struct xmemstream) {}; 31 | stream->out = open_memstream (&stream->buffer, &stream->length); 32 | if (stream->out == NULL) 33 | FAIL_EXIT1 ("open_memstream: %m"); 34 | errno = old_errno; 35 | } 36 | 37 | void 38 | xfclose_memstream (struct xmemstream *stream) 39 | { 40 | xfclose (stream->out); 41 | stream->out = NULL; 42 | } 43 | -------------------------------------------------------------------------------- /test/support/xmkdir.c: -------------------------------------------------------------------------------- 1 | /* mkdir with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | xmkdir (const char *path, mode_t mode) 25 | { 26 | if (mkdir (path, mode) != 0) 27 | FAIL_EXIT1 ("mkdir (\"%s\", 0%o): %m", path, mode); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xmmap.c: -------------------------------------------------------------------------------- 1 | /* mmap with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void * 24 | xmmap (void *addr, size_t length, int prot, int flags, int fd) 25 | { 26 | void *result = mmap (addr, length, prot, flags, fd, 0); 27 | if (result == MAP_FAILED) 28 | FAIL_EXIT1 ("mmap of %zu bytes, prot=0x%x, flags=0x%x: %m", 29 | length, prot, flags); 30 | return result; 31 | } 32 | -------------------------------------------------------------------------------- /test/support/xmprotect.c: -------------------------------------------------------------------------------- 1 | /* mprotect with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | xmprotect (void *addr, size_t length, int prot) 25 | { 26 | if (mprotect (addr, length, prot) != 0) 27 | FAIL_EXIT1 ("mprotect (%p, %zu, 0x%x): %m", addr, length, prot); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xmunmap.c: -------------------------------------------------------------------------------- 1 | /* munmap with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | void 24 | xmunmap (void *addr, size_t length) 25 | { 26 | if (munmap (addr, length) != 0) 27 | FAIL_EXIT1 ("munmap of %zu bytes: %m", length); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xopen.c: -------------------------------------------------------------------------------- 1 | /* open64 with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int 24 | xopen (const char *path, int flags, mode_t mode) 25 | { 26 | int ret = open64 (path, flags, mode); 27 | if (ret < 0) 28 | FAIL_EXIT1 ("open64 (\"%s\", 0x%x, 0%o): %m", path, flags, mode); 29 | return ret; 30 | } 31 | -------------------------------------------------------------------------------- /test/support/xpipe.c: -------------------------------------------------------------------------------- 1 | /* pipe with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | void 24 | xpipe (int fds[2]) 25 | { 26 | if (pipe (fds) < 0) 27 | FAIL_EXIT1 ("pipe: %m"); 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xpoll.c: -------------------------------------------------------------------------------- 1 | /* poll with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | int 26 | xpoll (struct pollfd *fds, nfds_t nfds, int timeout) 27 | { 28 | int ret = poll (fds, nfds, timeout); 29 | if (ret < 0) 30 | FAIL_EXIT1 ("poll: %m"); 31 | return ret; 32 | } 33 | -------------------------------------------------------------------------------- /test/support/xpthread_attr_destroy.c: -------------------------------------------------------------------------------- 1 | /* pthread_attr_destroy with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_attr_destroy (pthread_attr_t *attr) 23 | { 24 | xpthread_check_return ("pthread_attr_destroy", 25 | pthread_attr_destroy (attr)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_attr_init.c: -------------------------------------------------------------------------------- 1 | /* pthread_attr_init with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_attr_init (pthread_attr_t *attr) 23 | { 24 | xpthread_check_return ("pthread_attr_init", pthread_attr_init (attr)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_attr_setdetachstate.c: -------------------------------------------------------------------------------- 1 | /* pthread_attr_setdetachstate with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate) 23 | { 24 | xpthread_check_return ("pthread_attr_setdetachstate", 25 | pthread_attr_setdetachstate (attr, 26 | detachstate)); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xpthread_attr_setguardsize.c: -------------------------------------------------------------------------------- 1 | /* pthread_attr_setguardsize with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_attr_setguardsize (pthread_attr_t *attr, size_t guardsize) 23 | { 24 | xpthread_check_return ("pthread_attr_setguardize", 25 | pthread_attr_setguardsize (attr, guardsize)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_attr_setstacksize.c: -------------------------------------------------------------------------------- 1 | /* pthread_attr_setstacksize with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize) 23 | { 24 | xpthread_check_return ("pthread_attr_setstacksize", 25 | pthread_attr_setstacksize (attr, stacksize)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_barrier_destroy.c: -------------------------------------------------------------------------------- 1 | /* pthread_barrier_destroy with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_barrier_destroy (pthread_barrier_t *barrier) 23 | { 24 | xpthread_check_return ("pthread_barrier_destroy", 25 | pthread_barrier_destroy (barrier)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_barrier_init.c: -------------------------------------------------------------------------------- 1 | /* pthread_barrier_init with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_barrier_init (pthread_barrier_t *barrier, 23 | pthread_barrierattr_t *attr, unsigned int count) 24 | { 25 | xpthread_check_return ("pthread_barrier_init", 26 | pthread_barrier_init (barrier, attr, count)); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xpthread_barrier_wait.c: -------------------------------------------------------------------------------- 1 | /* pthread_barrier_wait with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | int 22 | xpthread_barrier_wait (pthread_barrier_t *barrier) 23 | { 24 | int ret = pthread_barrier_wait (barrier); 25 | if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) 26 | xpthread_check_return ("pthread_barrier_wait", ret); 27 | return ret == PTHREAD_BARRIER_SERIAL_THREAD; 28 | } 29 | -------------------------------------------------------------------------------- /test/support/xpthread_cancel.c: -------------------------------------------------------------------------------- 1 | /* pthread_cancel with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_cancel (pthread_t thr) 23 | { 24 | xpthread_check_return ("pthread_cancel", pthread_cancel (thr)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_check_return.c: -------------------------------------------------------------------------------- 1 | /* Return value checking for pthread functions, exit variant. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | void 27 | xpthread_check_return (const char *function, int value) 28 | { 29 | if (value != 0) 30 | { 31 | errno = value; 32 | FAIL_EXIT1 ("%s: %m", function); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/support/xpthread_cond_wait.c: -------------------------------------------------------------------------------- 1 | /* pthread_cond_wait with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) 23 | { 24 | xpthread_check_return 25 | ("pthread_cond_wait", pthread_cond_wait (cond, mutex)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_create.c: -------------------------------------------------------------------------------- 1 | /* pthread_create with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | pthread_t 22 | xpthread_create (pthread_attr_t *attr, 23 | void *(*thread_func) (void *), void *closure) 24 | { 25 | pthread_t thr; 26 | xpthread_check_return 27 | ("pthread_create", pthread_create (&thr, attr, thread_func, closure)); 28 | return thr; 29 | } 30 | -------------------------------------------------------------------------------- /test/support/xpthread_detach.c: -------------------------------------------------------------------------------- 1 | /* pthread_detach with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_detach (pthread_t thr) 23 | { 24 | xpthread_check_return ("pthread_detach", pthread_detach (thr)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_join.c: -------------------------------------------------------------------------------- 1 | /* pthread_join with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void * 22 | xpthread_join (pthread_t thr) 23 | { 24 | void *result; 25 | xpthread_check_return ("pthread_join", pthread_join (thr, &result)); 26 | return result; 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xpthread_mutex_consistent.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutex_consistent with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutex_consistent (pthread_mutex_t *mutex) 23 | { 24 | xpthread_check_return ("pthread_mutex_consistent", 25 | pthread_mutex_consistent (mutex)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_mutex_destroy.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutex_destroy with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutex_destroy (pthread_mutex_t *mutex) 23 | { 24 | xpthread_check_return ("pthread_mutex_destroy", 25 | pthread_mutex_destroy (mutex)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_mutex_init.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutex_init with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) 23 | { 24 | xpthread_check_return ("pthread_mutex_init", 25 | pthread_mutex_init (mutex, attr)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_mutex_lock.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutex_lock with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutex_lock (pthread_mutex_t *mutex) 23 | { 24 | xpthread_check_return ("pthread_mutex_lock", pthread_mutex_lock (mutex)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_mutex_unlock.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutex_unlock with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutex_unlock (pthread_mutex_t *mutex) 23 | { 24 | xpthread_check_return ("pthread_mutex_unlock", pthread_mutex_unlock (mutex)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_mutexattr_destroy.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutexattr_destroy with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutexattr_destroy (pthread_mutexattr_t *attr) 23 | { 24 | xpthread_check_return ("pthread_mutexattr_destroy", 25 | pthread_mutexattr_destroy (attr)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_mutexattr_init.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutexattr_init with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutexattr_init (pthread_mutexattr_t *attr) 23 | { 24 | xpthread_check_return ("pthread_mutexattr_init", pthread_mutexattr_init (attr)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_mutexattr_setprotocol.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutexattr_setprotocol with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutexattr_setprotocol (pthread_mutexattr_t *attr, int flag) 23 | { 24 | xpthread_check_return ("pthread_mutexattr_setprotocol", 25 | pthread_mutexattr_setprotocol (attr, flag)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_mutexattr_setpshared.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutexattr_setpshared with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutexattr_setpshared (pthread_mutexattr_t *attr, int flag) 23 | { 24 | xpthread_check_return ("pthread_mutexattr_setpshared", 25 | pthread_mutexattr_setpshared (attr, flag)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_mutexattr_setrobust.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutexattr_setrobust with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutexattr_setrobust (pthread_mutexattr_t *attr, int flag) 23 | { 24 | xpthread_check_return ("pthread_mutexattr_setrobust", 25 | pthread_mutexattr_setrobust (attr, flag)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_mutexattr_settype.c: -------------------------------------------------------------------------------- 1 | /* pthread_mutexattr_settype with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_mutexattr_settype (pthread_mutexattr_t *attr, int flag) 23 | { 24 | xpthread_check_return ("pthread_mutexattr_settype", 25 | pthread_mutexattr_settype (attr, flag)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_once.c: -------------------------------------------------------------------------------- 1 | /* pthread_once with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_once (pthread_once_t *guard, void (*func) (void)) 23 | { 24 | xpthread_check_return ("pthread_once", pthread_once (guard, func)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_rwlock_init.c: -------------------------------------------------------------------------------- 1 | /* pthread_rwlock_init with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_rwlock_init (pthread_rwlock_t *rwlock, 23 | const pthread_rwlockattr_t *attr) 24 | { 25 | xpthread_check_return ("pthread_rwlock_init", 26 | pthread_rwlock_init (rwlock, attr)); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xpthread_rwlock_rdlock.c: -------------------------------------------------------------------------------- 1 | /* pthread_rwlock_rdlock with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_rwlock_rdlock (pthread_rwlock_t *rwlock) 23 | { 24 | xpthread_check_return ("pthread_rwlock_rdlock", 25 | pthread_rwlock_rdlock (rwlock)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_rwlock_unlock.c: -------------------------------------------------------------------------------- 1 | /* pthread_rwlock_unlock with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_rwlock_unlock (pthread_rwlock_t *rwlock) 23 | { 24 | xpthread_check_return ("pthread_rwlock_unlock", 25 | pthread_rwlock_unlock (rwlock)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_rwlock_wrlock.c: -------------------------------------------------------------------------------- 1 | /* pthread_rwlock_wrlock with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_rwlock_wrlock (pthread_rwlock_t *rwlock) 23 | { 24 | xpthread_check_return ("pthread_rwlock_wrlock", 25 | pthread_rwlock_wrlock (rwlock)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_rwlockattr_init.c: -------------------------------------------------------------------------------- 1 | /* pthread_rwlockattr_init with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_rwlockattr_init (pthread_rwlockattr_t *attr) 23 | { 24 | xpthread_check_return ("pthread_rwlockattr_init", 25 | pthread_rwlockattr_init (attr)); 26 | } 27 | -------------------------------------------------------------------------------- /test/support/xpthread_rwlockattr_setkind_np.c: -------------------------------------------------------------------------------- 1 | /* pthread_rwlockattr_setkind_np with error checking. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_rwlockattr_setkind_np (pthread_rwlockattr_t *attr, 23 | int pref) 24 | { 25 | xpthread_check_return ("pthread_rwlockattr_setkind_np", 26 | pthread_rwlockattr_setkind_np (attr, pref)); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xpthread_sigmask.c: -------------------------------------------------------------------------------- 1 | /* pthread_sigmask with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | void 25 | xpthread_sigmask (int how, const sigset_t *set, sigset_t *oldset) 26 | { 27 | if (pthread_sigmask (how, set, oldset) != 0) 28 | { 29 | write_message ("error: pthread_setmask failed\n"); 30 | /* Do not use exit because pthread_sigmask can be called from a 31 | signal handler. */ 32 | _exit (1); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/support/xpthread_spin_lock.c: -------------------------------------------------------------------------------- 1 | /* pthread_spin_lock with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_spin_lock (pthread_spinlock_t *lock) 23 | { 24 | xpthread_check_return ("pthread_spin_lock", pthread_spin_lock (lock)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xpthread_spin_unlock.c: -------------------------------------------------------------------------------- 1 | /* pthread_spin_unlock with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | void 22 | xpthread_spin_unlock (pthread_spinlock_t *lock) 23 | { 24 | xpthread_check_return ("pthread_spin_unlock", pthread_spin_unlock (lock)); 25 | } 26 | -------------------------------------------------------------------------------- /test/support/xraise.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for raise. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | void 23 | xraise (int sig) 24 | { 25 | if (raise (sig) != 0) 26 | FAIL_EXIT1 ("raise (%d): %m" , sig); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xrealloc.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for realloc. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void * 26 | xrealloc (void *p, size_t n) 27 | { 28 | void *result = realloc (p, n); 29 | if (result == NULL && (n > 0 || p == NULL)) 30 | oom_error ("realloc", n); 31 | return result; 32 | } 33 | -------------------------------------------------------------------------------- /test/support/xrecvfrom.c: -------------------------------------------------------------------------------- 1 | /* recvfrom with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | size_t 26 | xrecvfrom (int fd, void *buf, size_t buflen, int flags, 27 | struct sockaddr *sa, socklen_t *salen) 28 | { 29 | ssize_t ret = recvfrom (fd, buf, buflen, flags, sa, salen); 30 | if (ret < 0) 31 | FAIL_EXIT1 ("error: recvfrom (%d), %zu bytes buffer: %m", fd, buflen); 32 | return ret; 33 | } 34 | -------------------------------------------------------------------------------- /test/support/xsendto.c: -------------------------------------------------------------------------------- 1 | /* sendto with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | xsendto (int fd, const void *buf, size_t buflen, int flags, 27 | const struct sockaddr *sa, socklen_t salen) 28 | { 29 | ssize_t ret = sendto (fd, buf, buflen, flags, sa, salen); 30 | if (ret < 0) 31 | FAIL_EXIT1 ("sendto (%d), %zu bytes, family %d: %m", 32 | fd, buflen, sa->sa_family); 33 | if (ret != buflen) 34 | FAIL_EXIT1 ("sendto (%d) sent %zd bytes instead of %zu", fd, ret, buflen); 35 | } 36 | -------------------------------------------------------------------------------- /test/support/xsetsockopt.c: -------------------------------------------------------------------------------- 1 | /* setsockopt with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | void 26 | xsetsockopt (int fd, int level, int name, const void *val, socklen_t vallen) 27 | { 28 | if (setsockopt (fd, level, name, val, vallen) != 0) 29 | FAIL_EXIT1 ("setsockopt (%d, %d, %d), %zu bytes: %m", 30 | fd, level, name, (size_t) vallen); 31 | } 32 | -------------------------------------------------------------------------------- /test/support/xsigaction.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for sigaction. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | void 23 | xsigaction (int sig, const struct sigaction *newact, struct sigaction *oldact) 24 | { 25 | if (sigaction (sig, newact, oldact)) 26 | FAIL_EXIT1 ("sigaction (%d): %m" , sig); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xsignal.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for signal. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | sighandler_t 23 | xsignal (int sig, sighandler_t handler) 24 | { 25 | sighandler_t result = signal (sig, handler); 26 | if (result == SIG_ERR) 27 | FAIL_EXIT1 ("signal (%d, %p): %m", sig, handler); 28 | return result; 29 | } 30 | -------------------------------------------------------------------------------- /test/support/xsocket.c: -------------------------------------------------------------------------------- 1 | /* socket with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | int 26 | xsocket (int domain, int type, int protocol) 27 | { 28 | int fd = socket (domain, type, protocol); 29 | if (fd < 0) 30 | FAIL_EXIT1 ("socket (%d, %d, %d): %m\n", domain, type, protocol); 31 | return fd; 32 | } 33 | -------------------------------------------------------------------------------- /test/support/xstdio.h: -------------------------------------------------------------------------------- 1 | /* Error-checking wrappers for stdio functions. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #ifndef SUPPORT_XSTDIO_H 20 | #define SUPPORT_XSTDIO_H 21 | 22 | #include 23 | #include 24 | 25 | __BEGIN_DECLS 26 | 27 | FILE *xfopen (const char *path, const char *mode); 28 | void xfclose (FILE *); 29 | 30 | __END_DECLS 31 | 32 | #endif /* SUPPORT_XSTDIO_H */ 33 | -------------------------------------------------------------------------------- /test/support/xstrdup.c: -------------------------------------------------------------------------------- 1 | /* strdup with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | char * 24 | xstrdup (const char *s) 25 | { 26 | char *p = strdup (s); 27 | if (p == NULL) 28 | oom_error ("strdup", strlen (s)); 29 | return p; 30 | } 31 | -------------------------------------------------------------------------------- /test/support/xstrndup.c: -------------------------------------------------------------------------------- 1 | /* strndup with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | char * 24 | xstrndup (const char *s, size_t length) 25 | { 26 | char *p = strndup (s, length); 27 | if (p == NULL) 28 | oom_error ("strndup", length); 29 | return p; 30 | } 31 | -------------------------------------------------------------------------------- /test/support/xsysconf.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for sysconf. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | long 24 | xsysconf (int name) 25 | { 26 | /* Detect errors by a changed errno value, in case -1 is a valid 27 | value. Make sure that the caller does not see the zero value for 28 | errno. */ 29 | int old_errno = errno; 30 | errno = 0; 31 | long result = sysconf (name); 32 | if (errno != 0) 33 | FAIL_EXIT1 ("sysconf (%d): %m", name); 34 | errno = old_errno; 35 | return result; 36 | } 37 | -------------------------------------------------------------------------------- /test/support/xunlink.c: -------------------------------------------------------------------------------- 1 | /* Error-checking wrapper for unlink. 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | #include 21 | 22 | void 23 | xunlink (const char *path) 24 | { 25 | if (unlink (path) != 0) 26 | FAIL_EXIT1 ("unlink (\"%s\"): %m", path); 27 | } 28 | -------------------------------------------------------------------------------- /test/support/xwaitpid.c: -------------------------------------------------------------------------------- 1 | /* waitpid with error checking. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | int 27 | xwaitpid (int pid, int *status, int flags) 28 | { 29 | pid_t result = waitpid (pid, status, flags); 30 | if (result < 0) 31 | FAIL_EXIT1 ("waitpid: %m\n"); 32 | return result; 33 | } 34 | -------------------------------------------------------------------------------- /test/support/xwrite.c: -------------------------------------------------------------------------------- 1 | /* write with error checking and retries. 2 | Copyright (C) 2016-2018 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, see 17 | . */ 18 | 19 | #include 20 | 21 | #include 22 | 23 | void 24 | xwrite (int fd, const void *buffer, size_t length) 25 | { 26 | const char *p = buffer; 27 | const char *end = p + length; 28 | while (p < end) 29 | { 30 | ssize_t ret = write (fd, p, end - p); 31 | if (ret < 0) 32 | FAIL_EXIT1 ("write of %zu bytes failed after %td: %m", 33 | length, p - (const char *) buffer); 34 | if (ret == 0) 35 | FAIL_EXIT1 ("write return 0 after writing %td bytes of %zu", 36 | p - (const char *) buffer, length); 37 | p += ret; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/test.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_TEST_H 3 | #define __QUARK_TEST_H 1 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "time/time_testcase.h" 10 | 11 | __BEGIN_DECLS 12 | 13 | typedef struct __st_test_case{ 14 | int (*func)(void) ; 15 | const char * name ; 16 | } test_case_t ; 17 | 18 | #define TEST_CASE(func) {func , #func} 19 | 20 | static test_case_t __test_cases__[] = { 21 | TEST_CASE(do_test_mktime) , 22 | 23 | {NULL , NULL} 24 | } ; 25 | 26 | __END_DECLS 27 | 28 | #endif /** __QUARK_TEST_H */ 29 | -------------------------------------------------------------------------------- /test/test.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/test/test.vcproj -------------------------------------------------------------------------------- /test/time/time_testcase.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __QUARK_TEST_TIME_TESTCASE_H 3 | #define __QUARK_TEST_TIME_TESTCASE_H 1 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | __BEGIN_DECLS 10 | 11 | extern int do_test_mktime(void) ; 12 | 13 | __END_DECLS 14 | 15 | #endif /** __QUARK_TEST_TIME_TESTCASE_H */ 16 | -------------------------------------------------------------------------------- /test/time/tst-mktime.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuarkCloud/quark/71ed73f74af05bd78f46f1bc23b03291fc1b2f2f/test/time/tst-mktime.cpp -------------------------------------------------------------------------------- /test/time/tst-mktime3.c: -------------------------------------------------------------------------------- 1 | /* Test program for mktime bugs with out-of-range tm_sec values. */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | struct tm tests[] = 8 | { 9 | { .tm_sec = -1, .tm_mday = 1, .tm_year = 104 }, 10 | { .tm_sec = 65, .tm_min = 59, .tm_hour = 23, .tm_mday = 31, 11 | .tm_mon = 11, .tm_year = 101 } 12 | }; 13 | struct tm expected[] = 14 | { 15 | { .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 31, 16 | .tm_mon = 11, .tm_year = 103, .tm_wday = 3, .tm_yday = 364 }, 17 | { .tm_sec = 5, .tm_mday = 1, .tm_year = 102, .tm_wday = 2 } 18 | }; 19 | 20 | static int 21 | do_test (void) 22 | { 23 | setenv ("TZ", "UTC", 1); 24 | int i; 25 | for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i) 26 | { 27 | if (mktime (&tests[i]) < 0) 28 | { 29 | printf ("mktime %d failed\n", i); 30 | return 1; 31 | } 32 | #define CHECK(name) \ 33 | if (tests[i].name != expected[i].name) \ 34 | { \ 35 | printf ("test %d " #name " got %d expected %d\n", \ 36 | i, tests[i].name, expected[i].name); \ 37 | return 1; \ 38 | } 39 | CHECK (tm_sec) 40 | CHECK (tm_min) 41 | CHECK (tm_hour) 42 | CHECK (tm_mday) 43 | CHECK (tm_mon) 44 | CHECK (tm_year) 45 | CHECK (tm_wday) 46 | CHECK (tm_yday) 47 | CHECK (tm_isdst) 48 | } 49 | return 0; 50 | } 51 | 52 | #define TEST_FUNCTION do_test () 53 | #include "../test-skeleton.c" 54 | -------------------------------------------------------------------------------- /test/time/tst-strptime-whitespace.c: -------------------------------------------------------------------------------- 1 | /* Verify that strptime accepts arbitrary whitespace between tokens. 2 | 3 | Copyright (C) 2013-2018 Free Software Foundation, Inc. 4 | This file is part of the GNU C Library. 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | The GNU C Library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public 17 | License along with the GNU C Library; if not, see 18 | . */ 19 | 20 | #define _XOPEN_SOURCE 21 | #include 22 | #include 23 | #include 24 | 25 | int 26 | do_test (void) 27 | { 28 | struct tm t; 29 | const char *in = "Tuesday \t 22 \t July\t1942"; 30 | 31 | char *r = strptime (in, "%A%d %b%Y", &t); 32 | 33 | if (r == NULL || r != in + strlen (in)) 34 | { 35 | printf ("strptime failed\n"); 36 | return 1; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | #define TEST_FUNCTION do_test () 43 | #include "../test-skeleton.c" 44 | -------------------------------------------------------------------------------- /test/time/tst_wcsftime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | main (int argc, char *argv[]) 6 | { 7 | wchar_t buf[200]; 8 | time_t t; 9 | struct tm *tp; 10 | int result = 0; 11 | size_t n; 12 | 13 | time (&t); 14 | tp = gmtime (&t); 15 | 16 | n = wcsftime (buf, sizeof (buf) / sizeof (buf[0]), 17 | L"%H:%M:%S %Y-%m-%d\n", tp); 18 | if (n != 21) 19 | result = 1; 20 | 21 | wprintf (L"It is now %ls", buf); 22 | 23 | wcsftime (buf, sizeof (buf) / sizeof (buf[0]), L"%A\n", tp); 24 | 25 | wprintf (L"The weekday is %ls", buf); 26 | 27 | return result; 28 | } 29 | --------------------------------------------------------------------------------