Contiki 2.6

newlib-syscalls.c

00001 #include <debug-uart.h>
00002 #include <sys/stat.h>
00003 #include <errno.h>
00004 #include <stdio.h>
00005 
00006 int
00007 _open(const char *name, int flags, int mode) {
00008   errno = ENOENT;
00009   return -1;
00010 }
00011 
00012 int
00013 _close(int file)
00014 {
00015   if (file == 1 || file == 2) {
00016     dbg_drain();
00017     return 0;
00018   }
00019   errno = EBADF;
00020   return -1;
00021 }
00022 
00023 int
00024 isatty(int file)
00025 {
00026   if (file >= 0 && file <= 2) return 1;
00027    return 0;
00028 }
00029 
00030 int
00031 _read(int file, char *ptr, int len){
00032   return 0;
00033 }
00034 
00035         
00036 
00037 int
00038 _write(int file, const char *ptr, int len){
00039   int sent = -1;
00040   if (file == 1 || file == 2) {
00041     sent = dbg_send_bytes((const unsigned char*)ptr, len);
00042   }
00043   return sent;
00044 }
00045 
00046 int
00047 _lseek(int file, int ptr, int dir){
00048     return 0;
00049 }
00050 
00051 int
00052 _fstat(int file, struct stat *st) {
00053   if (file >= 0 && file <= 2) {
00054     st->st_mode = S_IFCHR;
00055     return 0;
00056   }
00057   errno = EBADF;
00058   return -1;
00059 }
00060 
00061 int
00062 _stat(char *file, struct stat *st) {
00063   errno = ENOENT;
00064   return -1;
00065 }
00066 
00067 caddr_t
00068 _sbrk(int incr)
00069 {
00070   extern char __heap_start__;           /* Defined by the linker */
00071   extern char __heap_end__;             /* Defined by the linker */
00072   static char *heap_end = &__heap_start__;
00073   char *prev_heap_end;
00074  
00075   prev_heap_end = heap_end;
00076   if (heap_end + incr > &__heap_end__) {
00077     printf("Heap full (requested %d, available %d)\n",
00078             incr, (int)(&__heap_end__ - heap_end));
00079     errno = ENOMEM;
00080     return (caddr_t)-1;
00081   }
00082 
00083   heap_end += incr;
00084   return (caddr_t) prev_heap_end;
00085 }
00086 
00087 int
00088 fsync(int fd)
00089 {
00090   if (fd == 1 || fd == 2) {
00091     dbg_drain();
00092     return 0;
00093   }
00094   if (fd == 0) return 0;
00095   errno = EBADF;
00096   return -1;
00097 }
00098 
00099 void
00100 _exit(int status)
00101 {
00102   while(1);
00103 }
00104 
00105 void
00106 _abort()
00107 {
00108   while(1);
00109 }
00110 
00111 void
00112 _kill()
00113 {
00114   while(1);
00115 }
00116 
00117 pid_t
00118 _getpid(void)
00119 {
00120   return 1;
00121 }
00122 
00123 const unsigned long
00124 bkpt_instr = 0xe1200070;