/contrib/sdk/sources/newlib/libc/posix/closedir.c |
---|
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; |
} |
/contrib/sdk/sources/newlib/libc/posix/opendir.c |
---|
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; |
} |
/contrib/sdk/sources/newlib/libc/posix/readdir.c |
---|
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; |
} |
/contrib/sdk/sources/newlib/libc/posix/rewinddir.c |
---|
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; |
} |
/contrib/sdk/sources/newlib/libc/posix/seekdir.c |
---|
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; |
} |
/contrib/sdk/sources/newlib/libc/posix/telldir.c |
---|
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; |
} |