mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 15:23:02 +01:00
fixed posix build - it's buildable now
This commit is contained in:
parent
3f87477ac6
commit
5e045f18fc
@ -184,7 +184,7 @@ typedef struct mnt {
|
||||
#endif
|
||||
|
||||
#if (!defined NO_NFS || defined FREEBSD || defined NETBSD || defined SINIXZ)
|
||||
static int expand_filename2(const TEXT*, USHORT, TEXT*);
|
||||
static int expand_filename2(const Firebird::PathName&, Firebird::PathName&);
|
||||
#endif
|
||||
|
||||
#if defined(WIN_NT)
|
||||
@ -512,7 +512,7 @@ bool ISC_check_if_remote(const Firebird::PathName& file_name,
|
||||
|
||||
|
||||
#if (!defined NO_NFS || defined FREEBSD || defined NETBSD || defined SINIXZ)
|
||||
int ISC_expand_filename(const TEXT* from_buff, USHORT length, TEXT* to_buff)
|
||||
int ISC_expand_filename(const Firebird::PathName& from_buff, Firebird::PathName& to_buff)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
@ -526,7 +526,7 @@ int ISC_expand_filename(const TEXT* from_buff, USHORT length, TEXT* to_buff)
|
||||
*
|
||||
**************************************/
|
||||
|
||||
return expand_filename2(from_buff, length, to_buff);
|
||||
return expand_filename2(from_buff, to_buff);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1054,7 +1054,7 @@ int ISC_strip_extension(TEXT* file_name)
|
||||
|
||||
|
||||
#if (!defined NO_NFS || defined FREEBSD || defined NETBSD || defined SINIXZ)
|
||||
static int expand_filename2(const TEXT* from_buff, USHORT length, TEXT* to_buff)
|
||||
static int expand_filename2(const Firebird::PathName& from_buff, Firebird::PathName& to_buff)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
@ -1067,138 +1067,103 @@ static int expand_filename2(const TEXT* from_buff, USHORT length, TEXT* to_buff)
|
||||
* shows up, stop translating.
|
||||
*
|
||||
**************************************/
|
||||
TEXT temp[MAXPATHLEN], temp2[MAXPATHLEN];
|
||||
SSHORT n;
|
||||
struct passwd* passwd;
|
||||
typedef Firebird::PathName string;
|
||||
typedef string::size_type size;
|
||||
const size npos = string::npos;
|
||||
string src = from_buff;
|
||||
|
||||
const TEXT* from;
|
||||
if (length) {
|
||||
strncpy(temp2, from_buff, length);
|
||||
temp2[length] = 0;
|
||||
from = temp2;
|
||||
}
|
||||
else {
|
||||
strncpy(temp2, from_buff, MAXPATHLEN);
|
||||
temp2[MAXPATHLEN - 1] = 0;
|
||||
from = temp2;
|
||||
// If the filename contains a TCP node name, don't even try to expand it
|
||||
if (src.find(INET_FLAG) != npos) {
|
||||
to_buff = src;
|
||||
return to_buff.length();
|
||||
}
|
||||
|
||||
TEXT* to = to_buff;
|
||||
|
||||
/* If the filename contains a TCP node name, don't even try to expand it */
|
||||
|
||||
if (strchr(from, INET_FLAG)) {
|
||||
strcpy(to, from);
|
||||
return strlen(to);
|
||||
}
|
||||
|
||||
/* Handle references to default directories (tilde refs) */
|
||||
const char* from = src.c_str();
|
||||
to_buff = "";
|
||||
|
||||
// Handle references to default directories (tilde refs)
|
||||
if (*from == '~') {
|
||||
++from;
|
||||
TEXT* q = temp;
|
||||
string q;
|
||||
while (*from && *from != '/')
|
||||
*q++ = *from++;
|
||||
*q = 0;
|
||||
passwd = (temp[0]) ? getpwnam(temp) : getpwuid(geteuid());
|
||||
if (passwd) {
|
||||
expand_filename2(passwd->pw_dir, 0, temp);
|
||||
const TEXT* p = temp;
|
||||
while (*p)
|
||||
*to++ = *p++;
|
||||
*to = 0;
|
||||
q += *from++;
|
||||
struct passwd* password = q ? getpwnam(q.c_str()) : getpwuid(geteuid());
|
||||
if (password) {
|
||||
string temp;
|
||||
expand_filename2(password->pw_dir, to_buff);
|
||||
}
|
||||
}
|
||||
|
||||
/* If the file is local, expand partial pathnames with default directory */
|
||||
|
||||
if (*from && !strchr(from, INET_FLAG) && *from != '/' && GETWD(to)) {
|
||||
while (*to)
|
||||
++to;
|
||||
*to++ = '/';
|
||||
*to = 0;
|
||||
// If the file is local, expand partial pathnames with default directory
|
||||
if (*from && *from != '/') {
|
||||
if (! GETWD(to_buff)) {
|
||||
to_buff = "";
|
||||
}
|
||||
to_buff += '/';
|
||||
}
|
||||
|
||||
/* Process file name segment by segment looking for symbolic
|
||||
links. See ISC_analyze_nfs for how NFS mount points are
|
||||
handled. */
|
||||
|
||||
// Process file name segment by segment looking for symbolic links.
|
||||
// See ISC_analyze_nfs for how NFS mount points are handled.
|
||||
while (*from) {
|
||||
TEXT* segment = to;
|
||||
|
||||
/* skip dual // (will collapse /// to / as well) */
|
||||
// skip dual // (will collapse /// to / as well)
|
||||
if (*from == '/' && from[1] == '/') {
|
||||
++from;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Copy the leading slash, if any */
|
||||
|
||||
// Copy the leading slash, if any
|
||||
if (*from == '/') {
|
||||
if (to > to_buff + 1 && to[-1] == '/')
|
||||
if (to_buff && (to_buff.end()[-1] == '/'))
|
||||
++from;
|
||||
else
|
||||
*to++ = *from++;
|
||||
to_buff += *from++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Handle self references */
|
||||
|
||||
// Handle self references
|
||||
if (*from == '.' && (from[1] == '.' || from[1] == '/')) {
|
||||
if (*++from == '.') {
|
||||
++from;
|
||||
if (*from == '.') {
|
||||
++from;
|
||||
if (to > to_buff)
|
||||
--to;
|
||||
while (to > to_buff && to[-1] != '/')
|
||||
--to;
|
||||
if (to_buff.length() > 2) {
|
||||
size slash = to_buff.rfind('/', to_buff.length() - 2);
|
||||
to_buff = slash != npos ? to_buff.substr(0, slash + 1) : "/";
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Copy the rest of the segment name */
|
||||
|
||||
while (*from && *from != '/')
|
||||
*to++ = *from++;
|
||||
|
||||
/* If the file is local, check for a symbol link */
|
||||
|
||||
*to = 0;
|
||||
|
||||
n = readlink(to_buff, temp, MAXPATHLEN);
|
||||
// Copy the rest of the segment name
|
||||
int segment = to_buff.length();
|
||||
while (*from && *from != '/') {
|
||||
to_buff += *from++;
|
||||
}
|
||||
|
||||
// If the file is local, check for a symbol link
|
||||
TEXT temp[MAXPATHLEN];
|
||||
int n = readlink(to_buff.c_str(), temp, MAXPATHLEN);
|
||||
if (n < 0)
|
||||
continue;
|
||||
|
||||
/* We've got a link. If it contains a node name or it starts
|
||||
with a slash, it replaces the initial segment so far */
|
||||
|
||||
temp[n] = 0;
|
||||
const TEXT* p = temp;
|
||||
|
||||
if (strchr(temp, INET_FLAG)) {
|
||||
strcpy(to_buff, temp);
|
||||
return n;
|
||||
// We've got a link. If it contains a node name or it starts
|
||||
// with a slash, it replaces the initial segment so far.
|
||||
string link(temp, n);
|
||||
if (link.find(INET_FLAG) != npos) {
|
||||
to_buff = link;
|
||||
return to_buff.length();
|
||||
}
|
||||
if (link[0] == '/') {
|
||||
to_buff = link;
|
||||
}
|
||||
else {
|
||||
to_buff.replace(segment, to_buff.length() - segment, link);
|
||||
}
|
||||
|
||||
to = (*p == '/') ? to_buff : segment;
|
||||
|
||||
while (*p)
|
||||
*to++ = *p++;
|
||||
|
||||
/* Whole link needs translating -- recurse */
|
||||
|
||||
*to = 0;
|
||||
expand_filename2(to_buff, 0, temp);
|
||||
to = to_buff;
|
||||
p = temp;
|
||||
while (*p)
|
||||
*to++ = *p++;
|
||||
expand_filename2(to_buff, to_buff);
|
||||
}
|
||||
|
||||
*to = 0;
|
||||
|
||||
return to - to_buff;
|
||||
return to_buff.length();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1842,7 +1842,7 @@ ISC_STATUS GDS_CREATE_DATABASE(ISC_STATUS* user_status,
|
||||
break;
|
||||
default:
|
||||
ERR_post(isc_database_create_failed, isc_arg_string,
|
||||
expanded_name, isc_arg_gds, isc_inv_dialect_specified,
|
||||
expanded_name.c_str(), isc_arg_gds, isc_inv_dialect_specified,
|
||||
isc_arg_number, options.dpb_sql_dialect, isc_arg_gds,
|
||||
isc_valid_db_dialects, isc_arg_string, "1 and 3", 0);
|
||||
break;
|
||||
@ -4964,12 +4964,11 @@ static void get_options(const UCHAR* dpb,
|
||||
}
|
||||
}
|
||||
else { /*No home dir for this users here. Default to server dir */
|
||||
|
||||
**scratch = 0;
|
||||
if (fb_getcwd(*scratch, MIN(MAXPATHLEN, buf_size)))
|
||||
l = strlen(*scratch) + 1;
|
||||
else
|
||||
l = buf_size;
|
||||
Firebird::PathName buf;
|
||||
fb_getcwd(buf);
|
||||
l = buf.length() + 1 < buf_size ? buf.length() + 1 : buf_size;
|
||||
memcpy(*scratch, buf.c_str(), l);
|
||||
}
|
||||
options->dpb_working_directory = *scratch;
|
||||
*scratch += l;
|
||||
|
@ -12,7 +12,16 @@ const char* PathUtils::up_dir_link = "..";
|
||||
class PosixDirItr : public PathUtils::dir_iterator
|
||||
{
|
||||
public:
|
||||
PosixDirItr(const Firebird::PathName&);
|
||||
PosixDirItr(MemoryPool& p, const Firebird::PathName& path)
|
||||
: dir_iterator(p, path), file(p), dir(0), done(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
PosixDirItr(const Firebird::PathName& path)
|
||||
: dir_iterator(path), dir(0), done(0)
|
||||
{
|
||||
init();
|
||||
}
|
||||
~PosixDirItr();
|
||||
const PosixDirItr& operator++();
|
||||
const Firebird::PathName& operator*() { return file; }
|
||||
@ -22,10 +31,10 @@ private:
|
||||
DIR *dir;
|
||||
Firebird::PathName file;
|
||||
int done;
|
||||
void init();
|
||||
};
|
||||
|
||||
PosixDirItr::PosixDirItr(const Firebird::PathName& path)
|
||||
: dir_iterator(path), dir(0), done(0)
|
||||
void PosixDirItr::init()
|
||||
{
|
||||
dir = opendir(dirPrefix.c_str());
|
||||
if (!dir)
|
||||
@ -131,11 +140,6 @@ bool PathUtils::isSymLink(const Firebird::PathName& path)
|
||||
return st.st_ino != lst.st_ino;
|
||||
}
|
||||
|
||||
bool PathUtils::comparePaths(const Firebird::PathName& path1,
|
||||
const Firebird::PathName& path2) {
|
||||
return path1 == path2;
|
||||
}
|
||||
|
||||
bool PathUtils::canAccess(const Firebird::PathName& path, int mode) {
|
||||
return access(path.c_str(), mode) == 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user