endfile.c File Reference

#include "f2c.h"
#include "fio.h"
#include "unistd.h"
#include "stdlib.h"
#include "string.h"

Include dependency graph for endfile.c:

Go to the source code of this file.

Defines

#define FTRUNCATE   ftruncate

Functions

integer f_end (alist *a)
int t_runc (alist *a)

Variables

char * f__r_mode []
char * f__w_mode []


Define Documentation

#define FTRUNCATE   ftruncate

Referenced by t_runc().


Function Documentation

integer f_end ( alist a  ) 

Definition at line 35 of file endfile.c.

References a, b, err, f__units, FOPEN, MXUNIT, NULL, t_runc(), and tf.

00037 {
00038         unit *b;
00039         FILE *tf;
00040 
00041         if(a->aunit>=MXUNIT || a->aunit<0) err(a->aerr,101,"endfile");
00042         b = &f__units[a->aunit];
00043         if(b->ufd==NULL) {
00044                 char nbuf[10];
00045                 sprintf(nbuf,"fort.%ld",(long)a->aunit);
00046                 if (tf = FOPEN(nbuf, f__w_mode[0]))
00047                         fclose(tf);
00048                 return(0);
00049                 }
00050         b->uend=1;
00051         return(b->useek ? t_runc(a) : 0);
00052 }

Here is the call graph for this function:

int t_runc ( alist a  ) 

Definition at line 79 of file endfile.c.

References a, b, done, err, f__cf, f__units, FOPEN, FREOPEN, FSEEK, FTELL, FTRUNCATE, NULL, OFF_T, SEEK_END, and tf.

Referenced by f_back(), f_clos(), f_end(), and f_rew().

00081 {
00082         OFF_T loc, len;
00083         unit *b;
00084         int rc;
00085         FILE *bf;
00086 #ifdef NO_TRUNCATE
00087         FILE *tf;
00088 #endif
00089 
00090         b = &f__units[a->aunit];
00091         if(b->url)
00092                 return(0);      /*don't truncate direct files*/
00093         loc=FTELL(bf = b->ufd);
00094         FSEEK(bf,(OFF_T)0,SEEK_END);
00095         len=FTELL(bf);
00096         if (loc >= len || b->useek == 0)
00097                 return(0);
00098 #ifdef NO_TRUNCATE
00099         if (b->ufnm == NULL)
00100                 return 0;
00101         rc = 0;
00102         fclose(b->ufd);
00103         if (!loc) {
00104                 if (!(bf = FOPEN(b->ufnm, f__w_mode[b->ufmt])))
00105                         rc = 1;
00106                 if (b->uwrt)
00107                         b->uwrt = 1;
00108                 goto done;
00109                 }
00110         if (!(bf = FOPEN(b->ufnm, f__r_mode[0]))
00111          || !(tf = tmpfile())) {
00112 #ifdef NON_UNIX_STDIO
00113  bad:
00114 #endif
00115                 rc = 1;
00116                 goto done;
00117                 }
00118         if (copy(bf, (long)loc, tf)) {
00119  bad1:
00120                 rc = 1;
00121                 goto done1;
00122                 }
00123         if (!(bf = FREOPEN(b->ufnm, f__w_mode[0], bf)))
00124                 goto bad1;
00125         rewind(tf);
00126         if (copy(tf, (long)loc, bf))
00127                 goto bad1;
00128         b->uwrt = 1;
00129         b->urw = 2;
00130 #ifdef NON_UNIX_STDIO
00131         if (b->ufmt) {
00132                 fclose(bf);
00133                 if (!(bf = FOPEN(b->ufnm, f__w_mode[3])))
00134                         goto bad;
00135                 FSEEK(bf,(OFF_T)0,SEEK_END);
00136                 b->urw = 3;
00137                 }
00138 #endif
00139 done1:
00140         fclose(tf);
00141 done:
00142         f__cf = b->ufd = bf;
00143 #else /* NO_TRUNCATE */
00144         if (b->urw & 2)
00145                 fflush(b->ufd); /* necessary on some Linux systems */
00146 #ifndef FTRUNCATE
00147 #define FTRUNCATE ftruncate
00148 #endif
00149         rc = FTRUNCATE(fileno(b->ufd), loc);
00150         /* The following FSEEK is unnecessary on some systems, */
00151         /* but should be harmless. */
00152         FSEEK(b->ufd, (OFF_T)0, SEEK_END);
00153 #endif /* NO_TRUNCATE */
00154         if (rc)
00155                 err(a->aerr,111,"endfile");
00156         return 0;
00157         }

Here is the caller graph for this function:


Variable Documentation

char* f__r_mode[]

Definition at line 34 of file open.c.

Referenced by f__nowreading().

char * f__w_mode[]

Definition at line 35 of file open.c.

Referenced by f__nowreading(), and f__nowwriting().


Generated on Sun Mar 4 15:04:24 2007 for Scilab [trunk] by  doxygen 1.5.1