60 if (temp_dir[0] !=
'\0') {
65 if (GetTempPathA(
sizeof temp_dir, temp_dir) == 0) {
69 const char *req_tmp_dir = getenv(
"TMPDIR");
71 temp_dir[
sizeof temp_dir - 1] =
'\0';
72 strncpy(temp_dir, req_tmp_dir,
sizeof temp_dir - 1);
74 strcpy(temp_dir, P_tmpdir);
76 strncat(temp_dir,
"/",
sizeof temp_dir - strlen(temp_dir) - 1);
91 return realpath(
"/proc/self/exe", path) != NULL;
97#include <mach-o/dyld.h>
102 uint32_t raw_path_size = (uint32_t)(
sizeof(raw_path_name));
104 if (_NSGetExecutablePath(raw_path_name, &raw_path_size) != 0) {
107 return realpath(raw_path_name, path) != NULL;
121 char *last_path_delim =
strrpbrk(exec_path,
"/\\");
122 if (!last_path_delim) {
125 *last_path_delim =
'\0';
126 last_path_delim =
strrpbrk(exec_path,
"/\\");
127 if (!last_path_delim) {
130 if (strcmp(last_path_delim + 1,
"bin") == 0 || strcmp(last_path_delim + 1,
"MacOS") == 0) {
131 *last_path_delim =
'\0';
148 *filename = tmpnam(filename_buf);
149 return fopen(*filename,
"wbx");
151 *filename = filename_buf;
152 strncpy(filename_buf,
get_temp_dir(),
sizeof filename_buf - 1);
153 strncat(filename_buf,
"/uv.XXXXXX",
sizeof filename_buf - strlen(filename_buf) - 1);
154 umask(S_IRWXG|S_IRWXO);
155 int fd = mkstemp(filename_buf);
156 return fd == -1 ? NULL : fdopen(fd,
"wb");
165 const char *
const home = getenv(
"HOME");
166 if (strncmp(orig_path,
"~/", 2) != 0 || home == NULL) {
167 return strdup(orig_path);
171 assert(new_path != NULL);
173 strncat(new_path, orig_path + 1,
MAX_PATH_SIZE - strlen(new_path) - 1);
char * strdup_path_with_expansion(const char *orig_path)
const char * get_install_root(void)
const char * get_temp_dir(void)
FILE * get_temp_file(const char **filename)
int get_exec_path(char *path)
char * strrpbrk(char *s, const char *accept)
same as strpbrk but finds in a reverse order (last occurence returned)