3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "pathconfig.h"
29 #include <sys/param.h>
33 getDir(char *dir, bool physical)
38 if (!physical) return strdup(dir);
40 fd = open(".", O_RDONLY);
44 getcwd(tmp, sizeof tmp)!=0)
50 if (write(2, "FATAL error: failed to restore directory\n", 41)!=41) { /*...*/ }
58 vc_getVserverVdir(char const *id, vcCfgStyle style, bool physical)
60 size_t l1 = strlen(id);
63 if (style==vcCFG_NONE || style==vcCFG_AUTO)
64 style = vc_getVserverCfgStyle(id);
67 case vcCFG_NONE : return 0;
70 char buf[sizeof(DEFAULT_VSERVERDIR "/") + l1];
72 strcpy(buf, DEFAULT_VSERVERDIR "/");
73 strcpy(buf+sizeof(DEFAULT_VSERVERDIR "/") - 1, id);
75 res = getDir(buf, physical);
79 case vcCFG_RECENT_SHORT :
81 char buf[sizeof(CONFDIR) + l1 + sizeof("//vdir") - 1];
83 strcpy(buf, CONFDIR "/");
84 strcpy(buf+sizeof(CONFDIR "/") - 1, id);
85 strcpy(buf+sizeof(CONFDIR "/")+l1 - 1, "/vdir");
87 res = getDir(buf, physical);
91 case vcCFG_RECENT_FULL :
93 char buf[l1 + sizeof("/vdir")];
96 strcpy(buf+l1, "/vdir");
98 res = getDir(buf, physical);
105 // ignore physical-case; we went into the directory while determining
106 // the physical path so the directory exists
107 if (!physical && !utilvserver_isDirectory(res, true)) {