1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2004
* Tama Communications Corporation
* #ifdef __DJGPP__
* Contributed by Jason Hood <jadoxa@yahoo.com.au>, 2001.
# #endif
*
* This file is part of GNU GLOBAL.
*
* GNU GLOBAL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU GLOBAL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
#ifdef __DJGPP__
#include <fcntl.h> /* for _USE_LFN */
#endif
#include "gparam.h"
#include "path.h"
#include "strlimcpy.h"
/*
* isabspath: whether absolute path or not
*
* i) path path
* r) 1: absolute, 0: not absolute
*/
int
isabspath(p)
const char *p;
{
if (p[0] == '/')
return 1;
#if defined(_WIN32) || defined(__DJGPP__)
if (p[0] == '\\')
return 1;
if (isdrivechar(p[0]) && p[1] == ':' && (p[2] == '\\' || p[2] == '/'))
return 1;
#endif
return 0;
}
/*
* canonpath: make canonical path name.
*
* io) path path
* r) path
*
* Note: canonpath rewrite argument buffer.
*/
char *
canonpath(path)
char *path;
{
#ifdef __DJGPP__
char *p;
if (_USE_LFN) {
char name[260], sfn[13];
char *base;
/*
* Ensure we're using a complete long name, not a mixture
* of long and short.
*/
_truename(path, path);
/*
* _truename will successfully convert the path of a non-
* existant file, but it's probably still a mixture of long and
* short components - convert the path separately.
*/
if (access(path, F_OK) != 0) {
base = basename(path);
strcpy(name, base);
*base = '\0';
_truename(path, path);
strcat(path, name);
}
/*
* Convert the case of 8.3 names, as other djgpp functions do.
*/
if (!_preserve_fncase()) {
for (p = path+3, base = p-1; *base; p++) {
if (*p == '\\' || *p == '\0') {
memcpy(name, base+1, p-base-1);
name[p-base-1] = '\0';
if (!strcmp(_lfn_gen_short_fname(name, sfn), name)) {
while (++base < p)
if (*base >= 'A' && *base <= 'Z')
*base += 'a' - 'A';
} else
base = p;
}
}
}
}
/*
* Lowercase the drive letter and convert to slashes.
*/
path[0] = tolower(path[0]);
for (p = path+2; *p; ++p)
if (*p == '\\')
*p = '/';
#else
#ifdef _WIN32
char *p, *s;
p = path;
/*
* Change \ to / in a path (for DOS/Windows paths)
*/
while ((p = strchr(p, '\\')) != NULL)
*p = '/';
#ifdef __CYGWIN__
/*
* On NT with CYGWIN, getcwd can return something like
* "//c/tmp", which isn't usable. We change that to "c:/tmp".
*/
p = path;
if (p[0] == '/' && p[1] == '/' && isdrivechar(p[2]) && p[3] == '/') {
s = &p[2]; /* point drive char */
*p++ = *s++;
*p++ = ':';
while (*p++ = *s++)
;
}
#endif /* __CYGWIN__ */
#endif /* _WIN32 */
#endif /* __DJGPP__ */
return path;
}
#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
/*
* realpath: get the complete path
*/
char *
realpath(in_path, out_path)
const char *in_path;
char *out_path;
{
#ifdef __DJGPP__
/*
* I don't use _fixpath or _truename in LFN because neither guarantee
* a complete long name. This is mainly DOS's fault, since the cwd can
* be a mixture of long and short components.
*/
if (_USE_LFN) {
strlimcpy(out_path, in_path, MAXPATHLEN);
canonpath(out_path);
} else
_fixpath(in_path, out_path);
#else
_fullpath(out_path, in_path, MAXPATHLEN);
canonpath(out_path);
#endif
return out_path;
}
#endif
|