From: <ped...@us...> - 2007-06-25 01:06:17
|
Revision: 1006 http://svn.sourceforge.net/cegcc/?rev=1006&view=rev Author: pedroalves Date: 2007-06-24 18:06:15 -0700 (Sun, 24 Jun 2007) Log Message: ----------- Initial import. * LICENSE, README, TODO, ChangeLog, Makefile, errno.c errno.tab, errno_h.awk, errno_str.awk, errno_tab.awk: New files. Added Paths: ----------- trunk/cegcc/tools/errno/ trunk/cegcc/tools/errno/ChangeLog trunk/cegcc/tools/errno/LICENSE trunk/cegcc/tools/errno/Makefile trunk/cegcc/tools/errno/README trunk/cegcc/tools/errno/TODO trunk/cegcc/tools/errno/errno.c trunk/cegcc/tools/errno/errno.tab trunk/cegcc/tools/errno/errno_h.awk trunk/cegcc/tools/errno/errno_str.awk trunk/cegcc/tools/errno/errno_tab.awk Added: trunk/cegcc/tools/errno/ChangeLog =================================================================== --- trunk/cegcc/tools/errno/ChangeLog (rev 0) +++ trunk/cegcc/tools/errno/ChangeLog 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,14 @@ +2007-06-25 Pedro Alves <ped...@po...> + + Initial import. + + * LICENSE, README, TODO, ChangeLog, Makefile, errno.c errno.tab, + errno_h.awk, errno_str.awk, errno_tab.awk: New files. + + +Local Variables: +mode: change-log +left-margin: 8 +fill-column: 74 +version-control: never +End: Property changes on: trunk/cegcc/tools/errno/ChangeLog ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/cegcc/tools/errno/LICENSE =================================================================== --- trunk/cegcc/tools/errno/LICENSE (rev 0) +++ trunk/cegcc/tools/errno/LICENSE 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,25 @@ +/* Copyright (c) 2007, Pedro Alves + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ Added: trunk/cegcc/tools/errno/Makefile =================================================================== --- trunk/cegcc/tools/errno/Makefile (rev 0) +++ trunk/cegcc/tools/errno/Makefile 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,38 @@ +TARGET=arm-wince-mingw32ce + +CC=$(TARGET)-gcc +AR=$(TARGET)-ar + +INCLUDES=-I. +ALLFLAGS=$(CFLAGS) $(INCLUDES) + +GENFILES=errno.h errno_tab.c errno_str.c +OBJECTS=errno.o + +all: liberrno.a + +errno_tab.c: errno.tab errno_tab.awk Makefile + awk '{ print $$2 " " $$1 }' < errno.tab | sort | awk -f errno_tab.awk > $@ + +errno_str.c: errno.tab errno_str.awk Makefile + awk -f errno_str.awk < errno.tab > $@ + +errno.h: errno.tab errno_h.awk Makefile + awk -f errno_h.awk < errno.tab > $@ + +errno.o: errno.c errno_tab.c errno_str.c errno.h Makefile + $(CC) -c -o $@ $< $(ALLFLAGS) + +liberrno.a: errno.o Makefile + rm -f $@ + $(AR) r $@ $< + +clean: + rm -f liberrno.a $(OBJECTS) + +distclean: clean + rm -f $(GENFILES) + +regen: distclean $(GENFILES) + +.PHONY: all clean regen Property changes on: trunk/cegcc/tools/errno/Makefile ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/cegcc/tools/errno/README =================================================================== --- trunk/cegcc/tools/errno/README (rev 0) +++ trunk/cegcc/tools/errno/README 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,28 @@ +This is an errno <-> {Get|Set}LastError mapper. + +<describe here the technique used> + +Do *not* install errno.h into +/opt/mingw32ce/arm-wince-mingw32ce/include. + +You have been warned. + +This is only used as a porting aid. Ideally you use this as an +interim measure until you finish the port. If you chose to keep using +it, and you are writing a lib to be reused by others, be sure to *NOT* +export any header that includes errno.h. Do *NOT* expect your users +to have errno.h. If needed, copy errno.h and errno.c into your +project, but again, do *NOT* force it into the users. + +Have fun! + +Pedro Alves + +-- + +See the file LICENSE in the various directories, for a description of +the license the software is license in. + +REPORTING BUGS: +ce...@so... +pe...@po... Property changes on: trunk/cegcc/tools/errno/README ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/cegcc/tools/errno/TODO =================================================================== --- trunk/cegcc/tools/errno/TODO (rev 0) +++ trunk/cegcc/tools/errno/TODO 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1 @@ + Property changes on: trunk/cegcc/tools/errno/TODO ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/cegcc/tools/errno/errno.c =================================================================== --- trunk/cegcc/tools/errno/errno.c (rev 0) +++ trunk/cegcc/tools/errno/errno.c 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,112 @@ +/* Pedro Alves */ + +#include "errno.h" +#include <windows.h> + +/* There are more WinErr codes than errno codes. + To prevent having to do stuff like: + +- if (errno == ENOENT) ++ if (errno == ERROR_PATH_NOT_FOUND ++ || errno == ERROR_FILE_NOT_FOUND) + + ... we colapse the multiple WinErr mappings into one. */ + +int +__liberrno_errno (void) +{ + DWORD winerr = GetLastError (); + switch (winerr) + { +#include "errno_tab.c" + default: + return (int) winerr; + } +} + +#ifndef COUNTOF +#define COUNTOF(STR) (sizeof (STR) / sizeof ((STR)[0])) +#endif + +/* Map the Windows error number in ERROR to a locale-dependent error + message string and return a pointer to it. Typically, the values + for ERROR come from GetLastError. + + The string pointed to shall not be modified by the application, + but may be overwritten by a subsequent call to strwinerror + + The strwinerror function does not change the current setting + of GetLastError. */ + +static char * +strwinerror (char* buf, DWORD error) +{ + wchar_t *msgbuf; + DWORD lasterr = GetLastError (); + DWORD chars = FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM + | FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + error, + 0, /* Default language */ + (LPVOID)&msgbuf, + 0, + NULL); + if (chars != 0) + { + /* If there is an \r\n appended, zap it. */ + if (chars >= 2 + && msgbuf[chars - 2] == '\r' + && msgbuf[chars - 1] == '\n') + { + chars -= 2; + msgbuf[chars] = 0; + } + + if (chars > ((COUNTOF (buf)) - 1)) + { + chars = COUNTOF (buf) - 1; + msgbuf [chars] = 0; + } + + wcstombs (buf, msgbuf, chars + 1); + LocalFree (msgbuf); + } + else + sprintf (buf, "unknown win32 error (%ld)", error); + + SetLastError (lasterr); + return buf; +} + +__inline__ static const char* +get_errstr (DWORD winerr) +{ + switch (winerr) + { +#include "errno_str.c" + } + return NULL; +} + +char * +strerror (int error) +{ + static char buf[1024]; + DWORD winerr = (DWORD) error; + const char *str = get_errstr (winerr); + + if (str != NULL) + strcpy (buf, str); + else + strwinerror (buf, winerr); + return buf; +} + +void +perror (const char *s) +{ + if (s && *s) + fprintf (stderr, "%s: %s\n", s, strerror (errno)); + else + fprintf (stderr, "%s\n", strerror (errno)); +} Property changes on: trunk/cegcc/tools/errno/errno.c ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/cegcc/tools/errno/errno.tab =================================================================== --- trunk/cegcc/tools/errno/errno.tab (rev 0) +++ trunk/cegcc/tools/errno/errno.tab 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,165 @@ +# libceerrno v1.0 +# +# errno to Windows error mapping. + +EACCES ERROR_ACCESS_DENIED "Permission denied" +EACCES ERROR_LOCK_VIOLATION +EACCES ERROR_SHARING_VIOLATION + +EAGAIN ERROR_MORE_DATA "Resource temporarily unavailable" +EAGAIN ERROR_ACTIVE_CONNECTIONS +EAGAIN ERROR_DEVICE_IN_USE +EAGAIN ERROR_MAX_THRDS_REACHED +EAGAIN ERROR_NO_PROC_SLOTS +EAGAIN ERROR_OPEN_FILES + +EBADF ERROR_INVALID_HANDLE "Bad file descriptor" + +EBADRQC ERROR_INVALID_FUNCTION "Invalid request code" + +EBUSY ERROR_BUSY "Device or resource busy" +EBUSY ERROR_CHILD_NOT_COMPLETE +EBUSY ERROR_PIPE_BUSY +EBUSY ERROR_PIPE_CONNECTED +EBUSY ERROR_SIGNAL_PENDING + +ECHILD ERROR_WAIT_NO_CHILDREN "No child processes" + +ECOMM ERROR_PIPE_LISTENING "Communication error on send" +ECOMM ERROR_PIPE_NOT_CONNECTED + +EDEADLOCK ERROR_POSSIBLE_DEADLOCK "File locking deadlock error" + +EEXIST ERROR_FILE_EXISTS "File exists" +EEXIST ERROR_ALREADY_EXISTS + +EFAULT ERROR_PROCESS_ABORTED "Bad address" +EFAULT ERROR_NOACCESS + +EINTR ERROR_INVALID_AT_INTERRUPT_TIME "Interrupted system call" + +EINVAL ERROR_INVALID_PARAMETER "Invalid argument" +EINVAL ERROR_BAD_PIPE +EINVAL ERROR_BAD_USERNAME +EINVAL ERROR_FILENAME_EXCED_RANGE +EINVAL ERROR_INVALID_DATA +EINVAL ERROR_INVALID_SIGNAL_NUMBER +EINVAL ERROR_META_EXPANSION_TOO_LONG +EINVAL ERROR_NEGATIVE_SEEK +EINVAL ERROR_NO_TOKEN +EINVAL ERROR_THREAD_1_INACTIVE + +EIO ERROR_IO_DEVICE "Input/Output error" +EIO ERROR_CRC +EIO ERROR_NO_SIGNAL_SENT +EIO ERROR_OPEN_FAILED +EIO ERROR_SIGNAL_REFUSED + +EMFILE ERROR_TOO_MANY_OPEN_FILES "Too many open files" +ENFILE ERROR_NO_MORE_SEARCH_HANDLES + +ENMFILE ERROR_NO_MORE_FILES "No more files" + +ENODATA ERROR_HANDLE_EOF "No data available" + +ENODEV ERROR_BAD_DEVICE "No such device" +ENODEV ERROR_BAD_UNIT +ENODEV ERROR_INVALID_DRIVE + +ENOENT ERROR_FILE_NOT_FOUND "No such file or directory" +ENOENT ERROR_BAD_PATHNAME +ENOENT ERROR_INVALID_NAME +ENOENT ERROR_PATH_NOT_FOUND + +ENOERR NO_ERROR "No error" + +ENOLCK ERROR_SHARING_BUFFER_EXCEEDED "No locks available" + +ENOLINK ERROR_NOT_CONNECTED "Link has been severed" + +ENOMEDIUM ERROR_NOT_READY "No medium found" + +ENOMEM ERROR_NOT_ENOUGH_MEMORY "Cannot allocate memory" +ENOMEM ERROR_OUTOFMEMORY + +ENONET ERROR_REM_NOT_LIST "Machine is not on the network" + +ENOSHARE ERROR_BAD_NETPATH "No such host or network path" +ENOSHARE ERROR_BAD_NET_NAME + +ENOSPC ERROR_DISK_FULL "No space left on device" +ENOSPC ERROR_END_OF_MEDIA +ENOSPC ERROR_EOM_OVERFLOW +ENOSPC ERROR_HANDLE_DISK_FULL +ENOSPC ERROR_NO_DATA_DETECTED + +ENOSYS ERROR_CALL_NOT_IMPLEMENTED "Function not implemented" +ENOSYS ERROR_NOT_SUPPORTED + +ENOTDIR ERROR_DIRECTORY "Not a directory" + +ENOTEMPTY ERROR_DIR_NOT_EMPTY "Directory not empty" +ENOTEMPTY WSAENOTEMPTY + +ENOTUNIQ ERROR_DUP_NAME "Name not unique on network" + +ENXIO ERROR_FILE_INVALID "No such device or address" + +EOVERFLOW ERROR_ARITHMETIC_OVERFLOW "Value too large for defined data type" + +EPERM ERROR_CANNOT_MAKE "Operation not permitted" +EPERM ERROR_NOT_OWNER + +EPIPE ERROR_BROKEN_PIPE "Broken pipe" +EPIPE ERROR_NO_DATA + +# also defined as EOVERFLOW above +ERANGE ERROR_ARITHMETIC_OVERFLOW + +EROFS ERROR_WRITE_PROTECT "Read-only file system" + +ESPIPE ERROR_BEGINNING_OF_MEDIA "Illegal seek" +ESPIPE ERROR_SETMARK_DETECTED + +EXDEV ERROR_NOT_SAME_DEVICE "Invalid cross-device link" + +# Winsock codes + +EWOULDBLOCK +EINPROGRESS WSAEINPROGRESS +EALREADY WSAEALREADY +ENOTSOCK WSAENOTSOCK +EDESTADDRREQ WSAEDESTADDRREQ +EMSGSIZE WSAEMSGSIZE +EPROTOTYPE WSAEPROTOTYPE +ENOPROTOOPT WSAENOPROTOOPT +EPROTONOSUPPORT WSAEPROTONOSUPPORT +ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +EOPNOTSUPP WSAEOPNOTSUPP +EPFNOSUPPORT WSAEPFNOSUPPORT +EAFNOSUPPORT WSAEAFNOSUPPORT +EADDRINUSE WSAEADDRINUSE +EADDRNOTAVAIL WSAEADDRNOTAVAIL +ENETDOWN WSAENETDOWN +ENETUNREACH WSAENETUNREACH +ENETRESET WSAENETRESET +ECONNABORTED WSAECONNABORTED +ECONNRESET WSAECONNRESET +ENOBUFS WSAENOBUFS +EISCONN WSAEISCONN +ENOTCONN WSAENOTCONN +ESHUTDOWN WSAESHUTDOWN +ETOOMANYREFS WSAETOOMANYREFS +ETIMEDOUT WSAETIMEDOUT +ECONNREFUSED WSAECONNREFUSED +ELOOP WSAELOOP +ENAMETOOLONG WSAENAMETOOLONG +EHOSTDOWN WSAEHOSTDOWN +EHOSTUNREACH WSAEHOSTUNREACH +# Defined above because of conflict. +#ENOTEMPTY WSAENOTEMPTY +EPROCLIM WSAEPROCLIM +EUSERS WSAEUSERS +EDQUOT WSAEDQUOT +ESTALE WSAESTALE +EREMOTE WSAEREMOTE Added: trunk/cegcc/tools/errno/errno_h.awk =================================================================== --- trunk/cegcc/tools/errno/errno_h.awk (rev 0) +++ trunk/cegcc/tools/errno/errno_h.awk 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,41 @@ +BEGIN { + print "\ +#ifndef _LIB_CE_ERRNO_H\n\ +#define _LIB_CE_ERRNO_H\n\ +\n\ +#include <winerror.h>\n\ +\n\ +#define errno __liberrno_errno ()\n\ +#define __set_errno(ERR) SetLastError (ERR)\n\ +\n\ +#ifdef __cplusplus\n\ +extern \"C\" {\n\ +#endif\n\ +\n\ +int __liberrno_errno (void);\n\ +\n\ +char *strerror (int error);\n\ +void perror (const char *s);\n\ +\n\ +#ifdef __cplusplus\n\ +}\n\ +#endif\n\ +\n"; +} + +{ + errno = $1; + winerr = $2; + + if (errno != "" && substr (errno, 1, 1) != "#") + { + if (errno != prev_errno) + print "#define " errno " " winerr; + prev_errno = errno; + } +} + +END { + print ""; + print "#endif /* _LIB_CE_ERRNO_H */"; +} Property changes on: trunk/cegcc/tools/errno/errno_h.awk ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/cegcc/tools/errno/errno_str.awk =================================================================== --- trunk/cegcc/tools/errno/errno_str.awk (rev 0) +++ trunk/cegcc/tools/errno/errno_str.awk 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,12 @@ +BEGIN { +} + +{ + errno = $1; + winerr = $2; + # get tail beginning at $3 + msg=$0; for (i=1;i<3;i++) sub($i,"",msg); sub(/ */,"",msg) + + if (errno != "" && substr ($1, 1, 1) != "#" && msg != "") + print "case " winerr ": return " msg ";"; +} Property changes on: trunk/cegcc/tools/errno/errno_str.awk ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/cegcc/tools/errno/errno_tab.awk =================================================================== --- trunk/cegcc/tools/errno/errno_tab.awk (rev 0) +++ trunk/cegcc/tools/errno/errno_tab.awk 2007-06-25 01:06:15 UTC (rev 1006) @@ -0,0 +1,13 @@ +BEGIN { +} + +{ + winerr = $1; + errno = $2; + + if (errno != "" && substr (errno, 1, 1) != "#" && prev_winerr != winerr) + { + print "case " winerr ": return " errno ";"; + prev_winerr = winerr; + } +} Property changes on: trunk/cegcc/tools/errno/errno_tab.awk ___________________________________________________________________ Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |