%% options
copyright owner = Dirk Krause
copyright year = 2015-xxxx
license = bsd
%% header
/** @file
Retrieve host name in wchar_t characters.
CRT on Windows: Not used.
*/
#ifndef DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif
#ifndef DK4TYPES_H_INCLUDED
#include "dk4types.h"
#endif
#ifndef DK4ERROR_H_INCLUDED
#include "dk4error.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/** Retrieve host name (short host name without any domain).
@param buffer Result buffer.
@param sz Result buffer size (number of wchar_t).
@param erp Error report, may be NULL.
@return 1 on success, 0 on error.
Error codes:
- DK4_E_INVALID_ARGUMENTS
if buffer is NULL or sz is 0 or sz is too large,
- DK4_E_NOT_FOUND
if the system function to retrieve the host name failed,
- DK4_E_BUFFER_TOO_SMALL
if the result buffer is too small.
*/
int
dk4hostname_wc(wchar_t *buffer, size_t sz, dk4_er_t *erp);
#ifdef __cplusplus
}
#endif
%% module
#include "dk4hnamew.h"
#if DK4_ON_WINDOWS
#ifndef WINDOWS_H_INCLUDED
#include
#define WINDOWS_H_INCLUDED 1
#endif
#endif
#if DK4_HAVE_UNISTD_H
#ifndef UNISTD_H_INCLUDED
#include
#define UNISTD_H_INCLUDED 1
#endif
#endif
int
dk4hostname_wc(wchar_t *buffer, size_t sz, dk4_er_t *erp)
{
#if DK4_ON_WINDOWS
DWORD s;
#endif
int back = 0;
if ((NULL != buffer) && (0 < sz)) {
#if DK4_ON_WINDOWS
if ((dk4_um_t)sz <= (dk4_um_t)0xFFFFFFFFUL) {
s = (DWORD)sz;
if (GetComputerNameExW(ComputerNameNetBIOS, buffer, &s)) {
if ((size_t)s < sz) {
buffer[(size_t)s] = L'\0';
back = 1;
} else {
dk4error_set_simple_error_code(erp, DK4_E_BUFFER_TOO_SMALL);
}
} else {
dk4error_set_simple_error_code(erp, DK4_E_NOT_FOUND);
}
} else {
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
#else
dk4error_set_simple_error_code(erp, DK4_E_NOT_SUPPORTED);
#endif
} else {
dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS);
}
return back;
}