mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-11-13 07:17:28 +00:00
[common/client] windows: avoid deprecated CRT calls
This commit is contained in:
@@ -103,15 +103,13 @@ static bool string_parser(struct Option * opt, const char * str)
|
||||
|
||||
static char * int_toString(struct Option * opt)
|
||||
{
|
||||
int len = snprintf(NULL, 0, "%d", opt->value.x_int);
|
||||
char * ret = malloc(len + 1);
|
||||
if (!ret)
|
||||
char * ret;
|
||||
if (alloc_sprintf(&ret, "%d", opt->value.x_int) < 0)
|
||||
{
|
||||
DEBUG_ERROR("out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sprintf(ret, "%d", opt->value.x_int);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -122,15 +120,13 @@ static char * bool_toString(struct Option * opt)
|
||||
|
||||
static char * float_toString(struct Option * opt)
|
||||
{
|
||||
int len = snprintf(NULL, 0, "%f", opt->value.x_float);
|
||||
char * ret = malloc(len + 1);
|
||||
if (!ret)
|
||||
char * ret;
|
||||
if (alloc_sprintf(&ret, "%f", opt->value.x_float) < 0)
|
||||
{
|
||||
DEBUG_ERROR("out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sprintf(ret, "%f", opt->value.x_float);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,22 @@ FILE * lgOpenFile(const char * path, const char * mode)
|
||||
return fopen(path, mode);
|
||||
}
|
||||
|
||||
bool lgFileErrorString(int error, char * buffer, size_t size)
|
||||
{
|
||||
if (!buffer || !size)
|
||||
return false;
|
||||
|
||||
const char * message = strerror(error);
|
||||
if (!message)
|
||||
{
|
||||
buffer[0] = '\0';
|
||||
return false;
|
||||
}
|
||||
|
||||
str_copy(buffer, size, message, strlen(message));
|
||||
return true;
|
||||
}
|
||||
|
||||
StringList lgListDirectory(const char * path)
|
||||
{
|
||||
DIR * directory = opendir(path);
|
||||
|
||||
@@ -151,6 +151,15 @@ FILE * lgOpenFile(const char * path, const char * mode)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool lgFileErrorString(int error, char * buffer, size_t size)
|
||||
{
|
||||
if (!buffer || !size)
|
||||
return false;
|
||||
|
||||
buffer[0] = '\0';
|
||||
return strerror_s(buffer, size, error) == 0;
|
||||
}
|
||||
|
||||
StringList lgListDirectory(const char * path)
|
||||
{
|
||||
wchar_t * wide = widePath(path);
|
||||
|
||||
@@ -51,9 +51,14 @@ int valloc_sprintf(char ** str, const char * format, va_list ap)
|
||||
if (len < 0)
|
||||
return len;
|
||||
|
||||
*str = malloc(len + 1);
|
||||
*str = malloc((size_t)len + 1);
|
||||
if (!*str)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = vsnprintf(*str, len + 1, format, ap);
|
||||
int ret = vsnprintf(*str, (size_t)len + 1, format, ap);
|
||||
if (ret < 0)
|
||||
{
|
||||
free(*str);
|
||||
|
||||
Reference in New Issue
Block a user