summaryrefslogtreecommitdiffstats
path: root/contrib/libf2c/libI77/endfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libf2c/libI77/endfile.c')
-rw-r--r--contrib/libf2c/libI77/endfile.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/contrib/libf2c/libI77/endfile.c b/contrib/libf2c/libI77/endfile.c
index f7a78e1..980c91d 100644
--- a/contrib/libf2c/libI77/endfile.c
+++ b/contrib/libf2c/libI77/endfile.c
@@ -1,6 +1,10 @@
+#include "config.h"
#include "f2c.h"
#include "fio.h"
+#include <sys/types.h>
+#include <unistd.h>
+
#ifdef KR_headers
extern char *strcpy();
extern FILE *tmpfile();
@@ -38,6 +42,7 @@ integer f_end(alist *a)
return(b->useek ? t_runc(a) : 0);
}
+#ifndef HAVE_FTRUNCATE
static int
#ifdef KR_headers
copy(from, len, to) FILE *from, *to; register long len;
@@ -56,6 +61,7 @@ copy(FILE *from, register long len, FILE *to)
}
return 0;
}
+#endif /* !defined(HAVE_FTRUNCATE) */
int
#ifdef KR_headers
@@ -66,8 +72,11 @@ t_runc(alist *a)
{
long loc, len;
unit *b;
- FILE *bf, *tf;
- int rc = 0;
+ int rc;
+ FILE *bf;
+#ifndef HAVE_FTRUNCATE
+ FILE *tf;
+#endif /* !defined(HAVE_FTRUNCATE) */
b = &f__units[a->aunit];
if(b->url)
@@ -77,6 +86,8 @@ t_runc(alist *a)
len=ftell(bf);
if (loc >= len || b->useek == 0 || b->ufnm == NULL)
return(0);
+#ifndef HAVE_FTRUNCATE
+ rc = 0;
fclose(b->ufd);
if (!loc) {
if (!(bf = fopen(b->ufnm, f__w_mode[b->ufmt])))
@@ -118,6 +129,10 @@ done1:
fclose(tf);
done:
f__cf = b->ufd = bf;
+#else /* !defined(HAVE_FTRUNCATE) */
+ fflush(b->ufd);
+ rc = ftruncate(fileno(b->ufd), (off_t)loc);
+#endif /* !defined(HAVE_FTRUNCATE) */
if (rc)
err(a->aerr,111,"endfile");
return 0;
OpenPOWER on IntegriCloud