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 /src/common.c | |
parent | 4e23f6d1ce67d9155a2e201592dec0d963a1d822 (diff) | |
download | idevicerestore-169f60de912534baa3b6475cd116924ec9e96616.tar.gz idevicerestore-169f60de912534baa3b6475cd116924ec9e96616.tar.bz2 |
common: add simple guid generator function
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 21 |
1 files changed, 21 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; +} |