summaryrefslogtreecommitdiffstats
path: root/src/chgtype.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2018-03-17 17:29:28 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2018-03-17 17:29:28 +0100
commit09ecae700f224a23cfd8f63f98cebeccbe768cc0 (patch)
tree83fbfb551cc9330a02dfb6762e2c4b8e6015eecb /src/chgtype.c
parent331f0ef77e62140d0ee9252c33b23b383aa73084 (diff)
Use new functions check_command(), skip_comma_in_command() and get_int_from_command() to parse command line arguments
Diffstat (limited to 'src/chgtype.c')
-rw-r--r--src/chgtype.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/chgtype.c b/src/chgtype.c
index 5db0301..243faa3 100644
--- a/src/chgtype.c
+++ b/src/chgtype.c
@@ -37,6 +37,14 @@
extern const arch_fnct_t arch_gpt;
extern const arch_fnct_t arch_none;
+static int get_hex_from_command(char **current_cmd)
+{
+ const int tmp=strtol(*current_cmd, NULL, 16);
+ while(*current_cmd[0]!=',' && *current_cmd[0]!='\0')
+ (*current_cmd)++;
+ return tmp;
+}
+
void change_part_type_cli(const disk_t *disk_car,partition_t *partition, char **current_cmd)
{
assert(current_cmd!=NULL);
@@ -48,12 +56,9 @@ void change_part_type_cli(const disk_t *disk_car,partition_t *partition, char **
if(partition->arch==&arch_gpt)
{
partition->arch=&arch_none;
- while(*current_cmd[0]==',')
- (*current_cmd)++;
+ skip_comma_in_command(current_cmd);
{
- int tmp_val= strtol(*current_cmd, NULL, 16);
- while(*current_cmd[0]!=',' && *current_cmd[0]!='\0')
- (*current_cmd)++;
+ const int tmp_val=get_hex_from_command(current_cmd);
partition->arch->set_part_type(partition,tmp_val);
}
log_info("Change partition type:\n");
@@ -63,12 +68,9 @@ void change_part_type_cli(const disk_t *disk_car,partition_t *partition, char **
}
if(partition->arch->set_part_type==NULL)
return ;
- while(*current_cmd[0]==',')
- (*current_cmd)++;
+ skip_comma_in_command(current_cmd);
{
- int tmp_val= strtol(*current_cmd, NULL, 16);
- while(*current_cmd[0]!=',' && *current_cmd[0]!='\0')
- (*current_cmd)++;
+ const int tmp_val=get_hex_from_command(current_cmd);
partition->arch->set_part_type(partition,tmp_val);
}
log_info("Change partition type:\n");