delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2007/08/03/16:29:33

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Authenticated: #27081556
X-Provags-ID: V01U2FsdGVkX1+ULZlLL8OU2WNFKv2tPYI5t8UWdcl8eNZRLN5d3P
VqCPKH/gDM9zNB
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
To: djgpp-workers AT delorie DOT com
Subject: fseeko and ftello
Date: Fri, 3 Aug 2007 22:34:29 +0200
User-Agent: KMail/1.9.5
MIME-Version: 1.0
Message-Id: <200708032234.30007.juan.guerrero@gmx.de>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

While trying to port m4-1.4.10 I have noticed that the configuration script
founds a certain amount of missing functions.  The replacement functions
supplied by the gnulib library require some times a lot of djgpp specific
adjustment that leads me to the conclusion that those changes probably will
never be accepted by the gnulib maintainers.  So here is an attempt to fix
the  issue partially in djgpp itself.  Here is a small patch to implement
fseeko() and ftello().
fseeko() and ftello() are both declared in stdio.h an require off_t, so I
have replaced the inclusion of djtypes.h with types.h in stdio.h.  If this
is not wanted/correct, please let me know how to solve the issue.

Regards,
Juan M. Guerrero



2007-08-03  Juan Manuell Guerrero  <juan DOT guerrero AT gmx DOT de>

	* include/stdio.h: Declaration of fseeko and ftello and
	inclusion of sys/types instead of sys/djtypes for off_t
	definition.
	* src/docs/kb/wc204.txi: Add fseeko and ftello reference.
	* src/libc/ansi/stdio/fseeko.c: Definition of fseeko.
	* src/libc/ansi/stdio/fseeko.txh: Function description added.
	* src/libc/ansi/stdio/ftello.c: Definition of ftello.
	* src/libc/ansi/stdio/ftello.txh: Function description added.
	* src/libc/ansi/stdio/makefile: Add fseeko and ftello.


diff -aprNU3 djgpp.orig/include/stdio.h djgpp/include/stdio.h
--- djgpp.orig/include/stdio.h	2007-08-03 19:57:48 +0000
+++ djgpp/include/stdio.h	2007-08-03 22:08:52 +0000
@@ -1,3 +1,4 @@
+/* Copyright (C) 2007 DJ Delorie, see COPYING.DJ for details */
 /* 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 */
