Skip to content
Permalink
Browse files
[clean-up] Remove some erronous uses of const
Not a real issue but the code is more readable and it removes the need for
casting by removing some const stuff that is not needed.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Nov 7, 2014
1 parent f73b686 commit c2fe327edcc301a301b5a2d40d67c8f95c3ad7fb
Showing with 25 additions and 25 deletions.
  1. +11 −11 src/usb_moded-config.c
  2. +4 −4 src/usb_moded-config.h
  3. +10 −10 src/usb_moded-network.c
@@ -41,8 +41,8 @@
#include "usb_moded-modes.h"

static int get_conf_int(const gchar *entry, const gchar *key);
static const char * get_conf_string(const gchar *entry, const gchar *key);
static const char * get_kcmdline_string(const char *entry);
static char * get_conf_string(const gchar *entry, const gchar *key);
static char * get_kcmdline_string(const char *entry);

static int validate_ip(const char *ipadd)
{
@@ -132,31 +132,31 @@ const char * get_trigger_value(void)
return(get_conf_string(TRIGGER_ENTRY, TRIGGER_PROPERTY_VALUE_KEY));
}

const char * get_network_ip(void)
char * get_network_ip(void)
{
const char * ip = get_kcmdline_string(NETWORK_IP_KEY);
char * ip = get_kcmdline_string(NETWORK_IP_KEY);
if (ip != NULL)
if(!validate_ip(ip))
return(ip);

return(get_conf_string(NETWORK_ENTRY, NETWORK_IP_KEY));
}

const char * get_network_interface(void)
char * get_network_interface(void)
{
return(get_conf_string(NETWORK_ENTRY, NETWORK_INTERFACE_KEY));
}

const char * get_network_gateway(void)
char * get_network_gateway(void)
{
const char * gw = get_kcmdline_string(NETWORK_GATEWAY_KEY);
char * gw = get_kcmdline_string(NETWORK_GATEWAY_KEY);
if (gw != NULL)
return(gw);

return(get_conf_string(NETWORK_ENTRY, NETWORK_GATEWAY_KEY));
}

const char * get_network_nat_interface(void)
char * get_network_nat_interface(void)
{
return(get_conf_string(NETWORK_ENTRY, NETWORK_NAT_INTERFACE_KEY));
}
@@ -225,7 +225,7 @@ static int get_conf_int(const gchar *entry, const gchar *key)

}

static const char * get_conf_string(const gchar *entry, const gchar *key)
static char * get_conf_string(const gchar *entry, const gchar *key)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
@@ -262,11 +262,11 @@ static const char * get_conf_string(const gchar *entry, const gchar *key)

}

static const char * get_kcmdline_string(const char *entry)
static char * get_kcmdline_string(const char *entry)
{
int fd;
char cmdLine[1024];
const char *ret = NULL;
char *ret = NULL;
int len;
gint argc = 0;
gchar **argv = NULL;
@@ -74,10 +74,10 @@ const char * get_trigger_mode(void);
const char * get_trigger_property(void);
const char * get_trigger_value(void);

const char * get_network_ip(void);
const char * get_network_interface(void);
const char * get_network_gateway(void);
const char * get_network_nat_interface(void);
char * get_network_ip(void);
char * get_network_interface(void);
char * get_network_gateway(void);
char * get_network_nat_interface(void);

const char * get_android_manufacturer(void);
const char * get_android_vendor_id(void);
@@ -131,7 +131,7 @@ static char* get_interface(struct mode_list_elem *data)
*/
static int set_usb_ip_forward(struct mode_list_elem *data, struct ipforward_data *ipforward)
{
const char *interface, *nat_interface;
char *interface, *nat_interface;
char command[128];

interface = get_interface(data);
@@ -158,8 +158,8 @@ static int set_usb_ip_forward(struct mode_list_elem *data, struct ipforward_data
snprintf(command, 128, "/sbin/iptables -A FORWARD -i %s -o %s -j ACCEPT", interface, nat_interface);
system(command);

free((char *)interface);
free((char *)nat_interface);
free(interface);
free(nat_interface);
log_debug("ipforwarding success!\n");
return(0);
}
@@ -301,7 +301,7 @@ static int resolv_conf_dns(struct ipforward_data *ipforward)
static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_elem *data)
{
FILE *conffile;
const char *ip, *interface;
char *ip, *interface;
char *ipstart, *ipend;
int dot = 0, i = 0, test;
struct stat st;
@@ -361,8 +361,8 @@ static int write_udhcpd_conf(struct ipforward_data *ipforward, struct mode_list_

free(ipstart);
free(ipend);
free((char*)ip);
free((char*)interface);
free(ip);
free(interface);
fclose(conffile);
log_debug("/etc/udhcpd.conf written.\n");

@@ -832,7 +832,7 @@ static int append_variant(DBusMessageIter *iter, const char *property,
*/
int usb_network_up(struct mode_list_elem *data)
{
const char *ip = NULL, *gateway = NULL;
char *ip = NULL, *gateway = NULL;
int ret = -1;

#if CONNMAN_WORKS_BETTER
@@ -939,11 +939,11 @@ int usb_network_up(struct mode_list_elem *data)
}
dbus_connection_unref(dbus_conn_connman);
dbus_error_free(&error);
free((char *)service);
free(service);
if(ip)
free((char *)ip);
free(ip);
if(gateway)
free((char *)gateway);
free(gateway);
return(ret);

#else

0 comments on commit c2fe327

Please sign in to comment.