diff options
author | Nikias Bassen | 2012-02-02 00:56:03 +0100 |
---|---|---|
committer | Nikias Bassen | 2012-02-02 00:56:03 +0100 |
commit | 169f60de912534baa3b6475cd116924ec9e96616 (patch) | |
tree | 4fb29fd893353e9403ac69bc5c4313ccd9c1ed21 | |
parent | 4e23f6d1ce67d9155a2e201592dec0d963a1d822 (diff) | |
download | idevicerestore-169f60de912534baa3b6475cd116924ec9e96616.tar.gz idevicerestore-169f60de912534baa3b6475cd116924ec9e96616.tar.bz2 |
common: add simple guid generator function
-rw-r--r-- | src/common.c | 21 | ||||
-rw-r--r-- | src/common.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index 8e76697..57f465a 100644 --- a/src/common.c +++ b/src/common.c @@ -108,3 +108,24 @@ void print_progress_bar(double progress) { if(progress == 100) info("\n"); fflush(stdout); } + +#define GET_RAND(min, max) ((rand() % (max - min)) + min) + +char *generate_guid() +{ + char *guid = (char *) malloc(sizeof(char) * 37); + const char *chars = "ABCDEF0123456789"; + srand(time(NULL)); + int i = 0; + + for (i = 0; i < 36; i++) { + if (i == 8 || i == 13 || i == 18 || i == 23) { + guid[i] = '-'; + continue; + } else { + guid[i] = chars[GET_RAND(0, 16)]; + } + } + guid[36] = '\0'; + return guid; +} diff --git a/src/common.h b/src/common.h index b6873a2..5568930 100644 --- a/src/common.h +++ b/src/common.h @@ -171,6 +171,8 @@ void print_progress_bar(double progress); int read_file(const char* filename, void** data, size_t* size); int write_file(const char* filename, const void* data, size_t size); +char *generate_guid(); + extern struct idevicerestore_client_t* idevicerestore; #ifdef __cplusplus |