I'm busy on modifying Luna (a program that generates documents for the TI-Nspire).
I don't have that much experience with C, but I managed to do what I wanted. But I'm just wondering if I'm doing everything the right way.
It's the first time I use malloc and co, so you never know
Here is my code:
Code:
Any bad errors in that?
TIA
I don't have that much experience with C, but I managed to do what I wanted. But I'm just wondering if I'm doing everything the right way.
It's the first time I use malloc and co, so you never know
Here is my code:
Code:
//Extension by Jim Bauwens
if (argc>3){
FILE *FP;
int ifile;
fpos_t pos;
char *buf ;
for (ifile=3; ifile<argc; ifile++){
if ((FP=fopen(argv[ifile], "r")) == NULL) {
printf("Couldn't open %s for reading, ignoring it\n", argv[ifile]);
break;
}
if (fseek(FP, 0, SEEK_END)==-1){
printf("Couldn't jump to end of file\n");
break;
}
fgetpos(FP, &pos);
rewind(FP);
buf = (char *) malloc(pos.__pos);
if (buf == NULL) {
printf("Could not allocate memory!\n");
break;
}
fread(buf, sizeof(char), pos.__pos-1, FP);
if (ferror(FP)){
printf("Error reading %s!\n", argv[ifile]);
clearerr(FP);
break;
}
if (zipOpenNewFileInZip2(zf, argv[ifile], &zi, NULL, 0, NULL, 0, NULL, 0xD, 0, 1) != ZIP_OK) {
printf("can't zip %s", argv[ifile]);
goto close_quit;
}
if (zipWriteInFileInZip(zf, buf, pos.__pos) != ZIP_OK) {
puts("can't add file to zip file");
goto close_quit;
}
if (zipCloseFileInZipRaw(zf, pos.__pos, 0) != ZIP_OK) {
puts("can't close file in zip file");
goto unlink_quit;
}
fclose(FP);
free(buf);
}
}
//End Extension
Any bad errors in that?
TIA