printf("** %d - ACL Cancel invitation Request\n", ACL_GROUP_CANCEL_INVITE);
printf("** EXIT\n");
- printf("** %d - Exit cloud %s\n\n", EXIT, title);
+ printf("** %d - Exit cloud %s\n", EXIT, title);
printf("************************************************************\n");
-
- printf(">> Enter Menu number:\n");
}
void unlockMenu(void *data)
printMenu(mode);
int request = 0;
- scanf("%d", &request);
+ readInteger(&request, "Menu number", "see above");
switch (request)
{
//in case of optional parameters absence should be sent NULL
#define OPTIONAL(str) (str[0] ? str : NULL)
+/**
+ * Skip special characters from stdin
+ * */
+static void skipSpecialCharacters()
+{
+ for( ; 0x20<=getchar(); ); // for removing overflow garbages
+ // '0x20<=code' is character region
+}
+
static bool readOptional(const char* description)
{
if (NULL == description)
while(1)
{
scanf("%c", &choice);
- getchar();
+ skipSpecialCharacters();
switch (choice)
{
char template[8] = { 0 };
snprintf(template, sizeof(template), "%%%ds", length - 1);
scanf(template, item);
- getchar();
+ skipSpecialCharacters();
}
/**
{
printf("Enter %s (f.e. %s):\n", description, example);
scanf("%d", item);
- getchar();
+ skipSpecialCharacters();
}
/**
}
//Read file contents into buffer
- size_t realLen = fread(buffer, length, 1, file);
- if (realLen != (size_t)length)
+ size_t count = 1;
+ size_t realCount = fread(buffer, length, count, file);
+ if (realCount != count)
{
- OIC_LOG_V(ERROR, TAG, "Length mismatch: read %zu instead of %d bytes", realLen, length);
+ OIC_LOG_V(ERROR, TAG, "Read %d bytes %zu times instead of %zu", length, realCount, count);
goto exit;
}