delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2006/06/12/06:28:05

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Message-ID: <448D3C9E.9090501@oberhumer.com>
Date: Mon, 12 Jun 2006 12:06:22 +0200
From: "Markus F.X.J. Oberhumer" <markus AT oberhumer DOT com>
Organization: oberhumer.com
User-Agent: Thunderbird 1.5.0.2 (X11/20060501)
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: djgpp CVS patches
X-no-Archive: yes
X-Oberhumer-Conspiracy: There is no conspiracy. Trust us.
X-Virus-Scanned: amavisd-new at servus.at
Reply-To: djgpp-workers AT delorie DOT com

This is a multi-part message in MIME format.
--------------080301040501050007070203
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

As there seems to be some revived activity here it's probably a good time 
for sending some patches against the current CVS. Please review and apply 
if you find them useful (fseeko.patch definitely needs some review).

BTW, many thanks to Andris for providing Linux cross compiliers - this way 
I can still easily provide pre-built binaries of UPX.

~Markus

-- 
Markus Oberhumer, <markus AT oberhumer DOT com>, http://www.oberhumer.com/

--------------080301040501050007070203
Content-Type: text/x-patch;
 name="gcc4-build.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="gcc4-build.patch"

Allow building with gcc-3.4 and gcc-4.1.

Signed-off-by: Markus F.X.J. Oberhumer <markus AT oberhumer DOT com>


Index: b/src/gcc-l.opt
===================================================================
--- a/src/gcc-l.opt
+++ b/src/gcc-l.opt
@@ -1,6 +1,6 @@
 -MD
 -O2
--mcpu=pentium
 -march=i386
+-mtune=i586
 -Wall
 -nostdinc
Index: b/src/gcc.opt
===================================================================
--- a/src/gcc.opt
+++ b/src/gcc.opt
@@ -1,7 +1,7 @@
 -MD
 -O2
--mcpu=pentium
 -march=i386
+-mtune=i586
 -Wall
 -Wbad-function-cast
 -Wcast-qual
@@ -16,4 +16,5 @@
 -Wcast-align
 -Wsign-compare
 -nostdinc
-
+-fno-builtin-cabs
+-fno-builtin-cabsf
Index: b/src/makefile
===================================================================
--- a/src/makefile
+++ b/src/makefile
@@ -11,6 +11,8 @@
 # If you don't have ../zoneinfo/src, Make will report (and ignore) an
 # error when it tries to build files there; disregard it.
 
+GCC = gcc -g -O2
+
 MAKEFLAGS := --no-print-directory
 
 DIRS = \
@@ -23,16 +25,16 @@
 all : misc.exe $(DIRS) makemake.exe subs ../lib/libg.a ../lib/libpc.a
 
 misc.exe : misc.c
-	gcc -O2 misc.c -o misc.exe
+	$(GCC) misc.c -o misc.exe
 
 $(DIRS) :
 	./misc.exe mkdir $@
 
 makemake.exe : makemake.c
-	gcc -O2 makemake.c -o makemake.exe
+	$(GCC) makemake.c -o makemake.exe
 
 copyrite.exe : copyrite.cc
-	gcc -O2 copyrite.cc -o copyrite.exe
+	$(GCC) copyrite.cc -o copyrite.exe
 
 subs:
 	$(MAKE) -C djasm native
Index: b/zoneinfo/src/strftime.c
===================================================================
--- a/zoneinfo/src/strftime.c
+++ b/zoneinfo/src/strftime.c
@@ -128,7 +128,7 @@
 #define IN_ALL	3
 
 size_t
-strftime(s, maxsize, format, t)
+UNUSED_strftime(s, maxsize, format, t)
 char * const		s;
 const size_t		maxsize;
 const char * const	format;

--------------080301040501050007070203
Content-Type: text/x-patch;
 name="gcc4-src.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="gcc4-src.patch"

Various small fixes to avoid warnings with gcc-4.0 and gcc-4.1.
No functional changes, but somebody should review.

Signed-off-by: Markus F.X.J. Oberhumer <markus AT oberhumer DOT com>


Index: b/include/dpmi.h
===================================================================
--- a/include/dpmi.h
+++ b/include/dpmi.h
@@ -260,7 +260,7 @@
   unsigned long reserved[3];
 } _go32_dpmi_meminfo;
 
-#define _go32_dpmi_get_free_memory_information(x) __dpmi_get_free_memory_information((__dpmi_free_mem_info *)(x))
+#define _go32_dpmi_get_free_memory_information(x) __dpmi_get_free_memory_information((__dpmi_free_mem_info *)(void *)(x))
 
 #define _go32_dpmi_simulate_int		__dpmi_simulate_real_mode_interrupt
 #define _go32_dpmi_simulate_fcall	__dpmi_simulate_real_mode_procedure_retf
Index: b/include/ieeefp.h
===================================================================
--- a/include/ieeefp.h
+++ b/include/ieeefp.h
@@ -73,13 +73,13 @@
 #define __IEEE_FLT_NAN_EXP 0xff
 
 
-#define isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
-		   ((*(long *)&(x) & 0x007fffffL)!=0000000000L))
+#define isnanf(x) (((*(long *)(void *)&(x) & 0x7f800000L)==0x7f800000L) && \
+		   ((*(long *)(void *)&(x) & 0x007fffffL)!=0000000000L))
 
-#define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
-		   ((*(long *)&(x) & 0x007fffffL)==0000000000L))
+#define isinff(x) (((*(long *)(void *)&(x) & 0x7f800000L)==0x7f800000L) && \
+		   ((*(long *)(void *)&(x) & 0x007fffffL)==0000000000L))
 
-#define finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))
+#define finitef(x) (((*(long *)(void *)&(x) & 0x7f800000L)!=0x7f800000L))
 
 #ifdef __cplusplus
 }
Index: b/include/search.h
===================================================================
--- a/include/search.h
+++ b/include/search.h
@@ -54,7 +54,7 @@
   char q_data[0];
 } qelem;
 
