OSDN Git Service

monitor: Opencode strndupa in print_string
authorSzymon Janc <szymon.janc@tieto.com>
Wed, 31 Jul 2013 08:51:39 +0000 (10:51 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 1 Aug 2013 07:53:16 +0000 (10:53 +0300)
Strndupa is GNU extension. print_string is simple and opencoding
strndupa is not a big loss.

This fix linkage error with bionic library which doesn't provide
strndupa.

target Executable: btmon (out/target/product/grouper/obj/EXECUTABLES/
    btmon_intermediates/LINKED/btmon)
prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/../lib/gcc/
    arm-linux-androideabi/4.6.x-google/../../../../
    arm-linux-androideabi/bin/ld: out/target/product/grouper/obj/
    EXECUTABLES/btmon_intermediates/monitor/sdp.o: in function
    print_string:external/bluetooth/bluez/monitor/sdp.c:146: error:
    undefined reference to 'strndupa'
collect2: ld returned 1 exit status
make: *** [out/target/product/grouper/obj/EXECUTABLES/
    btmon_intermediates/LINKED/btmon] Error

monitor/sdp.c

index 45ee59b..4eb398b 100644 (file)
@@ -143,7 +143,11 @@ static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size)
 
 static void print_string(uint8_t indent, const uint8_t *data, uint32_t size)
 {
-       char *str = strndupa((const char *) data, size);
+       char *str = alloca(size + 1);
+
+       str[size] = '\0';
+       strncpy(str, (const char *) data, size);
+
        print_field("%*c%s [len %d]", indent, ' ', str, size);
 }