annotate path.c @ 33213:d7b577e7e644

Simplify by using FFMAX3.
author reimar
date Fri, 22 Apr 2011 16:43:14 +0000
parents 8e7537586f0b
children 139743f7e085
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12891
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
1 /*
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
2 * Get path to config dir/file.
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
3 *
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
4 * Return Values:
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
5 * Returns the pointer to the ALLOCATED buffer containing the
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
6 * zero terminated path string. This buffer has to be FREED
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
7 * by the caller.
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
8 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
9 * This file is part of MPlayer.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
10 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
11 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
12 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
14 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
15 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
16 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
19 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
20 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
21 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
22 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29212
diff changeset
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
12891
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
24 */
24242
76f5d8892c04 Clean up the way get_path is handled: Compile get_path.c to an object to link
diego
parents: 23806
diff changeset
25
76f5d8892c04 Clean up the way get_path is handled: Compile get_path.c to an object to link
diego
parents: 23806
diff changeset
26 #include <stdio.h>
76f5d8892c04 Clean up the way get_path is handled: Compile get_path.c to an object to link
diego
parents: 23806
diff changeset
27 #include <stdlib.h>
76f5d8892c04 Clean up the way get_path is handled: Compile get_path.c to an object to link
diego
parents: 23806
diff changeset
28 #include <string.h>
30591
60ad8ca441dc Add required header #include for config.h.
diego
parents: 30429
diff changeset
29 #include "config.h"
24242
76f5d8892c04 Clean up the way get_path is handled: Compile get_path.c to an object to link
diego
parents: 23806
diff changeset
30 #include "mp_msg.h"
30901
76a13038105e Rename get_path.[ch] --> path.[ch].
diego
parents: 30900
diff changeset
31 #include "path.h"
24242
76f5d8892c04 Clean up the way get_path is handled: Compile get_path.c to an object to link
diego
parents: 23806
diff changeset
32
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 27341
diff changeset
33 #ifdef CONFIG_MACOSX_BUNDLE
15237
55d9619d75e5 replace Carbon.h by coreFoundation.h, fix build with x11 enable on mac osx with --enable-macosx-bundle enable
nplourde
parents: 15145
diff changeset
34 #include <CoreFoundation/CoreFoundation.h>
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
35 #include <sys/types.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
36 #include <sys/stat.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
37 #include <unistd.h>
28364
3e3bd9da4c7e Use OS preprocessor checks with '#if defined()' consistently.
diego
parents: 27749
diff changeset
38 #elif defined(__MINGW32__)
24266
0fad7c7596be Fix linking on Windows.
diego
parents: 24242
diff changeset
39 #include <windows.h>
28364
3e3bd9da4c7e Use OS preprocessor checks with '#if defined()' consistently.
diego
parents: 27749
diff changeset
40 #elif defined(__CYGWIN__)
27722
a593f936d330 Add missing Cygwin header, fixes the warning:
diego
parents: 27397
diff changeset
41 #include <windows.h>
a593f936d330 Add missing Cygwin header, fixes the warning:
diego
parents: 27397
diff changeset
42 #include <sys/cygwin.h>
26056
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
43 #endif
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
44
30838
0bb5a351cdd7 Include osdep/osdep.h instead of checking a platfrom specific macro to include
komh
parents: 30591
diff changeset
45 #include "osdep/osdep.h"
0bb5a351cdd7 Include osdep/osdep.h instead of checking a platfrom specific macro to include
komh
parents: 30591
diff changeset
46
18889
e60c8c7399d2 get_path as const, patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents: 16872
diff changeset
47 char *get_path(const char *filename){
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
48 char *homedir;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
49 char *buff;
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
50 #ifdef __MINGW32__
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
51 static char *config_dir = "/mplayer";
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
52 #else
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
53 static char *config_dir = "/.mplayer";
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
54 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
55 int len;
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 27341
diff changeset
56 #ifdef CONFIG_MACOSX_BUNDLE
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
57 struct stat dummy;
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
58 CFIndex maxlen=256;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
59 CFURLRef res_url_ref=NULL;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
60 CFURLRef bdl_url_ref=NULL;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
61 char *res_url_path = NULL;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
62 char *bdl_url_path = NULL;
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
63 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
64
16872
9d4becb83656 Allow the user to set the $MPLAYER_HOME environment variable to point to the location
albeu
parents: 16781
diff changeset
65 if ((homedir = getenv("MPLAYER_HOME")) != NULL)
9d4becb83656 Allow the user to set the $MPLAYER_HOME environment variable to point to the location
albeu
parents: 16781
diff changeset
66 config_dir = "";
9d4becb83656 Allow the user to set the $MPLAYER_HOME environment variable to point to the location
albeu
parents: 16781
diff changeset
67 else if ((homedir = getenv("HOME")) == NULL)
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
68 #if defined(__MINGW32__) || defined(__CYGWIN__)
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
69 /* Hack to get fonts etc. loaded outside of Cygwin environment. */
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
70 {
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
71 int i,imax=0;
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
72 char exedir[260];
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
73 GetModuleFileNameA(NULL, exedir, 260);
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
74 for (i=0; i< strlen(exedir); i++)
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
75 if (exedir[i] =='\\')
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
76 {exedir[i]='/'; imax=i;}
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
77 exedir[imax]='\0';
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
78 homedir = exedir;
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
79 }
26056
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
80 #elif defined(__OS2__)
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
81 {
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
82 PPIB ppib;
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
83 char path[260];
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
84
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
85 // Get process info blocks
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
86 DosGetInfoBlocks(NULL, &ppib);
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
87
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
88 // Get full path of the executable
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
89 DosQueryModuleName(ppib->pib_hmte, sizeof( path ), path);
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
90
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
91 // Truncate name part including last backslash
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
92 *strrchr(path, '\\') = 0;
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
93
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
94 // Convert backslash to slash
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
95 _fnslashify(path);
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
96
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
97 homedir = path;
5ce6348b1a6e On OS/2, fall back on the directory where MPlayer is installed if both
diego
parents: 24267
diff changeset
98 }
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
99 #else
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
100 return NULL;
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
101 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
102 len = strlen(homedir) + strlen(config_dir) + 1;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
103 if (filename == NULL) {
23806
0a38ad149c5c Remove some more useless *alloc casts
reimar
parents: 18889
diff changeset
104 if ((buff = malloc(len)) == NULL)
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
105 return NULL;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
106 sprintf(buff, "%s%s", homedir, config_dir);
6a74454ea121 some cleanup
arpi
parents:
diff changeset
107 } else {
6a74454ea121 some cleanup
arpi
parents:
diff changeset
108 len += strlen(filename) + 1;
23806
0a38ad149c5c Remove some more useless *alloc casts
reimar
parents: 18889
diff changeset
109 if ((buff = malloc(len)) == NULL)
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
110 return NULL;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
111 sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
6a74454ea121 some cleanup
arpi
parents:
diff changeset
112 }
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
113
27397
d47744b95b78 Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents: 27341
diff changeset
114 #ifdef CONFIG_MACOSX_BUNDLE
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
115 if (stat(buff, &dummy)) {
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
116
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
117 res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
118 bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle());
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
119
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
120 if (res_url_ref&&bdl_url_ref) {
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
121
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
122 res_url_path=malloc(maxlen);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
123 bdl_url_path=malloc(maxlen);
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
124
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
125 while (!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) {
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
126 maxlen*=2;
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
127 res_url_path=realloc(res_url_path, maxlen);
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
128 }
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
129 CFRelease(res_url_ref);
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
130
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
131 while (!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) {
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
132 maxlen*=2;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
133 bdl_url_path=realloc(bdl_url_path, maxlen);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
134 }
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
135 CFRelease(bdl_url_ref);
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
136
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
137 if (strcmp(res_url_path, bdl_url_path) == 0)
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
138 res_url_path = NULL;
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
139 }
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
140
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
141 if (res_url_path&&filename) {
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
142 if ((strlen(filename)+strlen(res_url_path)+2)>maxlen) {
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
143 maxlen=strlen(filename)+strlen(res_url_path)+2;
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
144 }
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
145 free(buff);
23806
0a38ad149c5c Remove some more useless *alloc casts
reimar
parents: 18889
diff changeset
146 buff = malloc(maxlen);
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
147 strcpy(buff, res_url_path);
24267
70437b99ccee cosmetics: Fix up whitespace, indentation and similar things.
diego
parents: 24266
diff changeset
148
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
149 strcat(buff,"/");
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
150 strcat(buff, filename);
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
151 }
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
152 }
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
153 #endif
3746
d21bae2028a6 some debugging
arpi
parents: 2557
diff changeset
154 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
155 return buff;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
156 }
16781
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
157
27727
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27722
diff changeset
158 #if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
29212
eda346733b8c Add missing 'void' to parameterless function declarations.
diego
parents: 28364
diff changeset
159 void set_path_env(void)
16781
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
160 {
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
161 /*make our codec dirs available for LoadLibraryA()*/
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
162 char win32path[MAX_PATH];
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
163 #ifdef __CYGWIN__
30846
72ae3dd3aa6e Replace separate Win32, XAnim and Real codec directories by one global dir.
diego
parents: 30838
diff changeset
164 cygwin_conv_to_full_win32_path(BINARY_CODECS_PATH, win32path);
16781
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
165 #else /*__CYGWIN__*/
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
166 /* Expand to absolute path unless it's already absolute */
30846
72ae3dd3aa6e Replace separate Win32, XAnim and Real codec directories by one global dir.
diego
parents: 30838
diff changeset
167 if (!strstr(BINARY_CODECS_PATH,":") && BINARY_CODECS_PATH[0] != '\\') {
16781
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
168 GetModuleFileNameA(NULL, win32path, MAX_PATH);
30846
72ae3dd3aa6e Replace separate Win32, XAnim and Real codec directories by one global dir.
diego
parents: 30838
diff changeset
169 strcpy(strrchr(win32path, '\\') + 1, BINARY_CODECS_PATH);
16781
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
170 }
30846
72ae3dd3aa6e Replace separate Win32, XAnim and Real codec directories by one global dir.
diego
parents: 30838
diff changeset
171 else strcpy(win32path, BINARY_CODECS_PATH);
16781
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
172 #endif /*__CYGWIN__*/
30853
88e57c2b3f58 Get rid of pointless tmppath variable in set_path_env().
diego
parents: 30846
diff changeset
173 mp_msg(MSGT_WIN32, MSGL_V, "Setting PATH to %s\n", win32path);
88e57c2b3f58 Get rid of pointless tmppath variable in set_path_env().
diego
parents: 30846
diff changeset
174 if (!SetEnvironmentVariableA("PATH", win32path))
16781
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
175 mp_msg(MSGT_WIN32, MSGL_WARN, "Cannot set PATH!");
6809ca5dd307 allow mencoder to load win32 codecs properly patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents: 15625
diff changeset
176 }
27727
48c1ae64255b Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents: 27722
diff changeset
177 #endif /* (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL) */
30900
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
178
30907
b32527b30d17 Get rid of pointless def_path variable; use codec_path directly instead.
diego
parents: 30902
diff changeset
179 char *codec_path = BINARY_CODECS_PATH;
30900
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
180
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
181 static int needs_free = 0;
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
182
30902
f405a747a35a Rename SetCodecPath() --> set_codec_path().
diego
parents: 30901
diff changeset
183 void set_codec_path(const char *path)
30900
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
184 {
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
185 if (needs_free)
30907
b32527b30d17 Get rid of pointless def_path variable; use codec_path directly instead.
diego
parents: 30902
diff changeset
186 free(codec_path);
30900
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
187 if (path == 0) {
30907
b32527b30d17 Get rid of pointless def_path variable; use codec_path directly instead.
diego
parents: 30902
diff changeset
188 codec_path = BINARY_CODECS_PATH;
30900
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
189 needs_free = 0;
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
190 return;
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
191 }
30907
b32527b30d17 Get rid of pointless def_path variable; use codec_path directly instead.
diego
parents: 30902
diff changeset
192 codec_path = malloc(strlen(path) + 1);
b32527b30d17 Get rid of pointless def_path variable; use codec_path directly instead.
diego
parents: 30902
diff changeset
193 strcpy(codec_path, path);
30900
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
194 needs_free = 1;
e907ff9e7e77 Move SetCodecPath() from loader to get_path.c and make it unconditional.
diego
parents: 30853
diff changeset
195 }
32543
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
196
32645
715c9997201e Add brief description for mp_basename.
cboesch
parents: 32644
diff changeset
197 /**
715c9997201e Add brief description for mp_basename.
cboesch
parents: 32644
diff changeset
198 * @brief Returns the basename substring of a path.
715c9997201e Add brief description for mp_basename.
cboesch
parents: 32644
diff changeset
199 */
32543
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
200 const char *mp_basename(const char *path)
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
201 {
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
202 char *s;
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
203
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
204 #if HAVE_DOS_PATHS
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
205 s = strrchr(path, '\\');
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
206 if (s)
32545
25de211794e8 Handle correctly paths with mixed '/' and '\' in it.
cboesch
parents: 32544
diff changeset
207 path = s + 1;
32555
8a556b3aff79 Handle ':' on systems with DOS paths: it allows paths like C:foo.avi.
cboesch
parents: 32554
diff changeset
208 s = strrchr(path, ':');
8a556b3aff79 Handle ':' on systems with DOS paths: it allows paths like C:foo.avi.
cboesch
parents: 32554
diff changeset
209 if (s)
8a556b3aff79 Handle ':' on systems with DOS paths: it allows paths like C:foo.avi.
cboesch
parents: 32554
diff changeset
210 path = s + 1;
32543
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
211 #endif
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
212 s = strrchr(path, '/');
32544
9d5d8c799869 Fix crash on path without directories.
cboesch
parents: 32543
diff changeset
213 return s ? s + 1 : path;
32543
18338ee51c9d Export mp_basename in a function instead of duplicate macros in various places
cboesch
parents: 30907
diff changeset
214 }
32554
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
215
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
216 /**
32643
d68c55785751 Change Doxygen syntax for mp_dirname.
cboesch
parents: 32555
diff changeset
217 * @brief Allocates a new buffer containing the directory name
d68c55785751 Change Doxygen syntax for mp_dirname.
cboesch
parents: 32555
diff changeset
218 * @param path Original path. Must be a valid string.
32554
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
219 *
32643
d68c55785751 Change Doxygen syntax for mp_dirname.
cboesch
parents: 32555
diff changeset
220 * @note The path returned always contains a trailing slash '/'.
d68c55785751 Change Doxygen syntax for mp_dirname.
cboesch
parents: 32555
diff changeset
221 * On systems supporting DOS paths, '\' is also considered as a directory
d68c55785751 Change Doxygen syntax for mp_dirname.
cboesch
parents: 32555
diff changeset
222 * separator in addition to the '/'.
32554
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
223 */
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
224 char *mp_dirname(const char *path)
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
225 {
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
226 const char *base = mp_basename(path);
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
227 size_t len = base - path;
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
228 char *dirname;
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
229
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
230 if (len == 0)
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
231 return strdup("./");
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
232 dirname = malloc(len + 1);
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
233 if (!dirname)
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
234 return NULL;
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
235 strncpy(dirname, path, len);
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
236 dirname[len] = '\0';
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
237 return dirname;
8fffd26d06ae Add a mp_dirname function (unused at the moment)
cboesch
parents: 32545
diff changeset
238 }
32644
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
239
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
240 /**
32663
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
241 * @brief Join two paths if path is not absolute.
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
242 * @param base File or directory base path.
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
243 * @param path Path to concatenate with the base.
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
244 * @return New allocated string with the path, or NULL in case of error.
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
245 * @warning Do not forget the trailing path separator at the end of the base
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
246 * path if it is a directory: since file paths are also supported,
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
247 * this separator will make the distinction.
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
248 * @note Paths of the form c:foo, /foo or \foo will still depends on the
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
249 * current directory on Windows systems, even though they are considered
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
250 * as absolute paths in this function.
32644
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
251 */
32663
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
252 char *mp_path_join(const char *base, const char *path)
32644
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
253 {
32663
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
254 char *ret, *tmp;
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
255
32644
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
256 #if HAVE_DOS_PATHS
32663
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
257 if ((path[0] && path[1] == ':') || path[0] == '\\' || path[0] == '/')
32644
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
258 #else
32663
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
259 if (path[0] == '/')
32644
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
260 #endif
32663
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
261 return strdup(path);
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
262
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
263 ret = mp_dirname(base);
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
264 if (!ret)
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
265 return NULL;
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
266 tmp = realloc(ret, strlen(ret) + strlen(path) + 1);
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
267 if (!tmp) {
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
268 free(ret);
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
269 return NULL;
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
270 }
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
271 ret = tmp;
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
272 strcat(ret, path);
83c490a2e9f3 Replace mp_path_is_absolute with mp_path_join.
cboesch
parents: 32645
diff changeset
273 return ret;
32644
a6431ff5481f Add mp_path_is_absolute function.
cboesch
parents: 32643
diff changeset
274 }
32751
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
275
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
276 /**
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
277 * @brief Same as mp_path_join but always treat the first parameter as a
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
278 * directory.
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
279 * @param dir Directory base path.
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
280 * @param append Right part to append to dir.
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
281 * @return New allocated string with the path, or NULL in case of error.
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
282 */
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
283 char *mp_dir_join(const char *dir, const char *append)
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
284 {
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
285 char *tmp, *ret;
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
286 size_t dirlen = strlen(dir);
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
287 size_t i = dirlen - 1;
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
288
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
289 #if HAVE_DOS_PATHS
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
290 if ((dirlen == 2 && dir[0] && dir[1] == ':') // "X:" only
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
291 || dirlen == 0 || dir[i] == '\\' || dir[i] == '/')
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
292 #else
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
293 if (dirlen == 0 || dir[i] == '/')
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
294 #endif
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
295 return mp_path_join(dir, append);
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
296
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
297 tmp = malloc(dirlen + 2);
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
298 if (!tmp)
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
299 return NULL;
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
300 strcpy(tmp, dir);
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
301 strcpy(tmp + dirlen, "/");
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
302 ret = mp_path_join(tmp, append);
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
303 free(tmp);
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
304 return ret;
8e7537586f0b Add mp_dir_join function.
cboesch
parents: 32663
diff changeset
305 }