-unsigned long _hash2v(unsigned char *s, unsigned long *v2);
+unsigned long _hash2v(const unsigned char *s, unsigned long *v2);
 void insque(struct qelem *_elem, struct qelem *_pred);
 void remque(struct qelem *_elem);
 
Index: b/src/debug/common/dbgcom.c
===================================================================
--- a/src/debug/common/dbgcom.c
+++ b/src/debug/common/dbgcom.c
@@ -35,6 +35,12 @@
 #include <sys/fsext.h>
 #include <io.h>
 
+#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))
+# define __attribute_used __attribute__ ((__used__))
+#else
+# define __attribute_used
+#endif
+
 extern char __libdbg_ident_string[];
 static char *id = __libdbg_ident_string;
 
@@ -77,8 +83,8 @@
 static jmp_buf jumper;
 
 static int my_ds,my_cs,app_cs,app_exit_cs,app_ds;
-static unsigned int app_ds_size[DS_SIZE_COUNT];
-static int app_ds_index = 0;
+static unsigned int app_ds_size[DS_SIZE_COUNT] __attribute_used;
+static int app_ds_index __attribute_used = 0;
 static jmp_buf load_state;
 
 static int nset, breakhandle[4];
Index: b/src/libc/ansi/stdio/doprnt.c
===================================================================
--- a/src/libc/ansi/stdio/doprnt.c
+++ b/src/libc/ansi/stdio/doprnt.c
@@ -290,7 +290,7 @@
        * buffer, i.e. ``intf("%.2f", (double)9.999);'';
        * if the first char isn't NULL, it did.
        */
-      *buf = NULL;
+      *buf = '\0';
       size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf,
 		  buf + sizeof(buf));
       /*
Index: b/src/libc/ansi/stdio/fprintf.c
===================================================================
--- a/src/libc/ansi/stdio/fprintf.c
+++ b/src/libc/ansi/stdio/fprintf.c
@@ -22,7 +22,7 @@
     fflush(iop);
     iop->_flag |= _IONBF;
     iop->_base = NULL;
-    iop->_bufsiz = NULL;
+    iop->_bufsiz = 0;
     iop->_cnt = 0;
   }
   else
Index: b/src/libc/ansi/stdio/fputs.c
===================================================================
--- a/src/libc/ansi/stdio/fputs.c
+++ b/src/libc/ansi/stdio/fputs.c
@@ -29,7 +29,7 @@
       r = EOF;
     f->_flag |= _IONBF;
     f->_base = NULL;
-    f->_bufsiz = NULL;
+    f->_bufsiz = 0;
     f->_cnt = 0;
   }
 
Index: b/src/libc/ansi/stdlib/strtol.c
===================================================================
--- a/src/libc/ansi/stdlib/strtol.c
+++ b/src/libc/ansi/stdlib/strtol.c
@@ -88,6 +88,6 @@
   else if (neg)
     acc = -acc;
   if (endptr != 0)
-    *endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *);
+    *endptr = any ? (char *) unconst(s, unsigned char *) - 1 : unconst(nptr, char *);
   return acc;
 }
Index: b/src/libc/ansi/stdlib/strtoll.c
===================================================================
--- a/src/libc/ansi/stdlib/strtoll.c
+++ b/src/libc/ansi/stdlib/strtoll.c
@@ -77,6 +77,6 @@
   else if (neg)
     acc = -acc;
   if (endptr != 0)
-    *endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *);
+    *endptr = any ? (char *) unconst(s, unsigned char *) - 1 : unconst(nptr, char *);
   return acc;
 }
Index: b/src/libc/ansi/stdlib/strtoul.c
===================================================================
--- a/src/libc/ansi/stdlib/strtoul.c
+++ b/src/libc/ansi/stdlib/strtoul.c
@@ -72,6 +72,6 @@
   else if (neg)
     acc = -acc;
   if (endptr != 0)
-    *endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *);
+    *endptr = any ? (char *) unconst(s, unsigned char *) - 1 : unconst(nptr, char *);
   return acc;
 }
Index: b/src/libc/ansi/stdlib/strtoull.c
===================================================================
--- a/src/libc/ansi/stdlib/strtoull.c
+++ b/src/libc/ansi/stdlib/strtoull.c
@@ -74,6 +74,6 @@
   else if (neg)
     acc = -acc;
   if (endptr != 0)
-    *endptr = any ? unconst(s, char *) - 1 : unconst(nptr, char *);
+    *endptr = any ? (char *) unconst(s, unsigned char *) - 1 : unconst(nptr, char *);
   return acc;
 }
Index: b/src/libc/compat/mman/mprotect.c
===================================================================
--- a/src/libc/compat/mman/mprotect.c
+++ b/src/libc/compat/mman/mprotect.c
@@ -37,7 +37,7 @@
     meminfo.address = start - handle_info->address;
     meminfo.size = npage;
 
-    i = __dpmi_set_page_attributes(&meminfo, pageprot);
+    i = __dpmi_set_page_attributes(&meminfo, (short *) pageprot);
     if(i)
       errno = EACCES;
     return i;
Index: b/src/libc/compat/mntent/mntent.c
===================================================================
--- a/src/libc/compat/mntent/mntent.c
+++ b/src/libc/compat/mntent/mntent.c
@@ -63,7 +63,7 @@
 
 /* Static variables.  */
 
-static char          drive_number = -1;
+static signed char   drive_number = -1;
 static char          skip_drive_b = 0;
 static char          drive_a_mapping = 0;
 static char          w2k_bug;
@@ -72,11 +72,11 @@
 static int           cds_elsize;
 static unsigned short dos_mem_base, our_mem_base;
 static struct mntent mntent;
-static unsigned char drive_string[128];
+static char          drive_string[128];
 static char          *mnt_type;
