From: Masaki Muranaka <monaka@monami-ya.jp>
To: barebox@lists.infradead.org
Subject: Re: [PATCH] Use FILE structure for stdin/stdout/stderr.
Date: Mon, 3 Jun 2013 00:01:00 +0900 [thread overview]
Message-ID: <CAJBvFxOLE6=LnV2aeYJSev3aiimaf9U8Wms7SLFsc-Y_j7SbBQ@mail.gmail.com> (raw)
In-Reply-To: <1370102204-74399-1-git-send-email-monaka@monami-ya.com>
Hello,
This patch has side effects to echo.c.
Please reject it for now. I'm working in progress. I'll re-send soon.
2013/6/2 <monaka@monami-ya.jp>:
> From: Masaki Muranaka <monaka@monami-ya.com>
>
> Signed-off-by: Masaki Muranaka <monaka@monami-ya.com>
> ---
> common/console.c | 6 +++---
> common/console_common.c | 19 +++++++++----------
> include/filetype.h | 2 ++
> include/stdio.h | 17 +++++++++--------
> 4 files changed, 23 insertions(+), 21 deletions(-)
>
> diff --git a/common/console.c b/common/console.c
> index a0a06f6..7a8ac4f 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -246,13 +246,13 @@ int getc(void)
> }
> EXPORT_SYMBOL(getc);
>
> -int fgetc(int fd)
> +int fgetc(FILE *file)
> {
> char c;
>
> - if (!fd)
> + if (file == stdin)
> return getc();
> - return read(fd, &c, 1);
> + return read(file->no, &c, 1);
> }
> EXPORT_SYMBOL(fgetc);
>
> diff --git a/common/console_common.c b/common/console_common.c
> index d139d1a..34713f9 100644
> --- a/common/console_common.c
> +++ b/common/console_common.c
> @@ -66,7 +66,7 @@ EXPORT_SYMBOL(vprintf);
>
> #endif /* !CONFIG_CONSOLE_NONE */
>
> -int fprintf(int file, const char *fmt, ...)
> +int fprintf(FILE *file, const char *fmt, ...)
> {
> va_list args;
> char printbuffer[CFG_PBSIZE];
> @@ -85,26 +85,25 @@ int fprintf(int file, const char *fmt, ...)
> }
> EXPORT_SYMBOL(fprintf);
>
> -int fputs(int fd, const char *s)
> +int fputs(FILE *file, const char *s)
> {
> - if (fd == 1)
> + if (file == stdout)
> return puts(s);
> - else if (fd == 2)
> + else if (file == stderr)
> return eputs(s);
> else
> - return write(fd, s, strlen(s));
> + return write(file->no, s, strlen(s));
> }
> EXPORT_SYMBOL(fputs);
>
> -int fputc(int fd, char c)
> +int fputc(FILE *file, char c)
> {
> - if (fd == 1)
> + if (file == stdout)
> putchar(c);
> - else if (fd == 2)
> + else if (file == stderr)
> eputc(c);
> else
> - return write(fd, &c, 1);
> -
> + return write(file->no, &c, 1);
> return 0;
> }
> EXPORT_SYMBOL(fputc);
> diff --git a/include/filetype.h b/include/filetype.h
> index ee777ac..c73c64a 100644
> --- a/include/filetype.h
> +++ b/include/filetype.h
> @@ -1,6 +1,8 @@
> #ifndef __FILE_TYPE_H
> #define __FILE_TYPE_H
>
> +#include <linux/string.h>
> +
> /*
> * List of file types we know
> */
> diff --git a/include/stdio.h b/include/stdio.h
> index 5c091a8..00d1ed7 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -3,6 +3,7 @@
>
> #include <stdarg.h>
> #include <console.h>
> +#include <fs.h>
>
> /*
> * STDIO based functions (can always be used)
> @@ -93,15 +94,15 @@ static inline void putchar(char c)
> * FILE based functions
> */
>
> -#define stdin 0
> -#define stdout 1
> -#define stderr 2
> +#define stdin ((FILE *)0x10)
> +#define stdout ((FILE *)0x11)
> +#define stderr ((FILE *)0x12)
> #define MAX_FILES 128
>
> -int fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
> -int fputs(int file, const char *s);
> -int fputc(int file, const char c);
> -int ftstc(int file);
> -int fgetc(int file);
> +int fprintf(FILE *file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
> +int fputs(FILE *file, const char *s);
> +int fputc(FILE *file, const char c);
> +int ftstc(FILE *file);
> +int fgetc(FILE *file);
>
> #endif /* __STDIO_H */
> --
> 1.8.3
>
--
--
Masaki Muranaka
Monami-ya LLC, Japan.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2013-06-02 15:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-01 15:56 monaka
2013-06-02 15:01 ` Masaki Muranaka [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJBvFxOLE6=LnV2aeYJSev3aiimaf9U8Wms7SLFsc-Y_j7SbBQ@mail.gmail.com' \
--to=monaka@monami-ya.jp \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox