io.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #include <libc.h>
00036 #include <unistd.h>
00037 #include <stdio.h>
00038 #include <io/io.h>
00039 
00040 static char nl = '\n';
00041 
00042 int puts(const char * str)
00043 {
00044         size_t count;
00045         
00046         if (str == NULL) {
00047                 return putnchars("(NULL)",6 );
00048         }
00049         
00050         for (count = 0; str[count] != 0; count++);
00051         if (write(1, (void * ) str, count) == count) {
00052                 if (write(1, &nl, 1) == 1)
00053                         return 0;
00054         }
00055         
00056         return EOF;
00057 }
00058 
00064 int putnchars(const char * buf, size_t count)
00065 {
00066         if (write(1, (void * ) buf, count) == count) {
00067                         return 0;
00068         }
00069         
00070         return EOF;
00071 }
00072 
00076 int putstr(const char * str)
00077 {
00078         size_t count;
00079         
00080         if (str == NULL) {
00081                 return putnchars("(NULL)",6 );
00082         }
00083 
00084         for (count = 0; str[count] != 0; count++);
00085         if (write(1, (void * ) str, count) == count) {
00086                         return 0;
00087         }
00088         
00089         return EOF;
00090 }
00091 
00092 int putchar(int c)
00093 {
00094         unsigned char ch = c;
00095         if (write(1, (void *)&ch , 1) == 1) {
00096                         return c;
00097         }
00098         
00099         return EOF;
00100 }
00101 
00102 int getchar(void)
00103 {
00104         unsigned char c;
00105         if (read(0, (void *)&c , 1) == 1) {
00106                         return c;
00107         }
00108         
00109         return EOF;
00110 }
00111 
00112 
00113 
00114 

Generated on Sun Jun 18 17:54:21 2006 for HelenOS Userspace (ia32) by  doxygen 1.4.6