├── autotools ├── .deps │ ├── packcc.Po │ └── test.Po ├── src │ ├── .deps │ │ ├── packcc.Po │ │ └── test.Po │ ├── test.c │ └── Makefile.am ├── stamp-h1 ├── Makefile.am ├── config.h.in ├── config.h.in~ ├── config.h └── configure.ac ├── standard ├── iso │ ├── hello │ │ ├── hello3.h │ │ ├── hello2.h │ │ ├── hello │ │ ├── hello.o │ │ ├── hello2.c │ │ ├── hello3.c │ │ ├── hong.c │ │ ├── hello.c │ │ ├── conditioncompile2.c │ │ ├── conditioncompile.c │ │ ├── conditioncompile3.c │ │ └── hello.s │ ├── header │ │ ├── stdio.h │ │ │ ├── output.data │ │ │ ├── fprintf │ │ │ │ ├── test │ │ │ │ ├── Makefile │ │ │ │ └── test.c │ │ │ ├── perror.c │ │ │ ├── putchar.c │ │ │ ├── fputc.c │ │ │ ├── putc.c │ │ │ ├── tmpfile.c │ │ │ ├── fgetpos.c │ │ │ ├── fwrite.c │ │ │ ├── remove.c │ │ │ ├── fgetc.c │ │ │ ├── fread.c │ │ │ ├── getchar.c │ │ │ ├── fseek.c │ │ │ ├── puts.c │ │ │ ├── ftell.c │ │ │ ├── fputs.c │ │ │ ├── fgets.c │ │ │ ├── gets.c │ │ │ ├── rename.c │ │ │ └── freopen.c │ │ ├── math.h │ │ │ ├── modf.c │ │ │ ├── atan2.c │ │ │ ├── ceil.c │ │ │ ├── floor.c │ │ │ ├── atan.c │ │ │ ├── sqrt.c │ │ │ ├── tanh.c │ │ │ ├── fmod.c │ │ │ ├── acos.c │ │ │ ├── asin.c │ │ │ ├── sinh.c │ │ │ ├── log.c │ │ │ ├── cosh.c │ │ │ ├── exp.c │ │ │ ├── math.c │ │ │ ├── sin.c │ │ │ └── sin2.c │ │ ├── stdbool.h │ │ │ ├── bool.h │ │ │ ├── bool2.c │ │ │ ├── bool.c │ │ │ └── bool.s │ │ ├── stdlib.h │ │ │ ├── system.c │ │ │ ├── exit2.c │ │ │ ├── exit.c │ │ │ ├── abort.c │ │ │ ├── calloc.c │ │ │ ├── malloc.c │ │ │ ├── abs.c │ │ │ ├── atexit.c │ │ │ ├── realloc.c │ │ │ ├── abort2.c │ │ │ ├── putenv.c │ │ │ ├── unsetenv.c │ │ │ ├── realloc2.c │ │ │ ├── stdlib.c │ │ │ ├── rand.c │ │ │ ├── setenv.c │ │ │ ├── getenv.c │ │ │ └── str2num.c │ │ ├── string.h │ │ │ ├── strcpy.c │ │ │ ├── strcat.c │ │ │ ├── strncat.c │ │ │ ├── strncpy.c │ │ │ ├── strcmp.c │ │ │ ├── strlen.c │ │ │ ├── strerror_r.c │ │ │ └── strncmp.c │ │ ├── time.h │ │ │ ├── time.c │ │ │ ├── ctime.c │ │ │ ├── asctime.c │ │ │ ├── clock.c │ │ │ ├── mktime.c │ │ │ ├── tzset.c │ │ │ ├── difftime.c │ │ │ ├── strftime.c │ │ │ ├── localtime.c │ │ │ └── gmtime.c │ │ ├── locale.h │ │ │ ├── localeconv.c │ │ │ └── locale.c │ │ ├── assert.h │ │ │ ├── assert.c │ │ │ └── assert2.c │ │ ├── setjmp.h │ │ │ ├── goto2.c │ │ │ ├── goto.c │ │ │ ├── setjmp.c │ │ │ ├── setjmp2.c │ │ │ └── setjmp3.c │ │ ├── ctype.h │ │ │ ├── isalnum.c │ │ │ ├── isalpha.c │ │ │ ├── isascii.c │ │ │ ├── isblank.c │ │ │ ├── iscntrl.c │ │ │ ├── isdigit.c │ │ │ ├── isgraph.c │ │ │ ├── islower.c │ │ │ ├── isprint.c │ │ │ ├── ispunct.c │ │ │ ├── isspace.c │ │ │ ├── isupper.c │ │ │ └── isxdigit.c │ │ ├── limits.h │ │ │ └── limits.c │ │ ├── signal.h │ │ │ └── signal.c │ │ └── stdarg.h │ │ │ ├── stdarg.c │ │ │ └── stdarg2.c │ ├── comment │ │ └── comment.c │ ├── variable │ │ ├── other.c │ │ ├── other.h │ │ ├── auto.c │ │ ├── __thread │ │ │ ├── test.c │ │ │ └── Makefile │ │ ├── static.c │ │ ├── extern.c │ │ ├── extern2.c │ │ ├── local.c │ │ ├── register.c │ │ └── static2.c │ ├── function │ │ ├── main3.c │ │ ├── main2.c │ │ ├── main1.c │ │ └── main4.c │ ├── number │ │ ├── int │ │ │ ├── integer2.c │ │ │ ├── integer4.c │ │ │ ├── integer.h │ │ │ ├── integer3.c │ │ │ └── integer.c │ │ ├── number2.c │ │ ├── number.c │ │ └── float │ │ │ ├── float4.c │ │ │ ├── float2.c │ │ │ ├── float3.c │ │ │ └── float.c │ ├── data-type │ │ ├── pointer │ │ │ ├── pointer7.c │ │ │ ├── pointer2.c │ │ │ ├── pointer3.c │ │ │ ├── pointer4.c │ │ │ ├── swap.c │ │ │ ├── swap2.c │ │ │ ├── pointer5.c │ │ │ ├── swap3.c │ │ │ ├── pointer6.c │ │ │ ├── pointer8.c │ │ │ ├── pointer10.c │ │ │ ├── pointer.c │ │ │ └── pointer9.c │ │ ├── char │ │ │ ├── chinese.c │ │ │ ├── char.c │ │ │ └── char2.c │ │ ├── union │ │ │ ├── union4.c │ │ │ ├── union5.c │ │ │ ├── union.c │ │ │ ├── union2.c │ │ │ └── union3.c │ │ ├── array │ │ │ ├── array.c │ │ │ ├── 99MultipTable.c │ │ │ ├── array6.c │ │ │ ├── array8.c │ │ │ ├── array5.c │ │ │ ├── array4.c │ │ │ ├── array2.c │ │ │ ├── array7.c │ │ │ └── array3.c │ │ ├── struct │ │ │ ├── person6.c │ │ │ ├── person7.c │ │ │ ├── person4.c │ │ │ ├── person3.c │ │ │ ├── person5.c │ │ │ ├── person.c │ │ │ └── person2.c │ │ └── enum │ │ │ ├── enum3.c │ │ │ ├── enum2.c │ │ │ ├── enum5.c │ │ │ ├── enum4.c │ │ │ ├── enum8.c │ │ │ ├── enum6.c │ │ │ ├── enum.c │ │ │ └── enum7.c │ ├── macro │ │ └── build_in_macro.c │ └── operator │ │ ├── sizeof4.c │ │ ├── typedef.c │ │ ├── sizeof2.c │ │ ├── sizeof3.c │ │ └── sizeof.c ├── posix │ ├── dlfcn.h │ │ ├── add.c │ │ ├── compile_time_link.c │ │ ├── Makefile │ │ └── compile_time_do_not_link.c │ ├── sys │ │ ├── stat.h │ │ │ ├── stat64 │ │ │ ├── Makefile │ │ │ └── stat64.c │ │ └── syscall.c │ ├── unistd.h │ │ ├── gid.c │ │ ├── uid.c │ │ ├── getuid.c │ │ ├── getppid.c │ │ ├── getpid.c │ │ ├── _exit.c │ │ ├── exec.c │ │ ├── exec3.c │ │ ├── exec2.c │ │ ├── wait.c │ │ ├── getpgid.c │ │ ├── getcwd.c │ │ ├── fork.c │ │ ├── pipe.c │ │ ├── wait2.c │ │ ├── vfork.c │ │ ├── getopt.c │ │ ├── wait4.c │ │ ├── kill.c │ │ ├── chdir.c │ │ ├── wait3.c │ │ └── pathconf.c │ ├── langinfo.h │ │ ├── Makefile │ │ └── langinfo.c │ ├── spawn.h │ │ ├── Makefile │ │ └── posix_spawn_test.c │ ├── pthread.h │ │ ├── thread.c │ │ ├── thread2.c │ │ ├── thread4.c │ │ └── thread3.c │ └── examples │ │ └── socket │ │ ├── AF_INET │ │ └── client.c │ │ └── AF_LOCAL │ │ └── client.c └── linux │ └── eventpool.h │ ├── eventpooltest.c │ └── CMakeLists.txt ├── library ├── mbedTLS │ ├── HMAC │ │ ├── mbedtls │ │ │ ├── .!9834!config.h │ │ │ └── config.h │ │ ├── Android.mk │ │ └── Makefile │ ├── PBKDF2 │ │ ├── mbedtls │ │ │ ├── .!9834!config.h │ │ │ └── config.h │ │ ├── Android.mk │ │ ├── pbkdf2Test.html │ │ └── Makefile │ ├── MD5 │ │ ├── mbedtls │ │ │ └── config.h │ │ ├── md5Test │ │ ├── Android.mk │ │ ├── Makefile │ │ └── md5Test.c │ ├── SHA-1 │ │ ├── mbedtls │ │ │ └── config.h │ │ ├── Android.mk │ │ └── Makefile │ ├── SHA-224 │ │ ├── mbedtls │ │ │ └── config.h │ │ ├── Android.mk │ │ └── Makefile │ ├── SHA-256 │ │ ├── mbedtls │ │ │ └── config.h │ │ ├── Android.mk │ │ └── Makefile │ ├── SHA-384 │ │ ├── mbedtls │ │ │ └── config.h │ │ ├── Android.mk │ │ └── Makefile │ ├── SHA-512 │ │ ├── mbedtls │ │ │ └── config.h │ │ ├── Android.mk │ │ └── Makefile │ ├── RIPEMD-160 │ │ ├── mbedtls │ │ │ └── config.h │ │ ├── Android.mk │ │ └── Makefile │ ├── AES │ │ ├── mbedtls │ │ │ ├── config.h │ │ │ └── base16.h │ │ ├── Android.mk │ │ ├── AES.java │ │ └── Makefile │ └── base64 │ │ └── src │ │ ├── lib │ │ ├── base64.pc.in │ │ └── base64.c │ │ └── include │ │ └── base64.h ├── cJSON │ ├── cJSON.sh │ └── CMakeLists.txt ├── libcurl │ └── src │ │ ├── lib │ │ ├── http.pc.in │ │ └── httpConfig.cmake.in │ │ └── include │ │ └── http.h ├── libarchive │ └── src │ │ ├── lib │ │ ├── untar.pc.in │ │ └── untarConfig.cmake.in │ │ ├── include │ │ └── untar.h │ │ └── test │ │ └── untar.c ├── openssl │ └── SHA-256 │ │ └── src │ │ ├── lib │ │ ├── sha256sum.pc.in │ │ └── sha256sumConfig.cmake.in │ │ ├── include │ │ └── sha256sum.h │ │ └── test │ │ └── sha256sum.c ├── qrencode │ └── CMakeLists.txt ├── libcares │ └── CMakeLists.txt ├── libyaml │ ├── test.yml │ └── CMakeLists.txt ├── libelf │ └── CMakeLists.txt └── libgit2 │ ├── git-clone-simple.c │ └── git-open.c ├── .gitignore ├── compiler └── gcc │ ├── Doption │ ├── Makefile │ └── Doption.c ├── algorithm ├── convert │ ├── number │ │ ├── convertNum5.c │ │ ├── convertNum.c │ │ ├── convertNum2.c │ │ ├── convertNum3.c │ │ └── convertNum4.c │ └── convert.c ├── crc │ ├── Android.mk │ ├── CRC.h │ ├── Makefile │ ├── CRC.c │ └── CRCTest.c ├── bcc │ ├── src │ │ ├── lib │ │ │ ├── bcc.c │ │ │ ├── bcc.h │ │ │ └── bcc.pc.in │ │ └── test │ │ │ └── bcc.c │ └── CMakeLists.txt ├── lrc │ ├── src │ │ ├── lib │ │ │ ├── lrc.h │ │ │ ├── lrc.c │ │ │ └── lrc.pc.in │ │ ├── main │ │ │ └── lrcsum.c │ │ └── test │ │ │ └── lrc.c │ └── CMakeLists.txt ├── url │ ├── src │ │ └── lib │ │ │ ├── url.pc.in │ │ │ └── url.h │ └── CMakeLists.txt ├── base16 │ └── src │ │ ├── lib │ │ ├── base16.pc.in │ │ ├── base16Config.cmake.in │ │ ├── base16.h │ │ └── base16.c │ │ └── test │ │ └── base16.c └── chinese-calendar │ └── src │ ├── lib │ ├── chinese-calendar.pc.in │ └── chinese-calendar.h │ └── test │ └── chinese-calendar.c ├── utils ├── self_exe_path │ ├── main.c │ ├── self.h │ └── CMakeLists.txt └── sysinfo │ └── src │ ├── lib │ ├── sysinfo.pc.in │ ├── sysinfoConfig.cmake.in │ └── sysinfo.h │ └── test │ └── sysinfo.c └── .github └── workflows ├── codacy-analysis.yml ├── openbsd.yml ├── freebsd.yml ├── vcpkg-macos.yml ├── netbsd.yml └── vcpkg-ubuntu.yml /autotools/.deps/packcc.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /autotools/src/.deps/packcc.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /autotools/src/.deps/test.Po: -------------------------------------------------------------------------------- 1 | # dummy 2 | -------------------------------------------------------------------------------- /standard/iso/hello/hello3.h: -------------------------------------------------------------------------------- 1 | void xx(); 2 | -------------------------------------------------------------------------------- /autotools/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /library/mbedTLS/HMAC/mbedtls/.!9834!config.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /library/mbedTLS/PBKDF2/mbedtls/.!9834!config.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/output.data: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build.d/ 2 | output/ 3 | */**/*.pc 4 | -------------------------------------------------------------------------------- /standard/iso/hello/hello2.h: -------------------------------------------------------------------------------- 1 | void yyxx(); 2 | 3 | -------------------------------------------------------------------------------- /library/mbedTLS/MD5/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_MD5_C 2 | -------------------------------------------------------------------------------- /autotools/Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | SUBDIRS = src 3 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-1/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_SHA1_C 2 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-224/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_SHA256_C 2 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-256/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_SHA256_C 2 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-384/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_SHA512_C 2 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-512/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_SHA512_C 2 | -------------------------------------------------------------------------------- /library/mbedTLS/RIPEMD-160/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_RIPEMD160_C 2 | -------------------------------------------------------------------------------- /standard/posix/dlfcn.h/add.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b) { 2 | return a + b; 3 | } 4 | -------------------------------------------------------------------------------- /library/mbedTLS/HMAC/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_MD_C 2 | #define MBEDTLS_SHA256_C 3 | -------------------------------------------------------------------------------- /compiler/gcc/Doption: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leleliu008/C-examples/HEAD/compiler/gcc/Doption -------------------------------------------------------------------------------- /library/mbedTLS/AES/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_AES_C 2 | #define MBEDTLS_CIPHER_MODE_CBC 3 | -------------------------------------------------------------------------------- /standard/iso/comment/comment.c: -------------------------------------------------------------------------------- 1 | /* 这是从C89开始支持的注释方式 */ 2 | 3 | // 这是从C99开始支持的注释方式,为了移植性,请尽量使用第一种注释 4 | -------------------------------------------------------------------------------- /compiler/gcc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Doption: Doption.c 3 | $(CC) $(CFLAGS) -o $@ $< 4 | 5 | .PHONY: Doption 6 | -------------------------------------------------------------------------------- /standard/iso/hello/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leleliu008/C-examples/HEAD/standard/iso/hello/hello -------------------------------------------------------------------------------- /standard/iso/variable/other.c: -------------------------------------------------------------------------------- 1 | #include"other.h" 2 | 3 | void func() { 4 | extern a; 5 | a = 20; 6 | } 7 | -------------------------------------------------------------------------------- /standard/iso/variable/other.h: -------------------------------------------------------------------------------- 1 | #ifndef OTHER_H 2 | #define OTHER_H 3 | 4 | void func(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /library/mbedTLS/MD5/md5Test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leleliu008/C-examples/HEAD/library/mbedTLS/MD5/md5Test -------------------------------------------------------------------------------- /standard/iso/hello/hello.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leleliu008/C-examples/HEAD/standard/iso/hello/hello.o -------------------------------------------------------------------------------- /autotools/src/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Hello world!\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /standard/iso/function/main3.c: -------------------------------------------------------------------------------- 1 | /* main函数参数测试 */ 2 | 3 | int main(int argc, char *argv[]) { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /library/mbedTLS/PBKDF2/mbedtls/config.h: -------------------------------------------------------------------------------- 1 | #define MBEDTLS_PKCS5_C 2 | #define MBEDTLS_MD_C 3 | #define MBEDTLS_SHA256_C 4 | -------------------------------------------------------------------------------- /standard/iso/hello/hello2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include"hello2.h" 3 | void yyxx() { 4 | printf("hello2"); 5 | } 6 | -------------------------------------------------------------------------------- /standard/iso/hello/hello3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include"hello3.h" 3 | 4 | void xx() { 5 | printf("hello3"); 6 | } 7 | -------------------------------------------------------------------------------- /standard/posix/sys/stat.h/stat64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leleliu008/C-examples/HEAD/standard/posix/sys/stat.h/stat64 -------------------------------------------------------------------------------- /standard/iso/variable/auto.c: -------------------------------------------------------------------------------- 1 | /* auto关键字测试 */ 2 | 3 | int main() { 4 | auto int a[] = {1, 2, 3, 4, 5}; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fprintf/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leleliu008/C-examples/HEAD/standard/iso/header/stdio.h/fprintf/test -------------------------------------------------------------------------------- /standard/iso/variable/__thread/test.c: -------------------------------------------------------------------------------- 1 | // thread-local storage 2 | __thread int tls = 0; 3 | 4 | int main() { 5 | return tls; 6 | } 7 | -------------------------------------------------------------------------------- /standard/iso/function/main2.c: -------------------------------------------------------------------------------- 1 | /* main函数的返回值测试 */ 2 | 3 | #include 4 | 5 | int main() { 6 | printf("me too!\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/number/int/integer2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | short x = 32767; 5 | x ++; 6 | printf("x = %d\n", x); 7 | } 8 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer7.c: -------------------------------------------------------------------------------- 1 | /* 指针赋值为0的意义 */ 2 | 3 | int main() { 4 | int *pa; 5 | 6 | pa = 0; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/modf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | double x = M_E; 5 | double a; 6 | modf(x, &a); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/gid.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | gid_t gid = getgid(); 5 | gid_t egid = getegid(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/uid.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | uid_t uid = getuid(); 5 | uid_t euid = geteuid(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /standard/iso/function/main1.c: -------------------------------------------------------------------------------- 1 | /* main函数的返回值测试 */ 2 | 3 | #include 4 | 5 | int main() { 6 | printf("I love you!\n"); 7 | return 100; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/header/stdbool.h/bool.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOL_H 2 | #define BOOL_H 3 | 4 | typedef enum { 5 | false, 6 | true 7 | } bool; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /standard/posix/langinfo.h/Makefile: -------------------------------------------------------------------------------- 1 | langinfo: langinfo.c 2 | $(CC) $(CFLAGS) -fPIC -o $@ $^ 3 | 4 | clean: 5 | rm -f langinfo 6 | 7 | .PHONY: clean 8 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/getuid.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | uid_t uid = getuid(); 5 | uid_t euid = geteuid(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/perror.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | errno = 0; 6 | perror("fail!"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/posix/sys/stat.h/Makefile: -------------------------------------------------------------------------------- 1 | stat64: stat64.c 2 | $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ 3 | 4 | clean: 5 | rm stat64 6 | 7 | .PHONY: clean 8 | -------------------------------------------------------------------------------- /standard/iso/number/int/integer4.c: -------------------------------------------------------------------------------- 1 | /* 查看整形变量在内存中的存储二进制 */ 2 | 3 | int main() { 4 | unsigned short a = 6; 5 | short b = 6; 6 | short c = -6; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/variable/__thread/Makefile: -------------------------------------------------------------------------------- 1 | test: test.c 2 | $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ 3 | 4 | clean: 5 | rm -f test 6 | 7 | .PHONY: clean 8 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fprintf/Makefile: -------------------------------------------------------------------------------- 1 | test: test.c 2 | $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ 3 | 4 | clean: 5 | rm -f test 6 | 7 | .PHONY: clean 8 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/getppid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | pid_t ppid = getppid(); 6 | pid_t pid = getpid(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/system.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | system("echo Hello World!"); 6 | printf("Done!\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char dest[10] = "abc"; 5 | char *src = "defghk"; 6 | strcpy(dest, src); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/time.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | time_t t1 = time(NULL); 5 | 6 | time_t t2; 7 | time(&t2); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/number/int/integer.h: -------------------------------------------------------------------------------- 1 | #if INT_MAX < 3000 2 | typedef short integer 3 | #elif INT_MAX <= 10000 4 | typedef int integer 5 | #else 6 | typedef long integer 7 | #endif 8 | -------------------------------------------------------------------------------- /standard/iso/number/number2.c: -------------------------------------------------------------------------------- 1 | /* 变量不初始化 */ 2 | 3 | int main() { 4 | short a; 5 | int b; 6 | long c; 7 | float d; 8 | double e; 9 | char f; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/variable/static.c: -------------------------------------------------------------------------------- 1 | /* 变量作用域 - 本文件内的全局变量*/ 2 | 3 | static int a = 20; 4 | 5 | int main(int argc, char *argv[]) { 6 | int a = 10; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/getpid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | pid_t pid = getpid(); 6 | printf("my pid is %d\n", pid); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /algorithm/convert/number/convertNum5.c: -------------------------------------------------------------------------------- 1 | /* 交换两个数,不使用第三个参数*/ 2 | 3 | int main() { 4 | int a = 3; 5 | int b = 4; 6 | 7 | b = a + 0 * (a = b); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char dest[10] = "abc"; 5 | char *src = "def\0ghkl"; 6 | strcat(dest, src); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/number/number.c: -------------------------------------------------------------------------------- 1 | /* 查看整形变量在内存中的存储二进制 */ 2 | 3 | int main() { 4 | short a = 6; 5 | int b = 6; 6 | float c = 6.0f; 7 | double d = 6.0; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strncat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char dest[10] = "abc"; 5 | char *src = "def\0ghkl"; 6 | strncat(dest, src, 8); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/posix/spawn.h/Makefile: -------------------------------------------------------------------------------- 1 | posix_spawn_test: posix_spawn_test.c 2 | $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $^ 3 | 4 | clean: 5 | rm posix_spawn_test 6 | 7 | .PHONY: clean 8 | -------------------------------------------------------------------------------- /standard/posix/sys/syscall.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("use syscall,pid is:%d\n",syscall("__NR_getpid")); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /algorithm/crc/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := CRC 6 | LOCAL_SRC_FILES := CRC.c 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer2.c: -------------------------------------------------------------------------------- 1 | /* 指针的加减运算 */ 2 | 3 | int main() { 4 | int a = 100; 5 | int *pa = &a; 6 | int *pb = pa + 1; 7 | int *pc = pa - 1; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/header/locale.h/localeconv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | struct lconv *locale = localeconv(); 6 | locale- 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | if(-1 == putchar('#')) { 5 | perror("fputc error!"); 6 | } 7 | printf("\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/hello/hong.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MAX(a, b) a > b ? a : b 4 | 5 | int main() { 6 | int max = MAX(3, 4); 7 | printf("max = %d", max); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /library/cJSON/cJSON.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl -LO https://raw.githubusercontent.com/DaveGamble/cJSON/master/cJSON.h 4 | curl -LO https://raw.githubusercontent.com/DaveGamble/cJSON/master/cJSON.c 5 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fputc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | if(-1 == fputc('#', stdout)) { 5 | perror("fputc error!"); 6 | } 7 | printf("\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/putc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | if(-1 == putc('#', stdout)) { 5 | perror("fputc error!"); 6 | } 7 | printf("\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/number/float/float4.c: -------------------------------------------------------------------------------- 1 | /* 查看浮点数在内存中的二进制表示 */ 2 | 3 | int main() { 4 | float a = 10.0f; 5 | float b = -10.0f; 6 | double c = 10.0; 7 | double d = -10.0; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /algorithm/convert/number/convertNum.c: -------------------------------------------------------------------------------- 1 | /* 交换两个数,不使用第三个参数*/ 2 | 3 | int main() { 4 | int a = 3; 5 | int b = 4; 6 | 7 | a = a + b; 8 | b = a - b; 9 | a = a - b; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /algorithm/convert/number/convertNum2.c: -------------------------------------------------------------------------------- 1 | /* 交换两个数,不使用第三个参数*/ 2 | 3 | int main() { 4 | int a = 3; 5 | int b = 4; 6 | 7 | a = a - b; 8 | b = a + b; 9 | a = b - a; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /algorithm/convert/number/convertNum3.c: -------------------------------------------------------------------------------- 1 | /* 交换两个数,不使用第三个参数*/ 2 | 3 | int main() { 4 | int a = 3; 5 | int b = 4; 6 | 7 | a = a * b; 8 | b = a / b; 9 | a = a / b; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /algorithm/convert/number/convertNum4.c: -------------------------------------------------------------------------------- 1 | /* 交换两个数,不使用第三个参数*/ 2 | 3 | int main() { 4 | int a = 3; 5 | int b = 4; 6 | 7 | a = a ^ b; 8 | b = a ^ b; 9 | a = a ^ b; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/exit2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("output begin\n"); 6 | printf("content in buffer"); 7 | exit(0); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include"hello2.h" 3 | #include"hello3.h" 4 | 5 | int main() { 6 | //fdfdfdfd 7 | yyxx(); 8 | xx(); 9 | printf("hello world"); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/_exit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("output begin\n"); 6 | printf("content in buffer"); 7 | _exit(0); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /compiler/gcc/Doption.c: -------------------------------------------------------------------------------- 1 | /* 测试gcc的-D选项*/ 2 | 3 | #include 4 | 5 | int main() { 6 | #ifdef DEBUG 7 | printf("debug\n"); 8 | #else 9 | printf("release\n"); 10 | #endif 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/ctime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | time_t t = time(NULL); 6 | char *ft = ctime(&t); 7 | printf("现在是:%s\n", ft); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/variable/extern.c: -------------------------------------------------------------------------------- 1 | /* 变量作用域 - 全局变量*/ 2 | 3 | /* 默认就是extern的,所以在定义的时候不需要带extern这个关键字 */ 4 | int a = 20; 5 | 6 | int main(int argc, char *argv[]) { 7 | int a = 10; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/variable/extern2.c: -------------------------------------------------------------------------------- 1 | /* 变量作用域 - 全局变量*/ 2 | 3 | #include"other.c" 4 | 5 | int a = 20; 6 | 7 | int main(int argc, char *argv[]) { 8 | int a = 10; 9 | func(); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /library/mbedTLS/AES/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := aes 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /library/mbedTLS/HMAC/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := hmac 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /library/mbedTLS/MD5/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := md5 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-1/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := sha1 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /standard/iso/data-type/char/chinese.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char *str = "中国人"; 6 | int length = strlen(str); 7 | printf("%d\n", length); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/tmpfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *tmp = tmpfile(); 5 | if(NULL != tmp) { 6 | fprintf(tmp, "Hello"); 7 | fclose(tmp); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /library/mbedTLS/PBKDF2/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := pbkdf2 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-224/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := sha224 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-256/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := sha256 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-384/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := sha512 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-512/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := sha512 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer3.c: -------------------------------------------------------------------------------- 1 | /* 两个指针相减,两个指针相加没有意思 */ 2 | 3 | int main() { 4 | int a[6] = {1, 2, 3, 4, 5, 6}; 5 | int *p1 = a; 6 | int *p2 = &a[5]; 7 | int delta = p2 - p1; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fgetpos.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("fgetpos.c", "r"); 5 | if(NULL != fp) { 6 | fpos_t pos; 7 | fgetpos(fp, &pos); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/exit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("this process will exit\n"); 6 | exit(0); 7 | printf("never be displayed\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/hello/conditioncompile2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DEBUG 4 | 5 | int main() { 6 | #ifdef DEBUG 7 | printf("yes\n"); 8 | #else 9 | printf("no\n"); 10 | #endif 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /standard/iso/variable/local.c: -------------------------------------------------------------------------------- 1 | /* 变量作用域 - 局部变量*/ 2 | 3 | int main(int argc, char *argv[]) { 4 | int a = 10; 5 | 6 | if(a > 0) { 7 | 8 | } 9 | 10 | while(a < 0) { 11 | 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /library/mbedTLS/RIPEMD-160/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := ripemd160 6 | LOCAL_SRC_FILES := $(wildcard mbedtls/*.c) 7 | 8 | include $(BUILD_SHARED_LIBRARY) 9 | -------------------------------------------------------------------------------- /standard/iso/data-type/union/union4.c: -------------------------------------------------------------------------------- 1 | typedef union { 2 | int a; 3 | char b; 4 | } XX; 5 | 6 | 7 | #include 8 | 9 | int main() { 10 | printf("sizeof(XX) = %lu\n", sizeof(XX)); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strncpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char dest[10] = "abc"; 5 | char *src = "def\0ghklmnop"; 6 | strcpy(dest, src); 7 | strncpy(dest, src, 10); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/hello/conditioncompile.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define DEBUG 0 4 | 5 | int main() { 6 | #if DEBUG 7 | printf("debugging..."); 8 | #endif 9 | printf("running..."); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/abort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("It's about to abort!\n"); 6 | abort(); 7 | printf("This is never reached!\n"); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/posix/dlfcn.h/compile_time_link.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern int add(int a, int b); 4 | 5 | int main() { 6 | int value = add(2, 3); 7 | printf("add(2, 3) = %d\n", value); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /standard/iso/header/assert.h/assert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | assert(atoi(argv[1])); 7 | printf("assert success\n"); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /algorithm/convert/convert.c: -------------------------------------------------------------------------------- 1 | /* 两变量交换内容的通用方法 2 | * 使用gdb等调试器调试,观察变量的地址宽度 3 | */ 4 | 5 | int main() { 6 | char a = 'A'; 7 | char b = 'a'; 8 | char tmp; 9 | 10 | tmp = a; 11 | a = b; 12 | b = tmp; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /standard/iso/header/assert.h/assert2.c: -------------------------------------------------------------------------------- 1 | #define NDEBUG 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | int i = 0; 8 | 9 | assert(i); 10 | 11 | printf("assert success\n"); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/asctime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | time_t tt = time(NULL); 6 | struct tm *t = localtime(&tt); 7 | char *ft = asctime(t); 8 | printf("现在是:%s", ft); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/clock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | clock_t ct = clock(); 6 | 7 | printf("启动时间为:%ld毫秒\n", ct); 8 | printf("启动时间为:%ld秒\n", ct / CLOCKS_PER_SEC); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/header/stdbool.h/bool2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include"bool.h" 3 | 4 | int main() { 5 | bool isXXX = false; 6 | bool isYYY = true; 7 | printf("isXXX = %d\n", isXXX); 8 | printf("isYYY = %d\n", isYYY); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/calloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char * str = (char*) calloc(10, sizeof(char)); 6 | if(str) { 7 | strcpy(str, "Hello"); 8 | free(str); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/malloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char * str = (char*) malloc(10 * sizeof(char)); 6 | if(str) { 7 | strcpy(str, "Hello"); 8 | free(str); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/mktime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | time_t t = time(NULL); 6 | struct tm *loct = localtime(&t); 7 | loct->tm_year += 1; 8 | time_t t2 = mktime(loct); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/tzset.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | setenv("TZ", "GMT-9", 1); 6 | tzset(); 7 | time_t t = time(NULL); 8 | printf("%s\n", asctime(localtime(&t))); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/number/float/float2.c: -------------------------------------------------------------------------------- 1 | /* 测试浮点数的精度 */ 2 | 3 | #include 4 | 5 | int main() { 6 | float a = 1234567.89; 7 | double b = 1234567.89123456789; 8 | printf("a = %f\n", a); 9 | printf("b = %.11f\n", b); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/function/main4.c: -------------------------------------------------------------------------------- 1 | /* main函数参数测试 */ 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[], char *env[]) { 6 | int i = 0; 7 | while (NULL != env[i]) { 8 | printf("%s\n", env[i]); 9 | i++; 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /standard/iso/header/setjmp.h/goto2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i = 1; 5 | 6 | label: printf("%-4d", i); 7 | 8 | if(i < 10) { 9 | i++; 10 | goto label; 11 | } 12 | 13 | printf("\n"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strcmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char *str1 = "abc"; 5 | char *str2 = "abd"; 6 | char *str3 = "abcd"; 7 | int rc1 = strcmp(str1, str2); 8 | int rc2 = strcmp(str1, str3); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fprintf/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) { 4 | fprintf(stderr, "stderr argc = %d, %s\n", argc, argv[0]); 5 | fprintf(stdout, "stdout argc = %d, %s\n", argc, argv[0]); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("output.dat", "w"); 5 | if(NULL != fp) { 6 | char *str = "Hello World!"; 7 | fwrite(str, 1, 12, fp); 8 | fclose(fp); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /autotools/src/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS=test 2 | test_SOURCES=test.c 3 | 4 | noinst_PROGRAMS = packcc 5 | packcc_LINK = $(CC_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ 6 | 7 | packcc.o: packcc.c 8 | $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) -c -o $@ $< 9 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array.c: -------------------------------------------------------------------------------- 1 | /* 一维数组的定义*/ 2 | 3 | #define LENGTH 5 4 | 5 | int main() { 6 | int a[5]; 7 | float b[LENGTH]; 8 | char c[5 * 2]; 9 | 10 | /* C99支持的形式,C89、C90不支持 */ 11 | int n = 5; 12 | double d[n]; 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer4.c: -------------------------------------------------------------------------------- 1 | /* 任意的两个指针相减,没有意义 */ 2 | 3 | int main() { 4 | int a = 5; 5 | char b = 'A'; 6 | int c = 6; 7 | 8 | int *pa = &a; 9 | char *pb = &b; 10 | int *pc = &c; 11 | 12 | int delta = pc - pa; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/abs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("abs(-5) = %d\n", abs(-5)); 6 | printf("labs(-5L) = %ld\n", labs(-5L)); 7 | printf("llabs(-5LL) = %lld\n", llabs(-5LL)); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/atexit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void onexit() { 5 | printf("onexit()\n"); 6 | } 7 | 8 | int main() { 9 | if(0 != atexit(onexit)) { 10 | printf("atexit fail\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/variable/register.c: -------------------------------------------------------------------------------- 1 | /* 寄存器变量 */ 2 | 3 | #include 4 | 5 | int main() { 6 | register int i, sum; 7 | 8 | for(i = 0, sum = 0; i < 200; i++) { 9 | sum += i; 10 | } 11 | 12 | printf("sum = %d\n", sum); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/exec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | /* 环境变量 */ 6 | extern char **environ; 7 | int i; 8 | for(i = 0; i < 10; i++) { 9 | printf("%s\n", *(environ + i)); 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/remove.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int result = remove("output.dat"); 5 | if(0 == result) { 6 | printf("remore success!\n"); 7 | } else if(-1 == result) { 8 | perror("remove fail"); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/swap.c: -------------------------------------------------------------------------------- 1 | /* 两个数交换 */ 2 | void swap(int a, int b) { 3 | int tmp; 4 | tmp = a; 5 | a = b; 6 | b = tmp; 7 | } 8 | 9 | int main() { 10 | int a = 10; 11 | int b = 20; 12 | swap(a, b); 13 | 14 | /*此处打断点查看 */ 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/data-type/char/char.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char a = 'x'; 5 | char b = 'y'; 6 | 7 | printf("a = %c\n", a); 8 | printf("a = %d\n", a); 9 | printf("b = %c\n", b); 10 | printf("b = %d\n", b); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/swap2.c: -------------------------------------------------------------------------------- 1 | /* 两个数交换 */ 2 | void swap(int *a, int *b) { 3 | int tmp; 4 | tmp = *a; 5 | *a = *b; 6 | *b = tmp; 7 | } 8 | 9 | int main() { 10 | int a = 10; 11 | int b = 20; 12 | swap(&a, &b); 13 | 14 | /*此处打断点查看 */ 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/header/setjmp.h/goto.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | if(atoi(argv[1]) > 0) { 6 | printf("goto label\n"); 7 | goto label; 8 | } 9 | 10 | label: perror("occur error!"); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fgetc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("fgetc.c", "r"); 5 | if(NULL != fp) { 6 | int ch = fgetc(fp); 7 | if(EOF != ch) { 8 | printf("%c\n", ch); 9 | } 10 | 11 | fclose(fp); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/difftime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | time_t startt = time(NULL); 6 | sleep(2); 7 | time_t endt = time(NULL); 8 | double daltet = difftime(endt, startt); 9 | printf("耗时%f秒\n", daltet); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer5.c: -------------------------------------------------------------------------------- 1 | /* 两个指针相减,两个指针相加没有意思 */ 2 | 3 | int main() { 4 | int a[6] = {1, 2, 3, 4, 5, 6}; 5 | 6 | int *p1 = a; 7 | int *p2 = &a[3]; 8 | int *p3 = &a[5]; 9 | 10 | _Bool isXX = p2 > p1; 11 | _Bool isYY = p2 > p3; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fread.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("fread.c", "r"); 5 | if(NULL != fp) { 6 | char ch[1]; 7 | while(0 != fread(ch, 1, 1, fp)) { 8 | printf("%c", ch[0]); 9 | } 10 | fclose(fp); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/realloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char *p, *q; 5 | p = (char*) malloc(10 * sizeof(char)); 6 | q = (char*) realloc(p, 20); 7 | 8 | if(NULL == q) { 9 | free(p); 10 | } else { 11 | free(q); 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /standard/iso/variable/static2.c: -------------------------------------------------------------------------------- 1 | /* 局部静态变量 */ 2 | 3 | #include 4 | 5 | void func() { 6 | static int count; 7 | count++; 8 | printf("%d\n", count); 9 | } 10 | 11 | int main() { 12 | int i; 13 | for(i = 0; i < 10; i++) { 14 | func(); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/99MultipTable.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MAX 10 4 | 5 | int main() { 6 | int i, j; 7 | for(i = 1; i < MAX; i++) { 8 | for(j = 1; j <= i; j++) { 9 | printf("%dx%d=%-2d ", i, j, i*j); 10 | } 11 | printf("\n"); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/getchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = freopen("fgetc.c", "r", stdin); 5 | if(NULL != fp) { 6 | int ch = getchar(); 7 | if(EOF != ch) { 8 | printf("%c\n", ch); 9 | } 10 | 11 | fclose(fp); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/abort2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void signalHandler(int signum) { 6 | printf("catch signal SIGABRT\n"); 7 | } 8 | 9 | int main() { 10 | signal(SIGABRT, signalHandler); 11 | abort(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/putenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("PWD = %s\n", getenv("PWD")); 6 | 7 | if(0 != putenv("PWD=/")) { 8 | perror("putenv error!"); 9 | } 10 | 11 | printf("PWD = %s\n", getenv("PWD")); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/unsetenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("PWD = %s\n", getenv("PWD")); 6 | 7 | if(0 != unsetenv("PWD")) { 8 | perror("unsetenv fail!"); 9 | } 10 | printf("PWD = %s\n", getenv("PWD")); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fseek.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("output.dat", "w"); 5 | if(NULL != fp) { 6 | long dalte = ftell(fp); 7 | char *p = "Hello"; 8 | fwrite(p, 1, 5, fp); 9 | dalte = ftell(fp); 10 | 11 | fclose(fp); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/swap3.c: -------------------------------------------------------------------------------- 1 | /* 两个数交换 */ 2 | void swap(int *a, int *b) { 3 | int* tmp; 4 | *tmp = *a; /* tmp没有初始化就使用,出现了非法地址*/ 5 | *a = *b; 6 | *b = *tmp; 7 | } 8 | 9 | int main() { 10 | int a = 10; 11 | int b = 20; 12 | swap(&a, &b); 13 | 14 | /*此处打断点查看 */ 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/linux/eventpool.h/eventpooltest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | //__force __poll_t a; 6 | 7 | cpu_set_t a; 8 | 9 | //#if (NGX_READ_EVENT != (EPOLLIN|EPOLLRDHUP)) 10 | // return 1; 11 | //#endif 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /algorithm/bcc/src/lib/bcc.c: -------------------------------------------------------------------------------- 1 | //http://blog.fpliu.com/it/algorithm/check/BCC 2 | 3 | #include "bcc.h" 4 | 5 | unsigned char bcc(unsigned char *bytes, size_t nBytes) { 6 | unsigned char byte = 0; 7 | for (size_t i = 0; i < nBytes; i++) { 8 | byte ^= bytes[i]; 9 | } 10 | return byte; 11 | } 12 | -------------------------------------------------------------------------------- /algorithm/crc/CRC.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | unsigned char CRC(unsigned char *bytes, size_t nBytes); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array6.c: -------------------------------------------------------------------------------- 1 | /* C语言中数组越界并不会报错,但是越界可能会出现一些致命错误 */ 2 | 3 | #include 4 | 5 | #define LENGTH 5 6 | 7 | int main() { 8 | int a[LENGTH] = {1, 2, 3, 4, 5}; 9 | int i; 10 | for(i = 0; i <= LENGTH; i++) { 11 | printf("%d ", a[i]); 12 | } 13 | printf("\n"); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer6.c: -------------------------------------------------------------------------------- 1 | /* 两个任意类型的指针比较大小,没有意义 */ 2 | 3 | int main() { 4 | int a = 5; 5 | char b = 'A'; 6 | int c = 6; 7 | 8 | int *pa = &a; 9 | char *pb = &b; 10 | int *pc = &c; 11 | 12 | _Bool ba = pb > pa; 13 | _Bool bb = pc > pb; 14 | _Bool bc = pc > pa; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/hello/conditioncompile3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define ONE 1 4 | #define TWO 2 5 | #define THREE 3 6 | 7 | int main() { 8 | #ifdef ONE 9 | printf("%d\n", ONE); 10 | #elif defined TWO 11 | printf("%d\n", TWO); 12 | #else 13 | printf("%d\n", THREE); 14 | #endif 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /algorithm/lrc/src/lib/lrc.h: -------------------------------------------------------------------------------- 1 | #ifndef LRC_H 2 | #define LRC_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | unsigned char lrc(unsigned char *bytes, size_t nBytes); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/atan2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("atan(0.75) = %.16f\n", atan(0.75)); 7 | printf("atan2(3.0, 4.0) = %.16f\n", atan2(3.0, 4.0)); 8 | printf("tan2(DBL_MAX, DBL_MIN) = %.16f\n", atan2(DBL_MAX, DBL_MIN)); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/puts.c: -------------------------------------------------------------------------------- 1 | /* puts函数的测试 */ 2 | 3 | #include 4 | 5 | int main() { 6 | char str1[] = "I Love you!"; 7 | char *p = "C Program"; 8 | 9 | if(EOF == puts(str1)) { 10 | perror("puts发生了错误"); 11 | } 12 | 13 | if(puts(p)) { 14 | printf("success\n"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /algorithm/bcc/src/lib/bcc.h: -------------------------------------------------------------------------------- 1 | #ifndef BCC_H 2 | #define BCC_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | unsigned char bcc(unsigned char *bytes, size_t nBytes); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/ftell.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("ftell.c", "r"); 5 | if(fp) { 6 | if(0 == fseek(fp, 0L, SEEK_END)) { 7 | long length = ftell(fp); 8 | printf("ftell.c is %ld Byte\n", length); 9 | } 10 | 11 | fclose(fp); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/strftime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | time_t tt = time(NULL); 6 | struct tm *t = localtime(&tt); 7 | 8 | char buff[30]; 9 | buff[29] = '\0'; 10 | strftime(buff, 29, "%Y-%m-%d %H:%M:%S", t); 11 | printf("现在是北京时间:%s\n", buff); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer8.c: -------------------------------------------------------------------------------- 1 | /* 函数指针测试 */ 2 | 3 | #include 4 | 5 | int max(int a, int b) { 6 | return a > b ? a : b; 7 | } 8 | 9 | int main() { 10 | int a = 3; 11 | int b = 4; 12 | 13 | /* 定义指向函数入口的指针变量 */ 14 | int (*p)(); 15 | p = max; 16 | 17 | int max = (*p)(a,b); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /standard/iso/data-type/struct/person6.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { 4 | char *name; 5 | unsigned short age; 6 | char sex; 7 | bool issingle; 8 | float weight; 9 | } Person; 10 | 11 | #include 12 | 13 | int main() { 14 | printf("sizeof(Person) = %lu\n", sizeof(Person)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/posix/langinfo.h/langinfo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | setlocale(LC_ALL, "zh_CN.UTF-8"); 7 | //setlocale(LC_ALL, "en_US.UTF-8"); 8 | 9 | const char* codeset = nl_langinfo(CODESET); 10 | printf("%s\n", codeset); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/exec3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | pid_t pid = fork(); 6 | 7 | if (pid < 0) { 8 | perror("fork error!"); 9 | } else if (0 == pid) { 10 | if (execl("/bin/ls", "/bin/ls", NULL) < 0) { 11 | perror("execl error!"); 12 | } 13 | } 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /utils/self_exe_path/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "self.h" 5 | 6 | int main() { 7 | char p[PATH_MAX]; 8 | 9 | int ret = selfpath(p); 10 | 11 | if (ret > 0) { 12 | printf("%d:%s\n", ret, p); 13 | return 0; 14 | } else { 15 | return ret; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/realloc2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char *p, *q, *r; 5 | p = (char*) malloc(10 * sizeof(char)); 6 | r = (char*) malloc(10 * sizeof(char)); 7 | q = (char*) realloc(p, 30); 8 | 9 | if(NULL == q) { 10 | free(p); 11 | } else { 12 | free(q); 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /library/libcurl/src/lib/http.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libhttp 7 | URL: https://github.com/leleliu008/C 8 | Description: http C API 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lssl -lcurl -lhttp 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fputs.c: -------------------------------------------------------------------------------- 1 | /* fputs函数的测试 */ 2 | 3 | #include 4 | 5 | int main() { 6 | char str1[] = "I Love you!"; 7 | char *p = "C Program"; 8 | 9 | if(EOF == fputs(str1, stdout)) { 10 | perror("puts发生了错误"); 11 | } 12 | 13 | if(fputs(p, stdout)) { 14 | printf("success\n"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/exec2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | if (execl("/bin/ls", "", NULL) < 0) { 6 | perror("execl error!"); 7 | } 8 | //下面的代码根本不会被执行,因为exec系列的函数会用被执行命令的进程替换掉当前的进程,exec函数调用后面的代码无法被执行 9 | //通过观察这个现象,更能理解exec系列函数的特性 10 | printf("execl success!\n"); 11 | return 0; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /algorithm/bcc/src/lib/bcc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libbcc 7 | URL: https://github.com/leleliu008/C/algorithm/bcc 8 | Description: bcc check algorthm 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lbcc 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /algorithm/lrc/src/lib/lrc.c: -------------------------------------------------------------------------------- 1 | //http://blog.fpliu.com/it/algorithm/check/LRC 2 | 3 | #include "lrc.h" 4 | 5 | unsigned char lrc(unsigned char* bytes, size_t nBytes) { 6 | unsigned char byte = 0; 7 | for (size_t i = 0; i < nBytes; i++) { 8 | byte += bytes[i]; 9 | byte &= 0xFF; 10 | } 11 | return 256 - byte; 12 | } 13 | -------------------------------------------------------------------------------- /algorithm/lrc/src/lib/lrc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: liblrc 7 | URL: https://github.com/leleliu008/C/algorithm/lrc 8 | Description: lrc check algorthm 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -llrc 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /library/libarchive/src/lib/untar.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libhttp 7 | URL: https://github.com/leleliu008/C 8 | Description: untar C API 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -larchive -luntar 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /library/mbedTLS/base64/src/lib/base64.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: base16 7 | URL: https://github.com/leleliu008/C 8 | Description: base64 algorthm 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lbase64 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/ceil.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("ceil(3.5) = %.16f\n", ceil(3.5)); 7 | printf("ceil(-3.5) = %.16f\n", ceil(-3.5)); 8 | printf("ceil(DBL_MIN) = %.16f\n", ceil(DBL_MIN)); 9 | printf("ceil(-DBL_MIN) = %.16f\n", ceil(-DBL_MIN)); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/fgets.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("fgets.c", "r"); 5 | if(NULL != fp) { 6 | char buff[10]; 7 | buff[9] = '\0'; 8 | 9 | char *p = fgets(buff, 9, fp); 10 | if(NULL != p) { 11 | printf("%s\n", p); 12 | } 13 | 14 | fclose(fp); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/wait.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | pid_t pid = fork(); 7 | 8 | if(pid < 0) { 9 | perror("fork error!\n"); 10 | } else if(0 == pid) { 11 | /* 退出子进程 */ 12 | exit(0); 13 | } else { 14 | sleep(60); 15 | wait(NULL); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/stdlib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("NULL = %p\n", NULL); 6 | printf("EXIT_FAILURE = %d\n", EXIT_FAILURE); 7 | printf("EXIT_SUCCESS = %d\n", EXIT_SUCCESS); 8 | printf("RAND_MAX = %d\n", RAND_MAX); 9 | printf("MB_CUR_MAX = %d\n", (int)MB_CUR_MAX); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /algorithm/url/src/lib/url.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: liburl 7 | URL: https://github.com/leleliu008/C/algorithm/url 8 | Description: url encode/decode algorthm 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lurl 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/floor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("floor(3.5) = %.16f\n", floor(3.5)); 7 | printf("floor(-3.5) = %.16f\n", floor(-3.5)); 8 | printf("floor(DBL_MIN) = %.16f\n", floor(DBL_MIN)); 9 | printf("floor(-DBL_MIN) = %.16f\n", floor(-DBL_MIN)); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strlen.c: -------------------------------------------------------------------------------- 1 | /* strlen函数测试 */ 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | char str[] = "Hello\0world"; 8 | size_t length = strlen(str); 9 | printf("%s, %lu\n", str, length); 10 | 11 | str[5] = '\n'; 12 | length = strlen(str); 13 | printf("%s, %lu\n", str, length); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/localtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | time_t tt = time(NULL); 6 | struct tm *loct = localtime(&tt); 7 | printf("现在是北京时间:%d年%d月%d日 %-2d:%-2d:%-2d\n", \ 8 | 1900 + loct->tm_year, 1 + loct->tm_mon, loct->tm_mday, \ 9 | loct->tm_hour, loct->tm_min, loct->tm_sec); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /algorithm/base16/src/lib/base16.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: base16 7 | URL: https://github.com/leleliu008/C/algorithm/base16 8 | Description: base16 algorthm library 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lbase16 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /library/openssl/SHA-256/src/lib/sha256sum.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: sha256sum 7 | URL: https://github.com/leleliu008/C 8 | Description: sha256sum C API 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lcrypto -lsha256sum 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/atan.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("atan(DBL_MAX) = %.16f\n", atan(DBL_MAX)); 7 | printf("atan(-DBL_MAX) = %.16f\n", atan(-DBL_MAX)); 8 | printf("atan(DBL_MIN) = %.16f\n", atan(DBL_MIN)); 9 | printf("atan(-DBL_MIN) = %.16f\n", atan(-DBL_MIN)); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/gets.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = freopen("fgets.c", "r", stdin); 5 | if(NULL != fp) { 6 | fp->_flags; 7 | 8 | char buff[10] = {0}; 9 | 10 | char *p = gets(buff); 11 | if(NULL != p) { 12 | printf("%s\n", p); 13 | } 14 | 15 | fclose(fp); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/iso/number/float/float3.c: -------------------------------------------------------------------------------- 1 | /* 浮点数不能比较相等 */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main() { 8 | double a = 0.5; 9 | double b = sin(M_PI / 6.0); 10 | printf("b = %f\n", b); 11 | if(fabs(a - b) < DBL_EPSILON) { 12 | printf("a == b\n"); 13 | } else { 14 | printf("a != b\n"); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/number/int/integer3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | unsigned int a = -10; 5 | 6 | if(a > 0) { 7 | printf("%d\n", a); 8 | printf("%u\n", a); 9 | } 10 | 11 | unsigned int b = 10; 12 | 13 | if(b - 12 > 0) { 14 | printf("%d\n", b - 12); 15 | printf("%u\n", b - 12); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/getpgid.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | pid_t ppid = getppid(); 5 | pid_t pid = getpid(); 6 | 7 | pid_t pgid0 = getpgid(ppid); 8 | pid_t pgid1 = getpgid(pid); 9 | pid_t pgid2 = getpgid(0); 10 | 11 | setpgid(pid, ppid); 12 | 13 | pid_t pgid3 = getpgid(ppid); 14 | pid_t pgid4 = getpgid(pid); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array8.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a[3][4] = {{1, 2, 3, 4}, {5, 6, 7 ,8}, {9, 10 , 11, 12}}; 5 | 6 | int (*p)[4]; 7 | p = a; 8 | 9 | int i,j; 10 | 11 | for(i = 0; i < 3; i++) { 12 | for(j = 0; j < 4; j++) { 13 | printf("%-2d ", *(*(p + i) + j)); 14 | } 15 | printf("\n"); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/iso/data-type/union/union5.c: -------------------------------------------------------------------------------- 1 | //使用gdb调试,测试共用体的字节对齐问题 2 | #pragma pack(1) 3 | typedef union { 4 | char* a; 5 | char b[10]; 6 | } XX; 7 | 8 | int main() { 9 | XX x; 10 | char a = 65; 11 | x.a = &a; 12 | //在这里设置断点 13 | 14 | x.b[0] = 'A'; 15 | x.b[1] = 'B'; 16 | x.b[2] = 'C'; 17 | x.b[3] = 'D'; 18 | x.b[4] = '\0'; 19 | //在这里设置断点 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /library/libcurl/src/include/http.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTP_H 2 | #define HTTP_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplasplas 8 | extern "C" 9 | #endif 10 | 11 | int http_fetch(const char * url, FILE * outputFile, bool verbose, bool showProgress); 12 | 13 | #ifdef __cplasplas 14 | } 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/sqrt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("sqrt(5) = %f\n", sqrt(5)); 7 | 8 | double x = sqrt(-5); 9 | extern int errno; 10 | if(EDOM == errno) { 11 | printf("sqrt(-5)超过了定义域\n"); 12 | } else if(ERANGE == errno) { 13 | printf("sqrt(-5)的值超过了定义域\n"); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/rand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("RAND_MAX = %d\n", RAND_MAX); 7 | 8 | //产生随机种子 9 | srand(time(NULL)); 10 | 11 | int i, j; 12 | for(i = 0; i < 10; i++) { 13 | j = 10.0 * rand() / RAND_MAX; 14 | printf("%-4d", j); 15 | } 16 | 17 | printf("\n"); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /utils/sysinfo/src/lib/sysinfo.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: sysinfo 7 | URL: https://github.com/leleliu008/C/utils/sysinfo 8 | Description: C library to show your system's information 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lsysinfo 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isalnum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isalnum(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isalpha.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isalpha(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isascii.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isascii(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isblank.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isblank(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/iscntrl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(iscntrl(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isdigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isdigit(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isgraph.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isgraph(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/islower.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(islower(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isprint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isprint(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/ispunct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(ispunct(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isspace.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isspace(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isupper.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isupper(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/header/ctype.h/isxdigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int count = 0; 6 | int i = 0; 7 | 8 | for(i = 0; i <= 255; i++) { 9 | if(isxdigit(i)) { 10 | printf("\'%c\' = %-5d", i, i); 11 | 12 | if(++count % 7 == 0) { 13 | printf("\n"); 14 | } 15 | } 16 | } 17 | 18 | printf("\n"); 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer10.c: -------------------------------------------------------------------------------- 1 | /* 指针数组 */ 2 | 3 | #include 4 | 5 | int main() { 6 | int a[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; 7 | int *pa[3] = {a[0], a[1], a[2]}; 8 | 9 | int i, j; 10 | for(i = 0; i < 3; i++) { 11 | for(j = 0; j < 4; j++) { 12 | printf("%-2d ", *(pa[i] + j)); 13 | } 14 | printf("\n"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /standard/iso/header/setjmp.h/setjmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static jmp_buf env; 4 | 5 | void foo() { 6 | puts("in foo"); 7 | longjmp(env, 1); 8 | } 9 | 10 | int main() { 11 | if(!setjmp(env)) { 12 | puts("you can see this"); 13 | foo(); 14 | puts("never see this"); 15 | } else { 16 | puts("catch an exception"); 17 | } 18 | 19 | puts("finally"); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /utils/self_exe_path/self.h: -------------------------------------------------------------------------------- 1 | #ifndef _SELF_H 2 | #define _SELF_H 3 | 4 | /** get the current executing executable's absolute file path. 5 | * 6 | * On success, the legnth of buf is returned and buf is filled with the current executing executable's absolute file path. 7 | * On error, -1 is returned and errno is set to indicate the error. 8 | */ 9 | int selfpath(char buf[]); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /standard/iso/data-type/union/union.c: -------------------------------------------------------------------------------- 1 | union XX { 2 | int a; 3 | char b; 4 | }; 5 | 6 | 7 | #include 8 | 9 | int main() { 10 | union XX x; 11 | 12 | x.a = 65; 13 | printf("x.a = %d\n", x.a); 14 | printf("x.b = %c\n", x.b); 15 | 16 | printf("-------------\n"); 17 | 18 | x.b = 'a'; 19 | 20 | printf("x.a = %d\n", x.a); 21 | printf("x.b = %c\n", x.b); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/tanh.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("tanh(3.0) = %.16f\n", tanh(3.0)); 7 | printf("tanh(-3.0) = %.16f\n", tanh(-3.0)); 8 | printf("tanh(DBL_MAX) = %.16f\n", tanh(DBL_MAX)); 9 | printf("tanh(-DBL_MAX) = %.16f\n", tanh(-DBL_MAX)); 10 | printf("tanh(DBL_MIN) = %.16f\n", tanh(DBL_MIN)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /standard/iso/data-type/union/union2.c: -------------------------------------------------------------------------------- 1 | typedef union { 2 | int a; 3 | char b; 4 | } XX; 5 | 6 | 7 | #include 8 | 9 | int main() { 10 | XX x; 11 | 12 | x.a = 65; 13 | printf("x.a = %d\n", x.a); 14 | printf("x.b = %c\n", x.b); 15 | 16 | printf("-------------\n"); 17 | 18 | x.b = 'a'; 19 | 20 | printf("x.a = %d\n", x.a); 21 | printf("x.b = %c\n", x.b); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array5.c: -------------------------------------------------------------------------------- 1 | /* 字符数组测试 */ 2 | 3 | int main() { 4 | char a[10] = {'c', ' ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'}; 5 | char b[] = {'c', ' ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'}; 6 | char c[] = "c program"; 7 | char d[10] = "c program"; 8 | char e[9] = "c program"; 9 | 10 | char ch = 'A'; 11 | char* p1 = &ch; 12 | char* p2 = a; 13 | 14 | /* 此处打断点 */ 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strerror_r.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char buff[100]; 6 | 7 | #if defined (__USE_GNU) && __ANDROID_API__ >= 23 8 | char *ret = __gnu_strerror_r(ERANGE, buff sizeof(buff)); 9 | return 1; 10 | #else 11 | int ret = strerror_r (ERANGE, buff, sizeof(buff)); 12 | return ret; 13 | #endif 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/string.h/strncmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char *str1 = "abc"; 5 | char *str2 = "abd"; 6 | char *str3 = "abcd"; 7 | int rc1 = strncmp(str1, str2, 2); 8 | int rc2 = strncmp(str1, str3, 2); 9 | int rc3 = strncmp(str1, str2, 3); 10 | int rc4 = strncmp(str1, str3, 3); 11 | int rc5 = strncmp(str1, str2, 4); 12 | int rc6 = strncmp(str1, str3, 4); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/fmod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() { 6 | printf("fmod(5.0, 3.0) = %.16f\n", fmod(5.0, 3.0)); 7 | printf("fmod(5.2, 3.0) = %.16f\n", fmod(5.2, 3.0)); 8 | printf("fmod(-5.2, 3.0) = %.16f\n", fmod(-5.2, 3.0)); 9 | printf("fmod(5.2, -3.0) = %.16f\n", fmod(5.2, -3.0)); 10 | printf("fmod(5.2, int(5.2)) = %.16f\n", fmod(5.2, (int)5.2)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /algorithm/chinese-calendar/src/lib/chinese-calendar.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libchinese-calendar 7 | URL: https://github.com/leleliu008/C/algorithm/chinese-calendar 8 | Description: chinese festival/jieqi algorthm 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lchinese-calendar 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /standard/iso/header/limits.h/limits.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("CHAR_BIT = %d\n", CHAR_BIT); 6 | printf("SCHAR_MAX = %d\n", SCHAR_MAX); 7 | printf("SCHAR_MIN = %d\n", SCHAR_MIN); 8 | printf("UCHAR_MAX = %d\n", UCHAR_MAX); 9 | printf("CHAR_MAX = %d\n", CHAR_MAX); 10 | printf("CHAR_MIN = %d\n", CHAR_MIN); 11 | printf("MB_LEN_MAX = %d\n", MB_LEN_MAX); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/acos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("acos(1.0) = %f\n", acos(1.0)); 7 | printf("acos(-1.0) = %f\n", acos(-1.0)); 8 | 9 | double acos_5 = acos(5); 10 | extern int errno; 11 | if(EDOM == errno) { 12 | printf("cos(5)超过了定义域\n"); 13 | } else if (ERANGE == errno) { 14 | printf("cos(5)超过了值域\n"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/asin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("asin(1.0) = %f\n", asin(1.0)); 7 | printf("asin(-1.0) = %f\n", asin(-1.0)); 8 | 9 | double asin_5 = asin(5); 10 | extern int errno; 11 | if(EDOM == errno) { 12 | printf("sin(5)超过了定义域\n"); 13 | } else if (ERANGE == errno) { 14 | printf("sin(5)超过了值域\n"); 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /standard/iso/header/signal.h/signal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* 回调函数 */ 6 | void signalHandler(int signum) { 7 | if(SIGINT == signum) { 8 | printf("您点击了键盘Ctrl+C\n"); 9 | exit(0); 10 | } 11 | } 12 | 13 | int main() { 14 | /* 注册回调函数 */ 15 | signal(SIGINT, &signalHandler); 16 | 17 | /* 开始消息循环 */ 18 | while(1) { 19 | sleep(1); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/setenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("PWD = %s\n", getenv("PWD")); 6 | 7 | if(0 != setenv("PWD", "/", 1)) { 8 | perror("setenv fail!"); 9 | } 10 | printf("PWD = %s\n", getenv("PWD")); 11 | 12 | if(0 != setenv("PWD", "/home", 0)) { 13 | perror("setenv fail!"); 14 | } 15 | printf("PWD = %s\n", getenv("PWD")); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/getcwd.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) { 7 | char buff[PATH_MAX]; 8 | 9 | const char * cwd = getcwd(buff, PATH_MAX); 10 | 11 | if (cwd == NULL) { 12 | perror(NULL); 13 | return 1; 14 | } else { 15 | printf("current working dir is %s\n", cwd); 16 | return 0; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /standard/iso/data-type/char/char2.c: -------------------------------------------------------------------------------- 1 | /* 同一个字符的不同表示显示 */ 2 | 3 | #include 4 | 5 | int main() { 6 | char a = 'A'; 7 | char b = 65; 8 | char c = 0101; 9 | char d = 0x41; 10 | char e = '\101'; 11 | char f = '\x41'; 12 | 13 | printf("a = %c\n", a); 14 | printf("b = %c\n", b); 15 | printf("c = %c\n", c); 16 | printf("d = %c\n", d); 17 | printf("e = %c\n", e); 18 | printf("f = %c\n", f); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /library/cJSON/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(cJSONTest C) 4 | 5 | if (NOT CMAKE_BUILD_TYPE) 6 | set(CMAKE_BUILD_TYPE Release) 7 | endif() 8 | 9 | add_executable(cJSON-example cJSON.c cJSON-example.c) 10 | target_include_directories(cJSON-example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 11 | 12 | include(GNUInstallDirs) 13 | install(TARGETS cJSON-example RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 14 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum3.c: -------------------------------------------------------------------------------- 1 | /* 有名枚举的定义 */ 2 | 3 | enum WeekDay { 4 | MON, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | } today, tomorrow; 12 | 13 | #include 14 | 15 | int main() { 16 | today = SUN; 17 | tomorrow = MON; 18 | printf("today = %d\n", today); 19 | printf("tomorrow = %d\n", tomorrow); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum2.c: -------------------------------------------------------------------------------- 1 | /* 有名枚举的定义 */ 2 | 3 | enum WeekDay { 4 | MON, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | }; 12 | 13 | #include 14 | 15 | int main() { 16 | enum WeekDay today = SUN; 17 | enum WeekDay tomorrow = MON; 18 | printf("today = %d\n", today); 19 | printf("tomorrow = %d\n", tomorrow); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum5.c: -------------------------------------------------------------------------------- 1 | /* 有名枚举的定义 */ 2 | 3 | typedef enum { 4 | MON, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | } WeekDay; 12 | 13 | #include 14 | 15 | int main() { 16 | WeekDay today = SUN; 17 | WeekDay tomorrow = MON; 18 | printf("today = %d\n", today); 19 | printf("tomorrow = %d\n", tomorrow); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /standard/iso/macro/build_in_macro.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define DATE_TIME __DATE__" "__TIME__ 5 | 6 | void func() { 7 | printf("release date_time=%s, file=%s, line=%d, fuction=%s\n",\ 8 | DATE_TIME, __FILE__, __LINE__, __func__); 9 | } 10 | 11 | int main() { 12 | func(); 13 | printf("release date_time=%s, file=%s, line=%d, fuction=%s\n",\ 14 | DATE_TIME, __FILE__, __LINE__, __func__); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/fork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | pid_t pid = fork(); 6 | 7 | if(pid < 0) { 8 | perror("fork error!"); 9 | } else if (pid == 0) { 10 | printf("i'm child process and my pid is %d\n", getpid()); 11 | } else { 12 | printf("i'm parent process and my pid is %d\n", getpid()); 13 | printf("i'm parent process and new process pid is %d\n", pid); 14 | } 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum4.c: -------------------------------------------------------------------------------- 1 | /* 有名枚举的定义 */ 2 | 3 | typedef enum WeekDay { 4 | MON, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | } WEEKDAY; 12 | 13 | #include 14 | 15 | int main() { 16 | enum WeekDay today = SUN; 17 | WEEKDAY tomorrow = MON; 18 | printf("today = %d\n", today); 19 | printf("tomorrow = %d\n", tomorrow); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/sinh.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | printf("sinh(10) = %.16f\n", sinh(10)); 8 | printf("sinh(-10) = %.16f\n", sinh(-10)); 9 | 10 | double x = sinh(DBL_MAX); 11 | extern errno; 12 | if(EDOM == errno) { 13 | printf("sinh(DBL_MAX)超过了定义域\n"); 14 | } else if(ERANGE == errno) { 15 | printf("sinh(DBL_MAX)的值超过了范围\n"); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /standard/iso/operator/sizeof4.c: -------------------------------------------------------------------------------- 1 | //数组的sizeof 2 | 3 | #include 4 | 5 | void xx(char a3[4]) { 6 | printf("sizeof(a3) = %lu\n", sizeof(a3)); 7 | } 8 | 9 | void yy(int a4[]) { 10 | printf("sizeof(a4) = %lu\n", sizeof(a4)); 11 | } 12 | 13 | int main() { 14 | char a1[] = "abc"; 15 | int a2[3]; 16 | 17 | printf("sizeof(a1) = %lu\n", sizeof(a1)); 18 | printf("sizeof(a2) = %lu\n", sizeof(a2)); 19 | 20 | xx(a1); 21 | yy(a2); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a[3][4] = {1, 2,3 ,4, 5, 6, 7, 8, 9, 10, 11, 12}; 5 | int b[][4] = {1, 2,3 ,4, 5, 6, 7, 8, 9, 10, 11, 12}; 6 | int c[3][4] = {{1, 2,3 ,4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; 7 | int d[][4] = {{1, 2,3 ,4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; 8 | int e[3][4] = {{1, 2,3 ,4}, {5}, {9, 10}}; 9 | int f[3][4] = {{1, 2,3 ,4}, {5}}; 10 | 11 | /* 在此处打断点,查看各变量的值*/ 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum8.c: -------------------------------------------------------------------------------- 1 | /* 有名枚举的定义 */ 2 | 3 | typedef enum { 4 | MON, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | } WeekDay; 12 | 13 | #include 14 | 15 | int main() { 16 | WeekDay today = SUN; 17 | today = 1; 18 | today = 'A'; 19 | today += 2; 20 | int x = today; 21 | printf("x = %d\n", x); 22 | printf("today = %d\n", today); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /standard/iso/data-type/struct/person7.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #pragma pack(16) 4 | typedef struct { 5 | char *name; 6 | unsigned short age; 7 | char sex; 8 | float weight; 9 | bool issingle; 10 | } Person; 11 | 12 | #include 13 | #include 14 | 15 | int main() { 16 | size_t size = sizeof(Person); 17 | printf("sizeof(Person) = %lu\n", size); 18 | 19 | Person person = {"WangHua", 18u, 'F', 120.0f, true}; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/rename.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int result = rename("output.dat", "output.data"); 6 | if(0 == result) { 7 | printf("rename success!\n"); 8 | } else if(-1 == result) { 9 | perror("rename fail"); 10 | 11 | if(EACCES == errno) { 12 | printf("权限不够\n"); 13 | } else if(EBUSY == errno) { 14 | printf("BUSY\n"); 15 | } else { 16 | printf("位置错误!\n"); 17 | } 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /standard/iso/header/stdio.h/freopen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | if(NULL == freopen("freopen.c", "r", stdin)) { 5 | perror("将freopen.c重定向到stdin失败"); 6 | } 7 | 8 | if(NULL == freopen("output.data", "w", stdout)) { 9 | perror("将stdout重定向到output.data失败"); 10 | } 11 | printf("在output.data文件中"); 12 | 13 | if(NULL == freopen("/dev/tty", "w", stdout)) { 14 | perror("将output.data重定向到控制台失败"); 15 | } 16 | printf("在控制台显示\n"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/pipe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) { 5 | int p[2]; 6 | 7 | if (pipe(p) < 0) { 8 | perror("create a pipe failed"); 9 | return 1; 10 | } 11 | 12 | write(p[1], "I", 2); 13 | 14 | char buff[1024] = {0}; 15 | size_t size = 0; 16 | 17 | while ((size = read(p[0], buff, 1024)) != 0) { 18 | printf("%s\n", buff); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/wait2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | pid_t pid = fork(); 7 | 8 | if(pid < 0) { 9 | perror("fork error!\n"); 10 | } else if(0 == pid) { 11 | printf("this is child process wtih pid of %d\n", getpid()); 12 | sleep(10); 13 | } else { 14 | pid_t child_pid = wait(NULL); 15 | printf("main process catched a child process with pid of %d\n", child_pid); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/iso/header/stdarg.h/stdarg.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void func(int count, ...) { 5 | va_list vars; 6 | 7 | va_start(vars, count); 8 | 9 | int i; 10 | for(i = 0; i < count; i++) { 11 | int var = va_arg(vars, int); 12 | printf("%d ", var); 13 | } 14 | 15 | va_end(vars); 16 | 17 | putchar('\n'); 18 | } 19 | 20 | int main() { 21 | func(6, 10, -3, 2, 6, 9, -1); 22 | func(3, 2, 3, -1); 23 | func(1, -1); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/getenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | char *value; 6 | 7 | value = getenv("HOME"); 8 | if(value) { 9 | printf("HOME = %s\n", value); 10 | } 11 | 12 | value = getenv("PWD"); 13 | if(value) { 14 | printf("PWD = %s\n", value); 15 | } 16 | 17 | value = getenv("haha"); 18 | if(value) { 19 | printf("haha = %s\n", value); 20 | } else { 21 | printf("haha = NULL\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /algorithm/crc/Makefile: -------------------------------------------------------------------------------- 1 | CC = cc 2 | CFLAGS = -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | CRCTest: CRCTest.c CRC.c ../base16/base16.c 8 | $(CC) $(CFLAGS) -o $@ $^ 9 | 10 | test: CRCTest 11 | ./$^ hex 8301 12 | 13 | clean: 14 | rm -f CRCTest 15 | rm -rf libs 16 | rm -rf obj 17 | 18 | ndk-build: 19 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 20 | 21 | .PHONY: clean ndk-build 22 | -------------------------------------------------------------------------------- /algorithm/url/src/lib/url.h: -------------------------------------------------------------------------------- 1 | #ifndef URL_H 2 | #define URL_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | int url_encode(char* output, unsigned char* input, size_t inputLengthInBytes, bool isToUpper); 12 | 13 | int url_decode(unsigned char* output, size_t* outputLength, char* input); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /standard/iso/header/setjmp.h/setjmp2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static jmp_buf env; 4 | 5 | #define try if(!setjmp(env)) 6 | #define catch else 7 | #define throwException longjmp(env, 1) 8 | 9 | void foo() { 10 | puts("in foo"); 11 | throwException; 12 | } 13 | 14 | int main() { 15 | try { 16 | puts("you can see this"); 17 | foo(); 18 | puts("never see this"); 19 | } catch { 20 | puts("catch an exception"); 21 | } 22 | 23 | puts("finally"); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /standard/iso/header/locale.h/locale.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | //setlocale(LC_ALL, "zh_CN.UTF-8"); 8 | setlocale(LC_ALL, "en_US.UTF-8"); 9 | 10 | time_t tt = time(NULL); 11 | struct tm *tms = localtime(&tt); 12 | 13 | char buff[30] = {0}; 14 | strftime(buff, sizeof(buff), nl_langinfo(D_T_FMT), tms); 15 | 16 | printf("现在是当地时间:%s\n", buff); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum6.c: -------------------------------------------------------------------------------- 1 | /* 有名枚举的定义 */ 2 | 3 | typedef enum { 4 | MON, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | } WeekDay; 12 | 13 | #include 14 | 15 | int main() { 16 | WeekDay today = SUN; 17 | 18 | printf("sizeof(WeekDay) = %lu\n", sizeof(WeekDay)); 19 | printf("sizeof(today) = %lu\n", sizeof(today)); 20 | printf("sizeof(MON) = %lu\n", sizeof(MON)); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/log.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | printf("log(DBL_MAX) = %.16f\n", log(DBL_MAX)); 8 | printf("log(M_E) = %.16f\n", log(M_E)); 9 | printf("log(DBL_MIN) = %.16f\n", log(DBL_MIN)); 10 | 11 | double x = log(0.0); 12 | extern int errno; 13 | if(EDOM == errno) { 14 | printf("log(0.0)超过了定义域\n"); 15 | } else if(ERANGE == errno) { 16 | printf("log(0.0)的值超过了范围\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum.c: -------------------------------------------------------------------------------- 1 | /* 匿名枚举的定义 */ 2 | 3 | enum { 4 | MON, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | }; 12 | 13 | #include 14 | 15 | int main() { 16 | printf("MON = %d\n", MON); 17 | printf("TUE = %d\n", TUE); 18 | printf("WED = %d\n", WED); 19 | printf("THU = %d\n", THU); 20 | printf("FRI = %d\n", FRI); 21 | printf("SAT = %d\n", SAT); 22 | printf("SUN = %d\n", SUN); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/cosh.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | printf("cosh(10) = %.16f\n", cosh(10)); 8 | printf("cosh(-10) = %.16f\n", cosh(-10)); 9 | printf("cosh(DBL_MIN) = %.16f\n", cosh(DBL_MIN)); 10 | 11 | double x = cosh(DBL_MAX); 12 | extern errno; 13 | if(EDOM == errno) { 14 | printf("cosh(DBL_MAX)超过了定义域\n"); 15 | } else if(ERANGE == errno) { 16 | printf("cosh(DBL_MAX)的值超过了范围\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /algorithm/crc/CRC.c: -------------------------------------------------------------------------------- 1 | //http://blog.fpliu.com/it/algorithm/check/CRC 2 | 3 | #include"CRC.h" 4 | 5 | static unsigned char CRC7_POLY = 0x09; 6 | 7 | unsigned char CRC(unsigned char* bytes, size_t nBytes) { 8 | unsigned char crc = 0; 9 | for (size_t i = 0; i < nBytes; i++) { 10 | crc ^= bytes[i]; 11 | for (size_t j = 0; j < 8; j++) { 12 | if (crc & 1) { 13 | crc ^= CRC7_POLY; 14 | } 15 | crc >>= 1; 16 | } 17 | } 18 | return crc; 19 | } 20 | -------------------------------------------------------------------------------- /library/mbedTLS/PBKDF2/pbkdf2Test.html: -------------------------------------------------------------------------------- 1 | 2 | 10 | -------------------------------------------------------------------------------- /standard/iso/data-type/enum/enum7.c: -------------------------------------------------------------------------------- 1 | /* 改变枚举元素的初始值 */ 2 | 3 | enum { 4 | MON = 1, /* 星期一 */ 5 | TUE, /* 星期二 */ 6 | WED, /* 星期三 */ 7 | THU, /* 星期四 */ 8 | FRI, /* 星期五 */ 9 | SAT, /* 星期六 */ 10 | SUN /* 星期日 */ 11 | }; 12 | 13 | #include 14 | 15 | int main() { 16 | printf("MON = %d\n", MON); 17 | printf("TUE = %d\n", TUE); 18 | printf("WED = %d\n", WED); 19 | printf("THU = %d\n", THU); 20 | printf("FRI = %d\n", FRI); 21 | printf("SAT = %d\n", SAT); 22 | printf("SUN = %d\n", SUN); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/exp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | double x = exp(DBL_MAX); 8 | extern int errno; 9 | if(EDOM == errno) { 10 | printf("exp(DBL_MAX)超过了定义域\n"); 11 | } else if(ERANGE == errno) { 12 | printf("exp(DBL_MAX)的值超过了范围\n"); 13 | } 14 | 15 | printf("exp(-DBL_MAX) = %.16f\n", exp(-DBL_MAX)); 16 | printf("exp(DBL_MIN) = %.16f\n", exp(DBL_MIN)); 17 | printf("exp(-DBL_MIN) = %.16f\n", exp(-DBL_MIN)); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /standard/iso/header/stdlib.h/str2num.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char * argv[]) { 5 | int i; 6 | for(i = 1; i < argc; i++) { 7 | printf("atoi\(\"%s\") = %d\n", argv[i], atoi(argv[i])); 8 | printf("atol\(\"%s\") = %ld\n", argv[i], atol(argv[i])); 9 | printf("atoll\(\"%s\") = %lld\n", argv[i], atoll(argv[i])); 10 | printf("atof\(\"%s\") = %f\n", argv[i], atof(argv[i])); 11 | if(i < argc - 1) { 12 | printf("----------------------\n"); 13 | } 14 | } 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /standard/iso/operator/typedef.c: -------------------------------------------------------------------------------- 1 | //根据条件编译定义统一的类型 2 | #ifdef XX 3 | typedef int Integer 4 | #elif xx 5 | typedef int Integer 6 | #else 7 | typedef long Integer 8 | #endif 9 | 10 | //简化结构体、共用体、枚举类型的使用 11 | typedef struct { 12 | char name[10]; 13 | int age; 14 | char sex; 15 | } Person; 16 | 17 | typedef union { 18 | int x; 19 | char y; 20 | } XX; 21 | 22 | //定义bool类型 23 | typedef enum { 24 | false, 25 | true 26 | } bool; 27 | 28 | //定义数组类型 29 | typedef int ARRAY_INT_10[10] 30 | 31 | //定义字符串类型 32 | typedef char* String 33 | 34 | -------------------------------------------------------------------------------- /library/qrencode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(qrencode C) 4 | 5 | set(PROJECT_VERSION 1.0.0) 6 | 7 | set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR} ${CMAKE_MODULE_PATH}) 8 | find_package(LibQrencode REQUIRED) 9 | 10 | add_executable(qrencode qrencode.c) 11 | target_include_directories(qrencode PRIVATE ${LIBQRENCODE_INCLUDE_DIR}) 12 | target_link_libraries(qrencode ${LIBQRENCODE_LIBRARY}) 13 | 14 | include(GNUInstallDirs) 15 | install(TARGETS qrencode RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 16 | -------------------------------------------------------------------------------- /library/libarchive/src/lib/untarConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set(UNTAR_VERSION "@PROJECT_VERSION@") 4 | set(UNTAR_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@") 5 | set(UNTAR_VERSION_MINOR "@PROJECT_VERSION_MINOR@") 6 | set(UNTAR_VERSION_PATCH "@PROJECT_VERSION_PATCH@") 7 | 8 | set_and_check(UNTAR_INSTALL_DIR "${PACKAGE_PREFIX_DIR}") 9 | set_and_check(UNTAR_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") 10 | set_and_check(UNTAR_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib") 11 | 12 | include("${CMAKE_CURRENT_LIST_DIR}/untarTargets.cmake") 13 | -------------------------------------------------------------------------------- /standard/iso/header/stdbool.h/bool.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | _Bool isXXX = false; 6 | bool isYYY = true; 7 | bool isZZZ = 0; 8 | bool isVVV = 1; 9 | bool isTTT = -12; 10 | bool isNNN = 'A'; 11 | 12 | printf("sizeof(bool) = %lu\n", sizeof(bool)); 13 | printf("isXXX = %d\n", isXXX); 14 | printf("isYYY = %d\n", isYYY); 15 | printf("isZZZ = %d\n", isZZZ); 16 | printf("isVVV = %d\n", isVVV); 17 | printf("isTTT = %d\n", isTTT); 18 | printf("isNNN = %d\n", isNNN); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /algorithm/base16/src/lib/base16Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set(BASE16_VERSION "@PROJECT_VERSION@") 4 | set(BASE16_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@") 5 | set(BASE16_VERSION_MINOR "@PROJECT_VERSION_MINOR@") 6 | set(BASE16_VERSION_PATCH "@PROJECT_VERSION_PATCH@") 7 | 8 | set_and_check(BASE16_INSTALL_DIR "${PACKAGE_PREFIX_DIR}") 9 | set_and_check(BASE16_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") 10 | set_and_check(BASE16_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib") 11 | 12 | include("${CMAKE_CURRENT_LIST_DIR}/base16Targets.cmake") 13 | -------------------------------------------------------------------------------- /library/libcurl/src/lib/httpConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set(LIBHTTP_VERSION "@PROJECT_VERSION@") 4 | set(LIBHTTP_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@") 5 | set(LIBHTTP_VERSION_MINOR "@PROJECT_VERSION_MINOR@") 6 | set(LIBHTTP_VERSION_PATCH "@PROJECT_VERSION_PATCH@") 7 | 8 | set_and_check(LIBHTTP_INSTALL_DIR "${PACKAGE_PREFIX_DIR}") 9 | set_and_check(LIBHTTP_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") 10 | set_and_check(LIBHTTP_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib") 11 | 12 | include("${CMAKE_CURRENT_LIST_DIR}/httpTargets.cmake") 13 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array2.c: -------------------------------------------------------------------------------- 1 | /* 一维数组的定义*/ 2 | 3 | #define LENGTH 5 4 | 5 | int main() { 6 | /* 全部元素初始化 */ 7 | int a[5] = {1, 3, 5, 7, 9}; 8 | /* 部分元素初始化 */ 9 | int a2[5] = {1,2,3}; 10 | 11 | float b[LENGTH] = {2.0f, 3.1f, 4.2f, 5.3f, 8.9f}; 12 | char c[5 * 2] = {'A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e'}; 13 | char e[11] = "ABCDEabcde"; 14 | 15 | /* C99支持的形式,C89、C90不支持 */ 16 | int n = 5; 17 | double d[n]; 18 | d[0] = 2.0; 19 | d[1] = 3.0; 20 | d[2] = 4.0; 21 | d[3] = 5.0; 22 | d[4] = 6.0; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /standard/iso/header/stdarg.h/stdarg2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void func(int arg0, ...) { 5 | va_list vars; 6 | 7 | va_start(vars, arg0); 8 | 9 | printf("%d ", arg0); 10 | 11 | int var; 12 | while(1) { 13 | var = va_arg(vars, int); 14 | if(-1 != var) { 15 | printf("%d ", var); 16 | } else { 17 | break; 18 | } 19 | } 20 | 21 | va_end(vars); 22 | 23 | putchar('\n'); 24 | } 25 | 26 | int main() { 27 | func(6, 10, -3, 2, 6, 9, -1); 28 | func(3, 2, 3, -1); 29 | func(1, -1); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /utils/sysinfo/src/lib/sysinfoConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set(SYSINFO_VERSION "@PROJECT_VERSION@") 4 | set(SYSINFO_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@") 5 | set(SYSINFO_VERSION_MINOR "@PROJECT_VERSION_MINOR@") 6 | set(SYSINFO_VERSION_PATCH "@PROJECT_VERSION_PATCH@") 7 | 8 | set_and_check(SYSINFO_INSTALL_DIR "${PACKAGE_PREFIX_DIR}") 9 | set_and_check(SYSINFO_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") 10 | set_and_check(SYSINFO_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib") 11 | 12 | include("${CMAKE_CURRENT_LIST_DIR}/sysinfoTargets.cmake") 13 | -------------------------------------------------------------------------------- /library/libarchive/src/include/untar.h: -------------------------------------------------------------------------------- 1 | #ifndef UNTAR_H 2 | #define UNTAR_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #ifdef __cplasplas 11 | extern "C" 12 | #endif 13 | 14 | int untar_list(const char * inputFilePath, int flags); 15 | int untar_extract(const char * outputDir, const char * inputFilePath, int flags, bool verbose, size_t stripComponentsNumber); 16 | 17 | #ifdef __cplasplas 18 | } 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /standard/iso/header/time.h/gmtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | time_t tt = time(NULL); 6 | struct tm *gmt = gmtime(&tt); 7 | printf("现在是GMT时间:%d年%d月%d日 %-2d:%-2d:%-2d\n", \ 8 | 1900 + gmt->tm_year, 1 + gmt->tm_mon, gmt->tm_mday, \ 9 | gmt->tm_hour, gmt->tm_min, gmt->tm_sec); 10 | 11 | struct tm *loct = localtime(&tt); 12 | printf("现在是北京时间:%d年%d月%d日 %-2d:%-2d:%-2d\n", \ 13 | 1900 + loct->tm_year, 1 + loct->tm_mon, loct->tm_mday, \ 14 | loct->tm_hour, loct->tm_min, loct->tm_sec); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /standard/iso/operator/sizeof2.c: -------------------------------------------------------------------------------- 1 | //基本类型的sizeof计算 2 | 3 | #include 4 | 5 | int main() { 6 | printf("sizeof(char) = %lu\n", sizeof(char)); 7 | printf("sizeof(short) = %lu\n", sizeof(short)); 8 | printf("sizeof(int) = %lu\n", sizeof(int)); 9 | printf("sizeof(long) = %lu\n", sizeof(long)); 10 | printf("sizeof(long long) = %lu\n", sizeof(long long)); 11 | printf("sizeof(float) = %lu\n", sizeof(float)); 12 | printf("sizeof(double) = %lu\n", sizeof(double)); 13 | printf("sizeof(long double) = %lu\n", sizeof(long double)); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /standard/posix/pthread.h/thread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 线程要执行的函数 */ 5 | void *run(void *args) { 6 | printf("running start\n"); 7 | int i; 8 | for(i = 0; i < 100; i++) { 9 | printf("running...\n"); 10 | } 11 | printf("running end\n"); 12 | return NULL; 13 | } 14 | 15 | int main() { 16 | pthread_t threadId; 17 | 18 | int rc = pthread_create(&threadId, NULL, run, NULL); 19 | if(0 != rc) { 20 | printf("create thread fail!\n"); 21 | return -1; 22 | } 23 | printf("create thread success\n"); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /standard/iso/hello/hello.s: -------------------------------------------------------------------------------- 1 | .file "hello.c" 2 | .section .rodata 3 | .LC0: 4 | .string "Hello world!" 5 | .text 6 | .globl main 7 | .type main, @function 8 | main: 9 | .LFB0: 10 | .cfi_startproc 11 | pushq %rbp 12 | .cfi_def_cfa_offset 16 13 | .cfi_offset 6, -16 14 | movq %rsp, %rbp 15 | .cfi_def_cfa_register 6 16 | movl $.LC0, %edi 17 | call puts 18 | movl $0, %eax 19 | popq %rbp 20 | .cfi_def_cfa 7, 8 21 | ret 22 | .cfi_endproc 23 | .LFE0: 24 | .size main, .-main 25 | .ident "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2" 26 | .section .note.GNU-stack,"",@progbits 27 | -------------------------------------------------------------------------------- /standard/iso/operator/sizeof3.c: -------------------------------------------------------------------------------- 1 | //指针类型的sizeof计算 2 | 3 | #include 4 | 5 | int main() { 6 | printf("sizeof(char*) = %lu\n", sizeof(char*)); 7 | printf("sizeof(short*) = %lu\n", sizeof(short*)); 8 | printf("sizeof(int*) = %lu\n", sizeof(int*)); 9 | printf("sizeof(long*) = %lu\n", sizeof(long*)); 10 | printf("sizeof(long long*) = %lu\n", sizeof(long long*)); 11 | printf("sizeof(float*) = %lu\n", sizeof(float*)); 12 | printf("sizeof(double*) = %lu\n", sizeof(double*)); 13 | printf("sizeof(long double*) = %lu\n", sizeof(long double*)); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /library/openssl/SHA-256/src/lib/sha256sumConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | set(SHA256SUM_VERSION "@PROJECT_VERSION@") 4 | set(SHA256SUM_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@") 5 | set(SHA256SUM_VERSION_MINOR "@PROJECT_VERSION_MINOR@") 6 | set(SHA256SUM_VERSION_PATCH "@PROJECT_VERSION_PATCH@") 7 | 8 | set_and_check(SHA256SUM_INSTALL_DIR "${PACKAGE_PREFIX_DIR}") 9 | set_and_check(SHA256SUM_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") 10 | set_and_check(SHA256SUM_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib") 11 | 12 | include("${CMAKE_CURRENT_LIST_DIR}/sha256sumTargets.cmake") 13 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer.c: -------------------------------------------------------------------------------- 1 | /* 指针定义和初始化 */ 2 | 3 | #include 4 | 5 | int main() { 6 | int a = 100; 7 | float b = 20.0f; 8 | 9 | int *pa = &a; 10 | float *pb = &a; /* 这样会出现warnning,但不会出现error,这样很可能出现异常结果 */ 11 | int *pc = 0x7fffffffd870; 12 | 13 | int d = *pa; 14 | 15 | /* 通过malloc函数进行内存分配 */ 16 | int *pd = (int*) malloc(sizeof(int)); 17 | if(NULL != pd) { 18 | *pd = 30; 19 | 20 | /* 此处打断点查看*/ 21 | 22 | free(pd); 23 | } 24 | 25 | int e[5]; 26 | int *pe = e; 27 | pe = &e[0]; 28 | 29 | char *pf = "C Language"; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /standard/posix/pthread.h/thread2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 线程要执行的函数 */ 5 | void *run(void *args) { 6 | printf("running start\n"); 7 | int i; 8 | for(i = 0; i < 100; i++) { 9 | printf("running...\n"); 10 | } 11 | printf("running end\n"); 12 | return NULL; 13 | } 14 | 15 | int main() { 16 | pthread_t threadId; 17 | int rc = pthread_create(&threadId, NULL, run, NULL); 18 | if(0 != rc) { 19 | printf("create thread fail!\n"); 20 | return -1; 21 | } 22 | printf("create thread success\n"); 23 | 24 | pthread_exit("main thread exit\n"); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /standard/posix/pthread.h/thread4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 线程要执行的函数 */ 5 | void *run(void *args) { 6 | printf("running start\n"); 7 | int i; 8 | for(i = 0; i < 100; i++) { 9 | printf("running...\n"); 10 | } 11 | printf("running end\n"); 12 | return NULL; 13 | } 14 | 15 | int main() { 16 | pthread_t threadId; 17 | int rc = pthread_create(&threadId, NULL, run, NULL); 18 | if(0 != rc) { 19 | printf("create thread fail!\n"); 20 | return -1; 21 | } 22 | printf("create thread success\n"); 23 | 24 | /* 等待另一个线程结束 */ 25 | pthread_join(threadId, 0); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/vfork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int data = 0; 7 | pid_t pid = vfork(); 8 | 9 | if(pid < 0) { 10 | perror("vfork error!"); 11 | } else if (pid == 0) { 12 | printf("i'm child process and my pid is %d\n", getpid()); 13 | data = 20; 14 | sleep(5); 15 | execlp("ls", "ls", "-l", NULL); 16 | } else { 17 | printf("i'm parent process and my pid is %d\n", getpid()); 18 | printf("i'm parent process and new process pid is %d\n", pid); 19 | printf("parent process data = %d\n", data); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /standard/iso/operator/sizeof.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("sizeof(int) = %lu\n", sizeof(int)); 5 | printf("sizeof(2 + 3.0f) = %lu\n", sizeof(2 + 3.0f)); 6 | 7 | int i; 8 | printf("sizeof(i) = %lu\n", sizeof(i)); 9 | printf("sizeof i = %lu\n", sizeof i); 10 | 11 | printf("sizeof(2) = %lu\n", sizeof(2)); 12 | printf("sizeof 2 = %lu\n", sizeof 2); 13 | 14 | printf("sizeof(fabs(3.0f) = %lu\n)", sizeof(fabs(3.0f))); 15 | 16 | //编译时刻确定,所以是常量 17 | char ch1[sizeof(int) * 10]; 18 | 19 | int n = 10; 20 | char ch[n]; 21 | printf("sizeof(ch) = %lu\n", sizeof(ch)); 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/getopt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char * argv[]) { 5 | char ch; 6 | 7 | while(-1 != (ch = getopt(argc, argv, "a:bcd"))) { 8 | switch(ch) { 9 | case 'a': 10 | printf("%s\n", "a"); 11 | if(NULL != optarg) { 12 | printf("value of option a is %s\n", optarg); 13 | } 14 | break; 15 | case 'b': 16 | printf("%s\n", "b"); 17 | break; 18 | case 'c': 19 | printf("%s\n", "c"); 20 | break; 21 | case 'd': 22 | printf("%s\n", "d"); 23 | break; 24 | default: 25 | break; 26 | } 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /library/openssl/SHA-256/src/include/sha256sum.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA256SUM_H 2 | #define SHA256SUM_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | int sha256sum_of_bytes (char outputBuffer[65], unsigned char * inputBuffer, size_t inputBufferSizeInBytes); 11 | int sha256sum_of_string(char outputBuffer[65], const char * str); 12 | int sha256sum_of_file (char outputBuffer[65], const char * filepath); 13 | int sha256sum_of_stream(char outputBuffer[65], FILE * file); 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | #endif 18 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/wait4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | pid_t pid = fork(); 7 | 8 | if(pid < 0) { 9 | perror("fork error!"); 10 | } else if(0 == pid) { 11 | printf("fork success! my pid is %d\n", getpid()); 12 | exit(3); 13 | } else { 14 | int status; 15 | pid_t child_pid = wait(&status); 16 | if(WIFEXITED(status)) { 17 | printf("the child process %d exit normally!\n", child_pid); 18 | printf("the reutrn code is %d\n", WEXITSTATUS(status)); 19 | } else { 20 | printf("the child process %d exit abnormally!\n", child_pid); 21 | } 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /standard/iso/data-type/union/union3.c: -------------------------------------------------------------------------------- 1 | typedef union { 2 | int a; 3 | char b; 4 | } XX; 5 | 6 | #include 7 | #include 8 | 9 | int main() { 10 | XX x; 11 | x.a = 65; 12 | 13 | XX y = x; 14 | 15 | XX *z = (XX *)malloc(sizeof(XX)); 16 | if(NULL != z) { 17 | (*z).b = 'a'; 18 | } 19 | 20 | printf("x.a = %d\n", x.a); 21 | printf("x.b = %c\n", x.b); 22 | printf("-------------\n"); 23 | printf("y.a = %d\n", y.a); 24 | printf("y.b = %c\n", y.b); 25 | 26 | if(NULL != z) { 27 | printf("-------------\n"); 28 | printf("z->a = %d\n", z->a); 29 | printf("z->b = %c\n", z->b); 30 | 31 | free(z); 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/math.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | printf("M_E = %.20f\n", M_E); 6 | printf("M_LOG2E = %.20f\n", M_LOG2E); 7 | printf("M_LOG10E = %.20f\n", M_LOG10E); 8 | printf("M_LN2 = %.20f\n", M_LN2); 9 | printf("M_LN10 = %.20f\n", M_LN10); 10 | printf("M_PI = %.20f\n", M_PI); 11 | printf("M_PI_2 = %.20f\n", M_PI_2); 12 | printf("M_PI_4 = %.20f\n", M_PI_4); 13 | printf("M_1_PI = %.20f\n", M_1_PI); 14 | printf("M_2_PI = %.20f\n", M_2_PI); 15 | printf("M_2_SQRTPI = %.20f\n", M_2_SQRTPI); 16 | printf("M_SQRT2 = %.20f\n", M_SQRT2); 17 | printf("M_SQRT1_2 = %.20f\n", M_SQRT1_2); 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /standard/posix/spawn.h/posix_spawn_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | extern char **environ; 10 | 11 | int stub_system(const char* cmd) { 12 | char* const argv[] = {(char*)"sh", (char*)"-c", (char*)cmd, NULL}; 13 | 14 | pid_t pid; 15 | int status; 16 | status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); 17 | if (0 == status) { 18 | return waitpid(pid, &status, 0); 19 | } 20 | return status; 21 | } 22 | 23 | int main(int argc, char* argv[]) { 24 | return stub_system(argv[1]); 25 | } 26 | -------------------------------------------------------------------------------- /standard/iso/data-type/pointer/pointer9.c: -------------------------------------------------------------------------------- 1 | /* 指针型函数示例 */ 2 | 3 | typedef enum { 4 | MON, 5 | TUE, 6 | WED, 7 | THU, 8 | FRI, 9 | SAT, 10 | SUN 11 | } WeekDay; 12 | 13 | char *weekday[] = { "Monday", 14 | "Tuesday", 15 | "Wednesday", 16 | "Thursday", 17 | "Friday", 18 | "Saturday", 19 | "Sunday" 20 | }; 21 | 22 | char* getName(WeekDay whichDay) { 23 | return weekday[whichDay]; 24 | } 25 | 26 | int main() { 27 | char *a = getName(MON); 28 | char *b = getName(TUE); 29 | char *c = getName(WED); 30 | char *d = getName(THU); 31 | char *e = getName(FRI); 32 | char *f = getName(SAT); 33 | char *g = getName(SUN); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /standard/posix/pthread.h/thread3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 线程要执行的函数 */ 5 | void *run(void *args) { 6 | printf("running start\n"); 7 | int i; 8 | for(i = 0; i < 100; i++) { 9 | printf("running...\n"); 10 | } 11 | printf("running end\n"); 12 | return NULL; 13 | } 14 | 15 | int main() { 16 | pthread_t threadId; 17 | int rc = pthread_create(&threadId, NULL, run, NULL); 18 | if(0 != rc) { 19 | printf("create thread fail!\n"); 20 | return -1; 21 | } 22 | 23 | if(threadId, pthread_self()) { 24 | printf("是同一个线程!\n"); 25 | } 26 | 27 | printf("create thread success\n"); 28 | 29 | pthread_exit("main thread exit\n"); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/kill.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void signalHandler(int signum) { 7 | if(SIGINT == signum) { 8 | printf("收到了杀死进程%d的信号\n", getpid()); 9 | } 10 | } 11 | 12 | int main() { 13 | /* 注册消息处理 */ 14 | signal(SIGINT, signalHandler); 15 | 16 | /* 获得主进程的pid */ 17 | pid_t main_pid = getpid(); 18 | 19 | /* fork一个新进程 */ 20 | pid_t new_pid = fork(); 21 | 22 | if(new_pid < 0) { 23 | perror("fork error!\n"); 24 | } else if(0 == new_pid) { 25 | /* 杀死主进程 */ 26 | kill(main_pid, SIGINT); 27 | printf("process %d kill process %d\n", getpid(), main_pid); 28 | } else { 29 | sleep(10); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /autotools/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Name of package */ 4 | #undef PACKAGE 5 | 6 | /* Define to the address where bug reports for this package should be sent. */ 7 | #undef PACKAGE_BUGREPORT 8 | 9 | /* Define to the full name of this package. */ 10 | #undef PACKAGE_NAME 11 | 12 | /* Define to the full name and version of this package. */ 13 | #undef PACKAGE_STRING 14 | 15 | /* Define to the one symbol short name of this package. */ 16 | #undef PACKAGE_TARNAME 17 | 18 | /* Define to the home page for this package. */ 19 | #undef PACKAGE_URL 20 | 21 | /* Define to the version of this package. */ 22 | #undef PACKAGE_VERSION 23 | 24 | /* Version number of package */ 25 | #undef VERSION 26 | -------------------------------------------------------------------------------- /autotools/config.h.in~: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Name of package */ 4 | #undef PACKAGE 5 | 6 | /* Define to the address where bug reports for this package should be sent. */ 7 | #undef PACKAGE_BUGREPORT 8 | 9 | /* Define to the full name of this package. */ 10 | #undef PACKAGE_NAME 11 | 12 | /* Define to the full name and version of this package. */ 13 | #undef PACKAGE_STRING 14 | 15 | /* Define to the one symbol short name of this package. */ 16 | #undef PACKAGE_TARNAME 17 | 18 | /* Define to the home page for this package. */ 19 | #undef PACKAGE_URL 20 | 21 | /* Define to the version of this package. */ 22 | #undef PACKAGE_VERSION 23 | 24 | /* Version number of package */ 25 | #undef VERSION 26 | -------------------------------------------------------------------------------- /standard/posix/dlfcn.h/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(shell uname -s), Darwin) 2 | LD_SUFFIX = .dylib 3 | else 4 | LD_SUFFIX = .so 5 | endif 6 | 7 | LD_FILE_NAME = libadd$(LD_SUFFIX) 8 | 9 | override CFLAGS += -Os 10 | 11 | libadd: add.c 12 | $(CC) $(CFLAGS) -shared -fPIC -o $(LD_FILE_NAME) $^ 13 | 14 | compile_time_do_not_link: compile_time_do_not_link.c 15 | $(CC) $(CFLAGS) -o $@ $^ 16 | 17 | compile_time_do_not_link_test: compile_time_do_not_link 18 | ./$< $(LD_FILE_NAME) 19 | 20 | compile_time_link: compile_time_link.c 21 | $(CC) $(CFLAGS) -L. -ladd -o $@ $^ 22 | 23 | compile_time_link_test: compile_time_link 24 | ./$< 25 | 26 | clean: 27 | rm -f $(LD_FILE_NAME) 28 | rm -f compile_time_do_not_link 29 | rm -f compile_time_link 30 | 31 | .PHONY: clean 32 | -------------------------------------------------------------------------------- /utils/self_exe_path/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(self_exe_path C) 4 | 5 | set(PROJECT_VERSION 1.0.0) 6 | set(PROJECT_VERSION_MAJOR 1) 7 | set(PROJECT_VERSION_MINOR 0) 8 | set(PROJECT_VERSION_PATCH 0) 9 | 10 | if (NOT CMAKE_BUILD_TYPE) 11 | set(CMAKE_BUILD_TYPE Release) 12 | endif() 13 | 14 | ######################################################################################## 15 | 16 | add_executable(self_exe_path main.c self.c) 17 | add_executable(getexepath getexepath.c) 18 | 19 | ######################################################################################## 20 | 21 | include(GNUInstallDirs) 22 | 23 | install(TARGETS self_exe_path getexepath RUNTIME COMPONENT bin DESTINATION ${CMAKE_INSTALL_BINDIR}) 24 | -------------------------------------------------------------------------------- /library/mbedTLS/AES/mbedtls/base16.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE_16_H 2 | #define BASE_16_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /*base16编码 12 | *bytes 要编码的字节的起始指针 13 | *nBytes 要编码的字节的长度 14 | *isToUpper 是否编码为大写字母 15 | */ 16 | char* base16_encode (unsigned char *bytes, size_t nBytes, bool isToUpper); 17 | char* base16_encode_to_upper(unsigned char *bytes, size_t nBytes); 18 | char* base16_encode_to_lower(unsigned char *bytes, size_t nBytes); 19 | 20 | /*base16解码 21 | *hex base16编码的字符串 22 | */ 23 | unsigned char* base16_decode(char *hex); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /library/libcares/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(dns C) 4 | 5 | set(PROJECT_VERSION 1.0.0) 6 | set(PROJECT_VERSION_MAJOR 1) 7 | set(PROJECT_VERSION_MINOR 0) 8 | set(PROJECT_VERSION_PATCH 0) 9 | 10 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH}) 11 | 12 | find_package(PkgConfig REQUIRED) 13 | 14 | find_package(CARES REQUIRED) 15 | 16 | if (NOT CMAKE_BUILD_TYPE) 17 | set(CMAKE_BUILD_TYPE Release) 18 | endif() 19 | 20 | ########################################## 21 | 22 | add_executable(dns src/dns.c) 23 | target_link_libraries(dns CARES::libcares) 24 | 25 | ########################################## 26 | 27 | include(GNUInstallDirs) 28 | 29 | install(TARGETS dns RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 30 | -------------------------------------------------------------------------------- /standard/posix/dlfcn.h/compile_time_do_not_link.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char* argv[]) { 5 | if (1 == argc) { 6 | perror("please provide a library path"); 7 | return 1; 8 | } 9 | 10 | void* handle = dlopen(argv[1], RTLD_LAZY); 11 | if (NULL == handle) { 12 | printf("load %s error, %s\n", argv[1], dlerror()); 13 | return 1; 14 | } 15 | 16 | int (*add)(int a, int b); 17 | add = dlsym(handle, "add"); 18 | int value = add(2, 3); 19 | printf("load %s success.\n", argv[1]); 20 | printf("add(2, 3) = %d\n", value); 21 | 22 | int statusCode = dlclose(handle); 23 | printf("unload %s %s!\n", argv[1], statusCode ? "failed" : "success"); 24 | return statusCode; 25 | } 26 | -------------------------------------------------------------------------------- /library/libyaml/test.yml: -------------------------------------------------------------------------------- 1 | summary: Interpreted, interactive, object-oriented programming language 2 | webpage: https://www.python.org 3 | src-url: https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tgz 4 | src-sha: f3bcc65b1d5f1dc78675c746c98fcee823c038168fc629c5935b044d0911ad28 5 | git-url: https://github.com/python/cpython.git 6 | dep-pkg: expat libffi openssl sqlite bzip2 xz 7 | license: Python-2.0 8 | 9 | bsystem: configure 10 | install: | 11 | unset PYTHONHOME 12 | unset PYTHONPATH 13 | 14 | configure \ 15 | --with-system-expat \ 16 | --with-system-ffi \ 17 | --with-openssl=$openssl_INSTALL_DIR \ 18 | --with-ensurepip=no \ 19 | --with-lto \ 20 | --enable-ipv6 \ 21 | --enable-loadable-sqlite-extensions \ 22 | --disable-profiling 23 | -------------------------------------------------------------------------------- /.github/workflows/codacy-analysis.yml: -------------------------------------------------------------------------------- 1 | name: codacy-analysis 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | codacy-analysis: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@main 17 | 18 | - uses: codacy/codacy-analysis-cli-action@master 19 | with: 20 | output: results.sarif 21 | format: sarif 22 | # Adjust severity of non-security issues 23 | gh-code-scanning-compat: true 24 | # Force 0 exit code to allow SARIF file generation 25 | # This will handover control about PR rejection to the GitHub side 26 | max-allowed-issues: 2147483647 27 | 28 | - uses: github/codeql-action/upload-sarif@main 29 | with: 30 | sarif_file: results.sarif 31 | -------------------------------------------------------------------------------- /algorithm/base16/src/lib/base16.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE_16_H 2 | #define BASE_16_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* base16编码 12 | * output base16编码后的字符串 13 | * input 要编码的字节的起始指针 14 | * inputLengthInBytes 要编码的字节的长度 15 | * isToUpper 是否编码为大写字母 16 | */ 17 | int base16_encode(char * output, const unsigned char * input, size_t inputSizeInBytes, bool isToUpper); 18 | 19 | /* base16解码 20 | * input base16编码的字符串 21 | */ 22 | int base16_decode(unsigned char * output, const char * input, size_t inputSizeInBytes); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array7.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10 ,11, 12}}; 5 | 6 | printf("a = %p\n", a); 7 | printf("*a = %p\n", *a); 8 | printf("a[0] = %p\n", a[0]); 9 | printf("&a[0] = %p\n", &a[0]); 10 | printf("a[0][0] = %d\n", a[0][0]); 11 | printf("&a[0][0] = %p\n", &a[0][0]); 12 | 13 | printf("a + 1 = %p\n", a + 1); 14 | printf("*(a + 1) = %p\n", *(a + 1)); 15 | printf("a[1] = %p\n", a[1]); 16 | printf("&a[1] = %p\n", &a[1]); 17 | printf("&a[1][0] = %p\n", &a[1][0]); 18 | printf("a[1][0] = %d\n", a[1][0]); 19 | 20 | printf("a[2] + 1 = %p\n", a[2] + 1); 21 | printf("(a + 2) + 1 = %p\n", (a + 2) + 1); 22 | printf("*(a + 2) = %p\n", *(a + 2)); 23 | printf("*((a + 2) + 1) = %p\n", *((a + 2) + 1)); 24 | printf("*(*(a + 2) + 1) = %d\n", *(*(a + 2) + 1)); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /library/libelf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(elftools C) 4 | 5 | set(PROJECT_VERSION 1.0.0) 6 | set(PROJECT_VERSION_MAJOR 1) 7 | set(PROJECT_VERSION_MINOR 0) 8 | set(PROJECT_VERSION_PATCH 0) 9 | 10 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH}) 11 | 12 | find_package(PkgConfig REQUIRED) 13 | 14 | find_package(LIBELF REQUIRED) 15 | 16 | if (NOT CMAKE_BUILD_TYPE) 17 | set(CMAKE_BUILD_TYPE Release) 18 | endif() 19 | 20 | ########################################## 21 | 22 | add_executable(check-if-has-dynamic-section src/check-if-has-dynamic-section.c) 23 | target_link_libraries(check-if-has-dynamic-section LIBELF::libelf) 24 | 25 | ########################################## 26 | 27 | include(GNUInstallDirs) 28 | 29 | install(TARGETS check-if-has-dynamic-section RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 30 | -------------------------------------------------------------------------------- /library/libgit2/git-clone-simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | // https://libgit2.org/docs/guides/101-samples/ 6 | int do_git_clone(const char * url, const char * filepath) { 7 | git_libgit2_init(); 8 | 9 | git_repository * gitRepo = NULL; 10 | 11 | // https://libgit2.org/libgit2/#HEAD/group/clone/git_clone 12 | int resultCode = git_clone(&gitRepo, url, filepath, NULL); 13 | 14 | if (resultCode != 0) { 15 | const git_error * error = git_error_last(); 16 | fprintf(stderr, "%s\n", error->message); 17 | } 18 | 19 | git_repository_free(gitRepo); 20 | 21 | git_libgit2_shutdown(); 22 | 23 | return resultCode; 24 | } 25 | 26 | int main(int argc, char* argv[]) { 27 | if (argc < 3) { 28 | printf("%s \n", argv[0]); 29 | return 0; 30 | } 31 | return do_git_clone(argv[1], argv[2]); 32 | } 33 | -------------------------------------------------------------------------------- /standard/iso/data-type/struct/person4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { 4 | char *name; 5 | unsigned short age; 6 | char sex; 7 | bool issingle; 8 | float weight; 9 | } Person; 10 | 11 | #include 12 | 13 | #define NUM 5 14 | 15 | int main() { 16 | Person person[NUM]; 17 | int i = 0; 18 | 19 | for(i = 0; i < NUM; i++) { 20 | //实际开发中,这里往往是连接数据库获取数据的 21 | person[i].name = "WangHua"; 22 | person[i].age = 18u; 23 | person[i].sex = 'F'; 24 | person[i].issingle = true; 25 | person[i].weight = 120.0f; 26 | } 27 | 28 | for(i = 0; i < NUM; i++) { 29 | printf("person[%d].name = %s\n", i, person[i].name); 30 | printf("preson[%d].age = %u\n", i, person[i].age); 31 | printf("perosn[%d].sex = %c\n", i, person[i].sex); 32 | printf("person[%d].issingle = %d\n", i, person[i].issingle); 33 | printf("person[%d].weight = %f\n", i, person[i].weight); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /library/libgit2/git-open.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | // https://libgit2.org/docs/guides/101-samples/ 7 | int is_valid_git_repo(const char * dir) { 8 | git_libgit2_init(); 9 | 10 | git_repository * gitRepo = NULL; 11 | 12 | // https://libgit2.org/libgit2/#HEAD/group/clone/git_repository_open_ext 13 | int ret = git_repository_open_ext(&gitRepo, dir, GIT_REPOSITORY_OPEN_NO_SEARCH, NULL); 14 | 15 | if (ret != GIT_OK) { 16 | const git_error * error = git_error_last(); 17 | fprintf(stderr, "%s\n", error->message); 18 | } 19 | 20 | git_repository_free(gitRepo); 21 | 22 | git_libgit2_shutdown(); 23 | 24 | return ret; 25 | } 26 | 27 | int main(int argc, char* argv[]) { 28 | if (argc < 2) { 29 | printf("%s \n", argv[0]); 30 | return 0; 31 | } 32 | 33 | return is_valid_git_repo(argv[1]); 34 | } 35 | -------------------------------------------------------------------------------- /library/libyaml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(yaml-based-formula-parser C) 4 | 5 | if (NOT CMAKE_BUILD_TYPE) 6 | set(CMAKE_BUILD_TYPE Release) 7 | endif() 8 | 9 | ######################################################################################## 10 | 11 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH}) 12 | 13 | find_package(PkgConfig REQUIRED) 14 | find_package(LibYAML REQUIRED) 15 | 16 | ######################################################################################## 17 | 18 | add_executable(yaml-based-formula-parser yaml-based-formula-parser.c) 19 | 20 | target_link_libraries(yaml-based-formula-parser LIBYAML::LIBYAML) 21 | 22 | ######################################################################################## 23 | 24 | include(GNUInstallDirs) 25 | 26 | install(TARGETS yaml-based-formula-parser RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 27 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/chdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) { 8 | if (argc < 2) { 9 | printf("Usage: %s \n", argv[0]); 10 | return 1; 11 | } 12 | 13 | char buff[PATH_MAX]; 14 | const char * cwd = getcwd(buff, PATH_MAX); 15 | 16 | if (cwd == NULL) { 17 | perror(NULL); 18 | return 1; 19 | } 20 | 21 | printf("current working dir is %s\n", cwd); 22 | printf("change working dir to %s\n", argv[1]); 23 | 24 | if (chdir(argv[1]) == 0) { 25 | char buff[PATH_MAX]; 26 | const char * cwd = getcwd(buff, PATH_MAX); 27 | 28 | if (cwd == NULL) { 29 | perror(NULL); 30 | return 1; 31 | } 32 | 33 | printf("current working dir is %s\n", cwd); 34 | return 0; 35 | } else { 36 | perror(argv[1]); 37 | return 1; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/wait3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | pid_t create_process() { 6 | static count; 7 | count++; 8 | 9 | pid_t pid = fork(); 10 | if(pid < 0) { 11 | printf("创建第%d个进程失败!\n", count); 12 | } else if(0 == pid) { 13 | printf("创建第%d个进程成功,pid = %d\n", count, getpid()); 14 | } 15 | 16 | return pid; 17 | } 18 | 19 | int main() { 20 | printf("\n"); 21 | 22 | /* 创建3个子进程 */ 23 | pid_t pid1 = create_process(); 24 | if(pid1 > 0) { 25 | pid_t pid2 = create_process(); 26 | if(pid2 > 0) { 27 | pid_t pid3 = create_process(); 28 | if(pid3 > 0) { 29 | /* 睡眠1分钟,以便我们有充足的时间使用ps -au命令观察 */ 30 | sleep(60); 31 | 32 | printf("\n"); 33 | 34 | int i; 35 | pid_t child_pid; 36 | for(i = 1; (child_pid = wait(NULL)) > 0; i++) { 37 | printf("捕获了第%d个子进程,pid = %d\n", i, child_pid); 38 | } 39 | } 40 | } 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /autotools/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Name of package */ 5 | #define PACKAGE "full-package-name" 6 | 7 | /* Define to the address where bug reports for this package should be sent. */ 8 | #define PACKAGE_BUGREPORT "BUG-REPORT-ADDRESS" 9 | 10 | /* Define to the full name of this package. */ 11 | #define PACKAGE_NAME "FULL-PACKAGE-NAME" 12 | 13 | /* Define to the full name and version of this package. */ 14 | #define PACKAGE_STRING "FULL-PACKAGE-NAME VERSION" 15 | 16 | /* Define to the one symbol short name of this package. */ 17 | #define PACKAGE_TARNAME "full-package-name" 18 | 19 | /* Define to the home page for this package. */ 20 | #define PACKAGE_URL "" 21 | 22 | /* Define to the version of this package. */ 23 | #define PACKAGE_VERSION "VERSION" 24 | 25 | /* Version number of package */ 26 | #define VERSION "VERSION" 27 | -------------------------------------------------------------------------------- /utils/sysinfo/src/lib/sysinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSINFO_H 2 | #define SYSINFO_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef struct { 10 | char * kind; 11 | char * type; 12 | char * code; 13 | char * name; 14 | char * vers; 15 | char * arch; 16 | unsigned int libc; 17 | unsigned int ncpu; 18 | uid_t euid; 19 | gid_t egid; 20 | } SysInfo; 21 | 22 | int sysinfo_kind(char * buf, size_t bufSize); 23 | int sysinfo_type(char * buf, size_t bufSize); 24 | int sysinfo_code(char * buf, size_t bufSize); 25 | int sysinfo_name(char * buf, size_t bufSize); 26 | int sysinfo_vers(char * buf, size_t bufSize); 27 | int sysinfo_arch(char * buf, size_t bufSize); 28 | int sysinfo_libc(); 29 | int sysinfo_ncpu(); 30 | 31 | int sysinfo_make(SysInfo * sysinfo); 32 | void sysinfo_dump(SysInfo * sysinfo); 33 | void sysinfo_free(SysInfo * sysinfo); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /standard/linux/eventpool.h/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(CmakeTest) 4 | 5 | include(FindPkgConfig) 6 | 7 | pkg_check_modules(LIBSSH2 libssh2) 8 | 9 | message(${LIBSSH2_FOUND}) 10 | 11 | message(${LIBSSH2_LIBRARIES}) 12 | 13 | message(${LIBSSH2_INCLUDE_DIRS}) 14 | message(${LIBSSH2_LIBRARY_DIRS}) 15 | 16 | message(${LIBSSH2_CFLAGS}) 17 | message(${LIBSSH2_LDFLAGS}) 18 | 19 | message(${LIBSSH2_VERSION}) 20 | message(${LIBSSH2_PREFIX}) 21 | 22 | message(${CMAKE_PREFIX_PATH}) 23 | message("$ENV{PKG_CONFIG_PATH}") 24 | 25 | FOREACH(LIBRARY ${LIBSSH2_LIBRARIES}) 26 | FIND_LIBRARY(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${LIBSSH2_LIBRARY_DIRS}) 27 | message(${${LIBRARY}_RESOLVED}) 28 | IF(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND") 29 | MESSAGE(FATAL_ERROR "could not resolve ${LIBRARY}") 30 | ENDIF() 31 | LIST(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED}) 32 | ENDFOREACH(LIBRARY) 33 | -------------------------------------------------------------------------------- /algorithm/crc/CRCTest.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "CRC.h" 6 | #include "../base16/base16.h" 7 | 8 | void showHelp() { 9 | printf("usage: CRC hex xxxx\n"); 10 | printf(" CRC str xxxx\n"); 11 | exit(1); 12 | } 13 | 14 | int main(int argc, char *argv[]) { 15 | if (argc == 3) { 16 | if (strcmp("hex", argv[1]) == 0) { 17 | unsigned char* bytes = base16_decode(argv[2]); 18 | unsigned short nBytes = strlen(argv[2]) >> 1; 19 | unsigned char crc = CRC(bytes, nBytes); 20 | printf("hex:%02X\n", crc); 21 | } else if (strcmp("str", argv[1]) == 0) { 22 | unsigned char crc = CRC((unsigned char *)argv[2], strlen(argv[2]) >> 1); 23 | printf("hex:%02X\n", crc); 24 | } else { 25 | showHelp(); 26 | } 27 | } else { 28 | showHelp(); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /standard/iso/data-type/struct/person3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct person { 4 | char *name; 5 | unsigned short age; 6 | char sex; 7 | bool issingle; 8 | float weight; 9 | } PERSON; 10 | 11 | #include 12 | 13 | int main() { 14 | struct person person1 = {"WangHua", 18u, 'F', true, 120.0f}; 15 | PERSON person2 = {"WangHua", 18u, 'F', true, 120.0f}; 16 | 17 | printf("person1.name = %s\n", person1.name); 18 | printf("preson1.age = %u\n", person1.age); 19 | printf("perosn1.sex = %c\n", person1.sex); 20 | printf("person1.issingle = %d\n", person1.issingle); 21 | printf("person1.weight = %f\n", person1.weight); 22 | printf("---------------------\n"); 23 | printf("person2.name = %s\n", person2.name); 24 | printf("preson2.age = %u\n", person2.age); 25 | printf("perosn2.sex = %c\n", person2.sex); 26 | printf("person2.issingle = %d\n", person2.issingle); 27 | printf("person2.weight = %f\n", person2.weight); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /standard/iso/header/setjmp.h/setjmp3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static jmp_buf env; 5 | 6 | void func1(int i) { 7 | puts("in func1"); 8 | 9 | if(1 == i) { 10 | longjmp(env, 1); 11 | } 12 | } 13 | 14 | void func2(int i) { 15 | puts("in func2"); 16 | 17 | if(2 == i) { 18 | longjmp(env, 2); 19 | } 20 | } 21 | 22 | void func3(int i) { 23 | puts("in func3"); 24 | 25 | if(3 == i) { 26 | longjmp(env, 3); 27 | } 28 | } 29 | 30 | int main(int argc, char *argv[]) { 31 | switch(setjmp(env)) { 32 | case 0: 33 | puts("you can see this"); 34 | func1(atoi(argv[1])); 35 | func2(atoi(argv[1])); 36 | func3(atoi(argv[1])); 37 | puts("never see this"); 38 | break; 39 | case 1: 40 | puts("catch an exception1"); 41 | break; 42 | case 2: 43 | puts("catch an exception2"); 44 | break; 45 | case 3: 46 | puts("catch an exception3"); 47 | break; 48 | default: 49 | puts("default"); 50 | } 51 | 52 | puts("finally"); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /standard/iso/data-type/array/array3.c: -------------------------------------------------------------------------------- 1 | /*---------------------------九九乘法表---------------------------*/ 2 | /* 1x1=1 */ 3 | /* 2x1=2 2x2=4 */ 4 | /* 3x1=3 3x2=6 3x3=9 */ 5 | /* 4x1=4 4x2=8 4x3=12 4x4=16 */ 6 | /* 5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 */ 7 | /* 6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 */ 8 | /* 7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 */ 9 | /* 8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 */ 10 | /* 9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81 */ 11 | 12 | #include 13 | 14 | #define MAX 10 15 | 16 | int main() { 17 | int i, j; 18 | for(i = 1; i < MAX; i++) { 19 | for(j = 1; j <= i; j++) { 20 | printf("%dx%d=%-2d ", i, j, i*j); 21 | } 22 | printf("\n"); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /algorithm/lrc/src/main/lrcsum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "lrc.h" 7 | 8 | void showHelp() { 9 | printf("usage: lrc hex xxxx\n"); 10 | printf(" lrc str xxxx\n"); 11 | exit(1); 12 | } 13 | 14 | int main(int argc, char *argv[]) { 15 | if (argc == 3) { 16 | if (strcmp("hex", argv[1]) == 0) { 17 | unsigned short nBytes = strlen(argv[2]) >> 1; 18 | unsigned char bytes[nBytes + 1]; 19 | memset(bytes, 0, nBytes + 1); 20 | base16_decode(bytes, argv[2]); 21 | unsigned char lrcsum = lrc(bytes, nBytes); 22 | printf("%x\n", lrcsum); 23 | } else if (strcmp("str", argv[1]) == 0) { 24 | unsigned char lrcsum = lrc((unsigned char *)argv[2], strlen(argv[2]) >> 1); 25 | printf("%x\n", lrcsum); 26 | } else { 27 | showHelp(); 28 | } 29 | } else { 30 | showHelp(); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /standard/posix/sys/stat.h/stat64.c: -------------------------------------------------------------------------------- 1 | #define _DARWIN_C_SOURCE 2 | #define __DARWIN_ONLY_64_BIT_INO_T 0 3 | // int stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA); 4 | // 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() { 11 | struct stat64 info; 12 | 13 | if (stat64("/", &info) != 0) { 14 | perror("stat64() error"); 15 | return 1; 16 | } else { 17 | puts("stat64() returned the following information about root f/s:"); 18 | printf(" inode: %d\n", (int) info.st_ino); 19 | printf(" dev id: %d\n", (int) info.st_dev); 20 | printf(" mode: %08x\n", info.st_mode); 21 | printf(" links: %d\n", info.st_nlink); 22 | printf(" uid: %d\n", (int) info.st_uid); 23 | printf(" gid: %d\n", (int) info.st_gid); 24 | printf("created: %s", ctime(&info.st_birthtime)); 25 | return 0; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /library/mbedTLS/base64/src/lib/base64.c: -------------------------------------------------------------------------------- 1 | // http://blog.fpliu.com/it/software/mbedTLS/include/base64.h 2 | 3 | #include 4 | 5 | #include "base64_mbedtls.h" 6 | 7 | size_t get_base64_encode_output_length_in_bytes(size_t inputBufferSizeInBytes) { 8 | //看看需要分配多少个字节 9 | //编码后,长度变为原来的4/3倍 10 | size_t n = inputBufferSizeInBytes / 3U + (((inputBufferSizeInBytes % 3U) == 0) ? 0U : 1U); 11 | return (n << 2); 12 | } 13 | 14 | int base64_encode(char * outputBuffer, size_t outputBufferSizeInBytes, unsigned char * inputBuffer, size_t inputBufferSizeInBytes) { 15 | size_t writtenSizeInBytes; 16 | return mbedtls_base64_encode((unsigned char*)outputBuffer, outputBufferSizeInBytes, &writtenSizeInBytes, inputBuffer, inputBufferSizeInBytes); 17 | } 18 | 19 | int base64_decode(unsigned char * outputBuffer, size_t outputBufferSizeInBytes, size_t * writtenSizeInBytes, char * inputBuffer, size_t inputBufferSizeInBytes) { 20 | return mbedtls_base64_decode(outputBuffer, outputBufferSizeInBytes, writtenSizeInBytes, (unsigned char *)inputBuffer, inputBufferSizeInBytes); 21 | } 22 | -------------------------------------------------------------------------------- /algorithm/bcc/src/test/bcc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void test_bcc() { 7 | const char *input = "abcd"; 8 | size_t nBytes = strlen(input); 9 | unsigned char bccsum = bcc((unsigned char*)input, nBytes); 10 | CU_ASSERT_EQUAL(bccsum, 1); 11 | } 12 | 13 | // http://cunit.sourceforge.net/example.html 14 | int main() { 15 | CU_pSuite pSuite = NULL; 16 | 17 | /* initialize the CUnit test registry */ 18 | if (CUE_SUCCESS != CU_initialize_registry()) { 19 | return CU_get_error(); 20 | } 21 | 22 | /* add a suite to the registry */ 23 | pSuite = CU_add_suite("Suite_1", NULL, NULL); 24 | if (NULL == pSuite) { 25 | CU_cleanup_registry(); 26 | return CU_get_error(); 27 | } 28 | 29 | /* add the tests to the suite */ 30 | if ((NULL == CU_add_test(pSuite, "test bcc()", test_bcc))) { 31 | CU_cleanup_registry(); 32 | return CU_get_error(); 33 | } 34 | 35 | 36 | CU_run_all_tests(); 37 | 38 | CU_cleanup_registry(); 39 | 40 | return CU_get_error(); 41 | } 42 | -------------------------------------------------------------------------------- /algorithm/lrc/src/test/lrc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void test_lrc() { 7 | const char *input = "abcd"; 8 | size_t nBytes = strlen(input); 9 | unsigned char bccsum = bcc((unsigned char*)input, nBytes); 10 | CU_ASSERT_EQUAL(bccsum, 1); 11 | } 12 | 13 | // http://cunit.sourceforge.net/example.html 14 | int main() { 15 | CU_pSuite pSuite = NULL; 16 | 17 | /* initialize the CUnit test registry */ 18 | if (CUE_SUCCESS != CU_initialize_registry()) { 19 | return CU_get_error(); 20 | } 21 | 22 | /* add a suite to the registry */ 23 | pSuite = CU_add_suite("Suite_1", NULL, NULL); 24 | if (NULL == pSuite) { 25 | CU_cleanup_registry(); 26 | return CU_get_error(); 27 | } 28 | 29 | /* add the tests to the suite */ 30 | if ((NULL == CU_add_test(pSuite, "test lrc()", test_lrc))) { 31 | CU_cleanup_registry(); 32 | return CU_get_error(); 33 | } 34 | 35 | 36 | CU_run_all_tests(); 37 | 38 | CU_cleanup_registry(); 39 | 40 | return CU_get_error(); 41 | } 42 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/sin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("sin(-M_PI) = %f\n", sin(-M_PI)); 7 | printf("sin(M_PI) = %f\n", sin(M_PI)); 8 | printf("-------------------------------\n"); 9 | printf("sin(-M_PI_2) = %f\n", sin(-M_PI_2)); 10 | printf("sin(M_PI_2) = %f\n", sin(M_PI_2)); 11 | printf("-------------------------------\n"); 12 | printf("sin(-M_PI_4) = %f\n", sin(-M_PI_4)); 13 | printf("sin(M_PI_4) = %f\n", sin(M_PI_4)); 14 | printf("-------------------------------\n"); 15 | printf("sin(-M_PI / 6.0) = %f\n", sin(-M_PI / 6.0)); 16 | printf("sin(M_PI / 6.0) = %f\n", sin(M_PI / 6.0)); 17 | printf("-------------------------------\n"); 18 | printf("sin(100.0) = %f\n", sin(100.0)); 19 | printf("sin(-100.0) = %f\n", sin(-100.0)); 20 | printf("-------------------------------\n"); 21 | printf("sin(DBL_MAX) = %f\n", sin(DBL_MAX)); 22 | printf("sin(-DBL_MAX) = %f\n", sin(-DBL_MAX)); 23 | printf("-------------------------------\n"); 24 | printf("sin(DBL_MIN) = %f\n", sin(DBL_MIN)); 25 | printf("sin(-DBL_MIN) = %f\n", sin(-DBL_MIN)); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /standard/iso/header/math.h/sin2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | printf("sin(-M_PI) = %.16f\n", sin(-M_PI)); 7 | printf("sin(M_PI) = %.16f\n", sin(M_PI)); 8 | printf("-------------------------------\n"); 9 | printf("sin(-M_PI_2) = %.16f\n", sin(-M_PI_2)); 10 | printf("sin(M_PI_2) = %.16f\n", sin(M_PI_2)); 11 | printf("-------------------------------\n"); 12 | printf("sin(-M_PI_4) = %.16f\n", sin(-M_PI_4)); 13 | printf("sin(M_PI_4) = %.16f\n", sin(M_PI_4)); 14 | printf("-------------------------------\n"); 15 | printf("sin(-M_PI / 6.0) = %.16f\n", sin(-M_PI / 6.0)); 16 | printf("sin(M_PI / 6.0) = %.16f\n", sin(M_PI / 6.0)); 17 | printf("-------------------------------\n"); 18 | printf("sin(100.0) = %.16f\n", sin(100.0)); 19 | printf("sin(-100.0) = %.16f\n", sin(-100.0)); 20 | printf("-------------------------------\n"); 21 | printf("sin(DBL_MAX) = %.16f\n", sin(DBL_MAX)); 22 | printf("sin(-DBL_MAX) = %.16f\n", sin(-DBL_MAX)); 23 | printf("-------------------------------\n"); 24 | printf("sin(DBL_MIN) = %.16f\n", sin(DBL_MIN)); 25 | printf("sin(-DBL_MIN) = %.16f\n", sin(-DBL_MIN)); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /standard/iso/data-type/struct/person5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { 4 | char *name; 5 | unsigned short age; 6 | char sex; 7 | bool issingle; 8 | float weight; 9 | } Person; 10 | 11 | #include 12 | #include 13 | 14 | int main() { 15 | Person person = {"WangHua", 18u, 'F', true, 120.0f}; 16 | 17 | Person *p1 = &person; 18 | 19 | printf("p1->name = %s\n", p1->name); 20 | printf("p1->age = %u\n", p1->age); 21 | printf("p1->sex = %c\n", p1->sex); 22 | printf("p1->issingle = %d\n", p1->issingle); 23 | printf("p1->weight = %f\n", p1->weight); 24 | 25 | Person *p2 = (Person *)malloc(sizeof(Person)); 26 | 27 | if(NULL != p2) { 28 | (*p2).name = "WangHua"; 29 | (*p2).age = 18u; 30 | (*p2).sex = 'F'; 31 | (*p2).issingle = true; 32 | (*p2).weight = 120.0f; 33 | 34 | p2->name = "WangHua"; 35 | p2->age = 18u; 36 | p2->sex = 'F'; 37 | p2->issingle = true; 38 | p2->weight = 120.0f; 39 | 40 | printf("---------------------\n"); 41 | printf("p2->name = %s\n", p2->name); 42 | printf("p2->age = %u\n", p2->age); 43 | printf("p2->sex = %c\n", p2->sex); 44 | printf("p2->issingle = %d\n", p2->issingle); 45 | printf("p2->weight = %f\n", p2->weight); 46 | 47 | free(p2); 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /standard/posix/examples/socket/AF_INET/client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main() { 8 | int c_socket_fd = socket(AF_INET, SOCK_STREAM, 0); 9 | if(-1 == c_socket_fd) { 10 | perror("socket create error!"); 11 | goto label; 12 | } 13 | 14 | printf("socket create success!\n"); 15 | 16 | struct sockaddr_in server_address; 17 | server_address.sin_family = AF_INET; 18 | server_address.sin_addr.s_addr = htonl(INADDR_ANY); 19 | server_address.sin_port = htons(8000); 20 | 21 | if(-1 == connect(c_socket_fd, (struct sockaddr*)&server_address, sizeof(server_address))) { 22 | perror("socket connect error!"); 23 | goto label; 24 | } 25 | 26 | printf("socket connect success!\n"); 27 | 28 | char str[] = "I love you!"; 29 | if(-1 == write(c_socket_fd, str, sizeof(str))) { 30 | perror("write error!"); 31 | goto label; 32 | } 33 | 34 | printf("send message to server : %s\n", str); 35 | 36 | char buff[4098] = {'\0'}; 37 | if(-1 == read(c_socket_fd, buff, sizeof(buff))) { 38 | perror("read error!"); 39 | goto label; 40 | } 41 | 42 | printf("reveive message from server : %s\n", buff); 43 | 44 | label: 45 | close(c_socket_fd); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /.github/workflows/openbsd.yml: -------------------------------------------------------------------------------- 1 | name: OpenBSD 2 | 3 | on: 4 | push: 5 | branches: [ master, dev, tmp ] 6 | pull_request: 7 | branches: [ master, dev, tmp ] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | openbsd-version: ['7.7', '7.6', '7.5', '7.4', '7.3', '7.2'] 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - run: curl -LO https://raw.githubusercontent.com/leleliu008/ppkg/master/ppkg 22 | - run: chmod a+x ppkg 23 | 24 | - uses: cross-platform-actions/action@master 25 | with: 26 | operating_system: openbsd 27 | version: ${{ matrix.openbsd-version }} 28 | shell: bash 29 | run: | 30 | run() { 31 | printf "\033[0;35m==>\033[0m \033[0;32m%b\n\033[0m" "$*" 32 | eval "$@" 33 | } 34 | 35 | run ./ppkg setup --syspm 36 | run ./ppkg about 37 | run ./ppkg update 38 | run ./ppkg install c-examples 39 | run ~/.ppkg/installed/openbsd-${{ matrix.openbsd-version }}-amd64/c-examples/bin/self_exe_path 40 | run ~/.ppkg/installed/openbsd-${{ matrix.openbsd-version }}-amd64/c-examples/bin/getexepath 41 | -------------------------------------------------------------------------------- /library/mbedTLS/MD5/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | md5Test: md5Test.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: md5Test 15 | ./$< -x abc 16 | @printf "%b\n" "--------------" 17 | ./$< -X abc 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | clean: 23 | rm -rf libs 24 | rm -rf obj 25 | rm -f md5Test 26 | 27 | download-src: 28 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 29 | printf "%s" "#define MBEDTLS_MD5_C" > config.h && { \ 30 | for item in md5.h platform_util.h threading.h; \ 31 | do \ 32 | curl -LO $(BASE_URL_H)/$${item}; \ 33 | done \ 34 | } && { \ 35 | for item in md5.c platform_util.c threading.c; \ 36 | do \ 37 | curl -LO $(BASE_URL_C)/$${item}; \ 38 | done \ 39 | } && \ 40 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 41 | sed -i "" 's@mbedtls/@@g' * 42 | 43 | .PHONY: ndk-build clean download-src 44 | -------------------------------------------------------------------------------- /.github/workflows/freebsd.yml: -------------------------------------------------------------------------------- 1 | name: FreeBSD 2 | 3 | on: 4 | push: 5 | branches: [ master, dev, tmp ] 6 | pull_request: 7 | branches: [ master, dev, tmp ] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | freebsd-version: ['14.3', '14.2', '14.1', '14.0', '13.5', '13.4', '13.3', '13.2'] 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - run: curl -LO https://raw.githubusercontent.com/leleliu008/ppkg/master/ppkg 22 | - run: chmod a+x ppkg 23 | 24 | - uses: cross-platform-actions/action@master 25 | with: 26 | operating_system: freebsd 27 | version: ${{ matrix.freebsd-version }} 28 | shell: bash 29 | run: | 30 | run() { 31 | printf "\033[0;35m==>\033[0m \033[0;32m%b\n\033[0m" "$*" 32 | eval "$@" 33 | } 34 | 35 | run ./ppkg setup --syspm 36 | run ./ppkg about 37 | run ./ppkg update 38 | run ./ppkg install c-examples 39 | run ~/.ppkg/installed/freebsd-${{ matrix.freebsd-version }}-amd64/c-examples/bin/self_exe_path 40 | run ~/.ppkg/installed/freebsd-${{ matrix.freebsd-version }}-amd64/c-examples/bin/getexepath 41 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-1/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | sha1Test: sha1Test.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: sha1Test 15 | ./$< -x abc 16 | @printf "%b\n" "--------------" 17 | ./$< -X abc 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | clean: 23 | rm -rf libs 24 | rm -rf obj 25 | rm -f sha1Test 26 | 27 | download-src: 28 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 29 | printf "%b" "#define MBEDTLS_SHA1_C" > config.h && { \ 30 | for item in sha1.h platform_util.h threading.h; \ 31 | do \ 32 | curl -LO $(BASE_URL_H)/$${item}; \ 33 | done \ 34 | } && { \ 35 | for item in sha1.c platform_util.c threading.c; \ 36 | do \ 37 | curl -LO $(BASE_URL_C)/$${item}; \ 38 | done \ 39 | } && \ 40 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 41 | sed -i "" 's@mbedtls/@@g' * 42 | 43 | .PHONY: ndk-build clean download-src 44 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-224/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | sha224Test: sha224Test.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: sha224Test 15 | ./$< -x abc 16 | @printf "%b\n" "--------------" 17 | ./$< -X abc 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | clean: 23 | rm -rf libs 24 | rm -rf obj 25 | rm -f sha224Test 26 | 27 | download-src: 28 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 29 | printf "%s" "#define MBEDTLS_SHA256_C" > config.h && { \ 30 | for item in sha256.h platform_util.h threading.h; \ 31 | do \ 32 | curl -LO $(BASE_URL_H)/$${item}; \ 33 | done \ 34 | } && { \ 35 | for item in sha256.c platform_util.c threading.c; \ 36 | do \ 37 | curl -LO $(BASE_URL_C)/$${item}; \ 38 | done \ 39 | } && \ 40 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 41 | sed -i "" 's@mbedtls/@@g' * 42 | 43 | .PHONY: ndk-build clean download-src 44 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-256/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | sha256Test: sha256Test.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: sha256Test 15 | ./$< -x abc 16 | @printf "%b\n" "--------------" 17 | ./$< -X abc 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | clean: 23 | rm -rf libs 24 | rm -rf obj 25 | rm -f sha256Test 26 | 27 | download-src: 28 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 29 | printf "%s" "#define MBEDTLS_SHA256_C" > config.h && { \ 30 | for item in sha256.h platform_util.h threading.h; \ 31 | do \ 32 | curl -LO $(BASE_URL_H)/$${item}; \ 33 | done \ 34 | } && { \ 35 | for item in sha256.c platform_util.c threading.c; \ 36 | do \ 37 | curl -LO $(BASE_URL_C)/$${item}; \ 38 | done \ 39 | } && \ 40 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 41 | sed -i "" 's@mbedtls/@@g' * 42 | 43 | .PHONY: ndk-build clean download-src 44 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-384/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | sha384Test: sha384Test.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: sha384Test 15 | ./$< -x abc 16 | @printf "%b\n" "--------------" 17 | ./$< -X abc 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | clean: 23 | rm -rf libs 24 | rm -rf obj 25 | rm -f sha384Test 26 | 27 | download-src: 28 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 29 | printf "%s" "#define MBEDTLS_SHA512_C" > config.h && { \ 30 | for item in sha512.h platform_util.h threading.h; \ 31 | do \ 32 | curl -LO $(BASE_URL_H)/$${item}; \ 33 | done \ 34 | } && { \ 35 | for item in sha512.c platform_util.c threading.c; \ 36 | do \ 37 | curl -LO $(BASE_URL_C)/$${item}; \ 38 | done \ 39 | } && \ 40 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 41 | sed -i "" 's@mbedtls/@@g' * 42 | 43 | .PHONY: ndk-build clean download-src 44 | -------------------------------------------------------------------------------- /library/mbedTLS/SHA-512/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | sha512Test: sha512Test.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: sha512Test 15 | ./$< -x abc 16 | @printf "%b\n" "--------------" 17 | ./$< -X abc 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | clean: 23 | rm -rf libs 24 | rm -rf obj 25 | rm -f sha512Test 26 | 27 | download-src: 28 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 29 | printf "%s" "#define MBEDTLS_SHA512_C" > config.h && { \ 30 | for item in sha512.h platform_util.h threading.h; \ 31 | do \ 32 | curl -LO $(BASE_URL_H)/$${item}; \ 33 | done \ 34 | } && { \ 35 | for item in sha512.c platform_util.c threading.c; \ 36 | do \ 37 | curl -LO $(BASE_URL_C)/$${item}; \ 38 | done \ 39 | } && \ 40 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 41 | sed -i "" 's@mbedtls/@@g' * 42 | 43 | .PHONY: ndk-build clean download-src 44 | -------------------------------------------------------------------------------- /.github/workflows/vcpkg-macos.yml: -------------------------------------------------------------------------------- 1 | name: build via vcpkg on macOS 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | macos: 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | version: [15, 14, 13] 17 | 18 | runs-on: macos-${{ matrix.version }} 19 | 20 | steps: 21 | - uses: actions/checkout@main 22 | 23 | - run: brew update 24 | - run: brew install cmake ninja tree 25 | 26 | - run: echo "VCPKG_ROOT=$HOME/.vcpkg/root" >> "$GITHUB_ENV" 27 | - run: echo "PATH=$VCPKG_ROOT:$PATH" >> "$GITHUB_ENV" 28 | - run: install -d $VCPKG_ROOT 29 | - run: git clone https://github.com/microsoft/vcpkg.git $VCPKG_ROOT 30 | - run: cd $VCPKG_ROOT && ./bootstrap-vcpkg.sh 31 | - run: vcpkg install curl openssl libyaml libgit2 libarchive libqrencode 32 | 33 | - run: cmake --version 34 | - run: cmake -S . -B build.d -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX=./output -DBUILD_TESTING=OFF -DCMAKE_COLOR_MAKEFILE=ON -DCMAKE_VERBOSE_MAKEFILE=ON 35 | - run: cmake --build build.d 36 | - run: cmake --install build.d 37 | - run: tree output 38 | - run: output/bin/self_exe_path 39 | - run: output/bin/getexepath 40 | -------------------------------------------------------------------------------- /library/mbedTLS/base64/src/include/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE64_H 2 | #define BASE64_H 3 | 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | /* 获取base64编码成功后的字节数 */ 10 | size_t get_base64_encode_output_length_in_bytes(size_t inputBufferSizeInBytes); 11 | 12 | /* base64编码 13 | * outputBuffer base64编码后的字符串存放缓存区 14 | * outputBufferSizeInBytes base64编码后的字符串存放缓存区的大小 15 | * inputBuffer 要编码的字节的起始指针 16 | * inputBufferSizeInBytes 要编码的字节的长度 17 | */ 18 | int base64_encode(char * outputBuffer, size_t outputBufferSizeInBytes, unsigned char * inputBuffer, size_t inputBufferSizeInBytes); 19 | 20 | /* base64解码 21 | * outputBuffer base64解码后的字符串存放缓存区 22 | * outputBufferSizeInBytes base64解码后的字符串存放缓存区的大小 23 | * writenToOutputBufferSizeInBytes 真实的向缓存区写入了多少字节 24 | * input base64编码的字符串 25 | */ 26 | int base64_decode(unsigned char * outputBuffer, size_t outputBufferSizeInBytes, size_t * writenToOutputBufferSizeInBytes, char * inputBuffer, size_t inputBufferSizeInBytes); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif 32 | -------------------------------------------------------------------------------- /library/mbedTLS/RIPEMD-160/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | ripemd160Test: ripemd160Test.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: ripemd160Test 15 | ./$< -x abc 16 | @printf "%b\n" "--------------" 17 | ./$< -X abc 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | clean: 23 | rm -rf libs 24 | rm -rf obj 25 | rm -f ripemd160Test 26 | 27 | download-src: 28 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 29 | printf "%s" "#define MBEDTLS_RIPEMD160_C" > config.h && { \ 30 | for item in ripemd160.h platform_util.h threading.h; \ 31 | do \ 32 | curl -LO $(BASE_URL_H)/$${item}; \ 33 | done \ 34 | } && { \ 35 | for item in ripemd160.c platform_util.c threading.c; \ 36 | do \ 37 | curl -LO $(BASE_URL_C)/$${item}; \ 38 | done \ 39 | } && \ 40 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 41 | sed -i "" 's@mbedtls/@@g' * 42 | 43 | .PHONY: ndk-build clean download-src 44 | -------------------------------------------------------------------------------- /library/libarchive/src/test/untar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void test_untar_list() { 6 | int resultCode = untar_list("test.tar.xz", ARCHIVE_EXTRACT_TIME); 7 | CU_ASSERT_EQUAL(resultCode, 0); 8 | } 9 | 10 | void test_untar_extract() { 11 | const char * tempDir = mkdtemp("tmp.XXXXXXXXXX"); 12 | int resultCode = untar_extract(tempDir, "test.tar.xz", ARCHIVE_EXTRACT_TIME, true, 0); 13 | CU_ASSERT_EQUAL(resultCode, 0); 14 | } 15 | 16 | // http://cunit.sourceforge.net/example.html 17 | int main() { 18 | CU_pSuite pSuite = NULL; 19 | 20 | /* initialize the CUnit test registry */ 21 | if (CUE_SUCCESS != CU_initialize_registry()) { 22 | return CU_get_error(); 23 | } 24 | 25 | /* add a suite to the registry */ 26 | pSuite = CU_add_suite("Suite_1", NULL, NULL); 27 | if (NULL == pSuite) { 28 | CU_cleanup_registry(); 29 | return CU_get_error(); 30 | } 31 | 32 | /* add the tests to the suite */ 33 | if ((NULL == CU_add_test(pSuite, "test http_fetch()", test_untar_list)) || 34 | (NULL == CU_add_test(pSuite, "test http_fetch()", test_untar_extract))) { 35 | CU_cleanup_registry(); 36 | return CU_get_error(); 37 | } 38 | 39 | 40 | CU_run_all_tests(); 41 | 42 | CU_cleanup_registry(); 43 | 44 | return CU_get_error(); 45 | } 46 | -------------------------------------------------------------------------------- /library/mbedTLS/HMAC/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | #BRANCH=mbedtls-2.14 8 | BRANCH=development 9 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 10 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 11 | 12 | hmacTest: hmacTest.c mbedtls/*.c 13 | $(CC) $(CFLAGS) -o $@ $^ 14 | 15 | test: hmacTest 16 | ./$< -x 123456 abc 17 | @printf "%b\n" "--------------" 18 | ./$< -X 123456 abc 19 | 20 | ndk-build: 21 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 22 | 23 | clean: 24 | rm -rf libs 25 | rm -rf obj 26 | rm -f hmacTest 27 | 28 | download-src: 29 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 30 | printf "%b" "#define MBEDTLS_MD_C\n#define MBEDTLS_SHA256_C" > config.h && { \ 31 | for item in sha256.h md.h md_internal.h platform_util.h platform.h threading.h error.h; \ 32 | do \ 33 | curl -LO $(BASE_URL_H)/$${item}; \ 34 | done \ 35 | } && { \ 36 | for item in sha256.c md.c platform_util.c platform.c threading.c error.c; \ 37 | do \ 38 | curl -LO $(BASE_URL_C)/$${item}; \ 39 | done \ 40 | } && \ 41 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 42 | sed -i "" 's@mbedtls/@@g' * 43 | 44 | .PHONY: ndk-build clean download-src 45 | -------------------------------------------------------------------------------- /.github/workflows/netbsd.yml: -------------------------------------------------------------------------------- 1 | name: NetBSD 2 | 3 | on: 4 | push: 5 | branches: [ master, dev, tmp ] 6 | pull_request: 7 | branches: [ master, dev, tmp ] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | netbsd-version: ['10.1', '10.0', '9.4', '9.3', '9.2'] 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - run: curl -LO https://curl.se/ca/cacert.pem 22 | 23 | - run: curl -LO https://raw.githubusercontent.com/leleliu008/ppkg/master/ppkg 24 | - run: chmod a+x ppkg 25 | 26 | - uses: cross-platform-actions/action@master 27 | with: 28 | operating_system: netbsd 29 | version: ${{ matrix.netbsd-version }} 30 | shell: bash 31 | run: | 32 | run() { 33 | printf "\033[0;35m==>\033[0m \033[0;32m%b\n\033[0m" "$*" 34 | eval "$@" 35 | } 36 | 37 | run export SSL_CERT_FILE="$PWD/cacert.pem" 38 | 39 | run ./ppkg setup --syspm 40 | run ./ppkg about 41 | run ./ppkg update 42 | run ./ppkg install c-examples 43 | run ~/.ppkg/installed/netbsd-${{ matrix.netbsd-version }}-amd64/c-examples/bin/self_exe_path 44 | run ~/.ppkg/installed/netbsd-${{ matrix.netbsd-version }}-amd64/c-examples/bin/getexepath 45 | -------------------------------------------------------------------------------- /standard/iso/data-type/struct/person.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct person { 4 | char *name; 5 | unsigned short age; 6 | char sex; 7 | bool issingle; 8 | float weight; 9 | } person1, person2, person3; 10 | 11 | #include 12 | 13 | int main() { 14 | person1 = {"WangHua", 18u, 'F', true, 120.0f}; 15 | person2 = {.name = "WangHua", .age = 18u, .sex = 'F', .isisngle = true, .weight = 120.0f}; 16 | person3.name = "WangHua"; 17 | person3.age = 18u; 18 | person3.sex = 'F'; 19 | person3.issingle = true; 20 | person3.weight = 120.0f; 21 | 22 | printf("person1.name = %s\n", person1.name); 23 | printf("preson1.age = %u\n", person1.age); 24 | printf("perosn1.sex = %c\n", person1.sex); 25 | printf("person1.issingle = %d\n", person1.issingle); 26 | printf("person1.weight = %f\n", person1.weight); 27 | printf("---------------------\n"); 28 | printf("person2.name = %s\n", person2.name); 29 | printf("preson2.age = %u\n", person2.age); 30 | printf("perosn2.sex = %c\n", person2.sex); 31 | printf("person2.issingle = %d\n", person2.issingle); 32 | printf("person2.weight = %f\n", person2.weight); 33 | printf("---------------------\n"); 34 | printf("person3.name = %s\n", person3.name); 35 | printf("preson3.age = %u\n", person3.age); 36 | printf("perosn3.sex = %c\n", person3.sex); 37 | printf("person3.issingle = %d\n", person3.issingle); 38 | printf("person3.weight = %f\n", person3.weight); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /library/mbedTLS/PBKDF2/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | #BRANCH=mbedtls-2.14 8 | BRANCH=development 9 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 10 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 11 | 12 | pbkdf2Test: pbkdf2Test.c mbedtls/*.c 13 | $(CC) $(CFLAGS) -o $@ $^ 14 | 15 | test: pbkdf2Test 16 | ./$< -x 123456 abc 17 | @printf "%b\n" "--------------" 18 | ./$< -X 123456 abc 19 | 20 | ndk-build: 21 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 22 | 23 | clean: 24 | rm -rf libs 25 | rm -rf obj 26 | rm -f pbkdf2Test 27 | 28 | download-src: 29 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 30 | printf "%b" "#define MBEDTLS_PKCS5_C\n#define MBEDTLS_MD_C\n#define MBEDTLS_SHA256_C" > config.h && { \ 31 | for item in pkcs5.h sha256.h md.h md_internal.h platform_util.h platform.h threading.h error.h; \ 32 | do \ 33 | curl -LO $(BASE_URL_H)/$${item}; \ 34 | done \ 35 | } && { \ 36 | for item in pkcs5.c sha256.c md.c platform_util.c platform.c threading.c error.c; \ 37 | do \ 38 | curl -LO $(BASE_URL_C)/$${item}; \ 39 | done \ 40 | } && \ 41 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 42 | sed -i "" 's@mbedtls/@@g' * 43 | 44 | .PHONY: ndk-build clean download-src 45 | -------------------------------------------------------------------------------- /standard/posix/examples/socket/AF_LOCAL/client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main() { 9 | int c_socket_fd = socket(AF_LOCAL, SOCK_STREAM, 0); 10 | if(-1 == c_socket_fd) { 11 | perror("socket create error!"); 12 | goto label; 13 | } 14 | 15 | printf("socket create success!\n"); 16 | 17 | struct sockaddr_un server_address; 18 | 19 | /* 将server_address所占内存全部用0填充 */ 20 | memset(&server_address, 0, sizeof(server_address)); 21 | 22 | server_address.sun_family = AF_LOCAL; 23 | 24 | /* 将一个抽象的名字复制到sun_path的第二个字节处 */ 25 | strcpy(&server_address.sun_path[1], "com.leleliu008.localsockettest"); 26 | 27 | if(-1 == connect(c_socket_fd, (struct sockaddr*)&server_address, \ 28 | sizeof(server_address))) { 29 | perror("socket connect error! errno"); 30 | printf("errno = %d\n", errno); 31 | goto label; 32 | } 33 | 34 | printf("socket connect success!\n"); 35 | 36 | char str[] = "I love you!"; 37 | if(-1 == write(c_socket_fd, str, sizeof(str))) { 38 | perror("write error!"); 39 | goto label; 40 | } 41 | 42 | printf("send message to server : %s\n", str); 43 | 44 | char buff[4098] = {'\0'}; 45 | if(-1 == read(c_socket_fd, buff, sizeof(buff))) { 46 | perror("read error!"); 47 | goto label; 48 | } 49 | 50 | printf("reveive message from server : %s\n", buff); 51 | 52 | label: 53 | close(c_socket_fd); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /standard/posix/unistd.h/pathconf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | if(argc != 3) { 7 | perror("请输入一个序号和一个路径"); 8 | return 0; 9 | } 10 | 11 | int index = atoi(argv[2]); 12 | if(index < 0 || index >= 9) { 13 | perror("第二个参数必须是小于9的非负整数"); 14 | return 0; 15 | } 16 | 17 | char *namestr[] = {"_PC_LINK_MAX", "_PC_MAX_CANON", \ 18 | "_PC_MAX_INPUT", "_PC_NAME_MAX", \ 19 | "_PC_PATH_MAX", "_PC_PIPE_BUF", \ 20 | "_PC_CHOWN_RESTRICTED", \ 21 | "_PC_NO_TRUNC", "_PC_VDISABLE"}; 22 | 23 | int name[] = {_PC_LINK_MAX, _PC_MAX_CANON, \ 24 | _PC_MAX_INPUT, _PC_NAME_MAX, \ 25 | _PC_PATH_MAX, _PC_PIPE_BUF, \ 26 | _PC_CHOWN_RESTRICTED, \ 27 | _PC_NO_TRUNC, _PC_VDISABLE}; 28 | 29 | long limit = pathconf(argv[1], name[index]); 30 | 31 | if(limit < 0) { 32 | extern int errno; 33 | if(EACCES == errno) { 34 | perror("没有权限访问"); 35 | } else if(EINVAL == errno) { 36 | perror("name参数无效"); 37 | } else if(ELOOP == errno) { 38 | perror("嵌套层次太多"); 39 | } else if(ENAMETOOLONG == errno) { 40 | perror("path参数太长了"); 41 | } else if(ENOENT == errno) { 42 | perror("文件不存在"); 43 | } else if(ENOSYS == errno) { 44 | perror("无限制"); 45 | } else if(ENOTDIR == errno) { 46 | perror("不是一个目录"); 47 | } 48 | } else { 49 | printf("pathconf(\"%s\", %s) = %ld\n", \ 50 | argv[1], namestr[index], limit); 51 | } 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /.github/workflows/vcpkg-ubuntu.yml: -------------------------------------------------------------------------------- 1 | name: build via vcpkg on ubuntu 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | ubuntu: 12 | 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | tag: [24.04, 22.04] 17 | 18 | runs-on: ubuntu-latest 19 | container: ubuntu:${{ matrix.tag }} 20 | 21 | env: 22 | DEBIAN_FRONTEND: noninteractive 23 | TZ: Europe/London 24 | 25 | steps: 26 | - uses: actions/checkout@main 27 | 28 | - run: apt -y update 29 | - run: apt -y install pkg-config g++ linux-headers-generic cmake ninja-build tree git curl zip unzip tar 30 | 31 | - run: echo "VCPKG_ROOT=$HOME/.vcpkg/root" >> "$GITHUB_ENV" 32 | - run: echo "PATH=$VCPKG_ROOT:$PATH" >> "$GITHUB_ENV" 33 | - run: install -d $VCPKG_ROOT 34 | - run: git clone https://github.com/microsoft/vcpkg.git $VCPKG_ROOT 35 | - run: cd $VCPKG_ROOT && ./bootstrap-vcpkg.sh 36 | - run: vcpkg install curl openssl libyaml libgit2 libarchive libqrencode 37 | 38 | - run: cmake --version 39 | - run: cmake -S . -B build.d -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX=./output -DBUILD_TESTING=OFF -DCMAKE_COLOR_MAKEFILE=ON -DCMAKE_VERBOSE_MAKEFILE=ON 40 | - run: cmake --build build.d 41 | - run: cmake --install build.d 42 | - run: tree output 43 | - run: output/bin/self_exe_path 44 | - run: output/bin/getexepath 45 | -------------------------------------------------------------------------------- /library/mbedTLS/AES/AES.java: -------------------------------------------------------------------------------- 1 | import javax.crypto.spec.SecretKeySpec; 2 | import javax.crypto.spec.IvParameterSpec; 3 | import javax.crypto.Cipher; 4 | 5 | public class AES { 6 | public static byte[] aes_cbc_pkcs5padding(byte[] content, String key, byte[] iv) { 7 | try { 8 | SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes("ASCII"), "AES"); 9 | IvParameterSpec ivParameterSpec = new IvParameterSpec(iv); 10 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 11 | cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); 12 | return cipher.doFinal(content); 13 | } catch (Exception e) { 14 | e.printStackTrace(); 15 | return null; 16 | } 17 | } 18 | 19 | public static String bytesToHex(byte[] bytes) { 20 | StringBuilder buf = new StringBuilder(bytes.length << 2); 21 | for(byte b : bytes) { // 使用String的format方法进行转换 22 | buf.append(String.format("%02X", new Integer(b & 0xff))); 23 | } 24 | return buf.toString(); 25 | } 26 | 27 | public static void main(String[] args) throws Exception { 28 | String content = args[0]; 29 | String key = "abcdefghjklqwert"; 30 | byte[] iv = new byte[16]; 31 | for (int i = 0; i < 16; i++) { 32 | iv[i] = 0; 33 | } 34 | String hex = bytesToHex(aes_cbc_pkcs5padding(content.getBytes("ASCII"), key, iv)); 35 | System.out.printf("aes_cbc_pkcs5padding(content=%s,key=%s)=%s\n", content, key, hex); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /utils/sysinfo/src/test/sysinfo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void test_sysinfo_kind() { 7 | char osKind[31] = {0}; 8 | 9 | int ret = sysinfo_kind(osKind, 30); 10 | 11 | CU_ASSERT_EQUAL(ret, 0); 12 | } 13 | 14 | void test_sysinfo_type() { 15 | char osType[31] = {0}; 16 | 17 | int ret = sysinfo_type(osType, 30); 18 | 19 | CU_ASSERT_EQUAL(ret, 0); 20 | } 21 | 22 | void test_sysinfo_arch() { 23 | char osArch[31] = {0}; 24 | 25 | int ret = sysinfo_arch(osArch, 30); 26 | 27 | CU_ASSERT_EQUAL(ret, 0); 28 | } 29 | 30 | 31 | // http://cunit.sourceforge.net/example.html 32 | int main() { 33 | CU_pSuite pSuite = NULL; 34 | 35 | /* initialize the CUnit test registry */ 36 | if (CUE_SUCCESS != CU_initialize_registry()) { 37 | return CU_get_error(); 38 | } 39 | 40 | /* add a suite to the registry */ 41 | pSuite = CU_add_suite("Suite_1", NULL, NULL); 42 | if (NULL == pSuite) { 43 | CU_cleanup_registry(); 44 | return CU_get_error(); 45 | } 46 | 47 | /* add the tests to the suite */ 48 | if ((NULL == CU_add_test(pSuite, "test sysinfo_kind()", test_sysinfo_kind)) || 49 | (NULL == CU_add_test(pSuite, "test sysinfo_type()", test_sysinfo_type)) || 50 | (NULL == CU_add_test(pSuite, "test sysinfo_arch()", test_sysinfo_arch))) { 51 | CU_cleanup_registry(); 52 | return CU_get_error(); 53 | } 54 | 55 | 56 | CU_run_all_tests(); 57 | 58 | CU_cleanup_registry(); 59 | 60 | return CU_get_error(); 61 | } 62 | -------------------------------------------------------------------------------- /standard/iso/header/stdbool.h/bool.s: -------------------------------------------------------------------------------- 1 | .file "bool.c" 2 | .section .rodata 3 | .LC0: 4 | .string "sizeof(bool) = %lu\n" 5 | .LC1: 6 | .string "isXXX = %d\n" 7 | .LC2: 8 | .string "isYYY = %d\n" 9 | .LC3: 10 | .string "isZZZ = %d\n" 11 | .LC4: 12 | .string "isVVV = %d\n" 13 | .LC5: 14 | .string "isTTT = %d\n" 15 | .LC6: 16 | .string "isNNN = %d\n" 17 | .text 18 | .globl main 19 | .type main, @function 20 | main: 21 | .LFB0: 22 | .cfi_startproc 23 | pushq %rbp 24 | .cfi_def_cfa_offset 16 25 | .cfi_offset 6, -16 26 | movq %rsp, %rbp 27 | .cfi_def_cfa_register 6 28 | subq $16, %rsp 29 | movb $0, -6(%rbp) 30 | movb $1, -5(%rbp) 31 | movb $0, -4(%rbp) 32 | movb $1, -3(%rbp) 33 | movb $1, -2(%rbp) 34 | movb $1, -1(%rbp) 35 | movl $1, %esi 36 | movl $.LC0, %edi 37 | movl $0, %eax 38 | call printf 39 | movzbl -6(%rbp), %eax 40 | movl %eax, %esi 41 | movl $.LC1, %edi 42 | movl $0, %eax 43 | call printf 44 | movzbl -5(%rbp), %eax 45 | movl %eax, %esi 46 | movl $.LC2, %edi 47 | movl $0, %eax 48 | call printf 49 | movzbl -4(%rbp), %eax 50 | movl %eax, %esi 51 | movl $.LC3, %edi 52 | movl $0, %eax 53 | call printf 54 | movzbl -3(%rbp), %eax 55 | movl %eax, %esi 56 | movl $.LC4, %edi 57 | movl $0, %eax 58 | call printf 59 | movzbl -2(%rbp), %eax 60 | movl %eax, %esi 61 | movl $.LC5, %edi 62 | movl $0, %eax 63 | call printf 64 | movzbl -1(%rbp), %eax 65 | movl %eax, %esi 66 | movl $.LC6, %edi 67 | movl $0, %eax 68 | call printf 69 | movl $0, %eax 70 | leave 71 | .cfi_def_cfa 7, 8 72 | ret 73 | .cfi_endproc 74 | .LFE0: 75 | .size main, .-main 76 | .ident "GCC: (Ubuntu 4.8.2-19ubuntu1) 4.8.2" 77 | .section .note.GNU-stack,"",@progbits 78 | -------------------------------------------------------------------------------- /standard/iso/number/int/integer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | //有符号的短整型 6 | printf("sizeof(signed short int) = %d\n", sizeof(signed short int)); 7 | printf("SHRT_MAX = %d\n", SHRT_MAX); 8 | printf("SHRT_MIN = %d\n", SHRT_MIN); 9 | printf("\n"); 10 | 11 | //无符号的短整型 12 | printf("sizeof(unsigned short int) = %d\n", sizeof(unsigned short int)); 13 | printf("USHRT_MAX = %u\n", USHRT_MAX); 14 | printf("\n"); 15 | 16 | //有符号的整型 17 | printf("sizeof(singed int) = %d\n", sizeof(signed int)); 18 | printf("INT_MAX = %d\n", INT_MAX); 19 | printf("INT_MIN = %d\n", INT_MIN); 20 | printf("\n"); 21 | 22 | //无符号的整型 23 | printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int)); 24 | printf("UINT_MAX = %u\n", UINT_MAX); 25 | printf("\n"); 26 | 27 | //有符号的长整型 28 | printf("sizeof(signed long int) = %d\n", sizeof(signed long int)); 29 | printf("LONG_MAX = %ld\n", LONG_MAX); 30 | printf("LONG_MIN = %ld\n", LONG_MIN); 31 | printf("\n"); 32 | 33 | //无符号的长整型 34 | printf("sizeof(unsigned long int) = %d\n", sizeof(unsigned long int)); 35 | printf("ULONG_MAX = %lu\n", ULONG_MAX); 36 | printf("\n"); 37 | 38 | //有符号的增长整型 39 | printf("sizeof(signed long long int) = %d\n", sizeof(signed long long int)); 40 | printf("LLONG_MAX = %lld\n", LLONG_MAX); 41 | printf("LLONG_MIN = %lld\n", LLONG_MIN); 42 | printf("\n"); 43 | 44 | //无符号的增长整型 45 | printf("sizeof(unsigned long long int) = %d\n", sizeof(unsigned long long int)); 46 | printf("ULLONG_MAX = %llu\n", ULLONG_MAX); 47 | printf("\n"); 48 | 49 | /*---------------------------------------------------*/ 50 | 51 | /*---------------------------------------------------*/ 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /autotools/.deps/test.Po: -------------------------------------------------------------------------------- 1 | test.o: test.c /usr/include/stdc-predef.h /usr/include/stdio.h \ 2 | /usr/include/features.h /usr/include/x86_64-linux-gnu/sys/cdefs.h \ 3 | /usr/include/x86_64-linux-gnu/bits/wordsize.h \ 4 | /usr/include/x86_64-linux-gnu/gnu/stubs.h \ 5 | /usr/include/x86_64-linux-gnu/gnu/stubs-64.h \ 6 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h \ 7 | /usr/include/x86_64-linux-gnu/bits/types.h \ 8 | /usr/include/x86_64-linux-gnu/bits/typesizes.h /usr/include/libio.h \ 9 | /usr/include/_G_config.h /usr/include/wchar.h \ 10 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h \ 11 | /usr/include/x86_64-linux-gnu/bits/stdio_lim.h \ 12 | /usr/include/x86_64-linux-gnu/bits/sys_errlist.h \ 13 | /usr/include/x86_64-linux-gnu/bits/stdio.h \ 14 | /usr/include/x86_64-linux-gnu/bits/stdio2.h 15 | 16 | /usr/include/stdc-predef.h: 17 | 18 | /usr/include/stdio.h: 19 | 20 | /usr/include/features.h: 21 | 22 | /usr/include/x86_64-linux-gnu/sys/cdefs.h: 23 | 24 | /usr/include/x86_64-linux-gnu/bits/wordsize.h: 25 | 26 | /usr/include/x86_64-linux-gnu/gnu/stubs.h: 27 | 28 | /usr/include/x86_64-linux-gnu/gnu/stubs-64.h: 29 | 30 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h: 31 | 32 | /usr/include/x86_64-linux-gnu/bits/types.h: 33 | 34 | /usr/include/x86_64-linux-gnu/bits/typesizes.h: 35 | 36 | /usr/include/libio.h: 37 | 38 | /usr/include/_G_config.h: 39 | 40 | /usr/include/wchar.h: 41 | 42 | /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h: 43 | 44 | /usr/include/x86_64-linux-gnu/bits/stdio_lim.h: 45 | 46 | /usr/include/x86_64-linux-gnu/bits/sys_errlist.h: 47 | 48 | /usr/include/x86_64-linux-gnu/bits/stdio.h: 49 | 50 | /usr/include/x86_64-linux-gnu/bits/stdio2.h: 51 | -------------------------------------------------------------------------------- /algorithm/url/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(url C) 4 | 5 | set(PROJECT_VERSION 1.0.0) 6 | 7 | add_library(url-static STATIC src/lib/url.c) 8 | add_library(url-shared SHARED src/lib/url.c) 9 | 10 | set_target_properties(url-static PROPERTIES OUTPUT_NAME url CLEAN_DIRECT_OUTPUT 1) 11 | set_target_properties(url-shared PROPERTIES OUTPUT_NAME url CLEAN_DIRECT_OUTPUT 1) 12 | 13 | add_executable(url src/main/url.c) 14 | target_link_libraries(url url-static) 15 | target_include_directories(url PUBLIC src/lib) 16 | 17 | configure_file(src/lib/url.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/liburl.pc @ONLY) 18 | 19 | include(GNUInstallDirs) 20 | install(TARGETS url RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 21 | install(TARGETS url-static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 22 | install(TARGETS url-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 23 | install(FILES liburl.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 24 | install(FILES src/lib/url.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 25 | 26 | include(CTest) 27 | if (ENABLE_TESTING) 28 | add_executable(url-test src/test/url.c) 29 | target_include_directories(url-test PRIVATE src/lib) 30 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH}) 31 | include(FindCUnit) 32 | if (CUNIT_FOUND) 33 | target_include_directories(url-test PRIVATE ${CUNIT_INCLUDE_DIR}) 34 | target_link_libraries( url-test url-static) 35 | target_link_libraries( url-test ${CUNIT_LIBRARY}) 36 | else() 37 | message(FATAL_ERROR "Couldn't find CUnit library.") 38 | endif() 39 | add_test(NAME url-test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/url-test) 40 | endif() 41 | -------------------------------------------------------------------------------- /standard/iso/number/float/float.c: -------------------------------------------------------------------------------- 1 | /* 测试float.h头文件中定义的宏 */ 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | printf("sizeof(float) = %d\n", sizeof(float)); 8 | printf("FLT_MAX = %e\n", FLT_MAX); 9 | printf("FLT_MIN = %e\n", FLT_MIN); 10 | printf("FLT_MAX_EXP = %d\n", FLT_MAX_EXP); 11 | printf("FLT_MIN_EXP = %d\n", FLT_MIN_EXP); 12 | printf("FLT_MAX_10_EXP = %d\n", FLT_MAX_10_EXP); 13 | printf("FLT_MIN_10_EXP = %d\n", FLT_MIN_10_EXP); 14 | printf("FLT_EPSILON = %e\n", FLT_EPSILON); 15 | printf("FLT_MANT_DIG = %d\n", FLT_MANT_DIG); 16 | printf("FLT_DIG = %d\n", FLT_DIG); 17 | printf("FLT_RADIX = %d\n", FLT_RADIX); 18 | printf("FLT_ROUNDS = %d\n", FLT_ROUNDS); 19 | printf("\n"); 20 | 21 | printf("sizeof(double) = %d\n", sizeof(double)); 22 | printf("DBL_MAX = %e\n", DBL_MAX); 23 | printf("DBL_MIN = %e\n", DBL_MIN); 24 | printf("DBL_MAX_EXP = %d\n", DBL_MAX_EXP); 25 | printf("DBL_MIN_EXP = %d\n", DBL_MIN_EXP); 26 | printf("DBL_MAX_10_EXP = %d\n", DBL_MAX_10_EXP); 27 | printf("DBL_MIN_10_EXP = %d\n", DBL_MIN_10_EXP); 28 | printf("DBL_EPSILON = %e\n", DBL_EPSILON); 29 | printf("DBL_MANT_DIG = %d\n", DBL_MANT_DIG); 30 | printf("DBL_DIG = %d\n", DBL_DIG); 31 | printf("\n"); 32 | 33 | printf("sizeof(long double) = %d\n", sizeof(long double)); 34 | printf("LDBL_MAX = %le\n", LDBL_MAX); 35 | printf("LDBL_MIN = %le\n", LDBL_MIN); 36 | printf("LDBL_MAX_EXP = %d\n", LDBL_MAX_EXP); 37 | printf("LDBL_MIN_EXP = %d\n", LDBL_MIN_EXP); 38 | printf("LDBL_MAX_10_EXP = %d\n", LDBL_MAX_10_EXP); 39 | printf("LDBL_MIN_10_EXP = %d\n", LDBL_MIN_10_EXP); 40 | printf("LDBL_EPSILON = %e\n", LDBL_EPSILON); 41 | printf("LDBL_MANT_DIG = %d\n", LDBL_MANT_DIG); 42 | printf("LDBL_DIG = %d\n", LDBL_DIG); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /library/mbedTLS/AES/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS += -Os -v 3 | 4 | ANDROID_APP_PLATFORM = android-21 5 | NDK_BUILD_FLAGS = V=1 6 | 7 | BRANCH=mbedtls-2.14 8 | BASE_URL_H=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/include/mbedtls 9 | BASE_URL_C=https://raw.githubusercontent.com/ARMmbed/mbedtls/$(BRANCH)/library 10 | 11 | aesTest: aesTest.c mbedtls/*.c 12 | $(CC) $(CFLAGS) -o $@ $^ 13 | 14 | test: aesTest 15 | ./$< encode abc 16 | @printf "%b\n" "------------------------------------------" 17 | ./$< decode EBBF70FEF806D11C4F1FA1007597105A 18 | 19 | ndk-build: 20 | ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk APP_PLATFORM=$(ANDROID_APP_PLATFORM) $(NDK_BUILD_FLAGS) 21 | 22 | AES.class: AES.java 23 | javac -cp . $^ 24 | 25 | AES-java: AES.class 26 | java -cp . AES abc 27 | 28 | clean: 29 | rm -rf libs 30 | rm -rf obj 31 | rm -f aesTest 32 | rm -f AES.class 33 | 34 | download-src: 35 | ([ -d mbedtls ] || mkdir -p mbedtls) && cd mbedtls && \ 36 | printf "%b\n" "#define MBEDTLS_AES_C\n#define MBEDTLS_CIPHER_MODE_CBC" > config.h && { \ 37 | for item in aes.h platform_util.h platform.h threading.h; \ 38 | do \ 39 | curl -LO $(BASE_URL_H)/$${item}; \ 40 | done \ 41 | } && { \ 42 | for item in aes.c platform_util.c platform.c threading.c; \ 43 | do \ 44 | curl -LO $(BASE_URL_C)/$${item}; \ 45 | done \ 46 | } && \ 47 | curl -LO https://raw.githubusercontent.com/leleliu008/C/master/algorithm/base16/base16.h && \ 48 | curl -LO https://raw.githubusercontent.com/leleliu008/C/master/algorithm/base16/base16.c && \ 49 | sed -i 's@mbedtls/@@g' * 2> /dev/null || \ 50 | sed -i "" 's@mbedtls/@@g' * 51 | 52 | .PHONY: ndk-build clean download-src 53 | -------------------------------------------------------------------------------- /autotools/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) 6 | 7 | AC_CONFIG_AUX_DIR([build-aux]) 8 | 9 | AM_INIT_AUTOMAKE([foreign]) 10 | 11 | AC_CONFIG_SRCDIR([src/packcc.c]) 12 | AC_CONFIG_HEADERS([config.h]) 13 | AC_CONFIG_MACRO_DIR([m4]) 14 | 15 | #m4_ifndef([PKG_CHECK_EXISTS],[m4_fatal([must install pkg-config 0.18 or later before running autoconf/autogen])]) 16 | 17 | #PKG_CHECK_EXISTS([dummy]) 18 | 19 | # Checks for programs. 20 | #echo '----------------------------------------------' 21 | #AC_PROG_CC 22 | echo '----------------------------------------------' 23 | AX_PROG_CC_FOR_BUILD 24 | echo '----------------------------------------------' 25 | 26 | # We need to compile and run a program on the build machine. A 27 | # comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in 28 | # the AC archive is broken for autoconf 2.57. Given that there is no 29 | # newer version of that macro, we assume that it is also broken for 30 | # autoconf 2.61 and thus we use a simple but usually sufficient 31 | # approach. 32 | AC_MSG_CHECKING(for cc for build) 33 | if test "$cross_compiling" = "yes"; then 34 | CC_FOR_BUILD="${CC_FOR_BUILD-cc}" 35 | else 36 | CC_FOR_BUILD="${CC_FOR_BUILD-$CC}" 37 | fi 38 | AC_MSG_RESULT($CC_FOR_BUILD) 39 | AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler]) 40 | 41 | # Checks for libraries. 42 | 43 | # Checks for header files. 44 | 45 | # Checks for typedefs, structures, and compiler characteristics. 46 | 47 | # Checks for library functions. 48 | 49 | AC_CONFIG_FILES([Makefile 50 | src/Makefile]) 51 | AC_OUTPUT 52 | -------------------------------------------------------------------------------- /algorithm/lrc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(lrc C) 4 | 5 | set(PROJECT_VERSION 1.0.0) 6 | 7 | add_library(lrc-static STATIC src/lib/lrc.c) 8 | add_library(lrc-shared SHARED src/lib/lrc.c) 9 | 10 | set_target_properties(lrc-static PROPERTIES OUTPUT_NAME lrc CLEAN_DIRECT_OUTPUT 1) 11 | set_target_properties(lrc-shared PROPERTIES OUTPUT_NAME lrc CLEAN_DIRECT_OUTPUT 1) 12 | 13 | add_executable(lrcsum src/main/lrcsum.c ../base16/src/lib/base16.c) 14 | target_include_directories(lrcsum PRIVATE ../base16/src/lib) 15 | target_include_directories(lrcsum PRIVATE src/lib) 16 | target_link_libraries(lrcsum lrc-static) 17 | 18 | configure_file(src/lib/lrc.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/liblrc.pc @ONLY) 19 | 20 | include(GNUInstallDirs) 21 | install(TARGETS lrcsum RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 22 | install(TARGETS lrc-static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 23 | install(TARGETS lrc-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 24 | install(FILES liblrc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 25 | install(FILES src/lib/lrc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 26 | 27 | include(CTest) 28 | if (ENABLE_TESTING) 29 | add_executable(lrc-test src/test/lrc.c) 30 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH}) 31 | include(FindCUnit) 32 | if (CUNIT_FOUND) 33 | target_include_directories(lrc-test PRIVATE ${CUNIT_INCLUDE_DIR}) 34 | target_link_libraries(lrc-test lrc-static) 35 | target_link_libraries(lrc-test ${CUNIT_LIBRARY}) 36 | else() 37 | message(FATAL_ERROR "Couldn't find CUnit library.") 38 | endif() 39 | add_test(NAME lrc-test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/lrc-test) 40 | endif() 41 | -------------------------------------------------------------------------------- /algorithm/chinese-calendar/src/lib/chinese-calendar.h: -------------------------------------------------------------------------------- 1 | #ifndef CHINESE_CALENDAR_H 2 | #define CHINESE_CALENDAR_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 将阳历转换为阴历 9 | * solarYear 阳历的年 10 | * solarMonth 阳历的月 11 | * solarDay 阳历的日 12 | * return 示例: 正月初一, 二月初二, 腊月初八 13 | */ 14 | char* get_chinese_lunar_date(int solarYear, int solarMonth, int solarDay); 15 | 16 | /* 获得中国节日,以中国汉字输出 17 | * solarYear 阳历的年 18 | * solarMonth 阳历的月 19 | * solarDay 阳历的日 20 | */ 21 | char* get_chinese_festival1(int solarYear, int solarMonth, int solarDay); 22 | 23 | /* 获得中国节日,以中国汉字输出 24 | * chineseLunarDate 阴历的月日: 示例: 正月初一, 二月初二, 腊月初八 25 | */ 26 | char* get_chinese_festival2(const char *chineseLunarDate); 27 | 28 | /* 获得中国节日,以中国汉字输出 29 | * solarYear 阳历的年 30 | * solarMonth 阳历的月 31 | * solarDay 阳历的日 32 | * lunarMonthAndDay 阴历的月日: 示例: 正月初一, 二月初二, 腊月初八 33 | */ 34 | char* get_chinese_festival3(int solarYear, int solarMonth, int solarDay, const char *chineseLunarDate); 35 | 36 | /* 如果给定的阳历日期是某个节气,返回该节气,否则返回NULL 37 | * solarYear 阳历的年 38 | * solarMonth 阳历的月 39 | * solarDay 阳历的日 40 | */ 41 | char* get_chinese_jieqi(int solarYear, int solarMonth, int solarDay); 42 | 43 | /* 得到给定的阳历年的全部节气和对应阳历日期 44 | * solarYear 阳历的年 45 | */ 46 | char** get_chinese_jieqi_list(int solarYear); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | #endif 52 | -------------------------------------------------------------------------------- /algorithm/chinese-calendar/src/test/chinese-calendar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void test_solar2lunar() { 7 | char* result = get_chinese_lunar_date(2021, 6, 14); 8 | CU_ASSERT_PTR_NOT_NULL(result); 9 | CU_ASSERT_STRING_EQUAL(result, "五月初五"); 10 | } 11 | 12 | void test_jieri() { 13 | char* result = get_chinese_lunar_date(2021, 6, 14); 14 | CU_ASSERT_PTR_NOT_NULL(result); 15 | CU_ASSERT_STRING_EQUAL(result, "五月初五"); 16 | char* jieRi = get_chinese_festival3(2021, 6, 14, result); 17 | CU_ASSERT_PTR_NOT_NULL(jieRi); 18 | CU_ASSERT_STRING_EQUAL(jieRi, "端午节"); 19 | } 20 | 21 | void test_jieqi() { 22 | char* jieQi = get_chinese_jieqi(2021, 6, 5); 23 | CU_ASSERT_PTR_NOT_NULL(jieQi); 24 | CU_ASSERT_STRING_EQUAL(jieQi, "芒种"); 25 | } 26 | 27 | // http://cunit.sourceforge.net/example.html 28 | int main() { 29 | CU_pSuite pSuite = NULL; 30 | 31 | /* initialize the CUnit test registry */ 32 | if (CUE_SUCCESS != CU_initialize_registry()) { 33 | return CU_get_error(); 34 | } 35 | 36 | /* add a suite to the registry */ 37 | pSuite = CU_add_suite("Suite_1", NULL, NULL); 38 | if (NULL == pSuite) { 39 | CU_cleanup_registry(); 40 | return CU_get_error(); 41 | } 42 | 43 | /* add the tests to the suite */ 44 | if ((NULL == CU_add_test(pSuite, "test solar2lunar()", test_solar2lunar)) || 45 | (NULL == CU_add_test(pSuite, "test jieri()", test_jieri)) || 46 | (NULL == CU_add_test(pSuite, "test jieqi()", test_jieqi))) { 47 | CU_cleanup_registry(); 48 | return CU_get_error(); 49 | } 50 | 51 | 52 | CU_run_all_tests(); 53 | 54 | CU_cleanup_registry(); 55 | 56 | return CU_get_error(); 57 | } 58 | -------------------------------------------------------------------------------- /library/openssl/SHA-256/src/test/sha256sum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void test_sha256sum_of_bytes() { 7 | const char *input = "abcd"; 8 | char * sha256sum = sha256sum_of_bytes((unsigned char*)input, strlen(input)); 9 | CU_ASSERT_PTR_NOT_NULL(sha256sum); 10 | CU_ASSERT_STRING_EQUAL(sha256sum, "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"); 11 | } 12 | 13 | void test_sha256sum_of_string() { 14 | const char *input = "abcd"; 15 | char * sha256sum = sha256sum_of_string(input); 16 | CU_ASSERT_PTR_NOT_NULL(sha256sum); 17 | CU_ASSERT_STRING_EQUAL(sha256sum, "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"); 18 | } 19 | 20 | void test_sha256sum_of_file() { 21 | } 22 | 23 | // http://cunit.sourceforge.net/example.html 24 | int main() { 25 | CU_pSuite pSuite = NULL; 26 | 27 | /* initialize the CUnit test registry */ 28 | if (CUE_SUCCESS != CU_initialize_registry()) { 29 | return CU_get_error(); 30 | } 31 | 32 | /* add a suite to the registry */ 33 | pSuite = CU_add_suite("Suite_1", NULL, NULL); 34 | if (NULL == pSuite) { 35 | CU_cleanup_registry(); 36 | return CU_get_error(); 37 | } 38 | 39 | /* add the tests to the suite */ 40 | if ((NULL == CU_add_test(pSuite, "test sha256sum_of_bytes()", test_sha256sum_of_bytes)) || 41 | (NULL == CU_add_test(pSuite, "test sha256sum_of_string()", test_sha256sum_of_string)) || 42 | (NULL == CU_add_test(pSuite, "test sha256sum_of_file()", test_sha256sum_of_file))) { 43 | CU_cleanup_registry(); 44 | return CU_get_error(); 45 | } 46 | 47 | 48 | CU_run_all_tests(); 49 | 50 | CU_cleanup_registry(); 51 | 52 | return CU_get_error(); 53 | } 54 | -------------------------------------------------------------------------------- /algorithm/base16/src/lib/base16.c: -------------------------------------------------------------------------------- 1 | //http://blog.fpliu.com/it/data/text/coding/Base16 2 | 3 | #include 4 | #include "base16.h" 5 | 6 | int base16_encode(char * output, const unsigned char * input, size_t inputSizeInBytes, bool isToUpper) { 7 | const char * table = isToUpper ? "0123456789ABCDEF" : "0123456789abcdef"; 8 | 9 | unsigned char highByte, lowByte; 10 | size_t i, j; 11 | 12 | for (i = 0; i < inputSizeInBytes; i++) { 13 | //向右移动4bit,获得高4bit 14 | highByte = input[i] >> 4; 15 | //与0x0f做位与运算,获得低4bit 16 | lowByte = input[i] & 0x0F; 17 | 18 | //由于高4bit和低4bit都只有4个bit,他们转换成10进制的数字,范围都在0 ~ 15闭区间内 19 | //大端模式 20 | j = i << 1; 21 | output[j] = table[highByte]; 22 | output[j + 1] = table[lowByte]; 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | //把16进制字符转换成10进制表示的数字 29 | //通过man ascii命令查看ASCII编码表即可得到如下转换逻辑 30 | static short hex2dec(char c) { 31 | if ('0' <= c && c <= '9') { 32 | return c - '0'; 33 | } else if ('a' <= c && c <= 'f') { 34 | return c - 'a' + 10; 35 | } else if ('A' <= c && c <= 'F') { 36 | return c - 'A' + 10; 37 | } else { 38 | return 0; 39 | } 40 | } 41 | 42 | int base16_decode(unsigned char* output, const char* input, size_t inputSizeInBytes) { 43 | if (inputSizeInBytes == 0) { 44 | inputSizeInBytes = strlen(input); 45 | } 46 | 47 | //input指向的字符串长度必须是2的整数倍,也就是必须是偶数 48 | if (1 == (inputSizeInBytes & 1)) { 49 | return 1; 50 | } 51 | 52 | size_t halfInputSize = inputSizeInBytes >> 1; 53 | size_t i, j; 54 | 55 | for (i = 0; i < halfInputSize; i++) { 56 | //16进制数字转换为10进制数字的过程 57 | j = i << 1; 58 | output[i] = (hex2dec(input[j]) << 4) + hex2dec(input[j + 1]); 59 | } 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /algorithm/bcc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(bcc C) 4 | 5 | set(PROJECT_VERSION 1.0.0) 6 | 7 | add_library(bcc-static STATIC src/lib/bcc.c) 8 | add_library(bcc-shared SHARED src/lib/bcc.c) 9 | 10 | set_target_properties(bcc-static PROPERTIES OUTPUT_NAME bcc CLEAN_DIRECT_OUTPUT 1) 11 | set_target_properties(bcc-shared PROPERTIES OUTPUT_NAME bcc CLEAN_DIRECT_OUTPUT 1) 12 | 13 | add_executable(bccsum src/main/bccsum.c ../base16/src/lib/base16.c) 14 | target_include_directories(bccsum PRIVATE ../base16/src/lib) 15 | target_include_directories(bccsum PRIVATE src/lib) 16 | target_link_libraries(bccsum bcc-static) 17 | 18 | configure_file(src/lib/bcc.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/libbcc.pc @ONLY) 19 | 20 | include(GNUInstallDirs) 21 | install(TARGETS bccsum RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) 22 | install(TARGETS bcc-static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 23 | install(TARGETS bcc-shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) 24 | install(FILES libbcc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 25 | install(FILES src/lib/bcc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 26 | 27 | include(CTest) 28 | if (ENABLE_TESTING) 29 | add_executable(bcc-test src/test/bcc.c) 30 | set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH}) 31 | include(FindCUnit) 32 | if (CUNIT_FOUND) 33 | target_include_directories(bcc-test PRIVATE ${CUNIT_INCLUDE_DIR}) 34 | target_include_directories(bcc-test PRIVATE src/lib) 35 | target_link_libraries(bcc-test bcc-static) 36 | target_link_libraries(bcc-test ${CUNIT_LIBRARY}) 37 | else() 38 | message(FATAL_ERROR "Couldn't find CUnit library.") 39 | endif() 40 | add_test(NAME bcc-test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/bcc-test) 41 | endif() 42 | -------------------------------------------------------------------------------- /standard/iso/data-type/struct/person2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct person { 4 | char *name; 5 | unsigned short age; 6 | char sex; 7 | bool issingle; 8 | float weight; 9 | }; 10 | 11 | #include 12 | 13 | int main() { 14 | struct person person1 = {"WangHua", 18u, 'F', true, 120.0f}; 15 | struct person person2 = {.name = "WangHua", .age = 18u, .sex = 'F', .issingle = true, .weight = 120.0f}; 16 | struct person person3 = {name : "WangHua", age : 18u, sex : 'F', issingle : true, weight : 120.0f}; 17 | struct person person4; 18 | person4.name = "WangHua"; 19 | person4.age = 18u; 20 | person4.sex = 'F'; 21 | person4.issingle = true; 22 | person4.weight = 120.0f; 23 | printf("person1.name = %s\n", person1.name); 24 | printf("preson1.age = %u\n", person1.age); 25 | printf("perosn1.sex = %c\n", person1.sex); 26 | printf("person1.issingle = %d\n", person1.issingle); 27 | printf("person1.weight = %f\n", person1.weight); 28 | printf("---------------------\n"); 29 | printf("person2.name = %s\n", person2.name); 30 | printf("preson2.age = %u\n", person2.age); 31 | printf("perosn2.sex = %c\n", person2.sex); 32 | printf("person2.issingle = %d\n", person2.issingle); 33 | printf("person2.weight = %f\n", person2.weight); 34 | printf("---------------------\n"); 35 | printf("person3.name = %s\n", person3.name); 36 | printf("preson3.age = %u\n", person3.age); 37 | printf("perosn3.sex = %c\n", person3.sex); 38 | printf("person3.issingle = %d\n", person3.issingle); 39 | printf("person3.weight = %f\n", person3.weight); 40 | printf("---------------------\n"); 41 | printf("person4.name = %s\n", person4.name); 42 | printf("preson4.age = %u\n", person4.age); 43 | printf("perosn4.sex = %c\n", person4.sex); 44 | printf("person4.issingle = %d\n", person4.issingle); 45 | printf("person4.weight = %f\n", person4.weight); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /algorithm/base16/src/test/base16.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void test_base16_encode() { 7 | const char *input = "abcd"; 8 | size_t inputLength = strlen(input); 9 | size_t outputLength = inputLength << 1; 10 | char output[outputLength + 1]; 11 | memset(output, 0, outputLength + 1); 12 | int result = base16_encode(output, (unsigned char*)input, inputLength, true); 13 | CU_ASSERT_EQUAL(result, 0); 14 | CU_ASSERT_STRING_EQUAL(output, "61626364"); 15 | } 16 | 17 | void test_base16_decode() { 18 | const char *input = "61626364"; 19 | size_t inputLength = strlen(input); 20 | size_t outputLength = inputLength >> 1; 21 | unsigned char output[outputLength + 1]; 22 | memset(output, 0, outputLength + 1); 23 | int result = base16_decode(output, (char*)input); 24 | CU_ASSERT_EQUAL(result, 0); 25 | CU_ASSERT_STRING_EQUAL(output, "abcd"); 26 | } 27 | 28 | // http://cunit.sourceforge.net/example.html 29 | int main() { 30 | CU_pSuite pSuite = NULL; 31 | 32 | /* initialize the CUnit test registry */ 33 | if (CUE_SUCCESS != CU_initialize_registry()) { 34 | return CU_get_error(); 35 | } 36 | 37 | /* add a suite to the registry */ 38 | pSuite = CU_add_suite("Suite_1", NULL, NULL); 39 | if (NULL == pSuite) { 40 | CU_cleanup_registry(); 41 | return CU_get_error(); 42 | } 43 | 44 | /* add the tests to the suite */ 45 | if ((NULL == CU_add_test(pSuite, "test base16_encode()", test_base16_encode)) || 46 | (NULL == CU_add_test(pSuite, "test base16_decode()", test_base16_decode))) { 47 | CU_cleanup_registry(); 48 | return CU_get_error(); 49 | } 50 | 51 | 52 | CU_run_all_tests(); 53 | 54 | CU_cleanup_registry(); 55 | 56 | return CU_get_error(); 57 | } 58 | -------------------------------------------------------------------------------- /library/mbedTLS/MD5/md5Test.c: -------------------------------------------------------------------------------- 1 | //http://blog.fpliu.com/it/software/mbedTLS/include/md5.h 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include"mbedtls/md5.h" 8 | 9 | void showHelp() { 10 | printf("usage: md5 [option] \n"); 11 | printf("option: -x lower case, default true\n"); 12 | printf(" -X upper case\n"); 13 | printf("example:md5 -X sssssss\n"); 14 | exit(1); 15 | } 16 | 17 | void base16(unsigned char input[16], char* output, bool isToUpper) { 18 | const char *format = isToUpper ? "%02X" : "%02x"; 19 | char tmp[3] = {0}; 20 | for(int i = 0; i < 16; i++) { 21 | sprintf(tmp, format, input[i]); 22 | strcat(output, tmp); 23 | } 24 | } 25 | 26 | void performMD5(char* input, bool isToUpper) { 27 | //MD5算法能够根据任意长度的数据计算出一个固定长度(128bit=16byte)的唯一数据 28 | unsigned char output[16] = {0}; 29 | mbedtls_md5((unsigned char *)input, strlen(input), output); 30 | //为了便于比较,通常会把MD5运算后得到的128bit数据再用base16编码。因为每4bit可以表示一个十六进制字符,用十六进制表示就是32个字符。 31 | char hex[33] = {0}; 32 | base16(output, hex, isToUpper); 33 | printf("md5(%s)=%s\n", input, hex); 34 | } 35 | 36 | int main(int argc, char* argv[]) { 37 | if (argc == 1) { 38 | showHelp(); 39 | } else if (argc == 2) { 40 | if (strcmp("-h", argv[1]) == 0 41 | || strcmp("--help", argv[1]) == 0 42 | || strcmp("-x", argv[1]) == 0 43 | || strcmp("-X", argv[1]) == 0) { 44 | showHelp(); 45 | } else { 46 | performMD5(argv[1], 0); 47 | } 48 | } else { 49 | if (strcmp("-x", argv[1]) == 0) { 50 | performMD5(argv[2], 0); 51 | } else if (strcmp("-X", argv[1]) == 0) { 52 | performMD5(argv[2], 1); 53 | } else { 54 | showHelp(); 55 | } 56 | } 57 | 58 | return 0; 59 | } 60 | --------------------------------------------------------------------------------