Annotation of capa/capa51/pProj/capaSubjective.c, revision 1.1.1.1
1.1 albertel 1: #include "capaCommon.h"
2: #include <sys/stat.h>
3: #include <sys/types.h>
4: #include <fcntl.h>
5: #include <unistd.h>
6: #include <ctype.h>
7:
8: char* strtoupper(char* source)
9: {
10: char* result;
11: int i,len=strlen(source);
12: result=capa_malloc(len,1);
13: for(i=0;i<len;i++) result[i]=toupper(source[i]);
14: return result;
15: }
16:
17: int capa_set_subjective (int set,int problem,char *student_num,char* response)
18: {
19: char buf[FILE_NAME_LENGTH],*upperstunum;
20: FILE *responsefile;
21:
22: sprintf(buf,"records/set%d",set);
23: if( capa_access(buf, F_OK) == -1 ) {
24: if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -1; }
25: }
26:
27: sprintf(buf,"records/set%d/problem%d",set,problem);
28: if( capa_access(buf, F_OK) == -1 ) {
29: if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -2; }
30: }
31:
32: upperstunum=strtoupper(student_num);
33: sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
34: if ((responsefile=fopen(buf,"w"))==NULL) { return -3; }
35:
36: fwrite(response,strlen(response),1,responsefile);
37: fclose(responsefile);
38: return 0;
39: }
40:
41: char* capa_get_subjective (int set,int problem,char *student_num)
42: {
43: char buf[FILE_NAME_LENGTH],*upperstunum,*response;
44: FILE *responsefile;
45: long length;
46:
47: upperstunum=strtoupper(student_num);
48: sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
49: if ((responsefile=fopen(buf,"r"))==NULL) { return NULL; }
50: fseek(responsefile,0,SEEK_END);
51: length=ftell(responsefile);
52: rewind(responsefile);
53: response=capa_malloc(length+1,1);
54: fread(response,length,1,responsefile);
55: response[length]='\0';
56: return response;
57: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>