Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

6.13.5.4. Emulate ANSI C Functions

If you choose to omit the full implementation of newlib, but you need a limited number of ANSI-style functions, you can implement them easily using UNIX-style functions.

Example 6–15. Unbuffered getchar()

/* getchar: unbuffered single character input */
int getchar ( void )
{
char c;
return ( read ( 0, &c, 1 ) == 1 ) ? ( unsigned char ) c : EOF;
}

This example is from the book: The C Programming Language, Second Edition, by Brian W. Kernighan and Dennis M. Ritchie. This standard textbook contains many other useful functions.