internal/platform_name: move to const char*
authorThomas Ingleby <thomas.c.ingleby@intel.com>
Wed, 21 Jan 2015 15:35:54 +0000 (15:35 +0000)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Wed, 21 Jan 2015 15:35:54 +0000 (15:35 +0000)
Instead of plain char* to avoid need to malloc and do all the needed
error checking needed that goes along with that.

Signed-off-by: Thomas Ingleby <thomas.c.ingleby@intel.com>
api/mraa/common.h
src/mraa.c
src/x86/intel_de3815.c
src/x86/intel_edison_fab_c.c
src/x86/intel_galileo_rev_d.c
src/x86/intel_galileo_rev_g.c
src/x86/intel_minnow_max.c

index 86525e9..a348403 100644 (file)
@@ -175,8 +175,7 @@ typedef struct {
     int pwm_default_period; /**< The default PWM period is US */
     int pwm_max_period; /**< Maximum period in us */
     int pwm_min_period; /**< Minimum period in us */
-    unsigned int platform_name_length; /**< Platform Name length */
-    char* platform_name; /**< Platform Name pointer */
+    const char* platform_name; /**< Platform Name pointer */
     mraa_pininfo_t* pins;     /**< Pointer to pin array */
     /*@}*/
 } mraa_board_t;
index 91e48c1..d1d2598 100644 (file)
@@ -305,7 +305,7 @@ mraa_get_platform_name()
 {
     if (plat == NULL)
         return "Unknown";
-    return plat->platform_name;
+    return (char*) plat->platform_name;
 }
 
 unsigned int
index 970bf6a..669300c 100644 (file)
@@ -40,13 +40,7 @@ mraa_intel_de3815()
         return NULL;
     }
 
-    b->platform_name_length = strlen(PLATFORM_NAME) + 1;
-    b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
-    if (b->platform_name == NULL) {
-        goto error;
-    }
-    strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
-
+    b->platform_name = PLATFORM_NAME;
     b->phy_pin_count = 18;
     //b->gpio_count = 14;
     b->aio_count = 0;
index 8044248..e745af7 100644 (file)
@@ -1080,13 +1080,7 @@ mraa_intel_edison_fab_c()
         return NULL;
     }
 
-    b->platform_name_length = strlen(PLATFORM_NAME) + 1;
-    b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
-    if (b->platform_name == NULL) {
-        goto error;
-    }
-    strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
-
+    b->platform_name = PLATFORM_NAME;
     // This seciton will also check if the arduino board is there
     tristate = mraa_gpio_init_raw(214);
     if (tristate == NULL) {
index 08ddbf7..bd74625 100644 (file)
@@ -125,13 +125,7 @@ mraa_intel_galileo_rev_d()
         return NULL;
     }
 
-    b->platform_name_length = strlen(PLATFORM_NAME) + 1;
-    b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
-    if (b->platform_name == NULL) {
-        goto error;
-    }
-    strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
-
+    b->platform_name = PLATFORM_NAME;
     b->phy_pin_count = 20;
     b->gpio_count = 14;
     b->aio_count = 6;
index 414b6c5..a4d6ffb 100644 (file)
@@ -326,13 +326,7 @@ mraa_intel_galileo_gen2()
         return NULL;
     }
 
-    b->platform_name_length = strlen(PLATFORM_NAME) + 1;
-    b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
-    if (b->platform_name == NULL) {
-        goto error;
-    }
-    strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
-
+    b->platform_name = PLATFORM_NAME;
     b->phy_pin_count = 20;
     b->gpio_count = 14;
     b->aio_count = 6;
index faa9af8..57d8711 100644 (file)
@@ -87,13 +87,7 @@ mraa_intel_minnow_max()
         return NULL;
     }
 
-    b->platform_name_length = strlen(PLATFORM_NAME) + 1;
-    b->platform_name = (char*) malloc(sizeof(char) * b->platform_name_length);
-    if (b->platform_name == NULL) {
-        goto error;
-    }
-    strncpy(b->platform_name, PLATFORM_NAME, b->platform_name_length);
-
+    b->platform_name = PLATFORM_NAME;
     b->phy_pin_count = MRAA_INTEL_MINNOW_MAX_PINCOUNT;
     b->gpio_count = MRAA_INTEL_MINNOW_MAX_PINCOUNT;
     b->aio_count = 0;