@@ -15,7 +16,7 @@ extern "C" {
 #ifndef __dj_ENFORCE_ANSI_FREESTANDING
 
 #include <sys/version.h>
-#include <sys/djtypes.h>
+#include <sys/types.h>
   
 #define _IOFBF    	00001
 #define _IONBF    	00002
@@ -89,8 +90,10 @@ size_t	fread(void *_ptr, size_t _size, s
 FILE *	freopen(const char *_filename, const char *_mode, FILE *_stream);
 int	fscanf(FILE *_stream, const char *_format, ...);
 int	fseek(FILE *_stream, long _offset, int _mode);
+int	fseeko(FILE *_stream, off_t _offset, int _mode);
 int	fsetpos(FILE *_stream, const fpos_t *_pos);
 long	ftell(FILE *_stream);
+off_t	ftello(FILE *_stream);
 size_t	fwrite(const void *_ptr, size_t _size, size_t _nelem, FILE *_stream);
 int	getc(FILE *_stream);
 int	getchar(void);
diff -aprNU3 djgpp.orig/src/docs/kb/wc204.txi djgpp/src/docs/kb/wc204.txi
--- djgpp.orig/src/docs/kb/wc204.txi	2005-05-11 20:06:08 +0000
+++ djgpp/src/docs/kb/wc204.txi	2007-08-03 22:08:52 +0000
@@ -1094,3 +1094,8 @@ formats for @code{"%x"} and @code{"%X"} 
 
 @pindex djasm AT r{, cr4 register}
 @code{djasm} recognises the fourth control register, @code{cr4}.
+
+@findex fseeko
+@findex ftello
+Functions @code{fseeko} and @code{ftello} added.
+
diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/fseeko.c djgpp/src/libc/ansi/stdio/fseeko.c
--- djgpp.orig/src/libc/ansi/stdio/fseeko.c	1970-01-01 00:00:00 +0000
+++ djgpp/src/libc/ansi/stdio/fseeko.c	2007-08-03 22:08:52 +0000
@@ -0,0 +1,10 @@
+/* Copyright (C) 2007 DJ Delorie, see COPYING.DJ for details */
+#include <stdio.h>
+
+int
+fseeko(FILE *f, off_t offset, int ptrname)
+{
+  /*  As long as off_t is equal long, a cast should be enough.  */
+
+  return fseek(f, (long)offset, ptrname);
+}
diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/fseeko.txh djgpp/src/libc/ansi/stdio/fseeko.txh
--- djgpp.orig/src/libc/ansi/stdio/fseeko.txh	1970-01-01 00:00:00 +0000
+++ djgpp/src/libc/ansi/stdio/fseeko.txh	2007-08-03 22:16:24 +0000
@@ -0,0 +1,51 @@
+@node fseeko, stdio
+@findex fseeko
+@subheading Syntax
+
+@example
+#include <stdio.h>
+
+int fseeko(FILE *file, off_t offset, int mode);
+@end example
+
+@subheading Description
+
+The @code{fseeko} function is equivalent to the @code{fseek}
+function except that the @var{offset} argument is of type off_t.
+This function moves the file pointer for @var{file} according to
+@var{mode}:
+
+@table @code
+
+@item SEEK_SET
+
+The file pointer is moved to the offset specified.
+
+@item SEEK_CUR
+
+The file pointer is moved relative to its current position.
+
+@item SEEK_END
+
+The file pointer is moved to a position @var{offset} bytes from the end
+of the file.  The offset is usually nonpositive in this case. 
+
+@end table
+
+For further information see the documentation for the @code{fseek} function
+(@pxref{fseek}).
+
+@subheading Return Value
+
+Zero if successful, nonzero if not. 
+
+@subheading Portability
+
+@portability ansi, posix
+
+@subheading Example
+
+@example
+fseeko(stdin, 12, SEEK_CUR); /* skip 12 bytes */
+@end example
+
diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/ftello.c djgpp/src/libc/ansi/stdio/ftello.c
--- djgpp.orig/src/libc/ansi/stdio/ftello.c	1970-01-01 00:00:00 +0000
+++ djgpp/src/libc/ansi/stdio/ftello.c	2007-08-03 22:08:52 +0000
@@ -0,0 +1,10 @@
+/* Copyright (C) 2007 DJ Delorie, see COPYING.DJ for details */
+#include <stdio.h>
+
+off_t
+ftello(FILE *f)
+{
+  /*  As long as off_t is equal long, a cast should be enough.  */
+
+  return (off_t)ftell(f);
+}
diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/ftello.txh djgpp/src/libc/ansi/stdio/ftello.txh
--- djgpp.orig/src/libc/ansi/stdio/ftello.txh	1970-01-01 00:00:00 +0000
+++ djgpp/src/libc/ansi/stdio/ftello.txh	2007-08-03 22:16:20 +0000
@@ -0,0 +1,33 @@
+@node ftello, stdio
+@findex ftello
+@subheading Syntax
+
+@example
+#include <stdio.h>
+
+off_t ftello(FILE *file);
+@end example
+
+@subheading Description
+The @code{ftello} function is equivalent to the @code{ftell}
+function except that the return value is of type off_t.
+Returns the current file position for @code{file}.  This is suitable for
+a future call to @code{fseeko}.
+
+For further information see the documentation for the @code{ftell} function
+(@pxref{ftell}).
+
+@subheading Return Value
+
+The file position, or -1 on error. 
+
+@subheading Portability
+
+@portability ansi, posix
+
+@subheading Example
+
+@example
+off_t p = ftello(stdout);
+@end example
+
diff -aprNU3 djgpp.orig/src/libc/ansi/stdio/makefile djgpp/src/libc/ansi/stdio/makefile
--- djgpp.orig/src/libc/ansi/stdio/makefile	2001-05-21 20:25:48 +0000
+++ djgpp/src/libc/ansi/stdio/makefile	2007-08-03 22:08:52 +0000
@@ -1,3 +1,4 @@
+# Copyright (C) 2007 DJ Delorie, see COPYING.DJ for details
 # Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details
 # Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details
 # Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details
@@ -25,8 +26,10 @@ SRC += freopen.c
 SRC += frlist.c
 SRC += fscanf.c
 SRC += fseek.c
+SRC += fseeko.c
 SRC += fsetpos.c
 SRC += ftell.c
+SRC += ftello.c
 SRC += fwalk.c
 SRC += fwrite.c
 SRC += getc.c

- Raw text -


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