Skip to content

Commit dc4d18e

Browse files
committed
Add fseeko/ftello using fsetpos/fgetpos for BSD/OS.
1 parent 641b658 commit dc4d18e

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

configure

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10463,7 +10463,8 @@ fi
1046310463
1046410464
1046510465
10466-
for ac_func in gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
10466+
10467+
for ac_func in fseeko gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
1046710468
do
1046810469
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
1046910470
echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -11470,6 +11471,9 @@ fi
1147011471
done
1147111472
1147211473
11474+
case $host_os in bsdi*)
11475+
ac_cv_func_fseeko=yes
11476+
esac
1147311477
echo "$as_me:$LINENO: checking for _LARGEFILE_SOURCE value needed for large files" >&5
1147411478
echo $ECHO_N "checking for _LARGEFILE_SOURCE value needed for large files... $ECHO_C" >&6
1147511479
if test "${ac_cv_sys_largefile_source+set}" = set; then

configure.in

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $Header: /cvsroot/pgsql/configure.in,v 1.211 2002/09/25 13:23:15 momjian Exp $
2+
dnl $Header: /cvsroot/pgsql/configure.in,v 1.212 2002/10/23 20:56:24 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -835,7 +835,7 @@ else
835835
AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
836836
fi
837837

838-
AC_REPLACE_FUNCS([gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
838+
AC_REPLACE_FUNCS([fseeko gethostname getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
839839

840840
# Solaris has a very slow qsort in certain cases.
841841
case $host_os in
@@ -903,6 +903,9 @@ AC_CHECK_FUNCS(atexit, [],
903903
[AC_CHECK_FUNCS(on_exit, [],
904904
[AC_MSG_ERROR([neither atexit() nor on_exit() found])])])
905905

906+
case $host_os in bsdi*)
907+
ac_cv_func_fseeko=yes
908+
esac
906909
AC_FUNC_FSEEKO
907910

908911

src/port/fseeko.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* fseeko.c
4+
* 64-bit versions of fseeko/ftello()
5+
*
6+
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
*
10+
* IDENTIFICATION
11+
* $Header: /cvsroot/pgsql/src/port/fseeko.c,v 1.1 2002/10/23 20:56:24 momjian Exp $
12+
*
13+
*-------------------------------------------------------------------------
14+
*/
15+
16+
#ifdef __bsdi__
17+
18+
#include <stdio.h>
19+
#include <sys/types.h>
20+
#include <sys/stat.h>
21+
#include <errno.h>
22+
23+
/*
24+
* On BSD/OS, off_t and fpos_t are the same. Standards say
25+
* off_t is an arithmetic type, but not necessarily integral,
26+
* while fpos_t might be neither.
27+
*
28+
* I don't think this is thread-safe.
29+
*/
30+
31+
int
32+
fseeko(FILE *stream, off_t offset, int whence)
33+
{
34+
off_t floc;
35+
struct stat filestat;
36+
37+
switch (whence)
38+
{
39+
case SEEK_CUR:
40+
if (fgetpos(stream, &floc) != 0)
41+
return -1;
42+
floc += offset;
43+
if (fsetpos(stream, &floc) != 0)
44+
return -1;
45+
return 0;
46+
break;
47+
case SEEK_SET:
48+
if (fsetpos(stream, &offset) != 0)
49+
return -1;
50+
return 0;
51+
break;
52+
case SEEK_END:
53+
if (fstat(fileno(stream), &filestat) != 0)
54+
return -1;
55+
floc = filestat.st_size;
56+
if (fsetpos(stream, &floc) != 0)
57+
return -1;
58+
return 0;
59+
break;
60+
default:
61+
errno = EINVAL;
62+
return -1;
63+
}
64+
}
65+
66+
67+
off_t
68+
ftello(FILE *stream)
69+
{
70+
off_t floc;
71+
72+
if (fgetpos(stream, &floc) != 0)
73+
return -1;
74+
return floc;
75+
}
76+
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy