Move static `get_hostname()` to `BLI_hostname()` in `system.c`
This makes the `#include <Windows.h>` use more localised and out of the `image.c` file. Reviewers: LazyDodo Reviewed by: LazyDodo Differential revision: https://developer.blender.org/D4049
This commit is contained in:
parent
de491abf99
commit
6a5e809697
Notes:
blender-bot
2023-02-14 09:48:23 +01:00
Referenced by issue #59001, UV Editor - Crash when hiding all UVs while 3D view is open and sync selection enabled Referenced by issue #58985, Wireframe is not displayed correctly with reference images on empties Referenced by issue #58988, Closing Blender through preferences or multitasking in OS. Referenced by issue #58978, Text Editor - Crash when using Ctrl Z after unlinking a text block Referenced by issue #58950, wireframe/orthographic/front/side/topview crash 2.8
|
@ -35,16 +35,6 @@
|
|||
#ifndef WIN32
|
||||
# include <unistd.h>
|
||||
#else
|
||||
# ifndef NOGDI
|
||||
# define NOGDI
|
||||
# endif
|
||||
# ifndef NOMINMAX
|
||||
# define NOMINMAX
|
||||
# endif
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <Windows.h> /* for GetComputerName function */
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
|
@ -74,6 +64,7 @@
|
|||
#include "BLI_blenlib.h"
|
||||
#include "BLI_math_vector.h"
|
||||
#include "BLI_mempool.h"
|
||||
#include "BLI_system.h"
|
||||
#include "BLI_threads.h"
|
||||
#include "BLI_timecode.h" /* for stamp timecode format */
|
||||
#include "BLI_utildefines.h"
|
||||
|
@ -1566,32 +1557,6 @@ typedef struct StampData {
|
|||
} StampData;
|
||||
#undef STAMP_NAME_SIZE
|
||||
|
||||
/**
|
||||
* Obtain the hostname from the system.
|
||||
*
|
||||
* This simply determines the host's name, and doesn't do any DNS lookup of any
|
||||
* IP address of the machine. As such, it's only usable for identification
|
||||
* purposes, and not for reachability over a network.
|
||||
*
|
||||
* @param buffer Character buffer to write the hostname into.
|
||||
* @param bufsize Size of the character buffer, including trailing '\0'.
|
||||
*/
|
||||
static void get_hostname(char *buffer, size_t bufsize)
|
||||
{
|
||||
#ifndef WIN32
|
||||
if (gethostname(buffer, bufsize-1) < 0) {
|
||||
strncpy(buffer, "-unknown-", bufsize);
|
||||
}
|
||||
/* When gethostname() truncates, it doesn't guarantee the trailing \0. */
|
||||
buffer[bufsize - 1] = '\0';
|
||||
#else
|
||||
DWORD bufsize_inout = bufsize;
|
||||
if(!GetComputerName(buffer, &bufsize_inout)) {
|
||||
strncpy(buffer, "-unknown-", bufsize);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* \param do_prefix: Include a label like "File ", "Date ", etc. in the stamp data strings.
|
||||
* \param use_dynamic: Also include data that can change on a per-frame basis.
|
||||
|
@ -1744,7 +1709,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d
|
|||
|
||||
if (scene->r.stamp & R_STAMP_HOSTNAME) {
|
||||
char hostname[500]; /* sizeof(stamp_data->hostname) minus some bytes for a label. */
|
||||
get_hostname(hostname, sizeof(hostname));
|
||||
BLI_hostname_get(hostname, sizeof(hostname));
|
||||
SNPRINTF(stamp_data->hostname, do_prefix ? "Hostname %s" : "%s", hostname);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -34,6 +34,18 @@ void BLI_system_backtrace(FILE *fp);
|
|||
/* Get CPU brand, result is to be MEM_freeN()-ed. */
|
||||
char *BLI_cpu_brand_string(void);
|
||||
|
||||
/**
|
||||
* Obtain the hostname from the system.
|
||||
*
|
||||
* This simply determines the host's name, and doesn't do any DNS lookup of any
|
||||
* IP address of the machine. As such, it's only usable for identification
|
||||
* purposes, and not for reachability over a network.
|
||||
*
|
||||
* @param buffer Character buffer to write the hostname into.
|
||||
* @param bufsize Size of the character buffer, including trailing '\0'.
|
||||
*/
|
||||
void BLI_hostname_get(char *buffer, size_t bufsize);
|
||||
|
||||
/* getpid */
|
||||
#ifdef WIN32
|
||||
# define BLI_SYSTEM_PID_H <process.h>
|
||||
|
|
|
@ -31,9 +31,10 @@
|
|||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
/* for backtrace */
|
||||
/* for backtrace and gethostname/GetComputerName */
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
# include <execinfo.h>
|
||||
# include <unistd.h>
|
||||
#elif defined(WIN32)
|
||||
# include <windows.h>
|
||||
# include <dbghelp.h>
|
||||
|
@ -176,3 +177,19 @@ char *BLI_cpu_brand_string(void)
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void BLI_hostname_get(char *buffer, size_t bufsize)
|
||||
{
|
||||
#ifndef WIN32
|
||||
if (gethostname(buffer, bufsize-1) < 0) {
|
||||
BLI_strncpy(buffer, "-unknown-", bufsize);
|
||||
}
|
||||
/* When gethostname() truncates, it doesn't guarantee the trailing \0. */
|
||||
buffer[bufsize - 1] = '\0';
|
||||
#else
|
||||
DWORD bufsize_inout = bufsize;
|
||||
if(!GetComputerName(buffer, &bufsize_inout)) {
|
||||
strncpy(buffer, "-unknown-", bufsize);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue