Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.
All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.
All imported code from other projects is compatible with this license.
All GPL licensed code from other projects had previously been removed.
Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-02 17:38:16 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011, 2014, 2015 Jonas 'Sortie' Termansen.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* dirent/readdir.c
|
|
|
|
* Reads a directory entry from a directory stream into a DIR-specific buffer.
|
|
|
|
*/
|
Added readdir(3), closedir(3), rewinddir(3), dirfd(3), fdopendir(3),
opendir(3).
Also added non-standard dregister(3), dunregister(3), dclearerr(3),
derror(3), deof(3), dnewdir(3), dcloseall(3).
2012-01-14 14:54:02 -05:00
|
|
|
|
2015-11-19 20:57:09 -05:00
|
|
|
#include <sys/readdirents.h>
|
|
|
|
|
2013-07-11 12:32:54 -04:00
|
|
|
#include <dirent.h>
|
Added readdir(3), closedir(3), rewinddir(3), dirfd(3), fdopendir(3),
opendir(3).
Also added non-standard dregister(3), dunregister(3), dclearerr(3),
derror(3), deof(3), dnewdir(3), dcloseall(3).
2012-01-14 14:54:02 -05:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2016-02-28 06:11:02 -05:00
|
|
|
struct dirent* readdir(DIR* dir)
|
Added readdir(3), closedir(3), rewinddir(3), dirfd(3), fdopendir(3),
opendir(3).
Also added non-standard dregister(3), dunregister(3), dclearerr(3),
derror(3), deof(3), dnewdir(3), dcloseall(3).
2012-01-14 14:54:02 -05:00
|
|
|
{
|
2014-02-23 10:41:34 -05:00
|
|
|
int old_errno = errno;
|
2015-11-19 20:57:09 -05:00
|
|
|
struct dirent fallback;
|
|
|
|
struct dirent* entry = dir->entry ? dir->entry : &fallback;
|
|
|
|
size_t size = dir->entry ? dir->size : sizeof(fallback);
|
|
|
|
ssize_t amount;
|
|
|
|
while ( (amount = readdirents(dir->fd, entry, size)) < 0 )
|
Added readdir(3), closedir(3), rewinddir(3), dirfd(3), fdopendir(3),
opendir(3).
Also added non-standard dregister(3), dunregister(3), dclearerr(3),
derror(3), deof(3), dnewdir(3), dcloseall(3).
2012-01-14 14:54:02 -05:00
|
|
|
{
|
2015-11-19 20:57:09 -05:00
|
|
|
if ( errno != ERANGE )
|
|
|
|
return NULL;
|
|
|
|
errno = old_errno;
|
|
|
|
size_t needed = entry->d_reclen;
|
Added readdir(3), closedir(3), rewinddir(3), dirfd(3), fdopendir(3),
opendir(3).
Also added non-standard dregister(3), dunregister(3), dclearerr(3),
derror(3), deof(3), dnewdir(3), dcloseall(3).
2012-01-14 14:54:02 -05:00
|
|
|
free(dir->entry);
|
2015-11-19 20:57:09 -05:00
|
|
|
dir->entry = NULL;
|
|
|
|
struct dirent* new_dirent = (struct dirent*) malloc(needed);
|
|
|
|
if ( !new_dirent )
|
|
|
|
return NULL;
|
|
|
|
entry = dir->entry = new_dirent;
|
|
|
|
size = dir->size = needed;
|
Added readdir(3), closedir(3), rewinddir(3), dirfd(3), fdopendir(3),
opendir(3).
Also added non-standard dregister(3), dunregister(3), dclearerr(3),
derror(3), deof(3), dnewdir(3), dcloseall(3).
2012-01-14 14:54:02 -05:00
|
|
|
}
|
2015-11-19 20:57:09 -05:00
|
|
|
if ( amount == 0 )
|
|
|
|
return NULL;
|
2012-03-21 19:52:29 -04:00
|
|
|
return dir->entry;
|
Added readdir(3), closedir(3), rewinddir(3), dirfd(3), fdopendir(3),
opendir(3).
Also added non-standard dregister(3), dunregister(3), dclearerr(3),
derror(3), deof(3), dnewdir(3), dcloseall(3).
2012-01-14 14:54:02 -05:00
|
|
|
}
|