-static unsigned char mnt_dir[128];
-static unsigned char mnt_fsname[128];
-static          char dev_opts[] = "r ,dev=  ";
+static char          mnt_dir[128];
+static char          mnt_fsname[128];
+static char          dev_opts[] = "r ,dev=  ";
 
 static char NAME_dblsp[] = "dblsp";
 static char NAME_stac[] = "stac";
@@ -516,10 +516,10 @@
      allows for 32 disks (A-Z plus 6 more characters from '[' to '\'') */
   while (drive_number < 32)
     {
-      unsigned char *p, *q;
+      char          *p, *q;
       char *truename_result;
       struct ffblk   mnt_ff;
-      unsigned char  cds_path[128];
+      char           cds_path[128];
       unsigned short cds_flags = 0;
       int            drvstr_len;
       int            got_fsname = 0;
@@ -613,7 +613,7 @@
 	 don't always upcase the drive letter, so we must do that here.  */
       truename_result = _truename(drive_string, mnt_fsname);
       if (truename_result && mnt_fsname[0]
-	  && mnt_fsname[1] == ':' && islower(mnt_fsname[0]))
+	  && mnt_fsname[1] == ':' && islower((unsigned char)mnt_fsname[0]))
 	mnt_fsname[0] = toupper((unsigned char)mnt_fsname[0]);
 
       /* Get some info from the DOS Current Directory Structure (CDS).
Index: b/src/libc/compat/stdlib/random.c
===================================================================
--- a/src/libc/compat/stdlib/random.c
+++ b/src/libc/compat/stdlib/random.c
@@ -141,8 +141,8 @@
  * to point to randtbl[1] (as explained below).
  */
 
-static  long		*fptr			= &randtbl[ SEP_3 + 1 ];
-static  long		*rptr			= &randtbl[ 1 ];
+static  long		*fptr			= (long*) &randtbl[ SEP_3 + 1 ];
+static  long		*rptr			= (long*) &randtbl[ 1 ];
 
 /*
  * The following things are the pointer to the state information table,
@@ -156,11 +156,11 @@
  * the front and rear pointers have wrapped.
  */
 
-static  long		*state			= &randtbl[ 1 ];
+static  long		*state			= (long*) &randtbl[ 1 ];
 static  int		rand_type		= TYPE_3;
 static  int		rand_deg		= DEG_3;
 static  int		rand_sep		= SEP_3;
-static  long		*end_ptr		= &randtbl[ DEG_3 + 1 ];
+static  long		*end_ptr		= (long*) &randtbl[ DEG_3 + 1 ];
 
 /*
  * srandom:
Index: b/src/libc/compat/time/select.c
===================================================================
--- a/src/libc/compat/time/select.c
+++ b/src/libc/compat/time/select.c
@@ -148,6 +148,8 @@
   FD_ZERO (&oexcept);
   ready = 0;
 
+  then.tv_sec = 0;
+  then.tv_usec = 0;
   if (timeout)
   {
     if (timeout->tv_usec < 0)
Index: b/src/libc/dos/compat/d_read.c
===================================================================
--- a/src/libc/dos/compat/d_read.c
+++ b/src/libc/dos/compat/d_read.c
@@ -21,7 +21,8 @@
 {
   __dpmi_regs r;
   int dos_segment;
-  unsigned int dos_selector, dos_buffer_size, read_size;
+  int dos_selector;
+  unsigned int dos_buffer_size, read_size;
   unsigned char *p_buffer;
 
   /* Allocate ~64K or less transfer buffer from DOS */
Index: b/src/libc/dos/compat/d_write.c
===================================================================
--- a/src/libc/dos/compat/d_write.c
+++ b/src/libc/dos/compat/d_write.c
@@ -21,7 +21,8 @@
 {
   __dpmi_regs r;
   int dos_segment;
-  unsigned int dos_selector, dos_buffer_size, write_size;
+  int dos_selector;
+  unsigned int dos_buffer_size, write_size;
   const unsigned char *p_buffer;
 
   /* Allocates ~64K or less transfer buffer from DOS */
Index: b/src/libc/dos/dir/findfirs.c
===================================================================
--- a/src/libc/dos/dir/findfirs.c
+++ b/src/libc/dos/dir/findfirs.c
@@ -58,7 +58,7 @@
       dosmemget(__tb+pathlen, sizeof(struct ffblklfn), &ffblk32);
 
       ffblk->ff_attrib = (char)ffblk32.fd_attrib;
-      *(long *)(&ffblk->ff_ftime) = _Win32_to_DOS(ffblk32.fd_mtime);
+      *(long *)(void *)(&ffblk->ff_ftime) = _Win32_to_DOS(ffblk32.fd_mtime);
       ffblk->ff_fsize = ffblk32.fd_size;
       strcpy(ffblk->ff_name, ffblk32.fd_longname);
       strcpy(ffblk->lfn_magic, "LFN32");
@@ -72,8 +72,8 @@
       }
         
       ffblk->lfn_handle = r.x.ax;
-      *(long *)(&ffblk->lfn_ctime) = _Win32_to_DOS(ffblk32.fd_ctime);
-      *(long *)(&ffblk->lfn_atime) = _Win32_to_DOS(ffblk32.fd_atime);
+      *(long *)(void *)(&ffblk->lfn_ctime) = _Win32_to_DOS(ffblk32.fd_ctime);
+      *(long *)(void *)(&ffblk->lfn_atime) = _Win32_to_DOS(ffblk32.fd_atime);
 
       return 0;
     }
Index: b/src/libc/dos/dir/findnext.c
===================================================================
--- a/src/libc/dos/dir/findnext.c
+++ b/src/libc/dos/dir/findnext.c
@@ -52,11 +52,11 @@
       dosmemget(__tb, sizeof(struct ffblklfn), &ffblk32);
 
       ffblk->ff_attrib = (char)ffblk32.fd_attrib;
