⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 home.c

📁 一个很有名的浏览器
💻 C
字号:
/* Get home directory *//* $Id: home.c,v 1.53 2004/10/07 02:54:06 jonas Exp $ */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h> /* OS/2 needs this after sys/types.h */#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include "elinks.h"#include "main.h"#include "config/options.h"#include "intl/gettext/libintl.h"#include "lowlevel/home.h"#include "osdep/osdep.h"#include "util/memory.h"#include "util/string.h"unsigned char *elinks_home = NULL;int first_use = 0;static inline voidstrip_trailing_dir_sep(unsigned char *path){	int i;	for (i = strlen(path) - 1; i > 0; i--)		if (!dir_sep(path[i]))			break;	path[i + 1] = 0;}static unsigned char *test_confdir(unsigned char *home, unsigned char *path,	     unsigned char *error_message){	struct stat st;	unsigned char *confdir;	if (!path || !*path) return NULL;	if (home && *home && !dir_sep(*path))		confdir = straconcat(home, "/", path, NULL);	else		confdir = stracpy(path);	if (!confdir) return NULL;	strip_trailing_dir_sep(confdir);	if (stat(confdir, &st)) {		if (!mkdir(confdir, 0700)) {#if 0		/* I've no idea if following is needed for newly created		 * directories.  It's bad thing to do it everytime. --pasky */#ifdef HAVE_CHMOD			chmod(home_elinks, 0700);#endif#endif			return confdir;		}	} else if (S_ISDIR(st.st_mode)) {		first_use = 0;		return confdir;	}	if (error_message) {		usrerror(gettext(error_message), path, confdir);		sleep(3);	}	mem_free(confdir);	return NULL;}/* TODO: Check possibility to use <libgen.h> dirname. */static unsigned char *elinks_dirname(unsigned char *path){	int i;	unsigned char *dir;	if (!path) return NULL;	dir = stracpy(path);	if (!dir) return NULL;	for (i = strlen(dir) - 1; i >= 0; i--)		if (dir_sep(dir[i]))			break;	dir[i + 1] = 0;	return dir;}static unsigned char *get_home(void){	unsigned char *home_elinks;	unsigned char *envhome = getenv("HOME");	unsigned char *home = envhome ? stracpy(envhome)				      : elinks_dirname(path_to_exe);	if (home)		strip_trailing_dir_sep(home);	home_elinks = test_confdir(home,				   get_cmd_opt_str("config-dir"),				   N_("Commandline options -config-dir set to %s, "				      "but could not create directory %s."));	if (home_elinks) goto end;	home_elinks = test_confdir(home, getenv("ELINKS_CONFDIR"),				   N_("ELINKS_CONFDIR set to %s, "				      "but could not create directory %s."));	if (home_elinks) goto end;	home_elinks = test_confdir(home, ".elinks", NULL);	if (home_elinks) goto end;	home_elinks = test_confdir(home, "elinks", NULL);end:	if (home_elinks)		add_to_strn(&home_elinks, "/");	mem_free_if(home);	return home_elinks;}voidinit_home(void){	first_use = 1;	elinks_home = get_home();	if (!elinks_home) {		ERROR(gettext("Unable to find or create ELinks config "		      "directory. Please check if you have $HOME "		      "variable set correctly and if you have "		      "write permission to your home directory."));		sleep(3);		return;	}}voidfree_home(void){	mem_free_if(elinks_home);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -