笔记
1. strcasecmp
2. strcpy, strncpy, strlcpy的区别
1.strcpy 此函数历史最悠久,很早就出现在标准库里,由于当初的程序员认识不够,该函数的行为会造成缓冲区溢出。下面是溢出的例子:
2.strncpy 函数是strcpy的安全版,它有个缺点就是要手动加/0来结束一个字符串。
3.strlcpy 函数只有linux中才有提供,Windows 下是没有 strlcpy 的,对应的是strcpy_s函数。strlcpy与strncpy功能相类似,但会帮你加上/0,第3个参数不是拷贝的长度,而是目的缓冲区的大小。strlcpy不属于ANSI C,前面两个函数是ANSI C里面的函数。
参考:
原文链接:https://blog.csdn.net/feizenggu/article/details/5380279
3. strchr
C 库函数 char *strchr(const char *str, int c) 在参数 str 所指向的字符串中搜索第一次出现字符 c(一个无符号字符)的位置。
4. __attribute__((aligned(CLS))) FlowBucket;
结构体设置字节对齐方式,我们可以按照自己设定的对齐大小来编译程序,GNU使用__attribute__选项来设置,例子如下:
typedef struct FlowBucket_ { *** } __attribute__((aligned(64))) FlowBucket;/*按照64字节对齐*/
struct stu{ char sex; int length; char name[10];
}__attribute__ ((aligned (1))); /*按照1字节对齐*/ struct stu my_stu; 则sizeof(my_stu)可以得到大小为15。
typedef struct FlowBucket_ { /** head of the list of active flows for this row. */ Flow *head; /*可以形容为链表头*/ /** head of the list of evicted flows for this row. Waiting to be * collected by the Flow Manager. */ Flow *evicted; /*可以形容为链表尾*/ /*行锁*/ #ifdef FBLOCK_MUTEX SCMutex m; #elif defined FBLOCK_SPIN SCSpinlock s; #else #error Enable FBLOCK_SPIN or FBLOCK_MUTEX #endif /** timestamp in seconds of the earliest possible moment a flow * will time out in this row. Set by the flow manager. Cleared * to 0 by workers, either when new flows are added or when a * flow state changes. The flow manager sets this to INT_MAX for * empty buckets. */ SC_ATOMIC_DECLARE(int32_t, next_ts); }
5. pcre 函数,正则表达式预编译
.PCRE是一个NFA正则引擎,不然不能提供完全与Perl一致的正则语法功能。但它同时也实现了DFA,只是满足数学意义上的正则。
pcre_compile
函数原型:
pcre *pcre_compile(const char *pattern, int options, const char **errptr, int *erroffset, const unsigned char *tableptr)
功能:将一个正则表达式编译成一个内部表示,在匹配多个字符串时,可以加速匹配。其同pcre_compile2功能一样只是缺少一个参数errorcodeptr。
参数说明:
pattern 正则表达式
options 为0,或者其他参数选项
errptr 出错消息
erroffset 出错位置
tableptr 指向一个字符数组的指针,可以设置为空NULL。
PCRE-正则库及用法 - LiuYanYGZ - 博客园 (cnblogs.com)