3 // Copyright (C) 2005 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.
24 #include "pathconfig.h"
30 completePath(char const *id, size_t len, vcCfgStyle style, char *buf)
33 case vcCFG_RECENT_FULL : return id;
34 case vcCFG_RECENT_SHORT :
35 memcpy(buf, CONFDIR "/", sizeof(CONFDIR "/")-1);
36 memcpy(buf+sizeof(CONFDIR "/")-1, id, len+1); // appends '\0' implicitly
43 vc_compareVserverById(char const *lhs, vcCfgStyle lhs_style,
44 char const *rhs, vcCfgStyle rhs_style)
46 if (lhs_style==vcCFG_NONE || lhs_style==vcCFG_AUTO)
47 lhs_style = vc_getVserverCfgStyle(lhs);
49 if (rhs_style==vcCFG_NONE || rhs_style==vcCFG_AUTO)
50 rhs_style = vc_getVserverCfgStyle(rhs);
52 // compare legacy vservers by their names only resp. return false on mixed
54 if (lhs_style==vcCFG_LEGACY || rhs_style==vcCFG_LEGACY) {
55 if (lhs_style!=rhs_style) return lhs_style - rhs_style;
56 else return strcmp(lhs, rhs);
60 size_t len_lhs = strlen(lhs);
61 size_t len_rhs = strlen(rhs);
62 char buf_lhs[sizeof(CONFDIR "//") + len_lhs];
63 char buf_rhs[sizeof(CONFDIR "//") + len_rhs];
65 char const * path_lhs = completePath(lhs, len_lhs, lhs_style, buf_lhs);
66 char const * path_rhs = (path_lhs==0
67 ? 0 // skip following calculation
68 : completePath(rhs, len_rhs, rhs_style, buf_rhs));
73 // this is true only iff both path_* are 0; compare ids in this case
74 if (path_lhs==path_rhs) return strcmp(lhs, rhs);
75 if (path_lhs==0) return -1; // path_rhs!=0 is implied by check above
76 if (path_rhs==0) return +1;
78 if (stat(path_lhs, &st_lhs)==-1 ||
79 stat(path_rhs, &st_rhs)==-1) return strcmp(lhs,rhs);
81 return (st_lhs.st_dev - st_rhs.st_dev) + (st_lhs.st_ino - st_rhs.st_ino);