cfi new: fix new disabling buffer support
[barebox-mini2440.git] / common / misc.c
blob6754696598e326562b64b238af8bf5522f1c8445
1 /*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <common.h>
23 #include <mem_malloc.h>
24 #include <errno.h>
27 * Begin and End of memory area for malloc(), and current "brk"
29 static ulong malloc_start = 0;
30 static ulong malloc_end = 0;
31 static ulong malloc_brk = 0;
33 ulong mem_malloc_start(void)
35 return malloc_start;
38 ulong mem_malloc_end(void)
40 return malloc_end;
43 void mem_malloc_init (void *start, void *end)
45 malloc_start = (ulong)start;
46 malloc_end = (ulong)end;
47 malloc_brk = malloc_start;
50 void *sbrk_no_zero(ptrdiff_t increment)
52 ulong old = malloc_brk;
53 ulong new = old + increment;
55 if ((new < malloc_start) || (new > malloc_end))
56 return NULL;
58 malloc_brk = new;
60 return (void *)old;
63 void *sbrk (ptrdiff_t increment)
65 void *old = sbrk_no_zero(increment);
67 /* Only clear increment, if valid address was returned */
68 if (old != NULL)
69 memset (old, 0, increment);
71 return old;
74 int errno;
75 EXPORT_SYMBOL(errno);
78 const char *strerror(int errnum)
80 static char errno_string[10];
82 #ifdef CONFIG_ERRNO_MESSAGES
83 char *str;
84 switch(errnum) {
85 case 0 : str = "No error"; break;
86 case EPERM : str = "Operation not permitted"; break;
87 case ENOENT : str = "No such file or directory"; break;
88 case EIO : str = "I/O error"; break;
89 case ENXIO : str = "No such device or address"; break;
90 case E2BIG : str = "Arg list too long"; break;
91 case ENOEXEC : str = "Exec format error"; break;
92 case EBADF : str = "Bad file number"; break;
93 case ENOMEM : str = "Out of memory"; break;
94 case EACCES : str = "Permission denied"; break;
95 case EFAULT : str = "Bad address"; break;
96 case EBUSY : str = "Device or resource busy"; break;
97 case EEXIST : str = "File exists"; break;
98 case ENODEV : str = "No such device"; break;
99 case ENOTDIR : str = "Not a directory"; break;
100 case EISDIR : str = "Is a directory"; break;
101 case EINVAL : str = "Invalid argument"; break;
102 case ENOSPC : str = "No space left on device"; break;
103 case ESPIPE : str = "Illegal seek"; break;
104 case EROFS : str = "Read-only file system"; break;
105 case ENAMETOOLONG : str = "File name too long"; break;
106 case ENOSYS : str = "Function not implemented"; break;
107 case ENOTEMPTY : str = "Directory not empty"; break;
108 #if 0 /* These are probably not needed */
109 case ENOTBLK : str = "Block device required"; break;
110 case EFBIG : str = "File too large"; break;
111 case EBADSLT : str = "Invalid slot"; break;
112 case ENODATA : str = "No data available"; break;
113 case ETIME : str = "Timer expired"; break;
114 case ENONET : str = "Machine is not on the network"; break;
115 case EADV : str = "Advertise error"; break;
116 case ECOMM : str = "Communication error on send"; break;
117 case EPROTO : str = "Protocol error"; break;
118 case EBADMSG : str = "Not a data message"; break;
119 case EOVERFLOW : str = "Value too large for defined data type"; break;
120 case EBADFD : str = "File descriptor in bad state"; break;
121 case EREMCHG : str = "Remote address changed"; break;
122 case EMSGSIZE : str = "Message too long"; break;
123 case EPROTOTYPE : str = "Protocol wrong type for socket"; break;
124 case ENOPROTOOPT : str = "Protocol not available"; break;
125 case EPROTONOSUPPORT : str = "Protocol not supported"; break;
126 case ESOCKTNOSUPPORT : str = "Socket type not supported"; break;
127 case EPFNOSUPPORT : str = "Protocol family not supported"; break;
128 case EAFNOSUPPORT : str = "Address family not supported by protocol"; break;
129 case EADDRINUSE : str = "Address already in use"; break;
130 case EADDRNOTAVAIL : str = "Cannot assign requested address"; break;
131 case ENETDOWN : str = "Network is down"; break;
132 case ENETUNREACH : str = "Network is unreachable"; break;
133 case ENETRESET : str = "Network dropped connection because of reset"; break;
134 case ECONNABORTED : str = "Software caused connection abort"; break;
135 case ECONNRESET : str = "Connection reset by peer"; break;
136 case ENOBUFS : str = "No buffer space available"; break;
137 case ETIMEDOUT : str = "Connection timed out"; break;
138 case ECONNREFUSED : str = "Connection refused"; break;
139 case EHOSTDOWN : str = "Host is down"; break;
140 case EHOSTUNREACH : str = "No route to host"; break;
141 case EALREADY : str = "Operation already in progress"; break;
142 case EINPROGRESS : str = "Operation now in progress"; break;
143 case ESTALE : str = "Stale NFS file handle"; break;
144 case EISNAM : str = "Is a named type file"; break;
145 case EREMOTEIO : str = "Remote I/O error"; break;
146 #endif
147 default:
148 sprintf(errno_string, "error %d", errnum);
149 return errno_string;
152 return str;
153 #else
154 sprintf(errno_string, "error %d", errnum);
156 return errno_string;
157 #endif
159 EXPORT_SYMBOL(strerror);
161 const char *errno_str(void)
163 return strerror(-errno);
165 EXPORT_SYMBOL(errno_str);
167 void perror(const char *s)
169 #ifdef CONFIG_ERRNO_MESSAGES
170 printf("%s: %s\n", s, errno_str());
171 #else
172 printf("%s returned with %d\n", s, errno);
173 #endif
175 EXPORT_SYMBOL(perror);