comparison src/realpath.c @ 195:a2f645c6b9f8 r20-3b24

Import from CVS: tag r20-3b24
author cvs
date Mon, 13 Aug 2007 09:59:05 +0200
parents 376386a54a3c
children 850242ba4a81
comparison
equal deleted inserted replaced
194:2947057885e5 195:a2f645c6b9f8
75 75
76 /* Make a copy of the source path since we may need to modify it. */ 76 /* Make a copy of the source path since we may need to modify it. */
77 strcpy(copy_path, path); 77 strcpy(copy_path, path);
78 path = copy_path; 78 path = copy_path;
79 max_path = copy_path + PATH_MAX - 2; 79 max_path = copy_path + PATH_MAX - 2;
80 /* If it's a relative pathname use getwd for starters. */ 80 #ifdef WINDOWSNT
81 if (*path != '/') 81 /*
82 { 82 ** In NT we have two different cases: (1) the path name begins
83 #ifdef HAVE_GETCWD 83 ** with a drive letter, e.g., "C:"; and (2) the path name begins
84 ** with just a slash, which roots to the current drive. In the
85 ** first case we are going to leave things alone, in the second
86 ** case we will prepend the drive letter to the given path.
87 ** Note: So far in testing, I'm only seeing case #1, even though
88 ** I've tried to get the other cases to happen.
89 ** August Hill, 31 Aug 1997.
90 **
91 ** Check for a driver letter...C:/...
92 */
93 if (*(path + 1) == ':')
94 {
95 strncpy(new_path, path, 3);
96 new_path += 3;
97 path += 3;
98 }
99
100 /*
101 ** No drive letter, but a beginning slash? Prepend the drive
102 ** letter...
103 */
104 else if (*path == '/')
105 {
84 getcwd(new_path, PATH_MAX - 1); 106 getcwd(new_path, PATH_MAX - 1);
85 #else 107 new_path += 3;
86 getwd(new_path); 108 path++;
87 #endif 109 }
110
111 /*
112 ** Just a path name, prepend the current directory
113 */
114 else
115 {
116 getcwd(new_path, PATH_MAX - 1);
88 new_path += strlen(new_path); 117 new_path += strlen(new_path);
89 if (new_path[-1] != '/') 118 if (new_path[-1] != '/')
90 *new_path++ = '/'; 119 *new_path++ = '/';
91 } 120 }
121
122 #else
123 /* If it's a relative pathname use getwd for starters. */
124 if (*path != '/')
125 {
126 #ifdef HAVE_GETCWD
127 getcwd(new_path, PATH_MAX - 1);
128 #else
129 getwd(new_path);
130 #endif
131 new_path += strlen(new_path);
132 if (new_path[-1] != '/')
133 *new_path++ = '/';
134 }
92 else 135 else
93 { 136 {
94 *new_path++ = '/'; 137 *new_path++ = '/';
95 path++; 138 path++;
96 } 139 }
97 140 #endif
98 /* Expand each slash-separated pathname component. */ 141 /* Expand each slash-separated pathname component. */
99 while (*path != '\0') 142 while (*path != '\0')
100 { 143 {
101 /* Ignore stray "/". */ 144 /* Ignore stray "/". */
102 if (*path == '/') 145 if (*path == '/')