Devices: Return EOF after first read for some devices
Still not optimal.
This commit is contained in:
parent
d5a64319f9
commit
41f7232b77
@ -8,22 +8,6 @@
|
||||
|
||||
void cat(FILE* stream)
|
||||
{
|
||||
struct stat statbuf;
|
||||
fstat(fileno(stream), &statbuf);
|
||||
if (statbuf.st_mode == __VFS_DEVICE) // FIXME: Add S_ISDEV.
|
||||
{
|
||||
char buf[4096]; // FIXME: Do not limit ourselves to 4096 bytes. Devices which can't seek and are constant should
|
||||
// return EOF after the first read.
|
||||
fgets(buf, 4096, stream);
|
||||
if (ferror(stream))
|
||||
{
|
||||
perror(program_invocation_name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (feof(stream)) return;
|
||||
fputs(buf, stdout);
|
||||
return;
|
||||
}
|
||||
char buf[BUFSIZ];
|
||||
do {
|
||||
fgets(buf, BUFSIZ, stream);
|
||||
|
@ -16,9 +16,10 @@ VFS::Node* UptimeDevice::create_new(const char* devname)
|
||||
return dev;
|
||||
}
|
||||
|
||||
ssize_t UptimeDevice::read(VFS::Node* node, size_t, size_t size, char* buffer)
|
||||
ssize_t UptimeDevice::read(VFS::Node* node, size_t offset, size_t size, char* buffer)
|
||||
{
|
||||
if (!node) return -1;
|
||||
if (offset > 0) return 0; // EOF after first read (FIXME: Should be only if everything was read)
|
||||
snprintf(buffer, size + 1, "%ld", PIT::ms_since_boot); // FIXME: Support offseting this read
|
||||
return (ssize_t)size;
|
||||
}
|
@ -19,8 +19,7 @@ VFS::Node* VersionDevice::create_new(const char* devname)
|
||||
ssize_t VersionDevice::read(VFS::Node* node, size_t offset, size_t size, char* buffer)
|
||||
{
|
||||
if (!node) return -1;
|
||||
if (offset > node->length) return -1;
|
||||
if (offset + size > node->length) { size = node->length - offset; }
|
||||
if (offset > 0) return 0; // EOF after first read (FIXME: Should be only if everything was read)
|
||||
snprintf(buffer, size + 1, "moon %s", moon_version()); // FIXME: Support offseting this read
|
||||
return (ssize_t)size;
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
#include <bits/seek.h>
|
||||
|
||||
#define FOPEN_MAX 32 // Maximum number of files that can be simultaneously opened with fopen().
|
||||
#define BUFSIZ 32 // Standard buffer size.
|
||||
#define BUFSIZ 1024 // Standard buffer size.
|
||||
#define FILENAME_MAX 1024 // Dummy value, we don't have a limit for filenames right now.
|
||||
|
||||
/* A stream representing a file. */
|
||||
|
Loading…
Reference in New Issue
Block a user