ext/libuv/src/unix/freebsd.c in libuv-1.3.0 vs ext/libuv/src/unix/freebsd.c in libuv-2.0.0

- old
+ new

@@ -72,31 +72,48 @@ clock_gettime(CLOCK_MONOTONIC, &ts); return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } +#ifdef __DragonFly__ int uv_exepath(char* buffer, size_t* size) { char abspath[PATH_MAX * 2 + 1]; + ssize_t abspath_size; + + if (buffer == NULL || size == NULL || *size == 0) + return -EINVAL; + + abspath_size = readlink("/proc/curproc/file", abspath, sizeof(abspath)); + if (abspath_size < 0) + return -errno; + + assert(abspath_size > 0); + *size -= 1; + + if (*size > abspath_size) + *size = abspath_size; + + memcpy(buffer, abspath, *size); + buffer[*size] = '\0'; + + return 0; +} +#else +int uv_exepath(char* buffer, size_t* size) { + char abspath[PATH_MAX * 2 + 1]; int mib[4]; size_t abspath_size; if (buffer == NULL || size == NULL || *size == 0) return -EINVAL; -#ifdef __DragonFly__ mib[0] = CTL_KERN; mib[1] = KERN_PROC; - mib[2] = KERN_PROC_ARGS; - mib[3] = getpid(); -#else - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; -#endif - abspath_size = sizeof abspath;; + abspath_size = sizeof abspath; if (sysctl(mib, 4, abspath, &abspath_size, NULL, 0)) return -errno; assert(abspath_size > 0); abspath_size -= 1; @@ -108,12 +125,12 @@ memcpy(buffer, abspath, *size); buffer[*size] = '\0'; return 0; } +#endif - uint64_t uv_get_free_memory(void) { int freecount; size_t size = sizeof(freecount); if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0)) @@ -149,20 +166,20 @@ avg[2] = (double) info.ldavg[2] / info.fscale; } char** uv_setup_args(int argc, char** argv) { - process_title = argc ? strdup(argv[0]) : NULL; + process_title = argc ? uv__strdup(argv[0]) : NULL; return argv; } int uv_set_process_title(const char* title) { int oid[4]; if (process_title) uv__free(process_title); - process_title = strdup(title); + process_title = uv__strdup(title); oid[0] = CTL_KERN; oid[1] = KERN_PROC; oid[2] = KERN_PROC_ARGS; oid[3] = getpid(); @@ -313,11 +330,11 @@ cpu_info->cpu_times.nice = (uint64_t)(cp_times[CP_NICE+cur]) * multiplier; cpu_info->cpu_times.sys = (uint64_t)(cp_times[CP_SYS+cur]) * multiplier; cpu_info->cpu_times.idle = (uint64_t)(cp_times[CP_IDLE+cur]) * multiplier; cpu_info->cpu_times.irq = (uint64_t)(cp_times[CP_INTR+cur]) * multiplier; - cpu_info->model = strdup(model); + cpu_info->model = uv__strdup(model); cpu_info->speed = cpuspeed; cur+=CPUSTATES; } @@ -377,10 +394,10 @@ * devices. We're not interested in this information yet. */ if (ent->ifa_addr->sa_family == AF_LINK) continue; - address->name = strdup(ent->ifa_name); + address->name = uv__strdup(ent->ifa_name); if (ent->ifa_addr->sa_family == AF_INET6) { address->address.address6 = *((struct sockaddr_in6*) ent->ifa_addr); } else { address->address.address4 = *((struct sockaddr_in*) ent->ifa_addr);