-      *(long *)&ffblk->ff_ftime = _Win32_to_DOS(ffblk32.fd_mtime);
+      *(long *)(void *)&ffblk->ff_ftime = _Win32_to_DOS(ffblk32.fd_mtime);
       ffblk->ff_fsize = ffblk32.fd_size;
       strcpy(ffblk->ff_name, ffblk32.fd_longname);
-      *(long *)&ffblk->lfn_ctime = _Win32_to_DOS(ffblk32.fd_ctime);
-      *(long *)&ffblk->lfn_atime = _Win32_to_DOS(ffblk32.fd_atime);
+      *(long *)(void *)&ffblk->lfn_ctime = _Win32_to_DOS(ffblk32.fd_ctime);
+      *(long *)(void *)&ffblk->lfn_atime = _Win32_to_DOS(ffblk32.fd_atime);
 
       return 0;
     }
Index: b/src/libc/dos/dir/ftreewlk.c
===================================================================
--- a/src/libc/dos/dir/ftreewlk.c
+++ b/src/libc/dos/dir/ftreewlk.c
@@ -30,8 +30,8 @@
                int (*func)(const char *, const struct ffblk *))
 {
   struct ffblk  ff;
-  unsigned char searchspec[FILENAME_MAX];
-  unsigned char found[FILENAME_MAX], *dir_end;
+  char searchspec[FILENAME_MAX];
+  char found[FILENAME_MAX], *dir_end;
   int e = errno;
 
   if (dir == 0 || func == 0)
Index: b/src/libc/dos/dir/ftw.c
===================================================================
--- a/src/libc/dos/dir/ftw.c
+++ b/src/libc/dos/dir/ftw.c
@@ -108,8 +108,8 @@
     int ignored)
 {
   int flag;
-  unsigned char pathbuf[FILENAME_MAX];
-  unsigned char real_path[FILENAME_MAX];
+  char pathbuf[FILENAME_MAX];
+  char real_path[FILENAME_MAX];
   int dirattr;
   int len;
   int e = errno;
Index: b/src/libc/dos/lfn/_use_lfn.c
===================================================================
--- a/src/libc/dos/lfn/_use_lfn.c
+++ b/src/libc/dos/lfn/_use_lfn.c
@@ -159,10 +159,10 @@
       same_drive_as_last_time = 0;
     else
     {
-      int drv_no;
+      unsigned drv_no;
 
       _dos_getdrive(&drv_no);
-      if (drv_no - 1 + 'A' != last_drive)
+      if ((int)drv_no - 1 + 'A' != last_drive)
 	same_drive_as_last_time = 0;
     }
   }
