摘要: 通过zlib库是可以实现压缩和解压缩文件,或者是对字节流进行压缩、加密等功能。 这里实现了一个对文件的压缩和解压程序。 1. 函数原型 //compress a file int compressFile(const char *srcfile, unsigned long *srclen, con 阅读全文
posted @ 2021-05-19 18:32 castor_xu 阅读(5422) 评论(0) 推荐(0) 编辑
摘要: 1. 显示与位置参数(Positional Parameters ) 可以使用echo或者printf在终端中显示信息,例如: echo "hello $1" printf "the first argument is %s\n" $1 运行将显示: 注意,printf的格式化字符串和站位参数之间使 阅读全文
posted @ 2021-05-15 16:56 castor_xu 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 1. 下载与安装 官网地址是:http://www.zlib.net/,目前最新的版本是1.2.11。下载的文件包为zlib-1.2.11.tar.gz 在Linux下解压,然后在终端中进入其文件夹,之后使用如下命令: #配置 ./config #编译 sudo make #安装 sudo make 阅读全文
posted @ 2021-05-13 19:26 castor_xu 阅读(1584) 评论(0) 推荐(0) 编辑
摘要: C#中,byte数组在很多数据流中具有普遍的适用,尤其是和其他程序语言、其他架构设备、不同通讯协议等打交道时,字节流能够保证数据的传输安全可靠,可以认为是最接近底层的数据类型了,因此对字节数据的操作就很常见和必要了。常见的场景是字节数组的复制,截断等,常规、最简单粗暴的循环系列代码,这里就不啰嗦了, 阅读全文
posted @ 2021-04-30 19:12 castor_xu 阅读(12480) 评论(0) 推荐(1) 编辑
摘要: /* 将带有逗号分隔符的字符串数字转换为对应数字 对于诸如"1a2b3c",返回0,ok被修改为false ok标识是否转换成功 */ long str2num(const char* str,bool& ok) { long result=0; int t=1; ok=true; const ch 阅读全文
posted @ 2021-02-20 22:54 castor_xu 阅读(1137) 评论(0) 推荐(0) 编辑
摘要: 一般有两种方式发送信号:raise和kill raise函数原型为: #include <signal.h> int raise(int sig); 该函数向调用的进程或者线程发送信号,形参sig就是需要发送的信号。 返回值:成功返回0,失败返回非零值。需要说明的是,如果信号导致了处理函数(hand 阅读全文
posted @ 2021-02-07 15:14 castor_xu 阅读(220) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/utsname.h> #include <stdlib.h> #include <string.h> int main() { struct utsname 阅读全文
posted @ 2021-02-07 09:38 castor_xu 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 在捕获到信号的时候,可以将其对应的字符串输出。有以下几种方法: 1. 字符串数组 使用signal.h头文件下的字符串数组sys_siglist,将信号作为下标时,字符串就是对应的信号含义: #include <signal.h> extern const char * const sys_sigl 阅读全文
posted @ 2021-02-06 15:40 castor_xu 阅读(379) 评论(0) 推荐(0) 编辑
摘要: Linux环境下,一般使用signal函数或者sigaction绑定对特定信号的处理。 signal函数 原型如下: #include <signal.h> typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sigh 阅读全文
posted @ 2021-02-06 15:18 castor_xu 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 节选自《Advanced Linux Programming》 通常有两种方式,第一种是使用system函数,位于stlib.h头文件下,system 建立了一个运行着标准Bourne shell( /bin/sh)的子进程,然后将命令交由它执行 。因为 system 函数使用 shell 调用命令 阅读全文
posted @ 2021-02-04 16:58 castor_xu 阅读(645) 评论(0) 推荐(0) 编辑