201 |
ino_t dotino; |
ino_t dotino; |
202 |
bool mount_point; |
bool mount_point; |
203 |
int parent_status; |
int parent_status; |
204 |
|
size_t dirroom; |
205 |
|
size_t namlen; |
206 |
|
|
207 |
/* Look at the parent directory. */ |
/* Look at the parent directory. */ |
208 |
#ifdef AT_FDCWD |
#ifdef AT_FDCWD |
243 |
goto lose; |
goto lose; |
244 |
dotlist[dotlen++] = '/'; |
dotlist[dotlen++] = '/'; |
245 |
#endif |
#endif |
246 |
/* Clear errno to distinguish EOF from error if readdir returns |
for (;;) |
|
NULL. */ |
|
|
__set_errno (0); |
|
|
while ((d = __readdir (dirstream)) != NULL) |
|
247 |
{ |
{ |
248 |
|
/* Clear errno to distinguish EOF from error if readdir returns |
249 |
|
NULL. */ |
250 |
|
__set_errno (0); |
251 |
|
d = __readdir (dirstream); |
252 |
|
if (d == NULL) |
253 |
|
{ |
254 |
|
if (errno == 0) |
255 |
|
/* EOF on dirstream, which means that the current directory |
256 |
|
has been removed. */ |
257 |
|
__set_errno (ENOENT); |
258 |
|
goto lose; |
259 |
|
} |
260 |
if (d->d_name[0] == '.' && |
if (d->d_name[0] == '.' && |
261 |
(d->d_name[1] == '\0' || |
(d->d_name[1] == '\0' || |
262 |
(d->d_name[1] == '.' && d->d_name[2] == '\0'))) |
(d->d_name[1] == '.' && d->d_name[2] == '\0'))) |
314 |
break; |
break; |
315 |
} |
} |
316 |
} |
} |
|
if (d == NULL) |
|
|
{ |
|
|
if (errno == 0) |
|
|
/* EOF on dirstream, which means that the current directory |
|
|
has been removed. */ |
|
|
__set_errno (ENOENT); |
|
|
goto lose; |
|
|
} |
|
|
else |
|
|
{ |
|
|
size_t dirroom = dirp - dir; |
|
|
size_t namlen = _D_EXACT_NAMLEN (d); |
|
317 |
|
|
318 |
if (dirroom <= namlen) |
dirroom = dirp - dir; |
319 |
|
namlen = _D_EXACT_NAMLEN (d); |
320 |
|
|
321 |
|
if (dirroom <= namlen) |
322 |
|
{ |
323 |
|
if (size != 0) |
324 |
{ |
{ |
325 |
if (size != 0) |
__set_errno (ERANGE); |
326 |
{ |
goto lose; |
327 |
__set_errno (ERANGE); |
} |
328 |
goto lose; |
else |
329 |
} |
{ |
330 |
else |
char *tmp; |
331 |
{ |
size_t oldsize = allocated; |
|
char *tmp; |
|
|
size_t oldsize = allocated; |
|
332 |
|
|
333 |
allocated += MAX (allocated, namlen); |
allocated += MAX (allocated, namlen); |
334 |
if (allocated < oldsize |
if (allocated < oldsize |
335 |
|| ! (tmp = realloc (dir, allocated))) |
|| ! (tmp = realloc (dir, allocated))) |
336 |
goto memory_exhausted; |
goto memory_exhausted; |
337 |
|
|
338 |
/* Move current contents up to the end of the buffer. |
/* Move current contents up to the end of the buffer. |
339 |
This is guaranteed to be non-overlapping. */ |
This is guaranteed to be non-overlapping. */ |
340 |
dirp = memcpy (tmp + allocated - (oldsize - dirroom), |
dirp = memcpy (tmp + allocated - (oldsize - dirroom), |
341 |
tmp + dirroom, |
tmp + dirroom, |
342 |
oldsize - dirroom); |
oldsize - dirroom); |
343 |
dir = tmp; |
dir = tmp; |
|
} |
|
344 |
} |
} |
|
dirp -= namlen; |
|
|
memcpy (dirp, d->d_name, namlen); |
|
|
*--dirp = '/'; |
|
345 |
} |
} |
346 |
|
dirp -= namlen; |
347 |
|
memcpy (dirp, d->d_name, namlen); |
348 |
|
*--dirp = '/'; |
349 |
|
|
350 |
thisdev = dotdev; |
thisdev = dotdev; |
351 |
thisino = dotino; |
thisino = dotino; |