Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

endfile.c File Reference

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

Go to the source code of this file.


Defines

#define unlink   remove
#define L_tmpnam   16

Functions

integer f_end (alist *a)
int copy (FILE *from, register long len, FILE *to)
int t_runc (alist *a)

Variables

char * f__r_mode []
char * f__w_mode []

Define Documentation

#define L_tmpnam   16
 

Definition at line 106 of file endfile.c.

Referenced by t_runc().

#define unlink   remove
 

Definition at line 21 of file endfile.c.


Function Documentation

int copy FILE *    from,
register long    len,
FILE *    to
[static]
 

Definition at line 64 of file endfile.c.

Referenced by t_runc().

00066 {
00067         int k, len1;
00068         char buf[BUFSIZ];
00069 
00070         while(fread(buf, len1 = len > BUFSIZ ? BUFSIZ : (int)len, 1, from)) {
00071                 if (!fwrite(buf, len1, 1, to))
00072                         return 1;
00073                 if ((len -= len1) <= 0)
00074                         break;
00075                 }
00076         return 0;
00077         }

integer f_end alist   a
 

Definition at line 36 of file endfile.c.

References a, close(), err, f__w_mode, MXUNIT, t_runc(), unit::uend, unit::ufd, and unit::useek.

00038 {
00039         unit *b;
00040         if(a->aunit>=MXUNIT || a->aunit<0) err(a->aerr,101,"endfile");
00041         b = &f__units[a->aunit];
00042         if(b->ufd==NULL) {
00043                 char nbuf[10];
00044                 (void) sprintf(nbuf,"fort.%ld",a->aunit);
00045 #ifdef NON_UNIX_STDIO
00046                 { FILE *tf;
00047                         if (tf = fopen(nbuf, f__w_mode[0]))
00048                                 fclose(tf);
00049                         }
00050 #else
00051                 close(creat(nbuf, 0666));
00052 #endif
00053                 return(0);
00054                 }
00055         b->uend=1;
00056         return(b->useek ? t_runc(a) : 0);
00057 }

int t_runc alist   a
 

Definition at line 113 of file endfile.c.

References a, close(), copy(), err, f__r_mode, f__w_mode, L, L_tmpnam, mktemp(), unit::ufd, unit::ufmt, unit::ufnm, unlink, unit::url, unit::useek, and unit::uwrt.

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

00115 {
00116         char nm[L_tmpnam+12];   /* extra space in case L_tmpnam is tiny */
00117         long loc, len;
00118         unit *b;
00119 #ifdef NON_UNIX_STDIO
00120         FILE *bf, *tf;
00121 #else
00122         FILE *bf;
00123 #endif
00124         int rc = 0;
00125 
00126         b = &f__units[a->aunit];
00127         if(b->url)
00128                 return(0);      /*don't truncate direct files*/
00129         loc=ftell(bf = b->ufd);
00130         fseek(bf,0L,SEEK_END);
00131         len=ftell(bf);
00132         if (loc >= len || b->useek == 0 || b->ufnm == NULL)
00133                 return(0);
00134 #ifdef NON_UNIX_STDIO
00135         fclose(b->ufd);
00136 #else
00137         rewind(b->ufd); /* empty buffer */
00138 #endif
00139         if (!loc) {
00140 #ifdef NON_UNIX_STDIO
00141                 if (!(bf = fopen(b->ufnm, f__w_mode[b->ufmt])))
00142 #else
00143                 if (close(creat(b->ufnm,0666)))
00144 #endif
00145                         rc = 1;
00146                 if (b->uwrt)
00147                         b->uwrt = 1;
00148                 goto done;
00149                 }
00150 #ifdef _POSIX_SOURCE
00151         tmpnam(nm);
00152 #else
00153         strcpy(nm,"tmp.FXXXXXX");
00154         mktemp(nm);
00155 #endif
00156 #ifdef NON_UNIX_STDIO
00157         if (!(bf = fopen(b->ufnm, f__r_mode[0]))) {
00158  bad:
00159                 rc = 1;
00160                 goto done;
00161                 }
00162         if (!(tf = fopen(nm, f__w_mode[0])))
00163                 goto bad;
00164         if (copy(bf, loc, tf)) {
00165  bad1:
00166                 rc = 1;
00167                 goto done1;
00168                 }
00169         if (!(bf = freopen(b->ufnm, f__w_mode[0], bf)))
00170                 goto bad1;
00171         if (!(tf = freopen(nm, f__r_mode[0], tf)))
00172                 goto bad1;
00173         if (copy(tf, loc, bf))
00174                 goto bad1;
00175         if (f__w_mode[0] != f__w_mode[b->ufmt]) {
00176                 if (!(bf = freopen(b->ufnm, f__w_mode[b->ufmt|2], bf)))
00177                         goto bad1;
00178                 fseek(bf, loc, SEEK_SET);
00179                 }
00180 done1:
00181         fclose(tf);
00182         unlink(nm);
00183 done:
00184         f__cf = b->ufd = bf;
00185 #else
00186         if (copy(b->ufnm, loc, nm)
00187          || copy(nm, loc, b->ufnm))
00188                 rc = 1;
00189         unlink(nm);
00190         fseek(b->ufd, loc, SEEK_SET);
00191 done:
00192 #endif
00193         if (rc)
00194                 err(a->aerr,111,"endfile");
00195         return 0;
00196         }

Variable Documentation

char* f__r_mode[]
 

Definition at line 30 of file endfile.c.

Referenced by f_open(), and t_runc().

char * f__w_mode[]
 

Definition at line 30 of file endfile.c.

Referenced by f_end(), f_open(), and t_runc().

 

Powered by Plone

This site conforms to the following standards: