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 #pragma ident "@(#) libf/fio/fopn.c 92.6 09/20/99 11:41:08"
00043
00044 #include <errno.h>
00045 #include <fcntl.h>
00046 #include <liberrno.h>
00047 #ifndef _ABSOFT
00048 #include <malloc.h>
00049 #endif
00050 #include <stddef.h>
00051 #include <stdio.h>
00052 #include <string.h>
00053 #include <unistd.h>
00054 #include <stdlib.h>
00055 #include <sys/stat.h>
00056 #include <cray/nassert.h>
00057 #ifdef _UNICOS_MAX
00058 #include <mpp/globals.h>
00059 #endif
00060 #include <cray/assign.h>
00061 #include "fio.h"
00062 #include "util/utildefs.h"
00063 #include "ffio/spec_parse.h"
00064
00065 #define TRACK (42*BLKSIZE)
00066 #define FPARMAX 3
00067 #define SPECSZ (FPARMAX+2+1)
00068
00069
00070
00071 #define ACCESS_PERMS 0666
00072
00073 #if defined(_LITTLE_ENDIAN) && !defined(__sv2)
00074 #ifndef IOWRT
00075 #define IOWRT = _IO_CURRENTLY_PUTTING
00076 #endif
00077 #ifndef IORW
00078 #define IORW = _IO_TIED_PUTGET
00079 #endif
00080 extern FILE *fdopen(int, const char*);
00081 #endif
00082
00083 extern int __fdctrace_enable;
00084 static int _defbufsiz_warning;
00085
00086 static int
00087 make_fdspec(union spec_u *fdspec, char *layer, int intnum[FPARMAX]);
00088
00089 #ifdef KEY
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 static int suppress_repeats() {
00100 static int save_suppress_repeats = 2;
00101 return (2 != save_suppress_repeats) ?
00102 save_suppress_repeats :
00103 (save_suppress_repeats = (0 != getenv("FTN_SUPPRESS_REPEATS")));
00104 }
00105 #endif
00106
00107 #ifdef KEY
00108 extern void _ffconvert_stat(struct stat *src, struct stat *dest);
00109 #endif
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 int
00122 _f_opn(
00123 char *actnam,
00124 unit *cup,
00125 FIOSPTR css,
00126 int tufs,
00127
00128 int aifound,
00129 assign_info *aip,
00130 struct stat *statp,
00131 int statp_valid,
00132
00133 int catcherr,
00134 int o_sysflgs)
00135 {
00136 register short default_ftype;
00137 register short disk_file;
00138 register short i;
00139 register short not_open;
00140 register int fd;
00141 register int flags;
00142 register int opt_flags;
00143 register int acc_mode;
00144 int num[FPARMAX];
00145 char *ffio_layer;
00146 union spec_u specspace[SPECSZ];
00147 union spec_u *fdspec;
00148 struct fdinfo *fio;
00149 struct ffsw ffiostat;
00150 struct ffc_info_s info;
00151 #ifdef KEY
00152 struct stat ffio_statbuf;
00153 #else
00154 struct ffc_stat_s ffio_statbuf;
00155 #endif
00156
00157 extern int _def_cch_bufsiz;
00158 #ifdef _UNICOS_MAX
00159 extern int _def_cch_simbufsiz;
00160 #endif
00161 #ifdef KEY
00162
00163 #else
00164 extern void _ffconvert_stat(struct ffc_stat_s *src,
00165 struct stat *dest);
00166 #endif
00167
00168 disk_file = 1;
00169 not_open = 1;
00170 opt_flags = 0;
00171 flags = 0;
00172 fdspec = NULL;
00173
00174
00175
00176
00177
00178 if (_defbufsiz_warning == 0 && ((char *)getenv("DEFBUFSIZ") != NULL)) {
00179 _defbufsiz_warning = 1;
00180 _fwarn(FWDEFBSZ);
00181 }
00182
00183
00184
00185
00186
00187 if (! aifound || (! aip->s_fstrct_flg && ! aip->F_filter_flg))
00188 default_ftype = 1;
00189 else
00190 default_ftype = 0;
00191
00192
00193
00194
00195 if (aifound && aip->C_chrcnv_flg)
00196 cup->ucharset = aip->C_chrcnv;
00197 else
00198 cup->ucharset = 0;
00199
00200 if (aifound && aip->N_datcnv_flg)
00201 cup->unumcvrt = aip->N_datcnv;
00202 else
00203 cup->unumcvrt = 0;
00204
00205 if (cup->unumcvrt || cup->ucharset) {
00206
00207
00208
00209
00210
00211
00212 _setup_cvrt(cup);
00213 }
00214
00215 #if NUMERIC_DATA_CONVERSION_ENABLED
00216
00217
00218
00219
00220
00221
00222 cup->ualign = *__fndc_align[cup->unumcvrt];
00223
00224 if (cup->unumcvrt == 0)
00225 cup->ualignmask = (sizeof(long) << 3) - 1;
00226 else {
00227 cup->ualignmask = MAX(cup->ualign.gran, 1) - 1;
00228
00229
00230
00231
00232 if ( ! POWER_OF_TWO(cup->ualignmask + 1) )
00233 cup->ualignmask = ~0;
00234 }
00235 #endif
00236
00237
00238
00239
00240
00241
00242
00243
00244 cup->utrunc = 1;
00245
00246 if (cup->ufp.std != NULL) {
00247 register int fd = fileno(cup->ufp.std);
00248 if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
00249 cup->utrunc = 0;
00250 }
00251
00252 if (aifound && aip->T_utrunc_flg)
00253 cup->utrunc = aip->T_utrunc;
00254
00255 if (aifound && aip->m_multup_flg && aip->m_multup) {
00256 cup->umultup = 1;
00257 cup->utrunc = 0;
00258 }
00259
00260
00261
00262 if (statp_valid && ! S_ISREG(statp->st_mode))
00263 disk_file = 0;
00264
00265
00266
00267
00268 ffio_layer = NULL;
00269
00270 for (i = 0; i < FPARMAX; i++)
00271 num[i] = -1;
00272
00273
00274 switch (tufs) {
00275
00276
00277
00278
00279 case STD:
00280 if (cup->ufmt) {
00281 errno = FEOPNFMT;
00282 return(-1);
00283 }
00284 break;
00285
00286
00287
00288 case FS_TEXT:
00289 if (cup->ufmt && cup->useq && cup->ucharset)
00290 ffio_layer = "text";
00291 break;
00292
00293
00294
00295
00296 case FS_U:
00297 if (! (aifound && aip->T_utrunc_flg))
00298 cup->utrunc = 0;
00299
00300 opt_flags = O_RAW;
00301
00302 if (aifound && aip->a_sdsfil_flg) {
00303 register int presize;
00304
00305 if (aip->n_preall_flg)
00306 presize = aip->n_preall;
00307 else {
00308 errno = FESDSFSS;
00309 return(-1);
00310 }
00311
00312 ffio_layer = "sds.scr.novfl";
00313 num[0] = presize;
00314 num[1] = presize;
00315 num[2] = 0;
00316 }
00317 else
00318 ffio_layer = "syscall";
00319 break;
00320
00321
00322
00323
00324 case FS_F77:
00325 ffio_layer = "f77";
00326 if (aifound && aip->b_bufsiz_flg)
00327 num[1] = aip->b_bufsiz * BLKSIZE;
00328 break;
00329
00330
00331
00332
00333 case FS_COS:
00334 ffio_layer = "cos";
00335 if (aifound && aip->b_bufsiz_flg)
00336 num[0] = aip->b_bufsiz;
00337 break;
00338
00339
00340 #if !defined(_UNICOS) && !defined(__mips) && !defined(_LITTLE_ENDIAN)
00341
00342
00343
00344
00345 case FS_UNBLOCKED:
00346 case FS_BIN:
00347 if (tufs == FS_BIN) {
00348 if (! (aifound && aip->T_utrunc_flg))
00349 cup->utrunc = 0;
00350 }
00351
00352
00353
00354
00355 tufs = STD;
00356 break;
00357 #endif
00358
00359 #if defined(_UNICOS) || defined(__mips) || defined(_LITTLE_ENDIAN)
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 case FS_UNBLOCKED:
00372 case FS_BIN:
00373 if (!disk_file) {
00374 tufs = STD;
00375 break;
00376 }
00377
00378 if (cup->useq) {
00379 ffio_layer = "bufa";
00380 num[0] = SUBUFSZ;
00381 }
00382 else {
00383 #if defined(__mips) || defined(_LITTLE_ENDIAN)
00384 ffio_layer = "cache";
00385 #else
00386 ffio_layer = "cachea";
00387 #endif
00388 num[0] = DUBUFSZ;
00389 }
00390
00391 if (tufs == FS_BIN) {
00392 if (! (aifound && aip->T_utrunc_flg))
00393 cup->utrunc = 0;
00394 num[0] = DEF_BIN_BS;
00395 }
00396
00397 #ifdef _UNICOS_MAX
00398 if (_MPP_MPPSIM > 0) {
00399
00400
00401
00402
00403
00404 num[0] = _VALUE(_def_cch_simbufsiz);
00405 }
00406 #endif
00407 #if !defined(__mips) && !defined(_LITTLE_ENDIAN)
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 if (!cup->useq && default_ftype &&
00418 (DUBUFSZ * BLKSIZE) < cup->urecl) {
00419 register int bsize;
00420
00421 bsize = (cup->urecl + (BLKSIZE - 1)) / BLKSIZE;
00422
00423 if (bsize > 100)
00424 bsize = 100;
00425
00426 num[0] = bsize;
00427 }
00428
00429 #endif
00430
00431 if (aifound && aip->b_bufsiz_flg)
00432 num[0] = aip->b_bufsiz;
00433
00434 if (aifound && aip->u_bufcnt_flg)
00435 num[1] = aip->u_bufcnt;
00436
00437 break;
00438 #endif
00439
00440 #ifdef _UNICOS
00441
00442
00443
00444 case FS_TAPE:
00445 cup->ubmx = 1;
00446
00447
00448 case FS_TAPE50:
00449
00450 ffio_layer = "tape";
00451
00452 if (aifound && aip->b_bufsiz_flg)
00453 num[0] = aip->b_bufsiz;
00454
00455 if (aifound && aip->u_bufcnt_flg)
00456 num[1] = aip->u_bufcnt;
00457 break;
00458 #endif
00459 }
00460
00461 if (tufs == FS_FDC)
00462 fdspec = &aip->F_filter[0];
00463 else if (ffio_layer != NULL) {
00464 fdspec = specspace;
00465 make_fdspec(fdspec, ffio_layer, num);
00466 tufs = FS_FDC;
00467 }
00468
00469
00470
00471
00472
00473 if (tufs != FS_FDC &&
00474 (!cup->ufmt && cup->unumcvrt || (cup->ufmt && cup->ucharset))) {
00475 errno = FENOICNV;
00476 return(-1);
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 if (cup->uaction == OS_READWRITE ||
00491 (cup->uaction == OS_WRITE && disk_file) ||
00492 cup->uaction == OS_ACTION_UNSPECIFIED) {
00493
00494 flags = O_RDWR | o_sysflgs | opt_flags;
00495
00496 if (_do_open(cup, css, tufs, actnam, flags, aifound, aip,
00497 fdspec, catcherr) == 0)
00498 not_open = 0;
00499 }
00500
00501 if (not_open &&
00502 (cup->uaction == OS_READ ||
00503 cup->uaction == OS_ACTION_UNSPECIFIED)) {
00504
00505 flags = O_RDONLY | o_sysflgs | opt_flags;
00506
00507 if (_do_open(cup, css, tufs, actnam, flags, aifound, aip,
00508 fdspec, catcherr) == 0)
00509 not_open = 0;
00510 #ifdef KEY
00511
00512
00513
00514
00515
00516
00517 #else
00518 #if defined(__mips) || defined(_LITTLE_ENDIAN)
00519 else {
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 flags = flags & ~O_CREAT;
00531
00532 if (_do_open(cup, css, tufs, actnam, flags, aifound,
00533 aip, fdspec, catcherr) == 0)
00534 not_open = 0;
00535 }
00536 #endif
00537 #endif
00538 }
00539
00540 if (not_open &&
00541 (cup->uaction == OS_WRITE ||
00542 cup->uaction == OS_ACTION_UNSPECIFIED)) {
00543
00544 flags = O_WRONLY | o_sysflgs | opt_flags;
00545
00546 if (_do_open(cup, css, tufs, actnam, flags, aifound, aip,
00547 fdspec, catcherr) == 0)
00548 not_open = 0;
00549 }
00550
00551 if (not_open) {
00552
00553
00554
00555
00556 if (cup->uaction != OS_ACTION_UNSPECIFIED && errno == EACCES)
00557 errno = FEFILACT;
00558 return(-1);
00559 }
00560
00561 acc_mode = flags & O_ACCMODE;
00562 cup->usysread = (acc_mode == O_RDONLY || acc_mode == O_RDWR);
00563 cup->usyswrite = (acc_mode == O_WRONLY || acc_mode == O_RDWR);
00564
00565
00566
00567
00568 if (cup->uaction == OS_ACTION_UNSPECIFIED)
00569 cup->uaction = cup->uaction |
00570 (cup->usysread ? OS_READ : 0) |
00571 (cup->usyswrite ? OS_WRITE : 0);
00572
00573
00574
00575
00576 cup->ufs = tufs;
00577
00578
00579
00580
00581 if (aifound && aip->d_datrcv_flg) {
00582 register int ret;
00583
00584 if (tufs != FS_FDC) {
00585 errno = FENOSKPB;
00586 return(-1);
00587 }
00588 #if !defined(__mips) && !defined(_LITTLE_ENDIAN)
00589 ret = XRCALL(cup->ufp.fdc, fcntlrtn) cup->ufp.fdc, FC_AUTOBAD,
00590 ((aip->d_datrcv == AS_SKIPBAD) ? AUTO_SKIP : AUTO_ACPT),
00591 &cup->uffsw);
00592
00593 if (ret < 0) {
00594 errno = cup->uffsw.sw_error;
00595 return(-1);
00596 }
00597 #else
00598 return(-1);
00599 #endif
00600 }
00601
00602
00603
00604
00605
00606
00607
00608
00609 FFSTAT(cup->uffsw) = FFBOD;
00610 cup->uffsw.sw_error = 0;
00611 cup->uffsw.sw_count = 0;
00612
00613
00614
00615
00616
00617
00618
00619 cup->ufcompat = 0;
00620
00621 if ( aifound && aip->f_fortst_flg ) {
00622 (cup->uft90 = (aip->f_fortst == AS_FORTRAN90) ? 1 :
00623 (cup->uft90 = (aip->f_fortst == AS_IRIX_F90) ? 1 : 0));
00624 cup->ufcompat = aip->f_fortst;
00625 }
00626
00627 if ( aifound && aip->t_tmpfil_flg ) {
00628 cup->uscrtch = 1;
00629 cup->utmpfil = 1;
00630 }
00631
00632
00633
00634
00635
00636
00637
00638
00639 cup->ufunilist = 0;
00640 #ifdef KEY
00641
00642 cup->ufcomsep = 1;
00643 #else
00644 cup->ufcomsep = 0;
00645 #endif
00646 cup->ufcomplen = 0;
00647 #ifdef KEY
00648
00649 cup->ufrptcnt = 1;
00650 #else
00651 cup->ufrptcnt = 0;
00652 #endif
00653 #if !defined(__mips) && !defined(_LITTLE_ENDIAN)
00654 cup->ufnl_skip = 0;
00655 cup->ufnegzero = 0;
00656 #else
00657 cup->ufnl_skip = 1;
00658 cup->ufnegzero = 1;
00659 #endif
00660
00661
00662
00663
00664
00665
00666 if ( aifound && aip->U_unicoslist_flg ) {
00667 cup->ufunilist = aip->U_unicoslist;
00668 cup->ufcomsep = aip->U_unicoslist;
00669 cup->ufcomplen = aip->U_unicoslist;
00670 cup->ufrptcnt = aip->U_unicoslist;
00671 } else if (aifound && aip->f_fortst == AS_IRIX_F77) {
00672
00673
00674
00675
00676
00677 cup->ufunilist = 1;
00678 cup->ufcomsep = 1;
00679 cup->ufcomplen = 1;
00680 cup->ufrptcnt = 1;
00681 }
00682
00683
00684
00685
00686 if ( aifound && aip->S_comsep_flg ) {
00687 #ifdef KEY
00688
00689
00690
00691
00692 cup->ufcomsep = ! aip->S_comsep;
00693 #else
00694 cup->ufcomsep = aip->S_comsep;
00695 #endif
00696 }
00697
00698 if ( aifound && aip->W_compwidth_flg ) {
00699 cup->ufcomplen = aip->W_compwidth;
00700 }
00701
00702 if ( aifound && aip->y_reptcnt_flg ) {
00703 #ifdef KEY
00704
00705
00706
00707
00708 cup->ufrptcnt = ! aip->y_reptcnt;
00709 #else
00710 cup->ufrptcnt = aip->y_reptcnt;
00711 #endif
00712 }
00713 #ifdef KEY
00714 if (suppress_repeats()) {
00715 cup->ufrptcnt = 1;
00716 }
00717 #endif
00718
00719
00720
00721
00722
00723
00724
00725 if ( aifound && aip->Z_neg_zero_flg ) {
00726 cup->ufnegzero = aip->Z_neg_zero;
00727 }
00728
00729
00730
00731
00732
00733
00734
00735 if ( aifound && aip->Y_nl_skip_flg ) {
00736 cup->ufnl_skip = aip->Y_nl_skip;
00737 }
00738
00739
00740
00741
00742 switch( cup->ufs ) {
00743 register int ret;
00744
00745 case FS_TEXT:
00746 fd = fileno ( cup->ufp.std );
00747 if (cup->ufmt == 0) {
00748 errno = FEOPNUNF;
00749 return(-1);
00750 }
00751 cup->ublkd = 1;
00752 break;
00753
00754 case STD:
00755 fd = fileno ( cup->ufp.std );
00756 if (cup->ufmt)
00757 cup->ublkd = 1;
00758 else
00759 cup->ublkd = 0;
00760 break;
00761
00762 case FS_FDC:
00763
00764
00765
00766 ret = XRCALL(cup->ufp.fdc, fcntlrtn) cup->ufp.fdc,
00767 FC_GETINFO, &info, &ffiostat);
00768 if (ret < 0) {
00769 errno = ffiostat.sw_error;
00770 return(-1);
00771 }
00772
00773 cup->uflagword = info.ffc_flags;
00774
00775
00776
00777
00778 ret = XRCALL(cup->ufp.fdc, fcntlrtn) cup->ufp.fdc,
00779 FC_STAT, &ffio_statbuf, &ffiostat);
00780 if (ret < 0) {
00781 errno = ffiostat.sw_error;
00782 return(-1);
00783 }
00784
00785 _ffconvert_stat(&ffio_statbuf, statp);
00786 statp_valid = 1;
00787
00788
00789
00790
00791 cup->ublkd = ((cup->uflagword & FFC_REC) ? 1 : 0);
00792
00793
00794
00795
00796
00797 cup->umultfil = ((cup->uflagword & FFC_WEOF) ? 1 : 0);
00798
00799 if (cup->ufmt) {
00800
00801
00802
00803 if ((info.ffc_flags & FFC_CODED) == 0) {
00804 errno = FEOPNFMT;
00805 return(-1);
00806 }
00807
00808
00809
00810
00811 if (cup->useq && (info.ffc_flags & FFC_REC) == 0) {
00812 errno = FEOPNFMT;
00813 return(-1);
00814 }
00815 }
00816 else {
00817
00818
00819
00820
00821 if ((info.ffc_flags & FFC_BINARY) == 0) {
00822 errno = FEOPNUNF;
00823 return(-1);
00824 }
00825 }
00826
00827
00828
00829 if (cup->useq == 0) {
00830
00831
00832
00833
00834 if (info.ffc_reclen != 0) {
00835 if (info.ffc_reclen != (cup->urecl << 3)) {
00836
00837 errno = FEOPIVRL;
00838 return(-1);
00839 }
00840 }
00841
00842
00843
00844
00845 else if ((cup->uflagword & FFC_STRM) == 0) {
00846 errno = FEOPNNDA;
00847 return(-1);
00848 }
00849 }
00850
00851
00852
00853
00854 if (cup->useq && aifound && aip->T_utrunc_flg &&
00855 aip->T_utrunc == 0 &&
00856 (info.ffc_flags & FFC_WRTRUNC)) {
00857
00858 errno = FERQTRNC;
00859 return(-1);
00860 }
00861
00862 fd = info.ffc_fd;
00863 break;
00864
00865 default:
00866 errno = FEINTFST;
00867 return(-1);
00868 }
00869
00870 cup->usysfd = fd;
00871
00872
00873
00874
00875
00876 if (! statp_valid && fstat(fd, statp) == -1)
00877 return(-1);
00878 statp_valid = 1;
00879
00880
00881
00882
00883 if (fd != -1) {
00884 if ((S_ISREG(statp->st_mode) && !isatty(fd)) ||
00885 _gsys_qtape(statp))
00886 cup->useek = YES;
00887 else
00888 cup->useek = NO;
00889 }
00890
00891 #ifdef _UNICOS
00892
00893
00894
00895 if (fd != -1) {
00896 if (_prealloc(fd, aifound, aip, statp) == -1)
00897 return(-1);
00898 }
00899 #endif
00900
00901
00902
00903
00904
00905
00906
00907 cup->uasync = ASYNC_NOTOK;
00908
00909 if ((cup->unumcvrt | cup->ucharset) == 0 && cup->ufs == FS_FDC) {
00910 cup->uasync = ASYNC_OK;
00911 }
00912
00913
00914
00915
00916
00917 if (cup->useq == 0) {
00918 long recl;
00919 recl = cup->urecl;
00920 if (cup->ufmt && cup->ufs != FS_FDC)
00921 recl++;
00922
00923 cup->udamax = (statp->st_size + recl - 1) / recl;
00924 }
00925
00926 return(0);
00927 }
00928
00929
00930
00931
00932
00933
00934
00935 static int
00936 make_fdspec(
00937 union spec_u *fdspec,
00938 char *layer,
00939 int num[FPARMAX])
00940
00941 {
00942 register short i;
00943 register int ret;
00944 char buf[FPARMAX][30];
00945 char ffio_str[20+FPARMAX*30];
00946
00947
00948 for (i = 0; i < FPARMAX; i++) {
00949 if (num[i] == -1)
00950 buf[i][0] = '\0';
00951 else
00952 sprintf(buf[i], "%d", num[i]);
00953 }
00954
00955
00956
00957 (void) sprintf(ffio_str, "%s:%s:%s:%s", layer, buf[0], buf[1], buf[2]);
00958
00959 ret = _parse_forstr(fdspec, ffio_str, SPECSZ, 0, _LELVL_RETURN);
00960
00961 if (ret < 0)
00962 _ferr(NULL, FEINTUNK);
00963
00964 return(0);
00965 }
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976 int
00977 _do_open(
00978 unit *cup,
00979 FIOSPTR css,
00980 int tufs,
00981 char *actnam,
00982 int flags,
00983 int aifound,
00984 assign_info *aip,
00985 union spec_u *fdspec,
00986 int catcherr)
00987 {
00988 long bs;
00989 register int cbits;
00990 register int cblks;
00991 register int i;
00992 long asave[(AFLAGSIZE + sizeof(long)) / sizeof(long)];
00993 char *flagstr;
00994 char *attrstr;
00995 struct ffsw ffiostat;
00996 struct gl_o_inf gloinf;
00997 _ffopen_t otmp;
00998
00999 (void) memset(&gloinf, 0, sizeof(gloinf));
01000
01001 gloinf.open_type = OT_FORTRAN;
01002 gloinf.aip = aifound ? aip : NULL;
01003 gloinf.u.fort.unum = cup->uid;
01004 gloinf.u.fort.is_seq = cup->useq;
01005 gloinf.u.fort.is_fmt = cup->ufmt;
01006 gloinf.u.fort.reclen = cup->urecl;
01007
01008 cbits = 0;
01009 cblks = 0;
01010
01011
01012
01013
01014 if (aifound)
01015 _ae_setoflags(aip, &flags);
01016
01017 #ifdef _UNICOS
01018
01019
01020
01021 if (aifound && aip->pr_partit_flg) {
01022 flags = flags | O_PLACE;
01023 cbits = aip->pr_partit;
01024 }
01025
01026 if (aifound && (aip->n_stride_flg || aip->q_ocblks_flg)) {
01027 flags = flags | O_PLACE;
01028
01029 if (aip->q_ocblks_flg)
01030 cblks = aip->q_ocblks;
01031 else
01032 cblks = aip->n_stride;
01033 }
01034 #endif
01035
01036 switch ( tufs ) {
01037
01038 case FS_TEXT:
01039 case STD:
01040
01041
01042
01043
01044
01045 if (cup->ufp.std != NULL) {
01046 register int fdflags;
01047
01048 #if !defined(_LITTLE_ENDIAN) || (defined(_LITTLE_ENDIAN) && defined(__sv2))
01049 if (cup->ufp.std->_flag & _IORW)
01050 fdflags = O_RDWR;
01051 else if (cup->ufp.std->_flag & _IOWRT)
01052 fdflags = O_WRONLY;
01053 else
01054 fdflags = O_RDONLY;
01055
01056 if ((fdflags & O_ACCMODE) != (flags & O_ACCMODE)) {
01057 errno = EACCES;
01058 return(-1);
01059 }
01060 #endif
01061 }
01062 else {
01063
01064 #ifdef _UNICOS
01065
01066
01067
01068
01069
01070
01071
01072
01073 #ifndef _CRAYMPP
01074 i = _stdio_open(
01075 #else
01076 i = open(
01077 #endif
01078 actnam, flags, ACCESS_PERMS, cbits, cblks);
01079 #else
01080 i = open( actnam, flags, ACCESS_PERMS);
01081 #endif
01082 if (i < 0)
01083 return(-1);
01084
01085 if ((flags & O_ACCMODE) == O_RDWR)
01086 flagstr = "r+";
01087 else if ((flags & O_ACCMODE) == O_WRONLY) {
01088 if (flags & O_APPEND)
01089 flagstr = "a";
01090 else
01091 flagstr = "w";
01092 }
01093 else
01094 flagstr = "r";
01095
01096 MEM_LOCK(&_ioblock);
01097
01098 cup->ufp.std = fdopen(i, flagstr);
01099
01100 MEM_UNLOCK(&_ioblock);
01101
01102 if (cup->ufp.std == NULL)
01103 return(-1);
01104 }
01105
01106
01107
01108
01109
01110
01111
01112
01113 bs = DEF_SBIN_BS * BLKSIZE;
01114
01115 #ifdef _UNICOS_MAX
01116
01117
01118
01119
01120
01121 if (_MPP_MPPSIM > 0)
01122 bs = DEF_SBINSIM_BS * BLKSIZE;
01123 #endif
01124
01125 if (aifound && aip->b_bufsiz_flg)
01126 bs = aip->b_bufsiz * BLKSIZE;
01127 else
01128 if (cup->useq == 0 && cup->urecl < bs) {
01129 bs = cup->urecl + (cup->ufmt ? 1 : 0);
01130 if (bs < 16)
01131 bs = 16;
01132 }
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145 #if defined(BUILD_OS_DARWIN)
01146 if (cup->ufp.std->_bf._base == NULL &&
01147 fileno(cup->ufp.std) != STDERR_FILENO &&
01148 ! isatty(fileno(cup->ufp.std)))
01149 (void) setvbuf(cup->ufp.std, NULL, _IOFBF, bs);
01150 #elif defined(_LITTLE_ENDIAN) && !defined(__sv2)
01151 if (cup->ufp.std->_IO_buf_base == NULL &&
01152 fileno(cup->ufp.std) != STDERR_FILENO &&
01153 ! isatty(fileno(cup->ufp.std)))
01154 (void) setvbuf(cup->ufp.std, NULL, _IOFBF, bs);
01155 #else
01156 if (cup->ufp.std->_base == NULL &&
01157 fileno(cup->ufp.std) != STDERR_FILENO &&
01158 ! isatty(fileno(cup->ufp.std)))
01159
01160 (void) setvbuf(cup->ufp.std, NULL, _IOFBF, bs);
01161 #endif
01162
01163 break;
01164
01165 case FS_FDC:
01166
01167 #ifdef _UNICOS
01168
01169
01170
01171
01172 flags = flags | O_RAW;
01173 #endif
01174 if (aifound)
01175 _attr_copy(aip, (assign_info *)&asave);
01176
01177 otmp = _ffopen(actnam, flags, ACCESS_PERMS, fdspec,
01178 &ffiostat, cbits, cblks, NULL, &gloinf);
01179 if (otmp == _FFOPEN_ERR) {
01180
01181
01182
01183
01184 if (aifound)
01185 _attr_copy((assign_info *)&asave, aip);
01186
01187 errno = ffiostat.sw_error;
01188 return(-1);
01189 }
01190
01191 cup->ufp.fdc = (struct fdinfo *) otmp;
01192 cup->useek = YES;
01193 attrstr = NULL;
01194
01195 if (aifound && _attr_used(aip, &attrstr) == -1) {
01196 if (catcherr == 0)
01197 _ferr(css, errno, attrstr);
01198 return(-1);
01199 }
01200
01201 break;
01202
01203 default:
01204 errno = FEINTFST;
01205 return(-1);
01206
01207 }
01208 return(0);
01209 }
01210
01211
01212
01213
01214
01215
01216
01217
01218 void
01219 #ifdef KEY
01220 _ffconvert_stat(struct stat *src, struct stat *dest)
01221 #else
01222 _ffconvert_stat(struct ffc_stat_s *src, struct stat *dest)
01223 #endif
01224 {
01225 assert ( sizeof(*src) == sizeof(*dest) );
01226
01227 *dest = *(struct stat *)src;
01228
01229 return;
01230 }