write.c
Go to the documentation of this file.00001
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "compiler.h"
00048
00049
00050 #if ( defined(__ICCAVR32__) || defined(__ICCAVR__))
00051
00052 #include <yfuns.h>
00053
00054 _STD_BEGIN
00055
00056 #pragma module_name = "?__write"
00057
00059 #if defined(__ICCAVR32__)
00060 __no_init
00061 #endif
00062 volatile void *volatile stdio_base;
00063
00064 int (*ptr_put)(void volatile*,int);
00065
00079 size_t __write(int handle, const unsigned char *buffer, size_t size)
00080 {
00081 size_t nChars = 0;
00082
00083 if (buffer == 0){
00084
00085 return 0;
00086 }
00087
00088
00089
00090 if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
00091 return _LLIO_ERROR;
00092 }
00093
00094 for (; size != 0; --size) {
00095 if (ptr_put(stdio_base, *buffer++) < 0) {
00096 return _LLIO_ERROR;
00097 }
00098 ++nChars;
00099 }
00100
00101 return nChars;
00102 }
00103 _STD_END
00104
00105
00106 #elif (defined(__GNUC__) && !defined(XMEGA))
00107
00108 extern volatile void *volatile stdio_base;
00109 extern int (*ptr_put)(void volatile*,int);
00110
00111 int __attribute__((weak))
00112 _write (int file, char * ptr, int len)
00113 {
00114 int nChars = 0;
00115
00116 if ( (file != 1)
00117 && (file != 2) && (file!=3))
00118 return -1;
00119
00120 for (; len != 0; --len) {
00121 if (ptr_put(stdio_base, *ptr++) < 0) {
00122 return -1;
00123 }
00124 ++nChars;
00125 }
00126 return nChars;
00127 }
00128
00129 #elif (defined(__GNUC__) && defined(XMEGA))
00130
00131 extern volatile void *volatile stdio_base;
00132 extern int (*ptr_put)(void volatile*,int);
00133
00134 int _write (char c, int *f)
00135 {
00136 if (ptr_put(stdio_base,c) < 0)
00137 {
00138 return -1;
00139 }
00140 return 1;
00141 }
00142
00143 #endif