/****************************************************************************************
* 文件名: mytype.h
* 创建者: Kun
* 时 间: 2018/0/12
* 联 系: 153471503@qq.com
* 简 介: linux常用类型定义
*****************************************************************************************/
#ifndef _MYTYPE_H_
#define _MYTYPE_H_
//--------------------------< 预添加头文件包含 >----------------------//
#define USE_TIME 0
#define USE_SIGNAL 0
#define USE_SHARE_MEMORY 1
#define USE_SEMAPHORE 0
#define USE_FILE_CTL 0
//-------------------------------< end ----------------------------//
//---------------------------< includes >---------------------------//
// c标准库头文件
#include
#include
#include
// 信号使用相关头文件
#if USE_SIGNAL
#include
#endif // USE_SIGNAL
// 信号量操作相关头文件
#if USE_SEMAPHORE
#include
#include
#endif // USE_SEMAPHORE
// 共享内存操作相关头文件
#if USE_SHARE_MEMORY
#include
#endif // USE_SHARE_MEMORY
// 系统调用式文件编程头文件
#include
// 该文件所定义的接口通常都是大量针对系统调用的封装,
// 如 fork、pipe 以及各种 I/O 原语(read、write、close 等等)。
#include
// linux系统中类型定义相关头文件
#include
// 文件状态,是unix/linux系统定义文件状态所在的伪标准头文件。
#if USE_FILE_CTL
#include
#endif // USE_FILE_CTL
#if USE_TIME
// 时间编程相关头文件
#include
#endif // USE_TIME
//-------------------------< includes end >-------------------------//
// bool类型定义
#ifndef bool
typedef unsigned int bool;
#endif
enum
{
true = 1,
false = !true
};
// 常用无符号数据类型定义
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned short ushort;
//----------------------< 调试信息输入相关宏定义 >----------------------//
#define DEBUG_INFO(...) printf("Info: "); printf(__VA_ARGS__)
#define DEBUG_ERROR(...) printf("Error: "); printf(__VA_ARGS__)
#define DEBUG_WARNING(...) printf("Warning: "); printf(__VA_ARGS__)
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
//------------------------------------------------------------------//
// 信号量使用封装结构
#if USE_SEMAPHORE
typedef struct sem_use_st SEM_USE_ST;
struct sem_use_st
{
int semid;
key_t key;
struct sembuf sops;
};
#endif // USE_SEMAPHORE
// 共享内存使用封装结构
#if USE_SHARE_MEMORY
typedef struct shmem_use_st SHMEM_USE_ST;
struct shmem_use_st
{
int shmid;
key_t key;
};
#define BUF_SIZE 1024*1 //共享内存大小
typedef struct shmem_area SHMEM_AREA;
struct shmem_area
{
bool isnull;
char data[BUF_SIZE];
};
#endif // USE_SHARE_MEMORY
#endif // _TYPE_H_