diff options
author | Paul Kocialkowski <contact@paulk.fr> | 2014-02-09 13:51:38 +0100 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2014-02-09 13:51:38 +0100 |
commit | 828f125ee5957ee3f64d45329f5ac261a2a3c1a7 (patch) | |
tree | 7cb2c2433a4fae20f660dd60819350034ea1ebeb /samsung-ipc/misc.c | |
parent | 6cb0b59e3f0a7b8f2c9690b7e8d171d88d000270 (diff) | |
download | hardware_replicant_libsamsung-ipc-828f125ee5957ee3f64d45329f5ac261a2a3c1a7.tar.gz hardware_replicant_libsamsung-ipc-828f125ee5957ee3f64d45329f5ac261a2a3c1a7.tar.bz2 hardware_replicant_libsamsung-ipc-828f125ee5957ee3f64d45329f5ac261a2a3c1a7.zip |
Consistent coding style in helpers
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'samsung-ipc/misc.c')
-rw-r--r-- | samsung-ipc/misc.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/samsung-ipc/misc.c b/samsung-ipc/misc.c index 27b7341..f36403e 100644 --- a/samsung-ipc/misc.c +++ b/samsung-ipc/misc.c @@ -2,6 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2011 Simon Busch <morphis@gravedo.de> + * Copyright (C) 2014 Paul Kocialkowski <contact@paulk.fr> * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,17 +23,26 @@ #include <samsung-ipc.h> -#define DEFAULT_IMSI_LENGTH 15 - -char *ipc_misc_me_imsi_response_get_imsi(struct ipc_message_info *response) +char *ipc_misc_me_imsi_get_imsi(const void *data, size_t size) { - if (response == NULL || response->data[0] != DEFAULT_IMSI_LENGTH) + struct ipc_misc_me_imsi_header *header; + char *imsi; + size_t imsi_length; + + if (data == NULL || size < sizeof(struct ipc_misc_me_imsi_header)) return NULL; - char *buffer = (char *) malloc(sizeof(char) * DEFAULT_IMSI_LENGTH); - memcpy(buffer, &response->data[1], DEFAULT_IMSI_LENGTH); + header = (struct ipc_misc_me_imsi_header *) data; + + // header->length doesn't count the final null character + imsi_length = header->length + sizeof(char); + + imsi = (char *) calloc(1, imsi_length); + + strncpy(imsi, (char *) data + sizeof(struct ipc_misc_me_imsi_header), header->length); + imsi[header->length] = '\0'; - return buffer; + return imsi; } // vim:ts=4:sw=4:expandtab |