目標
設計乙個函式庫,封裝五個函式,實現日誌輸出與斷言判斷等功能
函式原型及其實現
2.1格式化日誌輸出函式:
printlog printtracelog
原型:int printlog(file *pfile, const char *pformat, …);
功能說明:按照字串
pformat
的內容,控制後繼引數的數量和格式,並在檔案流中輸出。
原型:int printtracelog(char *pformat, …);
功能說明:呼叫
printlog
將資訊寫入日誌檔案
2.2原始碼
int printlog(file *pfile, const char *pformat, ...)
int printtracelog(const char *pformat, ...)
return ret; }
2.3記憶體列印函式
原型:int printhexlog(file *pfile, void *pdata, int nsize)
功能:將一段記憶體內容寫入輸出流
原型:int printtracehexlog(void *pdata, int nsize)
功能:呼叫printhexlog
將一段記憶體內容寫入日誌檔案中
2.4原始碼
/****
列印一段記憶體*/
int printhexlog(file *pfile, void *pdata, int nsize)
nlen += sprintf(szbuf + nlen, "%02x ", cline[n] & 0x00ff); }
for(n = nlinesize; n < 16; n++)
nlen += sprintf(szbuf + nlen, " :");
for(n = 0; n < nlinesize; n++)
nlen += sprintf(szbuf + nlen, "/n"); }
if(fputs(szbuf, pfile) != eof && fflush(pfile) != eof)
return 0;
return -1; }
int printtracehexlog(void *pdata, int nsize)
return 0; }
2.5資訊判斷函式
原型:int verify(int bstatus, const char *szbuf, const char *szfile, int nline)
功能:當標誌
bstatus
為真時,函式不執行任何操作,否則
verify
將向日誌檔案輸出錯誤資訊。字串
szbuf
描述了錯誤資訊,字串
szfile
描述了發生了錯誤的原始檔名稱,引數
nline
代表發生錯誤所在的行號。
2.6原始碼
int verify(int bstatus, const char *szbuf, const char *szfile, int nline)
errno = 0; }
return bstatus; }
測試 3.1原始碼
#include "comlib.h"
int main()
3.2編譯
gcc –wall –o2 –o test test.c –i../include –l../lib -lcom
3.3檢視結果
控制台輸出:
info: 2009.12.16.22:29:26 [3712]: this is a test[1000]
info: 2009.12.16.22:29:26 [3712]: address[2276496] size[4]
[00]: e8 03 00 00:....
日誌檔案中的輸出:
info: 2009.12.16.22:29:26 [3712]: this is test[2278552]
info: 2009.12.16.22:29:26 [3712]: address[2276464] size[4]
[4200138]: e8 03 00 00:....
info: 2009.12.16.22:29:26 [3712]: ----------------------
info: 2009.12.16.22:29:26 [3712]: [3712]
> illegal seek
> in line 13 file src/td1.c
info: 2009.12.16.22:29:26 [3712]: -----------------------
info: 2009.12.16.22:29:26 [3712]: [3712]
> in line 15 file src/td1.c
info: 2009.12.16.22:29:26 [3712]: -----------------------
oracle SQL單行函式3 通用函式
通用函式 nvl exp1,a 如果exp1為null則返回a,否則返回exp1 select nvl null,33 from dual 33 nullif exp1,exp2 如果exp1 exp2,則返回空,否則返回exp1 select nullif 32,32 from dual 空 nv...
Funny Linq Part4 通用的級聯刪除
從父表中刪除外來鍵時也會刪除子表中的行。如果在乙個表的主鍵列上刪除了一些行,那麼在啟用級聯刪除的情況下,將在相關表的任何外來鍵列上刪除相同資訊。級聯刪除 從父表中刪除外來鍵時也會刪除子表中的行 public static void cascadingdeletes t tentity where t...
python程式設計 turtle函式庫筆記 4
補充例項 import turtle defmain turtle.pensize 3 turtle.penup turtle.goto 200,50 turtle.pendown turtle.begin fill turtle.color red turtle.circle 40,steps 3...