Replaced some large local variables by other means in xorriso/opts_p_z.c

This commit is contained in:
Thomas Schmitt 2011-05-06 12:06:44 +00:00
parent 65df49006f
commit 3c6db0ed4d
2 changed files with 75 additions and 47 deletions

View File

@ -139,7 +139,7 @@ int Xorriso_option_path_list(struct XorrisO *xorriso, char *adr, int flag)
int ret,linecount= 0, insertcount= 0, null= 0, was_failure= 0, fret= 0;
int was_ferror= 0, argc= 0, i;
FILE *fp= NULL;
char sfe[5*SfileadrL], **argv= NULL;
char **argv= NULL;
Xorriso_pacifier_reset(xorriso, 0);
if(adr[0]==0) {
@ -188,14 +188,17 @@ ex:;
Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
xorriso->pacifier_total, "", 1);
if(ret<=0) {
sprintf(xorriso->info_text, "Aborted reading of file %s in line number %d",
Text_shellsafe(adr, sfe, 0), linecount);
sprintf(xorriso->info_text, "Aborted reading of file ");
Text_shellsafe(adr, xorriso->info_text, 1);
sprintf(xorriso->info_text + strlen(xorriso->info_text),
" in line number %d", linecount);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
(fret==-2 ? "NOTE" : "FAILURE"), 0);
} else
ret= !was_ferror;
sprintf(xorriso->info_text, "Added %d items from file %s\n",
insertcount, Text_shellsafe(adr, sfe, 0));
sprintf(xorriso->info_text, "Added %d items from file ", insertcount);
Text_shellsafe(adr, xorriso->info_text, 1);
strcat(xorriso->info_text, "\n");
Xorriso_info(xorriso,0);
if(ret<=0)
return(ret);
@ -390,11 +393,10 @@ int Xorriso_option_pvd_info(struct XorrisO *xorriso, int flag)
/* Option -pwd alias -pwdi */
int Xorriso_option_pwdi(struct XorrisO *xorriso, int flag)
{
char sfe[5 * SfileadrL];
sprintf(xorriso->info_text,"current working directory in ISO image:\n");
Xorriso_info(xorriso,0);
sprintf(xorriso->result_line,"%s/\n", Text_shellsafe(xorriso->wdi, sfe, 0));
Text_shellsafe(xorriso->wdi, xorriso->result_line, 0);
strcat(xorriso->result_line, "/\n");
Xorriso_result(xorriso,0);
return(1);
}
@ -454,13 +456,11 @@ int Xorriso_option_report_about(struct XorrisO *xorriso, char *severity,
int flag)
{
int ret, sev;
char sfe[5*SfileadrL];
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0) {
sprintf(xorriso->info_text,
"-report_about: Not a known severity name : %s",
Text_shellsafe(severity, sfe, 0));
sprintf(xorriso->info_text, "-report_about: Not a known severity name : ");
Text_shellsafe(severity, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
return(ret);
}
@ -476,13 +476,12 @@ int Xorriso_option_return_with(struct XorrisO *xorriso, char *severity,
int exit_value, int flag)
{
int ret, sev;
char sfe[5*SfileadrL];
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0) {
sprintf(xorriso->info_text,
"-return_with: Not a known severity name : %s",
Text_shellsafe(severity, sfe, 0));
"-return_with: Not a known severity name : ");
Text_shellsafe(severity, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(ret);
}
@ -506,7 +505,7 @@ int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int i, ret, end_idx, was_failure= 0, fret;
char path[SfileadrL], eff_path[SfileadrL], sfe[5*SfileadrL];
char *path= NULL, *eff_path= NULL;
int optc= 0;
char **optv= NULL;
@ -514,6 +513,9 @@ int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv,
argc, argv, *idx, &end_idx, &optc, &optv, 0);
if(ret<=0)
goto ex;
Xorriso_alloc_meM(path, char, SfileadrL);
Xorriso_alloc_meM(eff_path, char, SfileadrL);
for(i= 0; i<optc; i++) {
if(Sfile_str(path,optv[i],0)<=0)
{ret= -1; goto problem_handler;}
@ -526,9 +528,9 @@ int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv,
if(ret<0)
goto problem_handler;
if(ret==0) {
sprintf(xorriso->info_text,
"Cannot find path %s in loaded ISO image for removal",
Text_shellsafe(path, sfe, 0));
sprintf(xorriso->info_text, "Cannot find path ");
Text_shellsafe(path, xorriso->info_text, 1);
strcat(xorriso->info_text, " in loaded ISO image for removal");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
goto problem_handler;
}
@ -554,6 +556,8 @@ problem_handler:;
ret= 1;
ex:;
(*idx)= end_idx;
Xorriso_free_meM(path);
Xorriso_free_meM(eff_path);
Xorriso_opt_args(xorriso, "-rm*i",
argc, argv, *idx, &end_idx, &optc, &optv, 256);
if(ret<=0)
@ -569,8 +573,9 @@ ex:;
int Xorriso_option_rollback(struct XorrisO *xorriso, int flag)
{
int ret;
char indev[SfileadrL], *which_will;
char *indev= NULL, *which_will;
Xorriso_alloc_meM(indev, char, SfileadrL);
if(xorriso->volset_change_pending)
which_will= "revoke the pending image changes";
else
@ -578,16 +583,18 @@ int Xorriso_option_rollback(struct XorrisO *xorriso, int flag)
if(!(flag&1)) {
ret= Xorriso_reassure(xorriso, "-rollback", which_will, 0);
if(ret<=0)
return(2);
{ret= 2; goto ex;}
}
if(Sfile_str(indev, xorriso->indev, 0)<=0)
return(-1);
{ret= -1; goto ex;}
ret= Xorriso_give_up_drive(xorriso, 1|8);
if(ret<=0)
return(ret);
goto ex;
xorriso->image_start_mode&= ~(1<<31); /* reactivate eventual -load address */
ret= Xorriso_option_dev(xorriso, indev, 1|4);
ex:;
Xorriso_free_meM(indev);
return(ret);
}
@ -678,21 +685,27 @@ int Xorriso_option_session_log(struct XorrisO *xorriso, char *path, int flag)
/* Option -setfacl_list alias -setfacl_listi */
int Xorriso_option_setfacl_listi(struct XorrisO *xorriso, char *path, int flag)
{
int ret, eaten;
int ret, eaten, line_size;
size_t buf_size= 0, buf_add= 64 * 1024, l, linecount= 0;
char line[SfileadrL * 4], *buf= NULL, *wpt, *new_buf, limit_text[80];
char file_path[SfileadrL], uid[161], gid[161];
char *line= NULL, *buf= NULL, *wpt, *new_buf, limit_text[80];
char *file_path= NULL, *uid= NULL, *gid= NULL;
FILE *fp= NULL;
line_size= SfileadrL * 4;
Xorriso_alloc_meM(line, char, line_size);
Xorriso_alloc_meM(file_path, char, SfileadrL);
Xorriso_alloc_meM(uid, char, 161);
Xorriso_alloc_meM(gid, char, 161);
Xorriso_pacifier_reset(xorriso, 0);
if(path[0]==0) {
sprintf(xorriso->info_text, "Empty file name given with -setfacl_list");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
{ret= 0; goto ex;}
}
ret= Xorriso_afile_fopen(xorriso, path, "rb", &fp, 0);
if(ret <= 0)
return(0);
{ret= 0; goto ex;}
buf_size= buf_add;
buf= calloc(buf_size, 1);
@ -703,7 +716,7 @@ int Xorriso_option_setfacl_listi(struct XorrisO *xorriso, char *path, int flag)
uid[0]= gid[0]= 0;
while(1) {
if(Sfile_fgets_n(line, sizeof(line), fp, 0) == NULL)
if(Sfile_fgets_n(line, line_size, fp, 0) == NULL)
break;
linecount++;
if(strncmp(line, "# file: ", 8) ==0) {
@ -799,6 +812,10 @@ ex:;
" aborted in line %.f\n", (double) linecount);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
}
Xorriso_free_meM(line);
Xorriso_free_meM(file_path);
Xorriso_free_meM(uid);
Xorriso_free_meM(gid);
return(ret);
out_of_mem:;
Xorriso_no_malloc_memory(xorriso, &buf, 0);
@ -942,25 +959,28 @@ ex:;
int Xorriso_option_setfattr_listi(struct XorrisO *xorriso, char *path,
int flag)
{
int ret, eaten;
int ret, eaten, line_size= SfileadrL * 4;
size_t linecount= 0, mem_used= 0, num_attr= 0, v_len;
char line[SfileadrL * 4], limit_text[80], *ept, *valuept;
char file_path[SfileadrL];
char *line= NULL, limit_text[80], *ept, *valuept;
char *file_path= NULL;
FILE *fp= NULL;
struct Xorriso_lsT *lst_curr= NULL, *lst_start= NULL;
Xorriso_alloc_meM(line, char, line_size);
Xorriso_alloc_meM(file_path, char, SfileadrL);
Xorriso_pacifier_reset(xorriso, 0);
if(path[0]==0) {
sprintf(xorriso->info_text, "Empty file name given with -setfattr_list");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
{ret= 0; goto ex;}
}
ret= Xorriso_afile_fopen(xorriso, path, "rb", &fp, 0);
if(ret <= 0)
return(0);
{ret= 0; goto ex;}
while(1) {
if(Sfile_fgets_n(line, sizeof(line), fp, 0) == NULL)
if(Sfile_fgets_n(line, line_size, fp, 0) == NULL)
break;
linecount++;
if(strncmp(line, "# file: ", 8) ==0) {
@ -1058,6 +1078,8 @@ ex:;
if(fp != NULL && fp != stdin)
fclose(fp);
Xorriso_lst_destroy_all(&lst_start, 0);
Xorriso_free_meM(line);
Xorriso_free_meM(file_path);
if(ret <= 0) {
sprintf(xorriso->info_text, "-setfattr_list ");
Text_shellsafe(path, xorriso->info_text, 1);
@ -1451,10 +1473,13 @@ int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path,
int ret, mem_pci, zero= 0, result, uret, follow_links, do_register= 1;
int not_in_iso= 0, not_on_disk= 0, made_di_array= 0;
double mem_lut= 0.0, start_time;
char *ipth, *argv[6], sfe[5*SfileadrL];
char eff_origin[SfileadrL], eff_dest[SfileadrL];
char *ipth, *argv[6];
char *eff_origin= NULL, *eff_dest= NULL;
struct stat stbuf;
Xorriso_alloc_meM(eff_origin, char, SfileadrL);
Xorriso_alloc_meM(eff_dest, char, SfileadrL);
start_time= Sfile_microtime(0);
ipth= iso_path;
@ -1463,16 +1488,16 @@ int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path,
if(disk_path[0]==0) {
sprintf(xorriso->info_text, "-update: Empty disk_path given");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1);
return(0);
{ret= 0; goto ex;}
}
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_origin,
2|4|8);
if(ret<=0)
return(ret);
goto ex;
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, ipth, eff_dest, 2|8);
if(ret<=0)
return(ret);
goto ex;
if(!(flag&2)) {
Xorriso_pacifier_reset(xorriso, 0);
@ -1482,10 +1507,11 @@ int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path,
xorriso->pacifier_interval= 5.0;
if(flag&1) {
sprintf(xorriso->info_text, "Updating %s to",
Text_shellsafe(eff_origin, sfe, 0));
sprintf(xorriso->info_text+strlen(xorriso->info_text), " %s\n",
Text_shellsafe(eff_dest, sfe, 0));
sprintf(xorriso->info_text, "Updating ");
Text_shellsafe(eff_origin, xorriso->info_text, 1);
strcat(xorriso->info_text, " to ");
Text_shellsafe(eff_dest, xorriso->info_text, 1 | 2);
strcat(xorriso->info_text, "\n");
Xorriso_info(xorriso,0);
}
if(xorriso->disk_excl_mode&8)
@ -1586,8 +1612,8 @@ int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path,
} else
ret= -1;
if(not_on_disk && not_in_iso) {
sprintf(xorriso->info_text, "Missing on disk and in ISO: disk_path %s",
Text_shellsafe(disk_path, sfe, 0));
sprintf(xorriso->info_text, "Missing on disk and in ISO: disk_path ");
Text_shellsafe(disk_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1);
ret= -1;
}
@ -1629,6 +1655,8 @@ report_outcome:;
Xorriso_info(xorriso,0);
ex:;
Xorriso_free_meM(eff_origin);
Xorriso_free_meM(eff_dest);
if(ret < 0)
return(ret);
return(1);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2011.05.06.120600"
#define Xorriso_timestamP "2011.05.06.120655"