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