forked from KolibriOS/kolibrios
NewLib:
Added missing dirent impl git-svn-id: svn://kolibrios.org@9955 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
6e3276cb4b
commit
75cc884573
25
contrib/sdk/sources/newlib/libc/posix/closedir.c
Normal file
25
contrib/sdk/sources/newlib/libc/posix/closedir.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) KolibriOS team 2024. All rights reserved.
|
||||||
|
* Distributed under terms of the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
_DEFUN(closedir, (dirp),
|
||||||
|
register DIR *dirp)
|
||||||
|
{
|
||||||
|
if (!dirp)
|
||||||
|
{
|
||||||
|
errno = EBADF;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dirp->path)
|
||||||
|
free(dirp->path);
|
||||||
|
|
||||||
|
free(dirp);
|
||||||
|
return 0;
|
||||||
|
}
|
42
contrib/sdk/sources/newlib/libc/posix/opendir.c
Normal file
42
contrib/sdk/sources/newlib/libc/posix/opendir.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) KolibriOS team 2024. All rights reserved.
|
||||||
|
* Distributed under terms of the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
|
/* TODO: Add thread safety */
|
||||||
|
|
||||||
|
DIR *
|
||||||
|
_DEFUN(opendir, (name),
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
ksys_file_info_t info;
|
||||||
|
if (_ksys_file_info(name, &info))
|
||||||
|
{
|
||||||
|
errno = ENOENT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(info.attr & (KSYS_FILE_ATTR_DIR | KSYS_FILE_ATTR_VOL_LABEL)))
|
||||||
|
{
|
||||||
|
errno = ENOTDIR;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
DIR* dir = malloc(sizeof(DIR));
|
||||||
|
if (!dir)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
dir->path = strdup(name);
|
||||||
|
if (!dir->path)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
dir->pos = 0;
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
47
contrib/sdk/sources/newlib/libc/posix/readdir.c
Normal file
47
contrib/sdk/sources/newlib/libc/posix/readdir.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) KolibriOS team 2024. All rights reserved.
|
||||||
|
* Distributed under terms of the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/ksys.h>
|
||||||
|
|
||||||
|
struct dirent *
|
||||||
|
_DEFUN(readdir, (dirp),
|
||||||
|
register DIR *dirp)
|
||||||
|
{
|
||||||
|
if (!dirp || !dirp->path)
|
||||||
|
{
|
||||||
|
errno = EBADF;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ksys_dir_entry_t *entry = calloc(sizeof(ksys_dir_entry_t) +
|
||||||
|
KSYS_FNAME_UTF8_SIZE, 1);
|
||||||
|
|
||||||
|
int status = _ksys_file_read_dir(dirp->path, dirp->pos,
|
||||||
|
KSYS_FILE_UTF8, 1, entry).status;
|
||||||
|
if (status == KSYS_FS_ERR_EOF)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (status)
|
||||||
|
{
|
||||||
|
errno = ENOENT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dirp->last_entry.d_ino = dirp->pos;
|
||||||
|
strncpy(dirp->last_entry.d_name, entry->info.name, KSYS_FNAME_UTF8_SIZE-1);
|
||||||
|
|
||||||
|
if (entry->info.attr & (KSYS_FILE_ATTR_DIR | KSYS_FILE_ATTR_VOL_LABEL))
|
||||||
|
dirp->last_entry.d_type = DT_DIR;
|
||||||
|
else
|
||||||
|
dirp->last_entry.d_type = DT_REG;
|
||||||
|
|
||||||
|
dirp->pos++;
|
||||||
|
|
||||||
|
return &dirp->last_entry;
|
||||||
|
}
|
13
contrib/sdk/sources/newlib/libc/posix/rewinddir.c
Normal file
13
contrib/sdk/sources/newlib/libc/posix/rewinddir.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) KolibriOS team 2024. All rights reserved.
|
||||||
|
* Distributed under terms of the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
_DEFUN(rewinddir, (dirp),
|
||||||
|
DIR *dirp)
|
||||||
|
{
|
||||||
|
dirp->pos = 0;
|
||||||
|
}
|
14
contrib/sdk/sources/newlib/libc/posix/seekdir.c
Normal file
14
contrib/sdk/sources/newlib/libc/posix/seekdir.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) KolibriOS team 2024. All rights reserved.
|
||||||
|
* Distributed under terms of the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
_DEFUN(seekdir, (dirp, loc),
|
||||||
|
DIR *dirp _AND
|
||||||
|
long loc)
|
||||||
|
{
|
||||||
|
dirp->pos = loc;
|
||||||
|
}
|
13
contrib/sdk/sources/newlib/libc/posix/telldir.c
Normal file
13
contrib/sdk/sources/newlib/libc/posix/telldir.c
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) KolibriOS team 2024. All rights reserved.
|
||||||
|
* Distributed under terms of the GNU General Public License
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
long
|
||||||
|
_DEFUN(telldir, (dirp),
|
||||||
|
DIR *dirp)
|
||||||
|
{
|
||||||
|
return dirp->pos;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user