Added missing dirent impl

git-svn-id: svn://kolibrios.org@9955 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2024-01-12 23:03:49 +00:00
parent 6e3276cb4b
commit 75cc884573
6 changed files with 154 additions and 0 deletions

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}