Moved dirent.h functions from unistd/directory.c to new dirent.c file.

Added dirfd() call for BeOS compatibility.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8951 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-09-14 22:10:43 +00:00
parent 80c565ca25
commit 3901fa14bf
3 changed files with 105 additions and 74 deletions
+1
View File
@@ -5,6 +5,7 @@ UsePrivateHeaders [ FDirName syslog_daemon ] ;
KernelMergeObject posix_main.o :
assert.c
dlfcn.c
dirent.c
errno.c
fnmatch.c
glob.c
+99
View File
@@ -0,0 +1,99 @@
/*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <syscalls.h>
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
#define BUFFER_SIZE 4096
#define RETURN_AND_SET_ERRNO(err) \
if (err < 0) { \
errno = err; \
return -1; \
} \
return err;
DIR *
opendir(const char *path)
{
DIR *dir;
int fd = _kern_open_dir(-1, path);
if (fd < 0) {
errno = fd;
return NULL;
}
/* allocate the memory for the DIR structure */
if ((dir = (DIR *)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) {
errno = B_NO_MEMORY;
_kern_close(fd);
return NULL;
}
dir->fd = fd;
return dir;
}
int
closedir(DIR *dir)
{
int status = _kern_close(dir->fd);
free(dir);
RETURN_AND_SET_ERRNO(status);
}
struct dirent *
readdir(DIR *dir)
{
/* get the next entry and return a pointer to a dirent structure
* containing the data
*/
ssize_t count = _kern_read_dir(dir->fd, &dir->ent, BUFFER_SIZE, 1);
if (count <= 0) {
if (count < 0)
errno = count;
return NULL;
}
return &dir->ent;
}
void
rewinddir(DIR *dir)
{
status_t status = _kern_rewind_dir(dir->fd);
if (status < 0)
errno = status;
}
/** This is no POSIX compatible call; it's not exported in the headers
* but here for BeOS compatiblity.
*/
int dirfd(DIR *dir);
int
dirfd(DIR *dir)
{
return dir->fd;
}
+5 -74
View File
@@ -1,19 +1,13 @@
/*
** Copyright 2002, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
** Copyright 2002-2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <unistd.h>
#include <syscalls.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFFER_SIZE 4096
#define RETURN_AND_SET_ERRNO(err) \
@@ -24,69 +18,6 @@
return err;
DIR *
opendir(const char *path)
{
DIR *dir;
int fd = _kern_open_dir(-1, path);
if (fd < 0) {
errno = fd;
return NULL;
}
/* allocate the memory for the DIR structure */
if ((dir = (DIR *)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) {
errno = B_NO_MEMORY;
_kern_close(fd);
return NULL;
}
dir->fd = fd;
return dir;
}
int
closedir(DIR *dir)
{
int status = _kern_close(dir->fd);
free(dir);
RETURN_AND_SET_ERRNO(status);
}
struct dirent *
readdir(DIR *dir)
{
/* get the next entry and return a pointer to a dirent structure
* containing the data
*/
ssize_t count = _kern_read_dir(dir->fd, &dir->ent, BUFFER_SIZE, 1);
if (count <= 0) {
if (count < 0)
errno = count;
return NULL;
}
return &dir->ent;
}
void
rewinddir(DIR *dirp)
{
status_t status = _kern_rewind_dir(dirp->fd);
if (status < 0)
errno = status;
}
int
chdir(const char *path)
{