diff options
author | Danny Smith <dannysmith@users.sourceforge.net> | 2002-04-10 01:11:28 +0000 |
---|---|---|
committer | Danny Smith <dannysmith@users.sourceforge.net> | 2002-04-10 01:11:28 +0000 |
commit | bd2c19cf6ed30f0200d2a5036c3e0c154c69071d (patch) | |
tree | 78c6948bf0d250f6967671635d0908964df90681 | |
parent | b457712be07abf2ffd23f45a3e0b0ff70fff67ee (diff) | |
download | newlib-bd2c19cf6ed30f0200d2a5036c3e0c154c69071d.zip newlib-bd2c19cf6ed30f0200d2a5036c3e0c154c69071d.tar.gz newlib-bd2c19cf6ed30f0200d2a5036c3e0c154c69071d.tar.bz2 |
* mingwex/mingw-fseek.c: New file, based on Mumit Khan
mingw-local patch to binutils.
Sun Nov 7 04:27:07 1999 Mumit Khan <khan@xraylith.wisc.edu>
(__mingw_fseek): New function to work around Win9x f/lseek bug.
(__mingw_fwrite): Likewise.
(__mingw_is_win9x): New helper function.
* include/stdio.h (__USE_MINGW_FSEEK): New define, guarding...
(__mingw_fseek): New prototype and define to replace fseek.
(__mingw_fseek): New prototype and define to replace fwrite.
* mingwex/Makefile.in: Add mingw-fseek.o to libmingwex.a.
* moldname-crtdll.def: Remove CR from end of line.
* moldname-msvcrt.def: Ditto.
-rw-r--r-- | winsup/mingw/ChangeLog | 16 | ||||
-rw-r--r-- | winsup/mingw/include/stdio.h | 13 | ||||
-rw-r--r-- | winsup/mingw/mingwex/Makefile.in | 6 | ||||
-rw-r--r-- | winsup/mingw/mingwex/mingw-fseek.c | 119 | ||||
-rw-r--r-- | winsup/mingw/moldname-crtdll.def | 284 | ||||
-rw-r--r-- | winsup/mingw/moldname-msvcrt.def | 284 |
6 files changed, 437 insertions, 285 deletions
diff --git a/winsup/mingw/ChangeLog b/winsup/mingw/ChangeLog index 87996de..b61b8e5 100644 --- a/winsup/mingw/ChangeLog +++ b/winsup/mingw/ChangeLog @@ -1,3 +1,19 @@ +2002-04-10 Danny Smith <dannysmith@sourceforge.users.net> + + * mingwex/mingw-fseek.c: New file, based on Mumit Khan + mingw-local patch to binutils. + Sun Nov 7 04:27:07 1999 Mumit Khan <khan@xraylith.wisc.edu> + (__mingw_fseek): New function to work around Win9x f/lseek bug. + (__mingw_fwrite): Likewise. + (__mingw_is_win9x): New helper function. + * include/stdio.h (__USE_MINGW_FSEEK): New define,guarding... + (__mingw_fseek): New prototype and define to replace fseek. + (__mingw_fwrite): New prototype and define to replace fwrite. + * mingwex/Makefile.in: Add mingw-fseek.o to libmingwex.a. + + * moldname-crtdll.def: Remove CR from end of line. + * moldname-msvcrt.def: Ditto. + 2002-04-09 Danny Smith <dannysmith@sourceforge.users.net> * profile/configure.in (CRT0S): Configure name of gcrt?.o diff --git a/winsup/mingw/include/stdio.h b/winsup/mingw/include/stdio.h index 65db38d..7a09250 100644 --- a/winsup/mingw/include/stdio.h +++ b/winsup/mingw/include/stdio.h @@ -261,6 +261,19 @@ int fseek (FILE*, long, int); long ftell (FILE*); void rewind (FILE*); +#ifdef __USE_MINGW_FSEEK /* These are in libmingwex.a */ +/* + * Workaround for limitations on win9x where a file contents are + * not zero'd out if you seek past the end and then write. + */ + +int __mingw_fseek (FILE *, long, int); +int __mingw_fwrite (const void*, size_t, size_t, FILE*); +#define fseek(fp, offset, whence) __mingw_fseek(fp, offset, whence) +#define fwrite(buffer, size, count, fp) __mingw_fwrite(buffer, size, count, fp) +#endif /* __USE_MINGW_FSEEK */ + + /* * An opaque data type used for storing file positions... The contents of * this type are unknown, but we (the compiler) need to know the size diff --git a/winsup/mingw/mingwex/Makefile.in b/winsup/mingw/mingwex/Makefile.in index 9166c1c..31f0670 100644 --- a/winsup/mingw/mingwex/Makefile.in +++ b/winsup/mingw/mingwex/Makefile.in @@ -26,6 +26,7 @@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ mkinstalldirs = $(SHELL) $(srcdir)/../mkinstalldirs DISTFILES = Makefile.in configure configure.in \ + mingw-fseek.c \ _Exit.c \ atoll.c \ dirent.c \ @@ -139,9 +140,12 @@ FENV_OBJS = fesetround.o fegetround.o \ feraiseexcept.o fetestexcept.o fesetexceptflag.o POSIX_OBJS = \ dirent.o +REPLACE_OBJS = \ + mingw-fseek.o LIB_OBJS = $(Q8_OBJS) $(STDLIB_STUB_OBJS) $(STDIO_STUB_OBJS) \ - $(MATH_OBJS) $(MATH_STUB_OBJS) $(FENV_OBJS) $(POSIX_OBJS) + $(MATH_OBJS) $(MATH_STUB_OBJS) $(FENV_OBJS) $(POSIX_OBJS) \ + $(REPLACE_OBJS) LIBS = $(LIBMINGWEX_A) DLLS = diff --git a/winsup/mingw/mingwex/mingw-fseek.c b/winsup/mingw/mingwex/mingw-fseek.c new file mode 100644 index 0000000..6a3b661 --- /dev/null +++ b/winsup/mingw/mingwex/mingw-fseek.c @@ -0,0 +1,119 @@ +/* + * Workaround for limitations on win9x where a file contents are + * not zero'd out if you seek past the end and then write. + * Copied from ming local-patch to binutils/bfd/libbfd.c written by + * Mumit Khan <khan@xraylith.wisc.edu> + */ + +#include <windows.h> +#include <stdio.h> +#include <io.h> + +#ifdef __GNUC__ +# define INLINE __inline__ +#elif defined _MSC_VER +# define INLINE __inline +#else +# define INLINE +#endif + +#define ZEROBLOCKSIZE 512 +static int __mingw_fseek_called; + +/* FIXME: put this in startup code and make os_platform_id global? + Or just get _osver from msvcrt.dll and bitest (_osver & 0x8000)? */ + +INLINE +static +int +__mingw_is_win9x (void) +{ + static DWORD os_platform_id = -1 ; + + if (os_platform_id == -1) + { + OSVERSIONINFO os_version_info; + memset (&os_version_info, 0, sizeof (OSVERSIONINFO)); + os_version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + GetVersionEx (&os_version_info); + + os_platform_id = os_version_info.dwPlatformId; + } + + /* Don't even bother to check for Win32s. */ + return os_platform_id == VER_PLATFORM_WIN32_WINDOWS; +} + +/* The fseek in Win9x runtime does not zero out the file if seeking past + the end; if you don't want random stuff from your disk included in your + output DLL/executable, use this version instead. On WinNT/Win2k, it + just calls runtime fseek(). + + CHECK/FIXME: Does this work for both text and binary modes?? */ + + +int +__mingw_fseek (FILE *fp, long offset, int whence) +{ +# undef fseek + __mingw_fseek_called = 1; + return fseek (fp, offset, whence); +} + +int +__mingw_fwrite (const void *buffer, size_t size, size_t count, FILE *fp) +{ +# undef fwrite + if ( __mingw_is_win9x () && __mingw_fseek_called) + { + DWORD actual_length, current_position; + __mingw_fseek_called = 0; + fflush (fp); + actual_length = GetFileSize ((HANDLE) _get_osfhandle (fileno (fp)), + NULL); + current_position = SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)), + 0, 0, FILE_CURRENT); +#ifdef DEBUG + printf ("__mingw_fwrite: current %ld, actual %ld\n", + current_position, actual_length); +#endif /* DEBUG */ + if (current_position > actual_length) + { + static char __mingw_zeros[ZEROBLOCKSIZE]; + long numleft; + + SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)), + 0, 0, FILE_END); + numleft = current_position - actual_length; + +#ifdef DEBUG + printf ("__mingw_fwrite: Seeking %ld bytes past end\n", numleft); +#endif /* DEBUG */ + while (numleft > 0) + { + DWORD nzeros = (numleft > ZEROBLOCKSIZE) + ? ZEROBLOCKSIZE : numleft; + DWORD written; + if (! WriteFile ((HANDLE) _get_osfhandle (fileno (fp)), + __mingw_zeros, nzeros, &written, NULL)) + { + /* Best we can hope for, or at least DJ says so. */ + SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)), + 0, 0, FILE_BEGIN); + return -1; + } + if (written < nzeros) + { + /* Likewise. */ + SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)), + 0, 0, FILE_BEGIN); + return -1; + } + + numleft -= written; + } + FlushFileBuffers ((HANDLE) _get_osfhandle (fileno (fp))); + } + } + return fwrite (buffer, size, count, fp); +} diff --git a/winsup/mingw/moldname-crtdll.def b/winsup/mingw/moldname-crtdll.def index f27fa15..3b641eb 100644 --- a/winsup/mingw/moldname-crtdll.def +++ b/winsup/mingw/moldname-crtdll.def @@ -1,142 +1,142 @@ -; -; moldname-crtdll.def -; -; Exports from the runtime except that these exports are actually preceeded -; by a underscore in the actual DLL. These correspond to functions which -; are non-ANSI and were prefixed with an underscore to avoid name space -; clutter. However many, in fact most programs still use a few of these -; functions without the underscore. This .def file is specially processed -; to make those non-underscored name function calls call the equivalent -; underscored functions. -; -; Contributors: -; Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp> -; Maintained by Mumit Khan <khan@xraylith.wisc.edu> -; -; THIS SOFTWARE IS NOT COPYRIGHTED -; -; This source code is offered for use in the public domain. You may -; use, modify or distribute it freely. -; -; This code is distributed in the hope that it will be useful but -; WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY -; DISCLAMED. This includes but is not limited to warrenties of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -; -EXPORTS -access -beep -cabs -chdir -chmod -chsize -close -creat -cwait - - - -dup -dup2 -ecvt -eof -execl -execle -execlp -execlpe -execv -execve -execvp -execvpe -fcvt -fdopen -fgetchar -fgetwchar -filelength -fileno -fpreset -fputchar -fputwchar -fstat -ftime -gcvt -getch -getche -getcwd -getpid -getw -heapwalk -hypot -isatty -itoa -j0 -j1 -jn -kbhit -lseek -ltoa -memccpy -memicmp -mkdir -mktemp -open -pclose -popen -putch -putenv -putw -read -rmdir -searchenv -seterrormode -setmode -sleep -sopen -spawnl -spawnle -spawnlp -spawnlpe -spawnv -spawnve -spawnvp -spawnvpe -stat -strcmpi -strdup -stricmp -stricoll -strlwr -strnicmp -strnset -strrev -strset -strupr -swab -tell -tempnam - - - -; export tzname for both. See <time.h> -tzname DATA -tzset -umask -ungetch -unlink -utime -wcsdup -wcsicmp -wcsicoll -wcslwr -wcsnicmp -wcsnset -wcsrev -wcsset -wcsupr - - - -write -y0 -y1 -yn +;
+; moldname-crtdll.def
+;
+; Exports from the runtime except that these exports are actually preceeded
+; by a underscore in the actual DLL. These correspond to functions which
+; are non-ANSI and were prefixed with an underscore to avoid name space
+; clutter. However many, in fact most programs still use a few of these
+; functions without the underscore. This .def file is specially processed
+; to make those non-underscored name function calls call the equivalent
+; underscored functions.
+;
+; Contributors:
+; Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
+; Maintained by Mumit Khan <khan@xraylith.wisc.edu>
+;
+; THIS SOFTWARE IS NOT COPYRIGHTED
+;
+; This source code is offered for use in the public domain. You may
+; use, modify or distribute it freely.
+;
+; This code is distributed in the hope that it will be useful but
+; WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
+; DISCLAMED. This includes but is not limited to warrenties of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+;
+EXPORTS
+access
+beep
+cabs
+chdir
+chmod
+chsize
+close
+creat
+cwait
+
+
+
+dup
+dup2
+ecvt
+eof
+execl
+execle
+execlp
+execlpe
+execv
+execve
+execvp
+execvpe
+fcvt
+fdopen
+fgetchar
+fgetwchar
+filelength
+fileno
+fpreset
+fputchar
+fputwchar
+fstat
+ftime
+gcvt
+getch
+getche
+getcwd
+getpid
+getw
+heapwalk
+hypot
+isatty
+itoa
+j0
+j1
+jn
+kbhit
+lseek
+ltoa
+memccpy
+memicmp
+mkdir
+mktemp
+open
+pclose
+popen
+putch
+putenv
+putw
+read
+rmdir
+searchenv
+seterrormode
+setmode
+sleep
+sopen
+spawnl
+spawnle
+spawnlp
+spawnlpe
+spawnv
+spawnve
+spawnvp
+spawnvpe
+stat
+strcmpi
+strdup
+stricmp
+stricoll
+strlwr
+strnicmp
+strnset
+strrev
+strset
+strupr
+swab
+tell
+tempnam
+
+
+
+; export tzname for both. See <time.h>
+tzname DATA
+tzset
+umask
+ungetch
+unlink
+utime
+wcsdup
+wcsicmp
+wcsicoll
+wcslwr
+wcsnicmp
+wcsnset
+wcsrev
+wcsset
+wcsupr
+
+
+
+write
+y0
+y1
+yn
diff --git a/winsup/mingw/moldname-msvcrt.def b/winsup/mingw/moldname-msvcrt.def index f6e9075..c341d2e 100644 --- a/winsup/mingw/moldname-msvcrt.def +++ b/winsup/mingw/moldname-msvcrt.def @@ -1,142 +1,142 @@ -; -; moldname-msvcrt.def -; -; Exports from the runtime except that these exports are actually preceeded -; by a underscore in the actual DLL. These correspond to functions which -; are non-ANSI and were prefixed with an underscore to avoid name space -; clutter. However many, in fact most programs still use a few of these -; functions without the underscore. This .def file is specially processed -; to make those non-underscored name function calls call the equivalent -; underscored functions. -; -; Contributors: -; Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp> -; Maintained by Mumit Khan <khan@xraylith.wisc.edu> -; -; THIS SOFTWARE IS NOT COPYRIGHTED -; -; This source code is offered for use in the public domain. You may -; use, modify or distribute it freely. -; -; This code is distributed in the hope that it will be useful but -; WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY -; DISCLAMED. This includes but is not limited to warrenties of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -; -EXPORTS -access -beep -cabs -chdir -chmod -chsize -close -creat -cwait - -daylight DATA - -dup -dup2 -ecvt -eof -execl -execle -execlp -execlpe -execv -execve -execvp -execvpe -fcvt -fdopen -fgetchar -fgetwchar -filelength -fileno -fpreset -fputchar -fputwchar -fstat -ftime -gcvt -getch -getche -getcwd -getpid -getw -heapwalk -hypot -isatty -itoa -j0 -j1 -jn -kbhit -lseek -ltoa -memccpy -memicmp -mkdir -mktemp -open -pclose -popen -putch -putenv -putw -read -rmdir -searchenv -seterrormode -setmode -sleep -sopen -spawnl -spawnle -spawnlp -spawnlpe -spawnv -spawnve -spawnvp -spawnvpe -stat -strcmpi -strdup -stricmp -stricoll -strlwr -strnicmp -strnset -strrev -strset -strupr -swab -tell -tempnam - -timezone DATA - -; export tzname for both. See <time.h> -tzname DATA -tzset -umask -ungetch -unlink -utime -wcsdup -wcsicmp -wcsicoll -wcslwr -wcsnicmp -wcsnset -wcsrev -wcsset -wcsupr - -wpopen - -write -y0 -y1 -yn +;
+; moldname-msvcrt.def
+;
+; Exports from the runtime except that these exports are actually preceeded
+; by a underscore in the actual DLL. These correspond to functions which
+; are non-ANSI and were prefixed with an underscore to avoid name space
+; clutter. However many, in fact most programs still use a few of these
+; functions without the underscore. This .def file is specially processed
+; to make those non-underscored name function calls call the equivalent
+; underscored functions.
+;
+; Contributors:
+; Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
+; Maintained by Mumit Khan <khan@xraylith.wisc.edu>
+;
+; THIS SOFTWARE IS NOT COPYRIGHTED
+;
+; This source code is offered for use in the public domain. You may
+; use, modify or distribute it freely.
+;
+; This code is distributed in the hope that it will be useful but
+; WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
+; DISCLAMED. This includes but is not limited to warrenties of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+;
+EXPORTS
+access
+beep
+cabs
+chdir
+chmod
+chsize
+close
+creat
+cwait
+
+daylight DATA
+
+dup
+dup2
+ecvt
+eof
+execl
+execle
+execlp
+execlpe
+execv
+execve
+execvp
+execvpe
+fcvt
+fdopen
+fgetchar
+fgetwchar
+filelength
+fileno
+fpreset
+fputchar
+fputwchar
+fstat
+ftime
+gcvt
+getch
+getche
+getcwd
+getpid
+getw
+heapwalk
+hypot
+isatty
+itoa
+j0
+j1
+jn
+kbhit
+lseek
+ltoa
+memccpy
+memicmp
+mkdir
+mktemp
+open
+pclose
+popen
+putch
+putenv
+putw
+read
+rmdir
+searchenv
+seterrormode
+setmode
+sleep
+sopen
+spawnl
+spawnle
+spawnlp
+spawnlpe
+spawnv
+spawnve
+spawnvp
+spawnvpe
+stat
+strcmpi
+strdup
+stricmp
+stricoll
+strlwr
+strnicmp
+strnset
+strrev
+strset
+strupr
+swab
+tell
+tempnam
+
+timezone DATA
+
+; export tzname for both. See <time.h>
+tzname DATA
+tzset
+umask
+ungetch
+unlink
+utime
+wcsdup
+wcsicmp
+wcsicoll
+wcslwr
+wcsnicmp
+wcsnset
+wcsrev
+wcsset
+wcsupr
+
+wpopen
+
+write
+y0
+y1
+yn
|