00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <cmplrs/fio.h>
00043 #include <mutex.h>
00044 #include <string.h>
00045 #include "endfile.h"
00046
00047 #include "close.h"
00048 #include "err.h"
00049 #include "fmt.h"
00050 #include "iomode.h"
00051 #include "util.h"
00052
00053 #ifdef _BSD
00054 #include <sys/types.h>
00055 #include <sys/file.h>
00056 #endif
00057 #if defined(_SYSV) || defined(_SYSTYPE_SVR4)
00058 #include <sys/fcntl.h>
00059 #endif
00060
00061 #include "vmsflags.h"
00062 static int one = 1;
00063 static char ctlz = '\032';
00064
00065
00066 #if 00
00067 static int f_end_com (alist64 *a, int lock);
00068 #else
00069 static int f_end_com (alist *a, int lock);
00070 #endif
00071
00072 int
00073 f_end (alist *a)
00074 {
00075 #if 00
00076 alist64 a64;
00077 a64.aerr = a->aerr;
00078 a64.aunit = a->aunit;
00079 return( f_end_com( &a64, 0 ) );
00080 #else
00081 return( f_end_com( a, 0 ) );
00082 #endif
00083 }
00084
00085 int
00086 f_end_mp (alist *a)
00087 {
00088 #if 00
00089 alist64 a64;
00090 a64.aerr = a->aerr;
00091 a64.aunit = a->aunit;
00092 return( f_end_com( &a64, 1 ) );
00093 #else
00094 return( f_end_com( a, 1 ) );
00095 #endif
00096 }
00097
00098 #if 00
00099 int
00100 f_end64 (alist64 *a)
00101 {
00102 return( f_end_com( a, 0 ) );
00103 }
00104
00105 int
00106 f_end64_mp (alist64 *a)
00107 {
00108 return( f_end_com( a, 1 ) );
00109 }
00110
00111 static int
00112 f_end_com (alist64 *a, int lock)
00113 #else
00114 static int
00115 f_end_com (alist *a, int lock)
00116 #endif
00117 {
00118 unit *b, *ftnunit;
00119 int n;
00120
00121 if ((ftnunit = b = map_luno (a->aunit)) == NULL)
00122 err (a->aerr, 114, "endfile");
00123 while (lock && test_and_set( &ftnunit->lock_unit, 1L ))
00124 ;
00125
00126 if (b->uacc == KEYED || b->uacc == DIRECT)
00127 errret(a->aerr, 169, "endfile");
00128
00129 if (b->uconn <= 0)
00130 goto end;
00131 b->uend = 1;
00132 if (b->useek == 0)
00133 goto end;
00134 if (f77vms_flag_[VMS_EF]) {
00135 if (b->uwrt != WR_READY && f77nowwriting (ftnunit))
00136 errret(a->aerr, 160, "endfile");
00137 if (b->ufmt == 1) {
00138 #ifdef I90
00139
00140 if (ftnunit->f90sw == 1 && ftnunit->f90nadv == 1 ) {
00141 putc ('\n', ftnunit->ufd);
00142 ftnunit->f90nadv = 0;
00143 }
00144 #endif
00145 putc ('\032', b->ufd);
00146 putc ('\n', b->ufd);
00147 } else {
00148 (void) fwrite (&one, sizeof (int), 1, b->ufd);
00149 (void) fwrite (&ctlz, 1, 1, b->ufd);
00150 if (fwrite (&one, sizeof (int), 1, b->ufd) != 1)
00151 errret(a->aerr, errno, "system write error");
00152 }
00153 } else {
00154 if (b->uwrt != WR_READY && f77nowwriting (ftnunit))
00155 errret(a->aerr, 160, "endfile");
00156
00157 #ifdef I90
00158
00159 if (ftnunit->f90sw == 1 && ftnunit->f90nadv == 1 ) {
00160 putc ('\n', b->ufd);
00161 ftnunit->f90nadv = 0;
00162 }
00163 #endif
00164 }
00165
00166 n = t_runc (b, a->aerr);
00167 if (lock) ftnunit->lock_unit = 0;
00168 return (n);
00169 end:
00170 if (lock) ftnunit->lock_unit = 0;
00171 return(0);
00172 }
00173
00174 #pragma weak f_end64 = f_end
00175 #pragma weak f_end64_mp = f_end_mp