diff mbox series

[ibsim,01/23] move sim_cmd_file into ibsim/sim_cmd.c

Message ID 20190102131318.5765-1-honli@redhat.com (mailing list archive)
State Not Applicable
Headers show
Series [ibsim,01/23] move sim_cmd_file into ibsim/sim_cmd.c | expand

Commit Message

Honggang LI Jan. 2, 2019, 1:12 p.m. UTC
The 'sim_cmd_file' function only called by 'do_cmd' function in the
sim_cmd.c file.

Signed-off-by: Honggang Li <honli@redhat.com>
---
 ibsim/ibsim.c   | 38 --------------------------------------
 ibsim/sim_cmd.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 38 deletions(-)

Comments

Hal Rosenstock Jan. 3, 2019, 3:39 p.m. UTC | #1
On 1/2/2019 8:12 AM, Honggang Li wrote:
> The 'sim_cmd_file' function only called by 'do_cmd' function in the
> sim_cmd.c file.
> 
> Signed-off-by: Honggang Li <honli@redhat.com>
> ---
>  ibsim/ibsim.c   | 38 --------------------------------------
>  ibsim/sim_cmd.c | 38 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 38 insertions(+), 38 deletions(-)
> 
> diff --git a/ibsim/ibsim.c b/ibsim/ibsim.c
> index debf591fea92..40e605c75429 100644
> --- a/ibsim/ibsim.c
> +++ b/ibsim/ibsim.c
> @@ -517,44 +517,6 @@ static int sim_read_pkt(int fd, int client)
>  	return -1;		// never reached
>  }
>  
> -int sim_cmd_file(FILE * f, char *s)
> -{
> -	char line[4096];
> -	FILE *cmd_file;
> -	char *p;
> -
> -	s++;
> -	while (isspace(*s))
> -		s++;
> -
> -	if (!s || !*s) {
> -		fprintf(f, "do_cmd_from_file: no file name - skip\n");
> -		return -1;
> -	}
> -
> -	p = s + strlen(s) - 1;
> -	while (isspace(*p)) {
> -		*p = '\0';
> -		p--;
> -	}
> -
> -	cmd_file = fopen(s, "r");
> -	if (!cmd_file) {
> -		fprintf(f, "do_cmd_from_file: cannot open file \'%s\': %s\n",
> -			s, strerror(errno));
> -		return -1;
> -	}
> -
> -	while (fgets(line, sizeof(line) - 1, cmd_file) != NULL) {
> -		if((p = strchr(line, '\n')) != NULL)
> -			*p = '\0';
> -		do_cmd(line, f);
> -	}
> -
> -	fclose(cmd_file);
> -	return 0;
> -}
> -
>  static int sim_init_net(char *netconf, FILE * out)
>  {
>  	DEBUG("reading %s", netconf);
> diff --git a/ibsim/sim_cmd.c b/ibsim/sim_cmd.c
> index 4b8fb62e0906..4345731e5081 100644
> --- a/ibsim/sim_cmd.c
> +++ b/ibsim/sim_cmd.c
> @@ -1143,6 +1143,44 @@ format_error:
>  	return -1;
>  }
>  
> +int sim_cmd_file(FILE * f, char *s)

I made this static and removed no longer needed declaration from sim.h

> +{
> +	char line[4096];
> +	FILE *cmd_file;
> +	char *p;
> +
> +	s++;
> +	while (isspace(*s))
> +		s++;
> +
> +	if (!s || !*s) {
> +		fprintf(f, "do_cmd_from_file: no file name - skip\n");
> +		return -1;
> +	}
> +
> +	p = s + strlen(s) - 1;
> +	while (isspace(*p)) {
> +		*p = '\0';
> +		p--;
> +	}
> +
> +	cmd_file = fopen(s, "r");
> +	if (!cmd_file) {
> +		fprintf(f, "do_cmd_from_file: cannot open file \'%s\': %s\n",
> +			s, strerror(errno));
> +		return -1;
> +	}
> +
> +	while (fgets(line, sizeof(line) - 1, cmd_file) != NULL) {
> +		if((p = strchr(line, '\n')) != NULL)
> +			*p = '\0';
> +		do_cmd(line, f);
> +	}
> +
> +	fclose(cmd_file);
> +	return 0;
> +}
> +
>  int netstarted;
>  
>  int do_cmd(char *buf, FILE *f)
> 

Thanks. Applied.

-- Hal
diff mbox series

Patch

diff --git a/ibsim/ibsim.c b/ibsim/ibsim.c
index debf591fea92..40e605c75429 100644
--- a/ibsim/ibsim.c
+++ b/ibsim/ibsim.c
@@ -517,44 +517,6 @@  static int sim_read_pkt(int fd, int client)
 	return -1;		// never reached
 }
 
-int sim_cmd_file(FILE * f, char *s)
-{
-	char line[4096];
-	FILE *cmd_file;
-	char *p;
-
-	s++;
-	while (isspace(*s))
-		s++;
-
-	if (!s || !*s) {
-		fprintf(f, "do_cmd_from_file: no file name - skip\n");
-		return -1;
-	}
-
-	p = s + strlen(s) - 1;
-	while (isspace(*p)) {
-		*p = '\0';
-		p--;
-	}
-
-	cmd_file = fopen(s, "r");
-	if (!cmd_file) {
-		fprintf(f, "do_cmd_from_file: cannot open file \'%s\': %s\n",
-			s, strerror(errno));
-		return -1;
-	}
-
-	while (fgets(line, sizeof(line) - 1, cmd_file) != NULL) {
-		if((p = strchr(line, '\n')) != NULL)
-			*p = '\0';
-		do_cmd(line, f);
-	}
-
-	fclose(cmd_file);
-	return 0;
-}
-
 static int sim_init_net(char *netconf, FILE * out)
 {
 	DEBUG("reading %s", netconf);
diff --git a/ibsim/sim_cmd.c b/ibsim/sim_cmd.c
index 4b8fb62e0906..4345731e5081 100644
--- a/ibsim/sim_cmd.c
+++ b/ibsim/sim_cmd.c
@@ -1143,6 +1143,44 @@  format_error:
 	return -1;
 }
 
+int sim_cmd_file(FILE * f, char *s)
+{
+	char line[4096];
+	FILE *cmd_file;
+	char *p;
+
+	s++;
+	while (isspace(*s))
+		s++;
+
+	if (!s || !*s) {
+		fprintf(f, "do_cmd_from_file: no file name - skip\n");
+		return -1;
+	}
+
+	p = s + strlen(s) - 1;
+	while (isspace(*p)) {
+		*p = '\0';
+		p--;
+	}
+
+	cmd_file = fopen(s, "r");
+	if (!cmd_file) {
+		fprintf(f, "do_cmd_from_file: cannot open file \'%s\': %s\n",
+			s, strerror(errno));
+		return -1;
+	}
+
+	while (fgets(line, sizeof(line) - 1, cmd_file) != NULL) {
+		if((p = strchr(line, '\n')) != NULL)
+			*p = '\0';
+		do_cmd(line, f);
+	}
+
+	fclose(cmd_file);
+	return 0;
+}
+
 int netstarted;
 
 int do_cmd(char *buf, FILE *f)