Index: b/src/libc/go32/gopint.c
===================================================================
--- a/src/libc/go32/gopint.c
+++ b/src/libc/go32/gopint.c
@@ -144,7 +144,7 @@
   do {							\
       if (!stack_length) {				\
 	  stack_length = _go32_interrupt_stack_size;	\
-	  stack = (char *)malloc(stack_length);		\
+	  stack = (unsigned char *)malloc(stack_length);\
 	  if (stack == 0) {				\
 	    free(wrapper);				\
 	    return 0x8015;				\
Index: b/src/libc/go32/gormcb.c
===================================================================
--- a/src/libc/go32/gormcb.c
+++ b/src/libc/go32/gormcb.c
@@ -94,8 +94,8 @@
 #define	MALLOC_STACK()					\
   do {							\
       if (!stack_length) {				\
-	  stack_length = _go32_rmcb_stack_size;	\
-	  stack = (char *)malloc(stack_length);		\
+	  stack_length = _go32_rmcb_stack_size;		\
+	  stack = (unsigned char *)malloc(stack_length);\
 	  if (stack == 0) {				\
 	    free(wrapper);				\
 	    return 0x8015;				\
@@ -195,7 +195,7 @@
 {
   unsigned char *stack;
 
-  stack = (char *)(*(long *)((long) info->size+0x12) - 4);
+  stack = (unsigned char *)(*(long *)((long) info->size+0x12) - 4);
   if (*(long *) stack & STACK_WAS_MALLOCED)
       free(stack);
 
Index: b/src/libc/pc_hw/kb/getxkstr.c
===================================================================
--- a/src/libc/pc_hw/kb/getxkstr.c
+++ b/src/libc/pc_hw/kb/getxkstr.c
@@ -10,7 +10,7 @@
    The encodings for unshifted arrow keys, F1-F12, Home, Insert, etc.
    match the encodings used by other x86 environments.  All others
    are invented for DJGPP.  */
-static const unsigned char *
+static const char *
 ecma48_encoding_table[] =
 {
 		/* 0x01: Alt-Escape */
@@ -184,6 +184,6 @@
   if (idx > ARRAY_SIZEOF(ecma48_encoding_table))
     return NULL;
 
-  return ecma48_encoding_table[idx];
+  return (const unsigned char *) ecma48_encoding_table[idx];
 }
 
Index: b/src/libc/posix/search/_hash2v.c
===================================================================
--- a/src/libc/posix/search/_hash2v.c
+++ b/src/libc/posix/search/_hash2v.c
@@ -58,7 +58,7 @@
   c -= a; c -= b; c ^= (b>>15); \
 }
 
-unsigned long _hash2v( unsigned char *k, unsigned long *v2 )
+unsigned long _hash2v( const unsigned char *k, unsigned long *v2 )
 {
   int cont, which;
   unsigned long a, b, c, len;
Index: b/src/libc/posix/search/hcreate.c
===================================================================
--- a/src/libc/posix/search/hcreate.c
+++ b/src/libc/posix/search/hcreate.c
@@ -72,7 +72,7 @@
 {
   unsigned long hash_value, hash_value_start, increment;
 
-  hash_value = _hash2v(item.key, &increment);
+  hash_value = _hash2v((const unsigned char *) item.key, &increment);
   hash_value &= mask;
   hash_value_start = hash_value;
   increment = 2*increment+1; /* Make sure increment is odd. */
Index: b/src/libc/posix/sys/stat/fstat.c
===================================================================
--- a/src/libc/posix/sys/stat/fstat.c
+++ b/src/libc/posix/sys/stat/fstat.c
@@ -527,7 +527,7 @@
             {
               /* Character device names are all at most 8-character long. */
               short i   = 8;
-              char *src = sft_buf + name_ofs;
+              unsigned char *src = sft_buf + name_ofs;
               char dev_name[16], *dst = dev_name + 7;
 
               strcpy(dev_name, "@:\\dev\\        "); /* pad with 8 blanks */
Index: b/src/libc/posix/sys/stat/lstat.c
===================================================================
--- a/src/libc/posix/sys/stat/lstat.c
+++ b/src/libc/posix/sys/stat/lstat.c
@@ -140,15 +140,16 @@
    it to be sure it will still work for future versions of GCC.  */
 
 struct full_dirent {
-  char           fname[8]      __attribute__ ((packed));
-  char           fext[3]       __attribute__ ((packed));
-  unsigned char  fattr         __attribute__ ((packed));
-  unsigned char  freserved[10] __attribute__ ((packed));
-  unsigned short ftime         __attribute__ ((packed));
-  unsigned short fdate         __attribute__ ((packed));
-  unsigned short fcluster      __attribute__ ((packed));
-  unsigned int   fsize         __attribute__ ((packed));
-};
+  char           fname[8];
+  char           fext[3];
+  unsigned char  fattr;
+  unsigned char  freserved[10];
+  unsigned short ftime;
+  unsigned short fdate;
+  unsigned short fcluster;
+  unsigned int   fsize;
+}
+__attribute__ ((packed));
 
 
 /* Static variables to speed up SDA DOS Swappable Data Area access on
@@ -270,7 +271,8 @@
       dirent_count = _farpeekw(_dos_ds, sda_list_walker); /* number of SDA's */
 
       /* Allocate storage for table.  */
-      tbl = dirent_table = (int *)malloc(dirent_count*sizeof(int));
+      dirent_table = (unsigned *)malloc(dirent_count*sizeof(int));
+      tbl = (int *) dirent_table;
       if (!dirent_table)
         {
           /* If malloc() failed, maybe later it will succeed, so don't
@@ -799,10 +801,10 @@
   if ( ! strcmp(ff_blk.lfn_magic,"LFN32") )
     {
       unsigned xtime;
-      xtime = *(unsigned *)&ff_blk.lfn_ctime;
+      xtime = *(unsigned *)(void *)&ff_blk.lfn_ctime;
       if(xtime)			/* May be zero if file written w/o lfn active */
         statbuf->st_ctime = _file_time_stamp(xtime);
-      xtime = *(unsigned *)&ff_blk.lfn_atime;
+      xtime = *(unsigned *)(void *)&ff_blk.lfn_atime;
       if(xtime > dos_ftime)	/* Accessed time is date only, no time */
         statbuf->st_atime = _file_time_stamp(xtime);
     }
Index: b/src/libc/posix/termios/tmread.c
===================================================================
--- a/src/libc/posix/termios/tmread.c
+++ b/src/libc/posix/termios/tmread.c
@@ -23,7 +23,7 @@
 #define SENSE_REG_KEY	1
 #define SENSE_EXT_KEY	2
 
-static struct tty_editline __libc_tty_editline = { 0, { 0 }, { 0 }, };
+struct tty_editline __libc_tty_editline = { 0, { 0 }, { 0 }, };
 unsigned char __libc_tty_queue_buffer[_TTY_QUEUE_SIZE];
 
 /* static data */
@@ -403,7 +403,7 @@
 		   && __libc_tty_editline.flag[col - 1] != _TTY_EDITLINE_INVALID))
     {
       /* check multibyte length */
-      mbsize = mblen (__libc_tty_editline.buf + col, 1);
+      mbsize = mblen ((const char *)__libc_tty_editline.buf + col, 1);
       if (mbsize == 1)
 	{
 	  /* single character */
@@ -431,7 +431,7 @@
 	  break;
 
       /* check whether it's multibyte sequence */
-      mbsize = mblen (__libc_tty_editline.buf + pcol, (col - pcol + 1));
+      mbsize = mblen ((const char *)__libc_tty_editline.buf + pcol, (col - pcol + 1));
       if (mbsize > 1)
 	{
 	  /* multibyte sequence is good */
@@ -625,9 +625,9 @@
 
 		    for (i = 0; i < 5; i++)
 		      if ((fds[i] = fcntl (i, F_DUPFD, 20)) < 0)
-		        __tty_screen_intface->puts("Suspend: cannot save fds\r\n");
+		        __tty_screen_intface->puts((const unsigned char *)"Suspend: cannot save fds\r\n");
 
-		    __tty_screen_intface->puts("\r\nSuspended\r\n");
+		    __tty_screen_intface->puts((const unsigned char *)"\r\nSuspended\r\n");
 		    /* keep cwd on exec */
 		    getcwd (oldcwd, sizeof (oldcwd));
 		    system ("");
Index: b/src/libc/posix/unistd/pathconf.c
===================================================================
--- a/src/libc/posix/unistd/pathconf.c
+++ b/src/libc/posix/unistd/pathconf.c
@@ -22,7 +22,7 @@
     {
       int name_max, path_max;
       int e = errno;
-      unsigned char *lfnenv = getenv ("LFN");
+      const char *lfnenv = getenv ("LFN");
 
       if (!lfnenv || TOLOWER (*lfnenv) != 'n')
 	{
Index: b/src/libemu/src/emu387.cc
===================================================================
--- a/src/libemu/src/emu387.cc
+++ b/src/libemu/src/emu387.cc
@@ -155,8 +155,8 @@
 #endif
 
 /* extern "C" void djshld(void *); */
-#define djshld(q) ((*(long long unsigned *)(q)) <<= 1)
-#define djshrd(q) ((*(long long unsigned *)(q)) >>= 1)
+#define djshld(q) ((*(long long unsigned *)(void *)(q)) <<= 1)
+#define djshrd(q) ((*(long long unsigned *)(void *)(q)) >>= 1)
 
 static int nan_type(reg& r)
 {
@@ -489,8 +489,8 @@
   }
   unsigned short *ss, *ts;
   unsigned long tmp;
-  ss = (unsigned short *)&s.sigl;
-  ts = (unsigned short *)&t.sigl;
+  ss = (unsigned short *)(void *)&s.sigl;
+  ts = (unsigned short *)(void *)&t.sigl;
   tmp = 0;
   for (int i=4; i>0; i--)
   {
@@ -538,8 +538,8 @@
   }
   unsigned short *ss, *ts;
   long tmp;
-  ss = (unsigned short *)&d.sigl;
-  ts = (unsigned short *)&t.sigl;
+  ss = (unsigned short *)(void *)&d.sigl;
+  ts = (unsigned short *)(void *)&t.sigl;
   tmp = 0;
   for (int i=4; i>0; i--)
   {
@@ -745,8 +745,8 @@
   else
   {
     unsigned short sl[9], carry[10];
-    unsigned short *as = (unsigned short *)(&a.sigl);
-    unsigned short *bs = (unsigned short *)(&b.sigl);
+    unsigned short *as = (unsigned short *)(void *)(&a.sigl);
+    unsigned short *bs = (unsigned short *)(void *)(&b.sigl);
     unsigned long l, sum;
     int ai, bi;
     for (ai=0; ai<8; ai++)
@@ -842,8 +842,8 @@
     {
       unsigned long long al, bl, ql, f;
       int i;
-      al = *(unsigned long long *)(&a.sigl);
-      bl = *(unsigned long long *)(&b.sigl);
+      al = *(unsigned long long *)(void *)(&a.sigl);
+      bl = *(unsigned long long *)(void *)(&b.sigl);
       ql = 0;
       f = (unsigned long long)1 << 63;
       for (i=0; i<64; i++)
@@ -856,7 +856,7 @@
         bl >>= 1;
         f >>= 1;
       }
-      *(unsigned long long *)(&q.sigl) = ql;
+      *(unsigned long long *)(void *)(&q.sigl) = ql;
       q.tag = TW_V;
     }
   }
@@ -1079,18 +1079,18 @@
     case RC_RND:
       if (half_or_more)
         if (more_than_half) // nearest
-          (*(long long *)(&r.sigl)) ++;
+          (*(long long *)(void *)(&r.sigl)) ++;
         else
           if (r.sigl & 1) // odd?
-            (*(long long *)(&r.sigl)) ++;
+            (*(long long *)(void *)(&r.sigl)) ++;
       break;
     case RC_DOWN:
       if ((half_or_more||more_than_half) && r.sign)
-        (*(long long *)(&r.sigl)) ++;
+        (*(long long *)(void *)(&r.sigl)) ++;
       break;
     case RC_UP:
       if ((half_or_more||more_than_half) && !r.sign)
-        (*(long long *)(&r.sigl)) ++;
+        (*(long long *)(void *)(&r.sigl)) ++;
       break;
     case RC_CHOP:
       break;
@@ -1303,7 +1303,7 @@
   reg t;
   t = s;
   round_to_int(t);
-  long long ll = *(long long *)(&t.sigl);
+  long long ll = *(long long *)(void *)(&t.sigl);
   int side = 0;
   int r, i;
   for (i=0; i<10; i++)
@@ -2347,7 +2347,7 @@
     return;
   }
 
-  unsigned long long val = *(unsigned long long *)(&st().sigl);
+  unsigned long long val = *(unsigned long long *)(void *)(&st().sigl);
   unsigned long long result = 0;
   unsigned long long side = 0;
   unsigned long long left = 0;
@@ -2357,12 +2357,12 @@
     st().exp++;
   }
   int exp = (st().exp - EXP_BIAS - 1)/2 - 64;
-  while (!(((long *)&result)[1] & 0x80000000))
+  while (!(((long *)(void *)&result)[1] & 0x80000000))
   {
     /* GCC between 2.8 and EGCS 1.1.1 optimizes this loop
        all wrong; the asm works around it. */
     asm volatile("" : : : "memory");
-    left = (left << 2) + (((unsigned *)&val)[1] >> 30);
+    left = (left << 2) + (((unsigned *)(void *)&val)[1] >> 30);
     djshld(&val);
     djshld(&val);
     if (left >= side*2 + 1)
Index: b/src/utils/djtar/epunzip.c
===================================================================
--- a/src/utils/djtar/epunzip.c
+++ b/src/utils/djtar/epunzip.c
@@ -58,25 +58,25 @@
       ((char *)&buffer)[0] = (char)get_byte();
       ((char *)&buffer)[1] = (char)get_byte();
 
-      if(*(short *)&buffer != *(short *)"PK")
+      if(*(short *)(void *)&buffer != *(const short *)(const void *)"PK")
 	break;
 
       ((char *)&buffer)[0] = (char)get_byte();
       ((char *)&buffer)[1] = (char)get_byte();
 
-      if(*(short *)&buffer == *(short *)"\x3\x4")
+      if(*(short *)(void *)&buffer == *(const short *)(const void *)"\x3\x4")
 	{
 	  /* local header */
 	  at_local_header = 1;
 	  break;
 	}
-      else if(*(short *)&buffer == *(short *)"\x30\x30")
+      else if(*(short *)(void *)&buffer == *(const short *)(const void *)"\x30\x30")
 	{
 	  /* spanning marker, but only one segment
 	   * => need to find local header. */
 	  continue;
 	}
-      else if(*(short *)&buffer == *(short *)"\x7\x8")
+      else if(*(short *)(void *)&buffer == *(const short *)(const void *)"\x7\x8")
 	{
 	  /* spanning marker, multiple segments. */
 	  fprintf(log_out, "%s: spanning is not supported\n", zipfilename);
@@ -108,7 +108,7 @@
 	  ((char *)&buffer)[0] = (char)get_byte();
 	  ((char *)&buffer)[1] = (char)get_byte();
 
-	  if(*(short *)&buffer != *(short *)"PK")
+	  if(*(short *)(void *)&buffer != *(short *)(void *)"PK")
 	    {
 	      fprintf(log_out, "%s: invalid zip file structure\n", zipfilename);
 	      break;
@@ -117,7 +117,7 @@
 	  ((char *)&buffer)[0] = (char)get_byte();
 	  ((char *)&buffer)[1] = (char)get_byte();
 
-	  if(*(short *)&buffer != *(short *)"\x3\x4")
+	  if(*(short *)(void *)&buffer != *(short *)(void *)"\x3\x4")
 	    {
 	      /* not a local header - all done */
 	      break;
@@ -135,17 +135,17 @@
       ((char *)&buffer)[0] = (char)get_byte();
       ((char *)&buffer)[1] = (char)get_byte();
 
-      if(*(short *)&buffer & CRYFLG)
+      if(*(short *)(void *)&buffer & CRYFLG)
 	{
 	  fprintf(log_out, "%s has encrypted file(s) - use unzip\n", zipfilename);
 	  break;
 	}
-      ext_header = *(short *)&buffer & EXTFLG ? 1 : 0;
+      ext_header = *(short *)(void *)&buffer & EXTFLG ? 1 : 0;
 
       ((char *)&buffer)[0] = (char)get_byte();
       ((char *)&buffer)[1] = (char)get_byte();
 
-      method = *(short *)&buffer;
+      method = *(short *)(void *)&buffer;
       if(method != 8 && method != 0)
 	{
 	  fprintf(log_out, "%s has file(s) compressed with unsupported method - use unzip\n", zipfilename);
@@ -178,11 +178,11 @@
 
       ((char *)&buffer)[0] = (char)get_byte();
       ((char *)&buffer)[1] = (char)get_byte();
-      name_length = *(short *)&buffer;
+      name_length = *(short *)(void *)&buffer;
 
       ((char *)&buffer)[0] = (char)get_byte();
       ((char *)&buffer)[1] = (char)get_byte();
-      extra_length = *(short *)&buffer;
+      extra_length = *(short *)(void *)&buffer;
 
       for(count = 0; count < name_length; count++)
 	{
@@ -320,7 +320,7 @@
       if(real_file)
 	{
 	  epoutfile = open(changed_name, O_RDONLY);
-	  setftime(epoutfile, (struct ftime *)&timedate);
+	  setftime(epoutfile, (struct ftime *)(void *)&timedate);
 	  close(epoutfile);
 	  real_file = 0;
 	}

--------------080301040501050007070203
Content-Type: text/x-patch;
 name="gcc4-null.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="gcc4-null.patch"

This patch fixes the define of NULL for recent gcc versions.

Signed-off-by: Markus F.X.J. Oberhumer <markus AT oberhumer DOT com>


Index: b/include/locale.h
===================================================================
--- a/include/locale.h
+++ b/include/locale.h
@@ -19,7 +19,16 @@
 #define LC_MONETARY	0x04
 #define LC_NUMERIC	0x08
 #define LC_TIME		0x10
-#define NULL		0
+
+/* Some programs think they know better... */
+#undef NULL
+#if (__GNUC__ >= 4) && defined(__cplusplus)
+#  define NULL          __null
+#elif defined(__cplusplus)
+#  define NULL          0
+#else
+#  define NULL          ((void*)0)
+#endif
 
 struct lconv {
   char *currency_symbol;
Index: b/include/stddef.h
===================================================================
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -11,8 +11,17 @@
 #endif
 
 #include <sys/djtypes.h>
-  
-#define NULL 0
+
+/* Some programs think they know better... */
+#undef NULL
+#if (__GNUC__ >= 4) && defined(__cplusplus)
+#  define NULL          __null
+#elif defined(__cplusplus)
+#  define NULL          0
+#else
+#  define NULL          ((void*)0)
+#endif
+
 #ifdef __cplusplus
 #define offsetof(s_type, mbr) ((std::size_t) &((s_type *)0)->mbr)
 #else
Index: b/include/stdio.h
===================================================================
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -23,13 +23,19 @@
 
 /* Some programs think they know better... */
 #undef NULL
+#if (__GNUC__ >= 4) && defined(__cplusplus)
+#  define NULL          __null
+#elif defined(__cplusplus)
+#  define NULL          0
+#else
+#  define NULL          ((void*)0)
+#endif
 
 #define BUFSIZ		16384
 #define EOF		(-1)
 #define FILENAME_MAX	260
 #define FOPEN_MAX	20
 #define L_tmpnam	260
-#define NULL		0
 #define TMP_MAX		999999
 
 #define SEEK_SET	0
Index: b/include/string.h
===================================================================
--- a/include/string.h
+++ b/include/string.h
@@ -16,8 +16,13 @@
     
 /* Some programs think they know better... */
 #undef NULL
-
-#define NULL 0
+#if (__GNUC__ >= 4) && defined(__cplusplus)
+#  define NULL          __null
+#elif defined(__cplusplus)
+#  define NULL          0
+#else
+#  define NULL          ((void*)0)
+#endif
 
 #ifndef _SIZE_T
 __DJ_size_t
Index: b/include/time.h
===================================================================
--- a/include/time.h
+++ b/include/time.h
@@ -21,8 +21,14 @@
   
 /* Some programs think they know better... */
 #undef NULL
+#if (__GNUC__ >= 4) && defined(__cplusplus)
+#  define NULL          __null
+#elif defined(__cplusplus)
+#  define NULL          0
+#else
+#  define NULL          ((void*)0)
+#endif
 
-#define NULL 0
 #ifndef _CLOCK_T
 __DJ_clock_t
 #define _CLOCK_T
Index: b/include/unistd.h
===================================================================
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -39,8 +39,13 @@
 
 /* Some programs think they know better... */
 #undef NULL
-
-#define NULL 0
+#if (__GNUC__ >= 4) && defined(__cplusplus)
+#  define NULL          __null
+#elif defined(__cplusplus)
+#  define NULL          0
+#else
+#  define NULL          ((void*)0)
+#endif
 
 #define F_OK	0x01
 #define R_OK	0x02

--------------080301040501050007070203
Content-Type: text/x-patch;
 name="fseeko.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fseeko.patch"

This patch adds support for an off64_t typedef and add the
fseeko(), fseeko64(), ftello() and ftello64() functions.

The patch is modelled after the mingw32 implementation and hopefully
does not introduce compatibility problems for applications.

TODO: verify the implementation of fseeko64 and ftello64
TODO: add docs for the 4 new functions

Signed-off-by: Markus F.X.J. Oberhumer <markus AT oberhumer DOT com>


Index: b/include/libc/stubs.h
===================================================================
--- a/include/libc/stubs.h
+++ b/include/libc/stubs.h
@@ -54,7 +54,11 @@
 #define filelength __filelength
 #define findfirst __findfirst
 #define findnext __findnext
+#define fseeko __fseeko
+#define fseeko64 __fseeko64
 #define fsync __fsync
+#define ftello __ftello
+#define ftello64 __ftello64
 #define getdisk __getdisk
 #define getdtablesize __getdtablesize
 #define getitimer __getitimer
Index: b/include/stdio.h
===================================================================
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -165,6 +165,19 @@
 void	setlinebuf(FILE *_f);
 int	_rename(const char *_old, const char *_new);	/* Simple (no directory) */
 
+#ifndef _OFF_T
+__DJ_off_t
+#define _OFF_T
+#endif
+#ifndef _OFF64_T
+__DJ_off64_t
+#define _OFF64_T
+#endif
+int	fseeko(FILE *_stream, off_t _offset, int _mode);
+off_t	ftello(FILE *_stream);
+int	fseeko64(FILE *_stream, off64_t _offset, int _mode);
+off64_t	ftello64(FILE *_stream);
+
 #endif /* !_POSIX_SOURCE */
 #endif /* !__STRICT_ANSI__ */
 #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
Index: b/include/sys/djtypes.h
===================================================================
--- a/include/sys/djtypes.h
+++ b/include/sys/djtypes.h
@@ -11,7 +11,8 @@
 #define __DJ_clock_t	typedef int clock_t;
 #define __DJ_gid_t	typedef int gid_t;
 #define __DJ_off_t	typedef int off_t;
-#define __DJ_offset_t	typedef long long offset_t;
+#define __DJ_off64_t	__extension__ typedef long long off64_t;
+#define __DJ_offset_t	__extension__ typedef long long offset_t;
 #define __DJ_pid_t	typedef int pid_t;
 #define __DJ_size_t	typedef long unsigned int size_t;
 #define __DJ_ssize_t	typedef long signed int ssize_t;
Index: b/include/sys/types.h
===================================================================
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -40,6 +40,10 @@
 __DJ_off_t
 #define _OFF_T
 #endif
+#ifndef _OFF64_T
+__DJ_off64_t
+#define _OFF64_T
+#endif
 #ifndef _OFFSET_T
 __DJ_offset_t
 #define _OFFSET_T
Index: b/src/libc/compat/stdio/fseeko.c
===================================================================
--- /dev/null
+++ b/src/libc/compat/stdio/fseeko.c
@@ -0,0 +1,12 @@
+/* Copyright (C) 2006 DJ Delorie, see COPYING.DJ for details */
+#include <libc/stubs.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+
+int
+fseeko(FILE *_stream, off_t _offset, int _mode)
+{
+  return fseek(_stream, _offset, _mode);
+}
+
Index: b/src/libc/compat/stdio/fseeko64.c
===================================================================
--- /dev/null
+++ b/src/libc/compat/stdio/fseeko64.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 2006 DJ Delorie, see COPYING.DJ for details */
+#include <libc/stubs.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int
+fseeko64(FILE *_stream, off64_t _offset, int _mode)
+{
+  /* FIXME ??? */
+  int r;
+  offset_t o;
+  r = fflush(_stream);
+  if (r != 0)
+    return -1;
+  o = llseek(fileno(_stream), _offset, _mode);
+  if (o == -1)
+    return -1;
+  return 0;
+}
+
Index: b/src/libc/compat/stdio/ftello.c
===================================================================
--- /dev/null
+++ b/src/libc/compat/stdio/ftello.c
@@ -0,0 +1,12 @@
+/* Copyright (C) 2006 DJ Delorie, see COPYING.DJ for details */
+#include <libc/stubs.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+
+off_t
+ftello(FILE *_stream)
+{
+  return ftell(_stream);
+}
+
Index: b/src/libc/compat/stdio/ftello64.c
===================================================================
--- /dev/null
+++ b/src/libc/compat/stdio/ftello64.c
@@ -0,0 +1,18 @@
+/* Copyright (C) 2006 DJ Delorie, see COPYING.DJ for details */
+#include <libc/stubs.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+off64_t
+ftello64(FILE *_stream)
+{
+  /* FIXME ??? */
+  int r;
+  r = fflush(_stream);
+  if (r != 0)
+    return -1;
+  return llseek(fileno(_stream), 0, SEEK_CUR);
+}
+
Index: b/src/libc/compat/stdio/makefile
===================================================================
--- a/src/libc/compat/stdio/makefile
+++ b/src/libc/compat/stdio/makefile
@@ -2,6 +2,10 @@
 # Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
 TOP=../..
 
+SRC += fseeko.c
+SRC += fseeko64.c
+SRC += ftello.c
+SRC += ftello64.c
 SRC += mkstemp.c
 SRC += mktemp.c
 SRC += tempnam.c

--------------080301040501050007070203--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019