/[path-sandbox]/trunk/getcwd.c
Gentoo

Diff of /trunk/getcwd.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 147 Revision 148
126 return path_buf; 126 return path_buf;
127 } 127 }
128 if (strlen(path_buf) + 4 > path_size) { 128 if (strlen(path_buf) + 4 > path_size) {
129 goto oops; 129 goto oops;
130 } 130 }
131 snprintf(path_buf, 4, "/.."); 131 snprintf(path_buf + strlen(path_buf), 4, "/..");
132 if (recurser(path_buf, path_size, root_dev, root_ino) == 0) 132 if (recurser(path_buf, path_size, root_dev, root_ino) == 0)
133 return 0; 133 return 0;
134 134
135 return search_dir(this_dev, this_ino, path_buf, path_size); 135 return search_dir(this_dev, this_ino, path_buf, path_size);
136oops: 136oops:
144 size_t len; 144 size_t len;
145 char *cwd; 145 char *cwd;
146 struct stat st; 146 struct stat st;
147 size_t olderrno; 147 size_t olderrno;
148 148
149 if (lstat("/", &st) < 0)
150 return -1;
149 olderrno = errno; 151 olderrno = errno;
150 len = -1; 152 len = -1;
151 cwd = recurser(buf, size, st.st_dev, st.st_ino); 153 cwd = recurser(buf, size, st.st_dev, st.st_ino);
152 if (cwd) { 154 if (cwd) {
153 len = strlen(buf); 155 len = strlen(buf);
173 if (buf == NULL) { 175 if (buf == NULL) {
174 path = malloc(alloc_size); 176 path = malloc(alloc_size);
175 if (path == NULL) 177 if (path == NULL)
176 return NULL; 178 return NULL;
177 } 179 }
180 snprintf(buf, 2, ".");
178 ret = __syscall_egetcwd(path, alloc_size); 181 ret = __syscall_egetcwd(path, alloc_size);
179 if (ret >= 0) 182 if (ret >= 0)
180 { 183 {
181 if (buf == NULL && size == 0) 184 if (buf == NULL && size == 0)
182 buf = realloc(path, ret); 185 buf = realloc(path, ret);
195 char *tmpbuf; 198 char *tmpbuf;
196 199
197 __set_errno(0); 200 __set_errno(0);
198 tmpbuf = getcwd(buf, size); 201 tmpbuf = getcwd(buf, size);
199 202
200 if (tmpbuf) { 203 if (tmpbuf)
201 lstat(buf, &st); 204 lstat(buf, &st);
202 } else { 205 else
203 return tmpbuf; 206 return tmpbuf;
204 }
205 207
206 if (errno) { 208 if (errno) {
207 /* If lstat() failed with eerror = ENOENT, then its 209 /* If lstat() failed with eerror = ENOENT, then its
208 * possible that we are running on an older kernel, 210 * possible that we are running on an older kernel,
209 * so use our generic version which *should* not fail. 211 * so use our generic version which *should* not fail.

Legend:
Removed from v.147  
changed lines
  Added in v.148

  ViewVC Help
Powered by ViewVC 1.1.20