Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
paths.cc
Go to the documentation of this file.
1/*
2 * File: paths.cc
3 *
4 * Copyright 2006-2009 Jorge Arellano Cid <jcid@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <unistd.h>
13#include <errno.h>
14#include <sys/stat.h>
15
16#include "msg.h"
17#include "../dlib/dlib.h"
18#include "paths.hh"
19
20/*
21 * Local data
22 */
23
24// Dillo works from an unmounted directory (/tmp)
25static char* oldWorkingDir = NULL;
26
31void Paths::init(void)
32{
33 char *path;
34 struct stat st;
35 int rc = 0;
36
39 rc = chdir("/tmp");
40 if (rc == -1) {
41 MSG("paths: Error changing directory to /tmp: %s\n",
42 dStrerror(errno));
43 }
44
45 path = dStrconcat(dGethomedir(), "/.dillo", NULL);
46 if (stat(path, &st) == -1) {
47 if (errno == ENOENT) {
48 MSG("paths: Creating directory '%s/'\n", path);
49 if (mkdir(path, 0700) < 0) {
50 MSG("paths: Error creating directory %s: %s\n",
51 path, dStrerror(errno));
52 }
53 } else {
54 MSG("Dillo: error reading %s: %s\n", path, dStrerror(errno));
55 }
56 }
57
58 dFree(path);
59}
60
65{
66 return oldWorkingDir;
67}
68
72void Paths::free(void)
73{
75}
76
80FILE *Paths::getPrefsFP(const char *rcFile)
81{
82 FILE *fp;
83 char *path = dStrconcat(dGethomedir(), "/.dillo/", rcFile, NULL);
84
85 if (!(fp = fopen(path, "r"))) {
86 MSG("paths: Cannot open file '%s': %s\n", path, dStrerror(errno));
87
88 char *path2 = dStrconcat(DILLO_SYSCONF, rcFile, NULL);
89 if (!(fp = fopen(path2, "r"))) {
90 MSG("paths: Cannot open file '%s': %s\n", path2, dStrerror(errno));
91 MSG("paths: Using internal defaults...\n");
92 } else {
93 MSG("paths: Using %s\n", path2);
94 }
95 dFree(path2);
96 }
97
98 dFree(path);
99 return fp;
100}
101
#define MSG(...)
Definition bookmarks.c:46
static char * getOldWorkingDir(void)
Return the initial current working directory in a string.
Definition paths.cc:64
static void init(void)
Changes current working directory to /tmp and creates ~/.dillo if not exists.
Definition paths.cc:31
static FILE * getPrefsFP(const char *rcFile)
Examines the path for "rcFile" and assign its file pointer to "fp".
Definition paths.cc:80
static void free(void)
Free memory.
Definition paths.cc:72
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
Definition dlib.c:102
void dFree(void *mem)
Definition dlib.c:68
char * dGethomedir(void)
Return the home directory in a static string (don't free)
Definition dlib.c:906
char * dGetcwd(void)
Return the current working directory in a new string.
Definition dlib.c:888
#define dStrerror
Definition dlib.h:95
static char * oldWorkingDir
Definition paths.cc:25
static void path()
Definition cookies.c:859