Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 424321 | Differences between
and this patch

Collapse All | Expand All

(-)file_not_specified_in_diff (-85 / +2 lines)
Line  Link Here
0
-- hatari-1.4.0.orig/src/paths.c
0
++ hatari-1.4.0/src/paths.c
Lines 109-179 Link Here
109
	free(pTmpName);
109
	free(pTmpName);
110
}
110
}
111
111
112
113
/**
114
 * Locate the directory where the hatari executable resides
115
 */
116
static char *Paths_InitExecDir(const char *argv0)
117
{
118
	char *psExecDir;  /* Path string where the hatari executable can be found */
119
120
	/* Allocate memory for storing the path string of the executable */
121
	psExecDir = malloc(FILENAME_MAX);
122
	if (!psExecDir)
123
	{
124
		fprintf(stderr, "Out of memory (Paths_Init)\n");
125
		exit(-1);
126
	}
127
128
	/* Determine the bindir...
129
	 * Start with empty string, then try to use OS specific functions,
130
	 * and finally analyze the PATH variable if it has not been found yet. */
131
	psExecDir[0] = '\0';
132
133
#if defined(__linux__)
134
	{
135
		int i;
136
		/* On Linux, we can analyze the symlink /proc/self/exe */
137
		i = readlink("/proc/self/exe", psExecDir, FILENAME_MAX);
138
		if (i > 0)
139
		{
140
			char *p;
141
			psExecDir[i] = '\0';
142
			p = strrchr(psExecDir, '/');    /* Search last slash */
143
			if (p)
144
				*p = 0;                     /* Strip file name from path */
145
		}
146
	}
147
//#elif defined(WIN32) || defined(__CEGCC__)
148
//	/* On Windows we can use GetModuleFileName for getting the exe path */
149
//	GetModuleFileName(NULL, psExecDir, FILENAME_MAX);
150
#endif
151
152
	/* If we do not have the execdir yet, analyze argv[0] and the PATH: */
153
	if (psExecDir[0] == 0)
154
	{
155
		if (strchr(argv0, PATHSEP) == 0)
156
		{
157
			/* No separator in argv[0], we have to explore PATH... */
158
			Paths_GetExecDirFromPATH(argv0, psExecDir, FILENAME_MAX);
159
		}
160
		else
161
		{
162
			/* There was a path separator in argv[0], so let's assume a
163
			 * relative or absolute path to the current directory in argv[0] */
164
			char *p;
165
			strncpy(psExecDir, argv0, FILENAME_MAX);
166
			psExecDir[FILENAME_MAX-1] = 0;
167
			p = strrchr(psExecDir, PATHSEP);  /* Search last slash */
168
			if (p)
169
				*p = 0;                       /* Strip file name from path */
170
		}
171
	}
172
173
	return psExecDir;
174
}
175
176
177
/**
112
/**
178
 * Initialize the users home directory string
113
 * Initialize the users home directory string
179
 * and Hatari's home directory (~/.hatari)
114
 * and Hatari's home directory (~/.hatari)
Lines 226-233 Link Here
226
 */
161
 */
227
void Paths_Init(const char *argv0)
162
void Paths_Init(const char *argv0)
228
{
163
{
229
	char *psExecDir;  /* Path string where the hatari executable can be found */
230
231
	/* Init working directory string */
164
	/* Init working directory string */
232
	if (getcwd(sWorkingDir, FILENAME_MAX) == NULL)
165
	if (getcwd(sWorkingDir, FILENAME_MAX) == NULL)
233
	{
166
	{
Lines 238-264 Link Here
238
	/* Init the user's home directory string */
171
	/* Init the user's home directory string */
239
	Paths_InitHomeDirs();
172
	Paths_InitHomeDirs();
240
173
241
	/* Get the directory where the executable resides */
174
	strcpy(sDataDir, BIN2DATADIR);
242
	psExecDir = Paths_InitExecDir(argv0);
243
244
	/* Now create the datadir path name from the bindir path name: */
245
	if (psExecDir && strlen(psExecDir) > 0)
246
	{
247
		snprintf(sDataDir, sizeof(sDataDir), "%s%c%s",
248
		         psExecDir, PATHSEP, BIN2DATADIR);
249
	}
250
	else
251
	{
252
		/* bindir could not be determined, let's assume datadir is relative
253
		 * to current working directory... */
254
		strcpy(sDataDir, BIN2DATADIR);
255
	}
256
175
257
	/* And finally make a proper absolute path out of datadir: */
176
	/* And finally make a proper absolute path out of datadir: */
258
	File_MakeAbsoluteName(sDataDir);
177
	File_MakeAbsoluteName(sDataDir);
259
178
260
	free(psExecDir);
261
262
	/* fprintf(stderr, " WorkingDir = %s\n DataDir = %s\n UserHomeDir = %s\n HatariHomeDir = %s\n",
179
	/* fprintf(stderr, " WorkingDir = %s\n DataDir = %s\n UserHomeDir = %s\n HatariHomeDir = %s\n",
263
	        sWorkingDir, sDataDir, sUserHomeDir, sHatariHomeDir); */
180
	        sWorkingDir, sDataDir, sUserHomeDir, sHatariHomeDir); */
264
}
181
}

Return to bug 424321