XS-libuv
view release on metacpan or search on metacpan
libuv-1.49.2/src/unix/core.c view on Meta::CPAN
if (buf == NULL)
goto fail;
ptr = strchr(buf, '=');
if (ptr == NULL) {
uv__free(buf);
continue;
}
*ptr = '\0';
envitem = &(*envitems)[cnt];
envitem->name = buf;
envitem->value = ptr + 1;
cnt++;
}
*count = cnt;
return 0;
fail:
for (i = 0; i < cnt; i++) {
envitem = &(*envitems)[cnt];
uv__free(envitem->name);
}
uv__free(*envitems);
*envitems = NULL;
*count = 0;
return UV_ENOMEM;
}
int uv_os_getenv(const char* name, char* buffer, size_t* size) {
char* var;
size_t len;
if (name == NULL || buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
var = getenv(name);
if (var == NULL)
return UV_ENOENT;
len = strlen(var);
if (len >= *size) {
*size = len + 1;
return UV_ENOBUFS;
}
memcpy(buffer, var, len + 1);
*size = len;
return 0;
}
int uv_os_setenv(const char* name, const char* value) {
if (name == NULL || value == NULL)
return UV_EINVAL;
if (setenv(name, value, 1) != 0)
return UV__ERR(errno);
return 0;
}
int uv_os_unsetenv(const char* name) {
if (name == NULL)
return UV_EINVAL;
if (unsetenv(name) != 0)
return UV__ERR(errno);
return 0;
}
int uv_os_gethostname(char* buffer, size_t* size) {
/*
On some platforms, if the input buffer is not large enough, gethostname()
succeeds, but truncates the result. libuv can detect this and return ENOBUFS
instead by creating a large enough buffer and comparing the hostname length
to the size input.
*/
char buf[UV_MAXHOSTNAMESIZE];
size_t len;
if (buffer == NULL || size == NULL || *size == 0)
return UV_EINVAL;
if (gethostname(buf, sizeof(buf)) != 0)
return UV__ERR(errno);
buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */
len = strlen(buf);
if (len >= *size) {
*size = len + 1;
return UV_ENOBUFS;
}
memcpy(buffer, buf, len + 1);
*size = len;
return 0;
}
uv_os_fd_t uv_get_osfhandle(int fd) {
return fd;
}
int uv_open_osfhandle(uv_os_fd_t os_fd) {
return os_fd;
}
uv_pid_t uv_os_getpid(void) {
return getpid();
}
uv_pid_t uv_os_getppid(void) {
return getppid();
}
int uv_cpumask_size(void) {
#if UV__CPU_AFFINITY_SUPPORTED
return CPU_SETSIZE;
#else
return UV_ENOTSUP;
#endif
}
( run in 1.768 second using v1.01-cache-2.11-cpan-39bf76dae61 )