~gnaservicesinc/tpad-project/tpad-project

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/********************************************************************************* 
 *     COPYRIGHT NOTICE:
 *     Copyright © 2018 Andrew Smith (GNA SERVICES INC) <Andrew@GNAServicesInc.com>
 *     All Rights Reserved.
 *
 *   This file, tpad_id.c , is part of tpad.
 *
 *   tpad is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   tpad is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with tpad.  If not, see <http://www.gnu.org/licenses/>.
 ********************************************************************************/
#include "tpad_headers.h"
gchar* tpad_id_get_id() {
/*
	sd_id128_t id;
	sd_id128_get_machine_app_specific(APP_ID_TPAD, &id);
	assert(sd_id128_is_null(id));
	gchar* rid = (gchar*) g_strdup_vprintf(SD_ID128_FORMAT_STR,SD_ID128_FORMAT_VAL(id));

return( (gchar*) rid);
*/
#define BUFF_SIZE_MIN 1
        sd_id128_t id;
	sd_id128_get_machine_app_specific(APP_ID_TPAD,&id);

int check=0;
size_t buffer_size = (size_t) BUFF_SIZE_MIN;

int inotdone=1;
char* buff = (char*) NULL;
char* LargerBuffer =NULL;

while (inotdone)
{
LargerBuffer = (char*) realloc(buff,buffer_size * sizeof(char));

if ( LargerBuffer != NULL){
	buff = LargerBuffer;
}
	else {
		free(buff);
		exit(1);
		}

check = snprintf(buff,buffer_size,SD_ID128_FORMAT_STR,SD_ID128_FORMAT_VAL(id));

//check = g_vsnprintf(buff,buffer_size,SD_ID128_FORMAT_STR,SD_ID128_FORMAT_VAL(id));

if (check >=0 && check < buffer_size) {
	inotdone = 0;
	break;
}
else if (check >= buffer_size){
	buffer_size = check + 1;
	continue;
}

else if (check < 0) {
	fprintf(stderr,"FAILED -- Encoding Error!\nERROR DETECTED IN tpad_id.c \nsnprintf returned less than zero in function tpad_id_get_id().\nPlease file a bug report at https://bugs.launchpad.net/tpad-project/+filebug");	 exit(1);
}

else exit(1);

}
return (buff);
//return (g_strdup(buff));

}