delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/22/15:36:16

Date: Wed, 22 Jan 2003 20:36:49 +0000
From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
Sender: rich AT phekda DOT freeserve DOT co DOT uk
To: djgpp-workers AT delorie DOT com
X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
Subject: ssize_t: int -> signed long [PATCH]
Message-Id: <E18bRab-0000c0-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Below is a patch to switch ssize_t from an int to a signed long,
to match the fact that size_t is an unsigned long.

I had to fix some code up in a couple of places:

* The _cnt member of FILE is now a long. In src/libc/ansi/stdio/filbuf.c
  &f->_cnt is passed to __libc_read_termios_hook, which expects a ssize_t
  argument. &f->_cnt being an int * cannot be converted without typecasts
  to ssize_t *. Hence I changed f->_cnt to be a long. I don't think this
  will have any bad side-effects since sizeof(int) == sizeof(long).

  This is probably the only contentious part of the patch.

* Some code was using a pointer to an int as a parameter to termios hooks.
  When ssize_t was an int, that was fine. Now it's a long. I changed
  the variable declarations to be ssize_t instead of int.

* A few definitions disagreed with their declarations. They had int
  as the return value instead of ssize_t (as the headers said).
  Namely: _read, _write, the read & write termios hooks.

* In write() the return value 'rv' was an int. But it's used to store
  both an int and a ssize_t. Now they are not the same as int,
  two variables are needed - 'i_rv' and 'ss_rv' for int and ssize_t
  respectively.

I was surprised how little broke on compilation.

Note that I haven't tried building any large applications
with these changes. I can't see why the changes (apart from the one
to FILE) would break anything.

OK to commit?

Thanks, bye, Rich =]

Index: include/sys/djtypes.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/sys/djtypes.h,v
retrieving revision 1.11
diff -p -c -3 -r1.11 djtypes.h
*** include/sys/djtypes.h	10 Jun 2002 00:01:30 -0000	1.11
--- include/sys/djtypes.h	22 Jan 2003 20:24:26 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
***************
*** 13,19 ****
  #define __DJ_offset_t	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 int ssize_t;
  #define __DJ_time_t	typedef unsigned int time_t;
  #define __DJ_uid_t	typedef int uid_t;
  
--- 14,20 ----
  #define __DJ_offset_t	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;
  #define __DJ_time_t	typedef unsigned int time_t;
  #define __DJ_uid_t	typedef int uid_t;
  
