资源描述:
《CSE 2011 Midterm Exam --v1.0.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、ComputerSystemEngineeringSpring2011MidtermExaminationProblem(1:(Naming(Scheme((8’)(!In!“bbs.fudan.edu.cn”,!when!an!article!is!posted,!it!would!be!stored!as!a!file!with!a!filename!by!prefix!and!timestamp,!rather!than!the!title!of!article,!as!following:!!/*
2、*##*#Creates#a#new#file#in#specific#location.##*#@param[in]#dir#The#directory.##*#@param[in]#pfx#Prefix#of#the#file.##*#@param[in,#out]#fname#The#resulting#filename.##*#@param[size]#The#size#of#fname.##*#@return#Filename#and#stream#on#success,#NULL#on#err
3、or.##*#@see#::date_to_fname.##*/#static#FILE#*get_fname(const#char#*dir,#const#char#*pfx,#################char#*fname,#size_t#size)#{#########const#char#c[]#=#"ZYXWVUTSRQPONMLKJIHGFEDCBA";#########int#t#=#(int)time(NULL);#########int#count#=#snprintf(fnam
4、e,#size,#"%s%s%d.#",#dir,#pfx,#t);##########int#fd;#########for#(int#i#=#sizeof(c)#a#1;#i#>=#0;#iaa)#{#################fname[count#a#1]#=#c[i];#################if#((fd#=#open(fname,#O_CREAT#
5、#O_WRONLY#
6、#O_EXCL,#0644))#>#0)#{#########################FILE#*
7、fp#=#fdopen(fd,#"w");#########################if#(fp)#{#################################return#fp;#########################}#else#{#################################close(fd);#################################return#NULL;#########################}##########
8、#######}#########}#########return#NULL;#}#*!snprintf()!does!not!write!more!than!size!bytes!(including!the!trailing!' ').!!Which(of(the(followings(are(true?((8’)((A.The!file!system!of!BBS!only!supports!a!limited!length!of!filename.!If!the!title!of!the!art
9、icle!exceeds!the!maximum!length!of!filename,!it!must!be!cut!off.!B.The!filename!is!generated!in!the!form!of!timestamp,!in!order!to!accelerate!the!discovery!and!read!procedures.!C.Many!articles!in!one!board!would!probably!have!similar,!or!even!the!same!tit
10、le.!So!using!timestamp!to!generate!a!unique!filename!could!mostly!avoid!the!problem.!D.The!filenames!are!generated!using!timestamps,!so!that!they!could!be!sorted!naturally,!and!thus!it!is!much!convenient!for!search!