Re: [問題]請問在FreeBSD底下設計程

看板FreeBSD作者時間21年前 (2005/03/08 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
> 我覺得你的結果是有點詭異的... > 為什麼同一個結果,不同次引用卻會有不同的值。 我就是覺得他詭異所以才問>_< 以下暫不討論malloc要free,free應該不是問題重點 unsigned char * b64_encode(unsigned char *str, uint32_t len){ unsigned char * b64_result; b64_len = (len%3==0)?(len/3*4+1):((len+3-(len%3))/3*4+1); b64_result = (unsigned char *) malloc(b64_len);     ...(略) return b64_result; } unsigned char * checksum_1(unsigned char * ary, uint32_t len){ uint32_t i; unsigned char tmp[512], *lala; for(i=0;i<512;i++){ tmp[i]=0; } for(i=0;i<len;i++){ tmp[i%512] ^= ary[i]; } return b64_encode(tmp, 512); } main(){ unsigned int k, i=0; unsigned char *p; struct stat fst; unsigned char * kkk; k = open("kanon.ove", O_RDWR); fstat(k, &fst); p = (unsigned char *) mmap(0, (uint32_t) fst.st_size, PROT_WRITE | PROT_READ, MAP_SHARED, k, 0); kkk=checksum_1(p, fst.st_size); printf("res1: %d, res2: %s%s\n", checksum_0(p, fst.st_size), kkk, kkk); munmap(p, fst.st_size); } 我的main()這部分只是寫來測試所以有點雜亂.. 前兩個函式另外放在別的.h裡 用以上的code跑出來結果是 res1: 135027, res2: (null)J1jU81sDfVKp6ra8B8XsA73XhBK0B7VQYeUMpmOXTqYZlX7PNd59CddZwDQOI14PSNtO0K3tfb11ksA+DT2l7VoByGlZkY49bqBYqNm1vQJOPnnRScEDN8Wpj0Zpdzn85b6UOrYasCl4tIywS11cgRB8/JdUiAXOsFhqE14puTBMqE3chCVma0FTarbawCSiWZurpWXWQtPTf o C k 1 4 h C 0 W z zbt90Q0GIotYbc9sMeX95t0oluISOVgqfaeeAxGzk46VbZUfJ9C/3sjZRCWCXy2NaLwu43iZ3F0pkWeIdUawDexq4UADJSnbVGclfCpwRSKIFto/3qt/fKaAHsZqc7qfhpcojfGEb3DKk8TWSCz76SkvVaRlzPeW7plsHOD892/fdIjtnYuLkPpRgP6zSYoSL9Is993NmqD0iw/00SBexEM0BOayR02L19uRzF9cm1Q8L0Rdj sBd5GJjLcrUv9gy0Iyu14MlFhS42lKz4gwGvZr4+y5Zj4w1TfGc+5ChXjbo1V/11gnT2GrMxg4b3sHaO4gzB2/7/OEjjROfb2c/Ta/BA5i2NYyz8Mz7tQyCuJ10AyUfV3bPtia3AB0129CYOJgYqAzkkxcrGnCa13t1Hid4aYp8YPzpj7wQwg3O0ytSYz7mPcWwQltbyfjHt5OTP66SP9vIq7idJ0U9mSAc= -- <師大附中 BBS 站> bbs.hs.ntnu.edu.tw ★ From: sw169-71-109.adsl.seed.net.tw
文章代碼(AID): #12B9R-00 (FreeBSD)
文章代碼(AID): #12B9R-00 (FreeBSD)