static gchar *get_unseen_seq_name(void) { static gchar *seq_name = NULL; if (!seq_name) { gchar buf[BUFFSIZE]; gchar *tmp; gchar *profile_path = g_strconcat( get_home_dir(), G_DIR_SEPARATOR_S, ".mh_profile", NULL); FILE *fp = g_fopen(profile_path, "r"); if (fp) { while (fgets(buf, sizeof(buf), fp) != NULL) { if (!strncmp(buf, "Unseen-Sequence:", strlen("Unseen-Sequence:"))) { gchar *seq_tmp = buf+strlen("Unseen-Sequence:"); while (*seq_tmp == ' ') seq_tmp++; seq_name = g_strdup(seq_tmp); seq_name = strretchomp(seq_name); break; } } fclose(fp); } if (!seq_name) seq_name = g_strdup("unseen"); tmp = g_strdup_printf("%s:", seq_name); g_free(seq_name); seq_name = tmp; } return seq_name; }
/* * Attempt to find a valid JPilot file. * Return: Filename, or home directory if not found, or empty string if * no home. Filename should be g_free() when done. */ gchar *jpilot_find_pilotdb( void ) { const gchar *homedir; gchar str[ WORK_BUFLEN ]; gint len; FILE *fp; homedir = get_home_dir(); if( ! homedir ) return g_strdup( "" ); strcpy( str, homedir ); len = strlen( str ); if( len > 0 ) { if( str[ len-1 ] != G_DIR_SEPARATOR ) { str[ len ] = G_DIR_SEPARATOR; str[ ++len ] = '\0'; } } strcat( str, JPILOT_DBHOME_DIR ); strcat( str, G_DIR_SEPARATOR_S ); strcat( str, JPILOT_DBHOME_FILE ); /* Attempt to open */ if( ( fp = g_fopen( str, "rb" ) ) != NULL ) { fclose( fp ); } else { /* Truncate filename */ str[ len ] = '\0'; } return g_strdup( str ); }
static char* get_current_short_dir() { static char path[STR_PATH_SIZE]; char *home_dir; char *current_dir; int home_dir_len; int current_dir_len; home_dir = get_home_dir(); current_dir = get_current_dir(); home_dir_len = strlen(home_dir); current_dir_len = strlen(current_dir); if( current_dir_len >= home_dir_len && strncmp(home_dir, current_dir, home_dir_len) == 0 ) { path[0] = '~'; strcpy(path+1, current_dir+home_dir_len); } else { strcpy(path, current_dir); } return path; }
/* * rpmemd_config_read -- read config from cl and config files * * cl param overwrites configuration from any config file. Config file are read * in order: * 1. Global config file * 2. User config file * or * cl provided config file */ int rpmemd_config_read(struct rpmemd_config *config, int argc, char *argv[]) { const char *cl_config_file = NULL; char user_config_file[PATH_MAX]; char home_dir[PATH_MAX]; uint64_t cl_options = 0; get_home_dir(home_dir, PATH_MAX); config_set_default(config, home_dir); parse_cl_args(argc, argv, config, &cl_config_file, &cl_options); if (cl_config_file) { if (parse_config_file(cl_config_file, config, cl_options, 1)) return 1; } else { if (parse_config_file(RPMEMD_GLOBAL_CONFIG_FILE, config, cl_options, 0)) return 1; concat_dir_and_file_name(user_config_file, PATH_MAX, home_dir, RPMEMD_USER_CONFIG_FILE); if (parse_config_file(user_config_file, config, cl_options, 0)) return 1; } config->poolset_dir = str_replace_home(config->poolset_dir, home_dir); return 0; }
int xdg_user_config_dir(char **ret, const char *suffix) { const char *e; char *j; int r; assert(ret); e = getenv("XDG_CONFIG_HOME"); if (e) j = strappend(e, suffix); else { _cleanup_free_ char *home = NULL; r = get_home_dir(&home); if (r < 0) return r; j = strjoin(home, "/.config", suffix); } if (!j) return -ENOMEM; *ret = j; return 0; }
static void telnet_load_history(struct telnet_connection *t_con) { FILE *histfp; char buffer[TELNET_BUFFER_SIZE]; int i = 0; char *history = get_home_dir(TELNET_HISTORY); if (history == NULL) { LOG_INFO("unable to get user home directory, telnet history will be disabled"); return; } histfp = fopen(history, "rb"); if (histfp) { while (fgets(buffer, sizeof(buffer), histfp) != NULL) { char *p = strchr(buffer, '\n'); if (p) *p = '\0'; if (buffer[0] && i < TELNET_LINE_HISTORY_SIZE) t_con->history[i++] = strdup(buffer); } t_con->next_history = i; t_con->next_history %= TELNET_LINE_HISTORY_SIZE; /* try to set to last entry - 1, that way we skip over any exit/shutdown cmds */ t_con->current_history = t_con->next_history > 0 ? i - 1 : 0; fclose(histfp); } free(history); }
static void readline_init(void) { rl_readline_name = "augtool"; rl_attempted_completion_function = readline_completion; rl_completion_entry_function = readline_path_generator; /* Set up persistent history */ char *home_dir = get_home_dir(getuid()); char *history_dir = NULL; if (home_dir == NULL) goto done; if (xasprintf(&history_dir, "%s/.augeas", home_dir) < 0) goto done; if (mkdir(history_dir, 0755) < 0 && errno != EEXIST) goto done; if (xasprintf(&history_file, "%s/history", history_dir) < 0) goto done; stifle_history(500); read_history(history_file); done: free(home_dir); free(history_dir); }
static char *specifier_user_home(char specifier, void *data, void *userdata) { Unit *u = userdata; ExecContext *c; int r; const char *username, *home; assert(u); c = unit_get_exec_context(u); /* return HOME if set, otherwise from passwd */ if (!c || !c->user) { char *h; r = get_home_dir(&h); if (r < 0) return NULL; return h; } username = c->user; r = get_user_creds(&username, NULL, NULL, &home, NULL); if (r < 0) return NULL; return strdup(home); }
static const char* pick_shader_id() { char filename[4096]; snprintf(filename, sizeof(filename), "%s/.wip24/shaders.txt", get_home_dir()); FILE* file = fopen(filename, "r"); if (!file) return NULL; static char ids[4096][8]; size_t id_count = 0; while (id_count<4096) { char id[8] = {0}; int c; while ((c=fgetc(file)) != '\n') { if (c == EOF) goto end; if (strlen(id)<7) id[strlen(id)] = c; } if (id[0] != '#') strcpy(ids[id_count++], id); } end: ; fclose(file); if (!id_count) return NULL; return ids[ya_random()%id_count]; }
char *file_find(const char *filename) { size_t i, max_len; char *full_path = (char*) calloc(1, PATH_MAX_LEN + 1); for (i = 0; i < ARRAY_SIZE(search_paths); i++) { memset(full_path, 0, PATH_MAX_LEN); max_len = PATH_MAX_LEN - 1; if (search_paths[i].prepend_home) { max_len -= get_home_dir(full_path, max_len); } strncat(full_path, search_paths[i].path, max_len); max_len = PATH_MAX_LEN - strlen(full_path); strncat(full_path, filename, max_len); if (access(full_path, ACCESS_FILE_EXISTS) != -1) { return full_path; } } free(full_path); return NULL; }
/* Transforms a tab complete starting with the shorthand "~" into the full home directory. */ static void complete_home_dir(ToxWindow *self, char *path, int pathsize, const char *cmd, int cmdlen) { ChatContext *ctx = self->chatwin; char homedir[MAX_STR_SIZE] = {0}; get_home_dir(homedir, sizeof(homedir)); char newline[MAX_STR_SIZE]; snprintf(newline, sizeof(newline), "%s %s%s", cmd, homedir, path + 1); snprintf(path, pathsize, "%s", &newline[cmdlen-1]); wchar_t wline[MAX_STR_SIZE]; if (mbs_to_wcs_buf(wline, newline, sizeof(wline) / sizeof(wchar_t)) == -1) { return; } int newlen = wcslen(wline); if (ctx->len + newlen >= MAX_STR_SIZE) { return; } wmemcpy(ctx->line, wline, newlen + 1); ctx->pos = newlen; ctx->len = ctx->pos; }
int xdg_user_data_dir(char **ret, const char *suffix) { const char *e; char *j; int r; assert(ret); assert(suffix); /* We don't treat /etc/xdg/systemd here as the spec * suggests because we assume that is a link to * /etc/systemd/ anyway. */ e = getenv("XDG_DATA_HOME"); if (e) j = strappend(e, suffix); else { _cleanup_free_ char *home = NULL; r = get_home_dir(&home); if (r < 0) return r; j = strjoin(home, "/.local/share", suffix); } if (!j) return -ENOMEM; *ret = j; return 1; }
void set_last_session_user(char *user, char *session) { if (last_session_policy == LS_NONE) return; if (!session) return; /* we write last session in user home dir */ if (user) { char *filename; FILE *fp; char *homedir = get_home_dir(user); if (homedir) { filename = (char *) calloc(strlen(homedir)+8, sizeof(char)); strcpy(filename, homedir); free(homedir); if (filename[strlen(filename)-1] != '/') strcat(filename, "/"); strcat(filename, ".qingy"); fp = fopen(filename, "w"); free(filename); if (fp) { fprintf(fp, "%s", session); fclose(fp); } } } }
static void foldersel_cb(GtkWidget *widget, gpointer data) { struct ArchiverPrefsPage *page = (struct ArchiverPrefsPage *) data; gchar *startdir = NULL; gchar *dirname; gchar *tmp; if (archiver_prefs.save_folder && *archiver_prefs.save_folder) startdir = g_strconcat(archiver_prefs.save_folder, G_DIR_SEPARATOR_S, NULL); else startdir = g_strdup(get_home_dir()); dirname = filesel_select_file_save_folder(_("Select destination folder"), startdir); if (!dirname) { g_free(startdir); return; } if (!is_dir_exist(dirname)) { alertpanel_error(_("'%s' is not a directory."),dirname); g_free(dirname); g_free(startdir); return; } if (dirname[strlen(dirname)-1] == G_DIR_SEPARATOR) dirname[strlen(dirname)-1] = '\0'; g_free(startdir); tmp = g_filename_to_utf8(dirname,-1, NULL, NULL, NULL); gtk_entry_set_text(GTK_ENTRY(page->save_folder), tmp); g_free(dirname); g_free(tmp); }
/* transforms a sendfile tab complete contaning the shorthand "~/" into the full home directory.*/ static void complt_home_dir(ToxWindow *self, char *path, int pathsize) { ChatContext *ctx = self->chatwin; char homedir[MAX_STR_SIZE]; get_home_dir(homedir, sizeof(homedir)); char newline[MAX_STR_SIZE]; snprintf(newline, sizeof(newline), "/sendfile \"%s%s", homedir, path + 1); snprintf(path, pathsize, "%s", &newline[11]); wchar_t wline[MAX_STR_SIZE]; if (mbs_to_wcs_buf(wline, newline, sizeof(wline)) == -1) return; int newlen = wcslen(wline); if (ctx->len + newlen >= MAX_STR_SIZE) return; wmemcpy(ctx->line, wline, newlen + 1); ctx->pos = newlen; ctx->len = ctx->pos; }
void SetupLoad (void) { char cfgfile[PATH_MAX]; char line2[2048]; FILE *cfg_fp; int n = 0; for (n = 0; n < G_LAST; n++) { ExpanderStat[n] = 0; } char homedir[PATH_MAX]; get_home_dir(homedir); setlocale(LC_NUMERIC, "C"); snprintf(cfgfile, PATH_MAX, "%s%s.cammill.cfg", homedir, DIR_SEP); cfg_fp = fopen(cfgfile, "r"); if (cfg_fp == NULL) { // fprintf(stderr, "Can not read Setup: %s\n", cfgfile); } else { char *line = NULL; size_t len = 0; ssize_t read; while ((read = getline(&line, &len, cfg_fp)) != -1) { trimline(line2, 1024, line); if (strncmp(line2, "GUI|PANED|Position", 18) == 0) { PannedStat = atoi(strstr(line2, "=") + 1); } else if (strncmp(line2, "GUI|EXPANDER|", 13) == 0) { int gn = 0; for (gn = 0; gn < G_LAST; gn++) { if (strncmp(line2 + 13, GROUPS[gn].name, strlen(GROUPS[gn].name)) == 0) { ExpanderStat[gn] = atoi(strstr(line2, "=") + 1); } } } else { for (n = 0; n < P_LAST; n++) { char name_str[1024]; if (strcmp(PARAMETER[n].group, "Objects") != 0) { snprintf(name_str, sizeof(name_str), "%s|%s=", PARAMETER[n].group, PARAMETER[n].name); if (strncmp(line2, name_str, strlen(name_str)) == 0) { if (PARAMETER[n].type == T_FLOAT) { PARAMETER[n].vfloat = atof(line2 + strlen(name_str)); } else if (PARAMETER[n].type == T_DOUBLE) { PARAMETER[n].vdouble = atof(line2 + strlen(name_str)); } else if (PARAMETER[n].type == T_INT) { PARAMETER[n].vint = atoi(line2 + strlen(name_str)); } else if (PARAMETER[n].type == T_SELECT) { PARAMETER[n].vint = atoi(line2 + strlen(name_str)); } else if (PARAMETER[n].type == T_BOOL) { PARAMETER[n].vint = atoi(line2 + strlen(name_str)); } else if (PARAMETER[n].type == T_STRING) { strncpy(PARAMETER[n].vstr, line2 + strlen(name_str), sizeof(PARAMETER[n].vstr)); } else if (PARAMETER[n].type == T_FILE) { strncpy(PARAMETER[n].vstr, line2 + strlen(name_str), sizeof(PARAMETER[n].vstr)); } } } } } } fclose(cfg_fp); } }
char *server_socket_fname () { char *buf = getenv(ENV_MMJVMD_DIR_NAME_ABS); char *dir = (buf != NULL && strlen(buf) > 1 ? copy_str(buf) : concat_paths(get_home_dir(), MMJVMD_DIR_NAME)); return concat_paths(dir, SERVER_SOCKET_FNAME); }
std::string clean_path( const std::string &path, bool add_trailing_slash ) { std::string retval = path; if ( retval.empty() ) return retval; #ifdef SFML_SYSTEM_WINDOWS // substitute systemroot leading %SYSTEMROOT% if (( retval.size() >= 12 ) && ( retval.compare( 0, 12, "%SYSTEMROOT%" ) == 0 )) { std::string sysroot; str_from_c( sysroot, getenv( "SystemRoot" ) ); retval.replace( 0, 12, sysroot ); } else if (( retval.size() >= 14 ) && ( retval.compare( 0, 14, "%PROGRAMFILES%" ) == 0 )) { std::string pf; str_from_c( pf, getenv( "ProgramFiles" ) ); retval.replace( 0, 14, pf ); } #endif // substitute home dir for leading ~ if (( retval.size() >= 1 ) && ( retval.compare( 0, 1, "~" ) == 0 )) retval.replace( 0, 1, get_home_dir() ); // substitute home dir for leading $HOME if (( retval.size() >= 5 ) && ( retval.compare( 0, 5, "$HOME" ) == 0 )) retval.replace( 0, 5, get_home_dir() ); if (( add_trailing_slash ) #ifdef SFML_SYSTEM_WINDOWS && (retval[retval.size()-1] != '\\') #endif && (retval[retval.size()-1] != '/') && (directory_exists(retval)) ) retval += '/'; return retval; }
/* * Get the documents directory. */ const gchar * get_documents_dir (void) { const gchar *documents_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); if (documents_dir == NULL) { documents_dir = get_home_dir (); } return documents_dir; }
static char * tilde_expand_word (char *filename) { char *dirname, *expansion, *username; int user_len; struct passwd *user_entry; if (filename == 0) return ((char *)NULL); if (*filename != '~') return (savestring (filename)); /* A leading `~/' or a bare `~' is *always* translated to the value of $HOME or the home directory of the current user, regardless of any preexpansion hook. */ if (filename[1] == '\0' || filename[1] == '/') { /* Prefix $HOME to the rest of the string. */ expansion = (char *) getenv ("HOME"); /* If there is no HOME variable, look up the directory in the password database. */ if (expansion == 0) expansion = get_home_dir (); return (glue_prefix_and_suffix (expansion, filename, 1)); } username = isolate_tilde_prefix (filename, &user_len); /* No preexpansion hook, or the preexpansion hook failed. Look in the password database. */ dirname = (char *)NULL; user_entry = getpwnam (username); if (user_entry == 0) { free (username); /* If we don't have a failure hook, or if the failure hook did not expand the tilde, return a copy of what we were passed. */ if (dirname == 0) dirname = savestring (filename); } else { free (username); dirname = glue_prefix_and_suffix (user_entry->pw_dir, filename, user_len); } #if HAVE_ENDPWENT endpwent (); #endif return (dirname); }
std::string system_posix::get_ini_name(const std::string& progname) { const char *p; if (_ini_name[0]) return _ini_name; //Already computed p = get_home_dir(progname).c_str(); strcpy(_ini_name, p); strcat(_ini_name, "."); strcat(_ini_name, progname.c_str()); return strcat(_ini_name, "rc"); }
static gchar *mh_item_get_path(Folder *folder, FolderItem *item) { gchar *folder_path, *path; gchar *real_path; cm_return_val_if_fail(folder != NULL, NULL); cm_return_val_if_fail(item != NULL, NULL); folder_path = g_strdup(LOCAL_FOLDER(folder)->rootpath); cm_return_val_if_fail(folder_path != NULL, NULL); /* FIXME: [W32] The code below does not correctly merge relative filenames; there should be a function to handle this. */ if ( !is_relative_filename (folder_path) ) { if (item->path) path = g_strconcat(folder_path, G_DIR_SEPARATOR_S, item->path, NULL); else path = g_strdup(folder_path); } else { if (item->path) path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, folder_path, G_DIR_SEPARATOR_S, item->path, NULL); else path = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, folder_path, NULL); } g_free(folder_path); real_path = mh_filename_from_utf8(path); if (!is_dir_exist(real_path) && is_dir_exist(path)) { /* mmh, older version did put utf8 filenames instead of * the correct encoding */ if (g_rename(path, real_path) == 0) folder_item_scan(item); } g_free(path); return real_path; }
static void set_shader_from_id(wip24_state* state, const char* id) { log_entry("Setting shader to %s\n", id); char cached_file[4096]; snprintf(cached_file, sizeof(cached_file), "%s/.wip24/cache/shaders/%s.json", get_home_dir(), id); FILE* cached = fopen(cached_file, "r"); if (!cached) { char url[2048]; snprintf(url, sizeof(url), "www.shadertoy.com/api/v1/shaders/%s?key=%s", id, API_KEY); char* json; size_t json_len; read_data(url, (void**)&json, &json_len); if (!json) return; set_shader_from_json(state, json, json_len); if (state->program) { cached = fopen(cached_file, "w"); fwrite(json, json_len, 1, cached); fclose(cached); } free(json); } else { fseek(cached, 0, SEEK_END); size_t size = ftell(cached); fseek(cached, 0, SEEK_SET); char *json = (char *)malloc(size); memset(json, 0, size); fread(json, 1, size, cached); set_shader_from_json(state, json, size); free(json); fclose(cached); struct stat buf; stat(cached_file, &buf); if (difftime(time(NULL), buf.st_mtime) > 172800) { //Two days remove(cached_file); log_entry("Removing cached shader %s\n", id); } } }
static _noreturn_ void add_keys(char **keys, int count) { /* command + end-of-opts + NULL + keys */ const char *home_dir = get_home_dir(); char *args[count + 3]; int i; args[0] = "/usr/bin/ssh-add"; args[1] = "--"; for (i = 0; i < count; i++) args[2 + i] = get_key_path(home_dir, keys[i]); args[2 + count] = NULL; execv(args[0], args); err(EXIT_FAILURE, "failed to launch ssh-add"); }
void wipe_last_session_file(char *user) { char *homedir = NULL; char *filename; if (!user) return; homedir = get_home_dir(user); if (!homedir) return; filename = (char *) calloc(strlen(homedir)+8, sizeof(char)); strcpy(filename, homedir); free(homedir); if (filename[strlen(filename)-1] != '/') strcat(filename, "/"); strcat(filename, ".qingy"); unlink(filename); free(filename); }
bool installer_get_target_path(struct installer *inst, char *buf, int sz) { assert(inst != NULL && buf != NULL && sz >= 0); char fname[] = "abcdef.exe"; if (!get_home_dir(buf, sz)) return false; sz -= str_len(buf); if (sz > str_len(fname)) str_cat(buf, fname); else return false; return true; }
void SetupSave (void) { char cfgfile[PATH_MAX]; FILE *cfg_fp; int n = 0; char homedir[PATH_MAX]; get_home_dir(homedir); setlocale(LC_NUMERIC, "C"); snprintf(cfgfile, PATH_MAX, "%s%s.cammill.cfg", homedir, DIR_SEP); cfg_fp = fopen(cfgfile, "w"); if (cfg_fp == NULL) { fprintf(stderr, "Can not write Setup: %s\n", cfgfile); return; } for (n = 0; n < P_LAST; n++) { char name_str[1024]; snprintf(name_str, sizeof(name_str), "%s|%s", PARAMETER[n].group, PARAMETER[n].name); if (PARAMETER[n].type == T_FLOAT) { fprintf(cfg_fp, "%s=%f\n", name_str, PARAMETER[n].vfloat); } else if (PARAMETER[n].type == T_DOUBLE) { fprintf(cfg_fp, "%s=%f\n", name_str, PARAMETER[n].vdouble); } else if (PARAMETER[n].type == T_INT) { fprintf(cfg_fp, "%s=%i\n", name_str, PARAMETER[n].vint); } else if (PARAMETER[n].type == T_SELECT) { fprintf(cfg_fp, "%s=%i\n", name_str, PARAMETER[n].vint); } else if (PARAMETER[n].type == T_BOOL) { fprintf(cfg_fp, "%s=%i\n", name_str, PARAMETER[n].vint); } else if (PARAMETER[n].type == T_STRING) { fprintf(cfg_fp, "%s=%s\n", name_str, PARAMETER[n].vstr); } else if (PARAMETER[n].type == T_FILE) { fprintf(cfg_fp, "%s=%s\n", name_str, PARAMETER[n].vstr); } } if (PARAMETER[P_O_PARAVIEW].vint == 0) { fprintf(cfg_fp, "GUI|PANED|Position=%i\n", gtk_paned_get_position(GTK_PANED(hbox))); int gn = 0; for (gn = 0; gn < G_LAST; gn++) { fprintf(cfg_fp, "GUI|EXPANDER|%s=%i\n", GROUPS[gn].name, gtk_expander_get_expanded(GTK_EXPANDER(GroupExpander[gn]))); } } fclose(cfg_fp); }
/* * Set default values. * Enter: ctl Export control data. */ static void exporthtml_default_values( ExportHtmlCtl *ctl ) { gchar *str; str = g_strconcat( get_home_dir(), G_DIR_SEPARATOR_S, DFL_DIR_CLAWS_OUT, NULL ); ctl->dirOutput = mgu_replace_string( ctl->dirOutput, str ); g_free( str ); ctl->fileHtml = mgu_replace_string( ctl->fileHtml, DFL_FILE_CLAWS_OUT ); ctl->encoding = NULL; ctl->stylesheet = EXPORT_HTML_ID_DEFAULT; ctl->nameFormat = EXPORT_HTML_FIRST_LAST; ctl->banding = TRUE; ctl->linkEMail = TRUE; ctl->showAttribs = TRUE; ctl->retVal = MGU_SUCCESS; }
/** * @brief Get the user's config directory. * * This is without a trailing slash. Resulting string must be freed. * * @return The users config dir or NULL on error. */ char *get_user_config_dir(void) { char home[NSS_BUFLEN_PASSWD] = {0}; get_home_dir(home, sizeof(home)); char *user_config_dir = NULL; size_t len = 0; # if defined(__APPLE__) len = strlen(home) + strlen("/Library/Application Support") + 1; user_config_dir = malloc(len); if (user_config_dir == NULL) return NULL; snprintf(user_config_dir, len, "%s/Library/Application Support", home); # else /* __APPLE__ */ const char *tmp = getenv("XDG_CONFIG_HOME"); if (tmp == NULL) { len = strlen(home) + strlen("/.config") + 1; user_config_dir = malloc(len); if (user_config_dir == NULL) return NULL; snprintf(user_config_dir, len, "%s/.config", home); } else { user_config_dir = strdup(tmp); } # endif /* __APPLE__ */ if (!file_exists(user_config_dir)) { free(user_config_dir); return NULL; } return user_config_dir; }
static void log_entry(const char*format, ...) { va_list list; va_list list2; va_start(list, format); va_copy(list2, list); char filename[4096]; snprintf(filename, sizeof(filename), "%s/.wip24/log.txt", get_home_dir()); FILE* file = fopen(filename, "a"); while (lockf(fileno(file), F_TLOCK, 0)<0 && errno==EAGAIN); fprintf(file, "[PID %lld] ", (long long)getpid()); vfprintf(file, format, list); lockf(fileno(file), F_ULOCK, 0); fclose(file); va_end(list); vprintf(format, list2); }