summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Albrecht <prom@berlin.ccc.de>2010-07-22 07:26:00 +0200
committerIngo Albrecht <prom@berlin.ccc.de>2010-08-17 00:29:08 +0200
commitfa16e773e4a3d44ba5ad4e6267037e520e27726e (patch)
tree127a103dc01e65742bd57c52d16b311ade2f778a
parentfc91df045af9e4efaaf40d7d5ae9687321ae62b2 (diff)
sys/file: added comments and added some BADF handlingprom/dietlibc
-rw-r--r--src/target/firmware/sys/file.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/target/firmware/sys/file.c b/src/target/firmware/sys/file.c
index 21fc280a..6b0b6ae0 100644
--- a/src/target/firmware/sys/file.c
+++ b/src/target/firmware/sys/file.c
@@ -208,6 +208,7 @@ struct file *file_for_fd(int fd)
return open_fds[fd];
}
+/* dummy open implementation */
int __libc_open(const char *pathname, int flags, ...)
{
errno = EOPNOTSUPP;
@@ -217,6 +218,7 @@ int __libc_open(const char *pathname, int flags, ...)
int open(const char *pathname, int flags, ...)
__attribute__ ((weak, alias("__libc_open")));
+/* close implementation */
int __libc_close(int fd)
{
struct file *file = file_for_fd(fd);
@@ -238,6 +240,7 @@ int __libc_close(int fd)
int close(int fd)
__attribute__ ((weak, alias("__libc_close")));
+/* read implementation */
ssize_t __libc_read(int fd, void *buf, size_t count)
{
struct file *f = file_for_fd(fd);
@@ -252,6 +255,7 @@ ssize_t __libc_read(int fd, void *buf, size_t count)
ssize_t read(int fd, void *buf, size_t count)
__attribute__ ((weak, alias("__libc_read")));
+/* write implementation */
ssize_t __libc_write(int fd, const void *buf, size_t count)
{
struct file *f = file_for_fd(fd);
@@ -266,6 +270,7 @@ ssize_t __libc_write(int fd, const void *buf, size_t count)
ssize_t write(int fd, const void *buf, size_t count)
__attribute__ ((weak, alias("__libc_write")));
+/* seek implementation */
off_t __libc_lseek(int fd, off_t offset, int whence)
{
struct file *f = file_for_fd(fd);
@@ -280,8 +285,15 @@ off_t __libc_lseek(int fd, off_t offset, int whence)
off_t lseek(int fd, off_t offset, int whence)
__attribute__ ((weak, alias("__libc_lseek")));
+/* dummy fstat implementation */
int __libc_fstat(int fd, struct stat *buf)
{
+ struct file *f = file_for_fd(fd);
+ if (!f) {
+ errno = EBADF;
+ return -1;
+ }
+
errno = EOPNOTSUPP;
return -1;
}
@@ -289,8 +301,16 @@ int __libc_fstat(int fd, struct stat *buf)
int fstat(int fd, struct stat *buf)
__attribute__ ((weak, alias("__libc_fstat")));
+
+/* dummy ioctl implementation */
int __libc_ioctl(int fd, long int request, ...)
{
+ struct file *f = file_for_fd(fd);
+ if (!f) {
+ errno = EBADF;
+ return -1;
+ }
+
errno = EOPNOTSUPP;
return -1;
}