Index: include/stdio.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/stdio.h,v
retrieving revision 1.8
diff -p -c -3 -r1.8 stdio.h
*** include/stdio.h	17 Oct 2002 23:00:24 -0000	1.8
--- include/stdio.h	22 Jan 2003 20:24:26 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2000 DJ Delorie, see COPYING.DJ for details */
*************** __DJ_size_t
*** 50,56 ****
     are here at all is to comply with ANSI specifictions. */
     
  typedef struct {
!   int     _cnt;
    char   *_ptr;
    char   *_base;
    size_t  _bufsiz;
--- 51,57 ----
     are here at all is to comply with ANSI specifictions. */
     
  typedef struct {
!   long    _cnt;
    char   *_ptr;
    char   *_base;
    size_t  _bufsiz;
Index: src/libc/ansi/stdio/fflush.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fflush.c,v
retrieving revision 1.10
diff -p -c -3 -r1.10 fflush.c
*** src/libc/ansi/stdio/fflush.c	17 Oct 2002 23:00:24 -0000	1.10
--- src/libc/ansi/stdio/fflush.c	22 Jan 2003 20:24:31 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
*************** int
*** 18,24 ****
  fflush(FILE *f)
  {
    char *base;
!   int n;
    size_t rn;
  
    if (f == NULL)
--- 19,25 ----
  fflush(FILE *f)
  {
    char *base;
!   ssize_t n;
    size_t rn;
  
    if (f == NULL)
Index: src/libc/ansi/stdio/flsbuf.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/flsbuf.c,v
retrieving revision 1.10
diff -p -c -3 -r1.10 flsbuf.c
*** src/libc/ansi/stdio/flsbuf.c	20 Jun 2001 17:57:26 -0000	1.10
--- src/libc/ansi/stdio/flsbuf.c	22 Jan 2003 20:24:31 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
*************** int
*** 17,23 ****
  _flsbuf(int c, FILE *f)
  {
    char *base;
!   int n;
    size_t rn;
    char c1;
    size_t size;
--- 18,24 ----
  _flsbuf(int c, FILE *f)
  {
    char *base;
!   ssize_t n;
    size_t rn;
    char c1;
    size_t size;
Index: src/libc/dos/io/_read.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/dos/io/_read.c,v
retrieving revision 1.2
diff -p -c -3 -r1.2 _read.c
*** src/libc/dos/io/_read.c	14 Jun 2002 14:25:44 -0000	1.2
--- src/libc/dos/io/_read.c	22 Jan 2003 20:24:36 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  #include <libc/stubs.h>
***************
*** 12,18 ****
  #include <libc/fsexthlp.h>
  #include <libc/dosio.h>
  
! int
  _read(int handle, void* buffer, size_t count)
  {
    size_t j, k;
--- 13,19 ----
  #include <libc/fsexthlp.h>
  #include <libc/dosio.h>
  
! ssize_t
  _read(int handle, void* buffer, size_t count)
  {
    size_t j, k;
Index: src/libc/dos/io/_write.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/dos/io/_write.c,v
retrieving revision 1.8
diff -p -c -3 -r1.8 _write.c
*** src/libc/dos/io/_write.c	14 Jun 2002 14:25:53 -0000	1.8
--- src/libc/dos/io/_write.c	22 Jan 2003 20:24:37 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
***************
*** 16,22 ****
  #include <libc/farptrgs.h>
  #include <libc/getdinfo.h>
  
! int
  _write(int handle, const void* buffer, size_t count)
  {
    __FSEXT_Function *func = __FSEXT_get_function(handle);
--- 17,23 ----
  #include <libc/farptrgs.h>
  #include <libc/getdinfo.h>
  
! ssize_t
  _write(int handle, const void* buffer, size_t count)
  {
    __FSEXT_Function *func = __FSEXT_get_function(handle);
Index: src/libc/posix/termios/readhook.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/termios/readhook.c,v
retrieving revision 1.1
diff -p -c -3 -r1.1 readhook.c
*** src/libc/posix/termios/readhook.c	21 Dec 2002 22:36:44 -0000	1.1
--- src/libc/posix/termios/readhook.c	22 Jan 2003 20:24:40 -0000
***************
*** 1,5 ****
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  #include <libc/ttyprvt.h>
  
! int (*__libc_read_termios_hook)(int handle, void *buffer, size_t count,
! 				ssize_t *rv) = NULL;
--- 1,6 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  #include <libc/ttyprvt.h>
  
! ssize_t (*__libc_read_termios_hook)(int handle, void *buffer, size_t count,
! 				    ssize_t *rv) = NULL;
Index: src/libc/posix/termios/writhook.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/termios/writhook.c,v
retrieving revision 1.1
diff -p -c -3 -r1.1 writhook.c
*** src/libc/posix/termios/writhook.c	21 Dec 2002 22:36:44 -0000	1.1
--- src/libc/posix/termios/writhook.c	22 Jan 2003 20:24:40 -0000
***************
*** 1,5 ****
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  #include <libc/ttyprvt.h>
  
! int (*__libc_write_termios_hook)(int handle, const void *buffer, size_t count,
! 				 ssize_t *rv) = NULL;
--- 1,6 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  #include <libc/ttyprvt.h>
  
! ssize_t (*__libc_write_termios_hook)(int handle, const void *buffer,
! 				     size_t count, ssize_t *rv) = NULL;
Index: src/libc/posix/unistd/write.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/write.c,v
retrieving revision 1.9
diff -p -c -3 -r1.9 write.c
*** src/libc/posix/unistd/write.c	21 Dec 2002 22:38:18 -0000	1.9
--- src/libc/posix/unistd/write.c	22 Jan 2003 20:24:43 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
*************** write(int handle, const void* buffer, si
*** 27,39 ****
    size_t bytes_in_tb = 0;
    size_t offset_into_buf = 0;
    int out;
!   ssize_t rv;
    __FSEXT_Function *func = __FSEXT_get_function(handle);
  
    /* termios special hook */
    if (__libc_write_termios_hook != NULL)
!       if (__libc_write_termios_hook(handle, buffer, count, &rv) != 0)
!         return rv;
  
    if (count == 0)
      return 0; /* POSIX.1 requires this */
--- 28,41 ----
    size_t bytes_in_tb = 0;
    size_t offset_into_buf = 0;
    int out;
!   ssize_t ss_rv;
!   int i_rv;
    __FSEXT_Function *func = __FSEXT_get_function(handle);
  
    /* termios special hook */
    if (__libc_write_termios_hook != NULL)
!       if (__libc_write_termios_hook(handle, buffer, count, &ss_rv) != 0)
!         return ss_rv;
  
    if (count == 0)
      return 0; /* POSIX.1 requires this */
*************** write(int handle, const void* buffer, si
*** 54,61 ****
    /* Let's handle FSEXT_write ! */
    /* if handler is installed, call extension and exit if handled. */
    if(func &&				
!      __FSEXT_func_wrapper(func, __FSEXT_write, &rv, handle, buffer, count))
!       return rv;
  
    if (__has_fd_properties(handle)
        && (__fd_properties[handle]->flags & FILE_DESC_ZERO_FILL_EOF_GAP))
--- 56,63 ----
    /* Let's handle FSEXT_write ! */
    /* if handler is installed, call extension and exit if handled. */
    if(func &&				
!      __FSEXT_func_wrapper(func, __FSEXT_write, &i_rv, handle, buffer, count))
!       return i_rv;
  
    if (__has_fd_properties(handle)
        && (__fd_properties[handle]->flags & FILE_DESC_ZERO_FILL_EOF_GAP))

- Raw text -


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