⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kf701.h

📁 一个收集所有最基本功能的函数库;所有的函数都是尽量短小和简单 使用 doxygen 生成文档 所有代码以在 Linux 系统上可以编译并运行为准;每当在 lib 目录里增加了一个功能函数
💻 H
字号:
/*************************************************************************** *            kf701.h * *  Tue May 21 11:06:27 2007 *  Copyright  2007  kf701 *  Email <kf701.ye AT gmail.com> ****************************************************************************//* *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#ifndef _KF701_LIB_H_#define _KF701_LIB_H_#include <stdint.h>#include <stdbool.h>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <netdb.h>/******************************************	1.	macro part*******************************************/#ifndef MAX#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)>(b)?(b):(a))#endif#ifndef BCD_TO_BIN#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)#endif#ifndef BIN_TO_BCD#define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)#endif/******************************************	2.	network part*******************************************/int connect_nonblock(char *ip,uint16_t port,uint32_t timeout); int open_listenfd(uint16_t port); int open_udp(uint16_t port); void setnonblocking(int fd);/* unix socket */int unix_socket_new(void);void unix_socket_free(int sockfd);int32_t unix_socket_send(int sockfd , const char *to_path, const char *data, uint32_t size);int unix_socket_new_listen(const char *unix_path);/* send email */typedef struct{	char *smtp;	char *passwd;	char *from;	char **to;	uint32_t  numto;	char *context;	char *subject;#define EMAIL_CHARSET	"utf-8"#define EMAIL_MAXLINE	128#define EMAIL_MIME	"MIME-Version: 1.0"#define EMAIL_BOUNDARY	"---kf701libofmailsend---"} mail_t;bool send_mail(mail_t *mail);/* network server */typedef void (*tcp_data_func)(int, uint8_t*, uint32_t);void tcp_server_epoll( uint16_t port, uint32_t psize, tcp_data_func func);void tcp_server_select( uint16_t port, uint32_t psize, tcp_data_func func);typedef void (*tcp_fd_func)(int);void tcp_server_select_2( uint16_t port, tcp_fd_func func);typedef void(*udp_data_func)(struct sockaddr*, uint8_t*, uint32_t);void udp_server(uint16_t port, uint32_t psize, udp_data_func func);typedef void(*un_data_func)(const char*, uint8_t*, uint32_t);void unix_socket_server( const char *unix_path, uint32_t psize, un_data_func func);/******************************************	3.	algorithm part*******************************************/uint8_t reverse_char(uint8_t);int32_t encode_b64(uint8_t *dest,const uint8_t *src,uint32_t size);int32_t decode_b64(uint8_t *desc,const uint8_t *src,uint32_t size);int32_t b64_file_to_buf (uint8_t *b64_buf, const char *file);void bin2hex(uint8_t *dest,const uint8_t *src, uint32_t len);void hex2bin(uint8_t *dest,const uint8_t *src, uint32_t len);void string_encrypt(uint8_t *dest, const uint8_t *src, const uint8_t *key);void string_decrypt(uint8_t *dest, const uint8_t *src, const uint8_t *key);/******************************************	4.	tty control part*******************************************/bool set_parity(int fd,int32_t databits,int32_t stopbits,int32_t parity);bool set_speed(int fd, int32_t speed);/******************************************	5.	log and debug*******************************************/int debug_verbose;int sys_message(const char *fmt, ...);#define sys_debug(args...)			\	do{                    			\		if (debug_verbose >=4)		\			sys_message(args);	\	} while(0)#define sys_log(args...)			\	do{                    			\		if (debug_verbose >=3)		\			sys_message(args);	\	} while(0)#define sys_warn(args...)			\	do{                       		\		if (debug_verbose >= 2)		\			sys_message(args);	\	} while(0)	#define sys_err(args...)			\	do{                       		\		if (debug_verbose >= 1)		\			sys_message(args);	\	} while(0)	/******************************************	6.	robust io*******************************************/int32_t rio_read(int fd, void * buf, uint32_t size);int32_t rio_write(int fd, void * buf, uint32_t size);int32_t readline2(int fd, void *vptr, uint32_t maxlen);/******************************************	7.	thread part*******************************************/typedef void * (*thread_entry_func)(void *);bool create_normal_thread(thread_entry_func th_func, void *data);bool create_rr_thread(thread_entry_func th_func, void *data);/******************************************	8.	file util part*******************************************/bool pad_file(char *filein, char *fileout, uint32_t align_size);char *iconv_string (const char *str, const char *from_codeset,		const char *to_codeset);/******************************************	9.	rand util	*******************************************/int32_t rand_int32_area(int32_t min, int32_t max);uint32_t rand_int32_from_str(const char *str);char *rand_ip(char *buffer, uint32_t size);uint8_t rand_digit(void);uint8_t rand_alpha_lower(void);uint8_t rand_alpha_upper(void);uint8_t *rand_string(uint8_t *buf, uint32_t size);uint8_t *rand_bytes(uint8_t *buf, uint32_t size);/******************************************	10.	draw math util*******************************************/typedef struct{	int32_t x;	int32_t y;	int32_t z;} m3d_point;typedef struct{	uint8_t r;	uint8_t g;	uint8_t b;	uint8_t a;} m3d_color;typedef void (*draw_dot_func)(m3d_point, m3d_color);void draw_line(m3d_point p1, m3d_point p2, m3d_color color, draw_dot_func func);void draw_polygon(uint32_t num, m3d_point *array, m3d_color color, draw_dot_func func);void draw_triangle(m3d_point p1, m3d_point p2, m3d_point p3, m3d_color color, draw_dot_func func);void draw_circle(m3d_point center, uint32_t radius, m3d_color color, draw_dot_func func);void draw_parabola_x(m3d_point center, int32_t a, m3d_color color, draw_dot_func func);void draw_parabola_y(m3d_point center, int32_t a, m3d_color color, draw_dot_func func);#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -