Compare commits
No commits in common. "7b0b3dabc4e1859fde1b171b777af5ec4411807a" and "0847cfcb65079dfc374a56b0cc83d9be1ba67d5f" have entirely different histories.
7b0b3dabc4
...
0847cfcb65
@ -11,4 +11,3 @@ luna_app(cat.c cat)
|
||||
luna_app(edit.c edit)
|
||||
luna_app(sh.c sh)
|
||||
luna_app(date.c date)
|
||||
luna_app(ls.c ls)
|
||||
|
32
apps/ls.c
32
apps/ls.c
@ -1,32 +0,0 @@
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* pathname;
|
||||
if (argc == 1) pathname = "/";
|
||||
else
|
||||
pathname = argv[1];
|
||||
|
||||
DIR* dp = opendir(pathname);
|
||||
if (!dp)
|
||||
{
|
||||
perror("opendir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int first_ent = 1;
|
||||
do {
|
||||
struct dirent* ent = readdir(dp);
|
||||
if (!ent) break;
|
||||
printf(first_ent ? "%s" : " %s", ent->d_name);
|
||||
first_ent = 0;
|
||||
} while (1);
|
||||
|
||||
putchar('\n');
|
||||
|
||||
closedir(dp);
|
||||
return 0;
|
||||
}
|
@ -10,7 +10,6 @@ namespace TmpFS
|
||||
{
|
||||
SharedPtr<FileSystem> fs = TRY(adopt_shared_if_nonnull(new (std::nothrow) FileSystem()));
|
||||
SharedPtr<VFS::Inode> root = TRY(fs->create_dir_inode({}));
|
||||
root->chmod(0755);
|
||||
fs->set_root(root);
|
||||
return (SharedPtr<VFS::FileSystem>)fs;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ set(SOURCES
|
||||
src/ctype.cpp
|
||||
src/time.cpp
|
||||
src/init.cpp
|
||||
src/dirent.cpp
|
||||
src/setjmp.cpp
|
||||
src/sys/stat.cpp
|
||||
src/sys/mman.cpp
|
||||
|
@ -1,32 +0,0 @@
|
||||
/* dirent.h: Directory streams interface. */
|
||||
|
||||
#ifndef _DIRENT_H
|
||||
#define _DIRENT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int _fd;
|
||||
} DIR;
|
||||
|
||||
struct dirent
|
||||
{
|
||||
ino_t d_ino;
|
||||
char d_name[129];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
DIR* opendir(const char* path);
|
||||
struct dirent* readdir(DIR* stream);
|
||||
int closedir(DIR* stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,55 +0,0 @@
|
||||
#include <bits/getdents.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
DIR* opendir(const char* path)
|
||||
{
|
||||
DIR* dp = (DIR*)malloc(sizeof(DIR));
|
||||
if (!dp) { return nullptr; }
|
||||
|
||||
// FIXME: Use O_DIRECTORY (validate that path is actually a directory)
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
free(dp);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dp->_fd = fd;
|
||||
|
||||
return dp;
|
||||
}
|
||||
|
||||
struct dirent* readdir(DIR* stream)
|
||||
{
|
||||
// FIXME: Very hackish, right now luna_dirent and dirent have the same layout.
|
||||
static luna_dirent ent;
|
||||
|
||||
long rc = syscall(SYS_getdents, stream->_fd, &ent, 1);
|
||||
if (rc < 0)
|
||||
{
|
||||
errno = -rc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// End-of-file (no more directory entries)
|
||||
if (rc < 1) return nullptr;
|
||||
|
||||
return (struct dirent*)&ent;
|
||||
}
|
||||
|
||||
int closedir(DIR* stream)
|
||||
{
|
||||
if (close(stream->_fd) < 0) return -1;
|
||||
|
||||
free(stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -106,13 +106,13 @@ template <typename T> class Vector
|
||||
const T& operator[](usize index) const
|
||||
{
|
||||
check(index < m_size);
|
||||
return m_data[index];
|
||||
return m_data[m_size];
|
||||
}
|
||||
|
||||
T& operator[](usize index)
|
||||
{
|
||||
check(index < m_size);
|
||||
return m_data[index];
|
||||
return m_data[m_size];
|
||||
}
|
||||
|
||||
Iterator begin()
|
||||
|
Loading…
Reference in New Issue
Block a user