0
0
mirror of https://github.com/libretro/Lakka-LibreELEC.git synced 2025-03-01 06:51:22 +00:00
Lakka-LibreELEC/packages/addons/service/usbmuxd/patches/usbmuxd-0001-remove-duplicate-functions.patch
2020-11-01 19:37:08 +01:00

208 lines
4.2 KiB
Diff

diff --git a/src/utils.c b/src/utils.c
index 206c684..2ce59ff 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -160,170 +160,6 @@ char *stpcpy(char * s1, const char * s2)
}
#endif
-/**
- * Concatenate strings into a newly allocated string
- *
- * @note: Specify NULL for the last string in the varargs list
- *
- * @str: The first string in the list
- * @...: Subsequent strings. Use NULL for the last item.
- *
- * @return a newly allocated string, or NULL if @str is NULL. This will also
- * return NULL and set errno to ENOMEM if memory is exhausted.
- */
-char *string_concat(const char *str, ...)
-{
- size_t len;
- va_list args;
- char *s;
- char *result;
- char *dest;
-
- if (!str)
- return NULL;
-
- /* Compute final length */
-
- len = strlen(str) + 1; /* plus 1 for the null terminator */
-
- va_start(args, str);
- s = va_arg(args, char *);
- while (s) {
- len += strlen(s);
- s = va_arg(args, char*);
- }
- va_end(args);
-
- /* Concat each string */
-
- result = malloc(len);
- if (!result)
- return NULL; /* errno remains set */
-
- dest = result;
-
- dest = stpcpy(dest, str);
-
- va_start(args, str);
- s = va_arg(args, char *);
- while (s) {
- dest = stpcpy(dest, s);
- s = va_arg(args, char *);
- }
- va_end(args);
-
- return result;
-}
-
-int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length)
-{
- FILE *f;
- uint64_t size;
-
- *length = 0;
-
- f = fopen(filename, "rb");
- if (!f) {
- return 0;
- }
-
- fseek(f, 0, SEEK_END);
- size = ftell(f);
- rewind(f);
-
- if (size == 0) {
- fclose(f);
- return 0;
- }
-
- *buffer = (char*)malloc(sizeof(char)*(size+1));
-
- if (!buffer) {
- return 0;
- }
-
- int ret = 1;
- if (fread(*buffer, sizeof(char), size, f) != size) {
- usbmuxd_log(LL_ERROR, "%s: ERROR: couldn't read %d bytes from %s", __func__, (int)size, filename);
- free(*buffer);
- ret = 0;
- errno = EIO;
- }
- fclose(f);
-
- *length = size;
- return ret;
-}
-
-int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length)
-{
- FILE *f;
-
- f = fopen(filename, "wb");
- if (f) {
- size_t written = fwrite(buffer, sizeof(char), length, f);
- fclose(f);
-
- if (written == length) {
- return 1;
- }
- else {
- // Not all data could be written.
- errno = EIO;
- return 0;
- }
- }
- else {
- // Failed to open the file, let the caller know.
- return 0;
- }
-}
-
-int plist_read_from_filename(plist_t *plist, const char *filename)
-{
- char *buffer = NULL;
- uint64_t length;
-
- if (!filename)
- return 0;
-
- if (!buffer_read_from_filename(filename, &buffer, &length)) {
- return 0;
- }
-
- if ((length > 8) && (memcmp(buffer, "bplist00", 8) == 0)) {
- plist_from_bin(buffer, length, plist);
- } else {
- plist_from_xml(buffer, length, plist);
- }
-
- free(buffer);
-
- return 1;
-}
-
-int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format)
-{
- char *buffer = NULL;
- uint32_t length;
-
- if (!plist || !filename)
- return 0;
-
- if (format == PLIST_FORMAT_XML)
- plist_to_xml(plist, &buffer, &length);
- else if (format == PLIST_FORMAT_BINARY)
- plist_to_bin(plist, &buffer, &length);
- else
- return 0;
-
- int res = buffer_write_to_filename(filename, buffer, length);
-
- free(buffer);
-
- return res;
-}
-
#ifndef HAVE_CLOCK_GETTIME
typedef int clockid_t;
#define CLOCK_MONOTONIC 1
diff --git a/src/utils.h b/src/utils.h
index b5cab3f..f862271 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <libimobiledevice/utils.h>
+
#ifndef UTILS_H
#define UTILS_H
@@ -73,18 +75,6 @@ void collection_copy(struct collection *dest, struct collection *src);
#ifndef HAVE_STPCPY
char *stpcpy(char * s1, const char * s2);
#endif
-char *string_concat(const char *str, ...);
-
-int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length);
-int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length);
-
-enum plist_format_t {
- PLIST_FORMAT_XML,
- PLIST_FORMAT_BINARY
-};
-
-int plist_read_from_filename(plist_t *plist, const char *filename);
-int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format);
uint64_t mstime64(void);
void get_tick_count(struct timeval * tv);