随笔分类 -  unix编程

上一页 1 2

记录锁
摘要:intbase_class::getWriteLock(string&filename){intfd=open(filename.c_str(),O_RDWR|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);if(fd<0){cerr<<"open"<<filename<<"fail!"<<endl;return-1;}structflockfl;fl.l_type=F_WRLCK;fl.l_start=0;fl.l_whence=SEEK_SET;fl.l_ 阅读全文

posted @ 2012-08-07 11:24 山本二十八 阅读(120) 评论(0) 推荐(0)

DEBUG ZONE
摘要:#include<stdio.h>#include<stdlib.h>#include<stdarg.h>/***COPYRIGHTNOTICE*Copyright(c)2010,ffcs(版权声明)*Allrightsreserved.*@fileDebug.h*@brief按DEBUG_ZONE输出调试消息**当宏DEBUG被打开时,根据设置的DEBUG_ZONE输出相应的消息。DEBUG_ZONE可以通过*修改g_debug_setting的zone_mask修改。**@versionv1.0*@author*@date2010/11/09**修订说明 阅读全文

posted @ 2012-08-07 11:23 山本二十八 阅读(253) 评论(0) 推荐(0)

互斥区代码
摘要:char*getCurrFileName(){FILE*stream;charfullname[1024];stream=popen("pwd","r");fread(fullname,sizeof(char),sizeof(fullname),stream);{inti;for(i=0;i<strlen(fullname);i++){if(fullname[i]=='\n'){fullname[i]=0;break;}}}sprintf(fullname,"%s/%s",fullname,__FILE__);p 阅读全文

posted @ 2012-08-07 11:21 山本二十八 阅读(392) 评论(0) 推荐(0)

信号处理测试代码
摘要:#include<sys/sem.h>#include<stdio.h>#include<signal.h>#include<unistd.h>#include<stdarg.h>#include<string.h>sigset_toldset;typedefstruct__sig_mask{sigset_tsig_newset,sig_oldset;intset_flag;/*当调用完mask_procmask后,置1,否则,为0*/int(*mask_addsig)(struct__sig_mask*pSigMask, 阅读全文

posted @ 2012-08-07 11:20 山本二十八 阅读(371) 评论(0) 推荐(0)

linux时间函数
摘要:我们在编程中可能会经常用到时间,比如取得系统的时间(获取系统的年、月、日、时、分、秒,星期等),或者是隔一段时间去做某事,那么我们就用到一些时间函数。linux下存储时间常见的有两种存储方式,一个是从1970年到现在经过了多少秒,一个是用一个结构来分别存储年月日时分秒的。time_t 这种类型就是用来存储从1970年到现在经过了多少秒,要想更精确一点,可以用结构struct timeval,它精确到微妙。struct timeval{ long tv_sec; /*秒*/ long tv_usec; /*微秒*/};而直接存储年月日的是一个结构:struct tm{ int tm_sec... 阅读全文

posted @ 2012-08-07 11:17 山本二十八 阅读(179) 评论(0) 推荐(0)

两日期间的天数
摘要:#include"stdio.h"intdays[2][13]={365,31,28,31,30,31,30,31,31,30,31,30,31,366,31,29,31,30,31,30,31,31,30,31,30,31};intLeap(intyear)//判断是否为闰年{return((year%400==0)||(year%4==0&&year%100!=0));}intDeal(intdat0,intdat1){inti,temp,sum0,sum;intyear0,month0,day0,year1,month1,day1;sum0=sum=0 阅读全文

posted @ 2012-08-07 11:14 山本二十八 阅读(203) 评论(0) 推荐(0)

字符串分割_链表
摘要:/*str_tok.h*/#ifndef_H_STR_TOK#define_H_STR_TOK#include<string.h>#include<stdio.h>#include"FPL_types.h"typedefstruct__NODE{char*pch;struct__NODE*next;}_NODE;typedefstruct__STRCK_TOK{int_MAXLEN;char*pStr;_NODE*phead;void(*setMaxLen)(struct__STRCK_TOK*,int);int(*getMaxLen)(struct 阅读全文

posted @ 2012-08-07 11:06 山本二十八 阅读(667) 评论(0) 推荐(0)

我实现的一个正则表达式代码
摘要:#include"stdafx.h"#include<stdarg.h>#include<stdio.h>#include<string.h>#include<stdlib.h>#ifndefDEBUG#defineDEBUG1#endif/*enumbool{false=0,true};typedefenumboolbool;*/boolmatch(char*name2,char*pre2);char*FPF_StrSpilit(constchar*str,char*token,constchar*delimit){char 阅读全文

posted @ 2012-08-07 10:50 山本二十八 阅读(1056) 评论(0) 推荐(0)

上一页 1 2

导航