Commit 50276413 authored by Ivan Tyagov's avatar Ivan Tyagov

Cleanup.

parent e05da676
...@@ -6,11 +6,10 @@ ...@@ -6,11 +6,10 @@
#include <stdio.h> #include <stdio.h>
#include <open62541/server.h> #include <open62541/server.h>
unsigned long int getMilliSecondsSinceEpoch() { unsigned long int getMilliSecondsSinceEpoch() {
/* /*
* Return milli seconds since epoch. * Return milli seconds since epoch.
*/ */
struct timeval current_time; struct timeval current_time;
gettimeofday(&current_time, NULL); gettimeofday(&current_time, NULL);
unsigned long int ms = current_time.tv_sec * 1000 + current_time.tv_usec / 1000; unsigned long int ms = current_time.tv_sec * 1000 + current_time.tv_usec / 1000;
...@@ -21,8 +20,7 @@ unsigned long int getMilliSecondsSinceEpoch() { ...@@ -21,8 +20,7 @@ unsigned long int getMilliSecondsSinceEpoch() {
* *
* @param path specifies the file name given in argv[] * @param path specifies the file name given in argv[]
* @return Returns the file content after parsing */ * @return Returns the file content after parsing */
static UA_INLINE UA_ByteString static UA_INLINE UA_ByteString loadFile(const char *const path) {
loadFile(const char *const path) {
UA_ByteString fileContents = UA_STRING_NULL; UA_ByteString fileContents = UA_STRING_NULL;
/* Open the file */ /* Open the file */
...@@ -49,25 +47,29 @@ loadFile(const char *const path) { ...@@ -49,25 +47,29 @@ loadFile(const char *const path) {
return fileContents; return fileContents;
} }
char *randomString(size_t length) char *randomString(size_t length) {
{ /*
static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; * Generate a random string.
char *randomString = NULL; */
if (length) { static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
randomString = malloc(sizeof(char) * (length +1)); char *randomString = NULL;
if (randomString) { if (length) {
for (int n = 0;n < length;n++) { randomString = malloc(sizeof(char) * (length +1));
if (randomString) {
for (int n = 0;n < length;n++) {
int key = rand() % (int)(sizeof(charset) -1); int key = rand() % (int)(sizeof(charset) -1);
randomString[n] = charset[key]; randomString[n] = charset[key];
} }
randomString[length] = '\0'; randomString[length] = '\0';
}
} }
return randomString; }
return randomString;
} }
char *convertInt2Str(int my_int){ char *convertInt2Str(int my_int){
/* Convert integer to string */ /*
* Convert integer to string.
*/
int length = snprintf( NULL, 0, "%d", my_int); int length = snprintf( NULL, 0, "%d", my_int);
char *my_str = malloc(length + 1); char *my_str = malloc(length + 1);
snprintf(my_str, length + 1, "%d", my_int); snprintf(my_str, length + 1, "%d", my_int);
...@@ -75,16 +77,18 @@ char *convertInt2Str(int my_int){ ...@@ -75,16 +77,18 @@ char *convertInt2Str(int my_int){
} }
char *convertLongInt2Str(long int my_int){ char *convertLongInt2Str(long int my_int){
/* Convert integer to string */ /*
* Convert a long integer to string.
*/
int length = snprintf( NULL, 0, "%ld", my_int); int length = snprintf( NULL, 0, "%ld", my_int);
char *my_str = malloc(length + 1); char *my_str = malloc(length + 1);
snprintf(my_str, length + 1, "%ld", my_int); snprintf(my_str, length + 1, "%ld", my_int);
return my_str; return my_str;
} }
/*
* dictionary implementation based on https://gist.github.com/kylef/86784/fe97567ec9baf5c0dce3c7fcbec948e21dfcce09
// XXX: dictionary implementation based on https://gist.github.com/kylef/86784/fe97567ec9baf5c0dce3c7fcbec948e21dfcce09 */
typedef struct dict_t_struct { typedef struct dict_t_struct {
char *key; char *key;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment