1 /*
2  * Copyright (c) 2002-2018, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /* clang-format off */
19 
20 /** \file
21  * \brief Implements the Fortran OPEN statment
22  */
23 
24 #include <stdarg.h>
25 #include <errno.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "global.h"
29 #include "open_close.h"
30 #include "async.h"
31 #include <fcntl.h>
32 
33 #if defined(WIN32) || defined(WIN64)
34 #define access _access
35 #endif
36 
37 static FIO_FCB *Fcb; /* pointer to the file control block */
38 
39 int next_newunit = -13;
40 
41 /* --------------------------------------------------------------------- */
42 int
ENTF90IO(GET_NEWUNIT,get_newunit)43 ENTF90IO(GET_NEWUNIT, get_newunit)()
44 {
45   set_gbl_newunit(TRUE);
46   return next_newunit--;
47 }
48 
49 /* --------------------------------------------------------------------- */
50 
51 /** \brief Function called from within fiolib to open a file.
52  */
53 int
__fortio_open(int unit,int action_flag,int status_flag,int dispose_flag,int acc_flag,int blank_flag,int form_flag,int delim_flag,int pos_flag,int pad_flag,__INT8_T reclen,char * name,__CLEN_T namelen)54 __fortio_open(int unit, int action_flag, int status_flag, int dispose_flag,
55              int acc_flag, int blank_flag, int form_flag, int delim_flag,
56              int pos_flag, int pad_flag, __INT8_T reclen, char *name,
57              __CLEN_T namelen)
58 {
59   char *q;
60   char *perms;
61   char bfilename[MAX_NAMELEN + 1];
62   char *filename;
63   int long_name;
64   FILE *lcl_fp; /* local file fp */
65   FIO_FCB *f;   /* local file control block ptr */
66   __CLEN_T i;
67   int fd;
68 
69   if (ILLEGAL_UNIT(unit))
70     return __fortio_error(FIO_EUNIT);
71 
72   lcl_fp = NULL;
73   f = NULL;
74 
75   /* ------- if file name specified, delete trailing blanks, copy
76               into filename buffer and null-terminate it:  */
77 
78   long_name = 0;
79   filename = bfilename;
80 
81 #undef EXIT_OPEN
82 #define EXIT_OPEN(ec)                                                          \
83   {                                                                            \
84     if (long_name)                                                             \
85       free(filename);                                                          \
86     return ec;                                                                 \
87   }
88 
89   if (name != NULL) {
90     /*  remove trailing blanks:  */
91     while (namelen > 0 && name[namelen - 1] == ' ')
92       --namelen;
93     /*  remove preceding blanks:  */
94     while (namelen > 0 && name[0] == ' ')
95       name++, namelen--;
96     if (namelen <= 0)
97       return __fortio_error(FIO_ENAME);
98 
99     if (namelen > MAX_NAMELEN) {
100       filename = malloc(namelen + 1);
101       long_name = 1;
102     }
103     for (i = 0; i < namelen; i++)
104       filename[i] = name[i];
105     filename[namelen] = '\0';
106 #if defined(WINNT)
107     if (filename[0] == '/' && filename[1] == '/' && filename[3] == '/') {
108       /* convert posix format to win32 format */
109       filename[0] = filename[2]; /* drive letter */
110       filename[1] = ':';
111       filename[2] = '\\';
112       strcpy(filename + 3, filename + 4);
113       namelen--;
114     }
115 #endif
116     /*  check that file is not already connected to different unit: */
117     for (f = fioFcbTbls.fcbs; f; f = f->next)
118       if (f->named && strcmp(filename, f->name) == 0)
119         if (unit != f->unit)
120           EXIT_OPEN(__fortio_error(FIO_EOPENED))
121   }
122 
123   /* ------- handle situation in which unit is already connected:  */
124 
125   f = __fortio_find_unit(unit);
126 
127   if (f != NULL) {
128     if (name == NULL || strcmp(filename, f->name) == 0) {
129       /*  case 1:  file to be connected is the same:  */
130       /*  make sure no specifier other than BLANK is different than
131           the one currently in effect */
132 
133       if (status_flag == FIO_SCRATCH && f->status != FIO_SCRATCH)
134         EXIT_OPEN(__fortio_error(FIO_ECOMPAT))
135       if (acc_flag != f->acc || form_flag != f->form)
136         EXIT_OPEN(__fortio_error(FIO_ECOMPAT))
137       if (acc_flag == FIO_DIRECT && reclen != (f->reclen / f->wordlen))
138         EXIT_OPEN(__fortio_error(FIO_ECOMPAT))
139 
140       f->blank = blank_flag;
141       if (pos_flag == FIO_REWIND) {
142         __io_fseek(f->fp, (seekoffx_t)0L, SEEK_SET);
143       } else if (pos_flag == FIO_APPEND) {
144         __io_fseek(f->fp, (seekoffx_t)0L, SEEK_END);
145       }
146       f->reclen = reclen * f->wordlen;
147 
148       Fcb = f;     /* save pointer to the fcb for any augmented opens */
149       EXIT_OPEN(0) /* no error occurred */
150     } else {
151       /*  case 2:  file to be connected is NOT the same:  */
152       if (__fortio_close(f, 0 /*dispose flag*/) != 0)
153         EXIT_OPEN(ERR_FLAG)
154     }
155   }
156 
157   /* ------- create default name if none specified:  */
158 
159   if (name == NULL) {
160     /*  for unnamed unit, first check environment variable */
161     sprintf(filename, "FOR%03d", unit);
162     if ((q = __fort_getenv(filename)) != NULL)
163       strcpy(filename, q);
164     else if (status_flag != FIO_SCRATCH)
165       sprintf(filename, GET_FIO_CNFG_DEFAULT_NAME, unit);
166     else { /*  unnamed SCRATCH file:  */
167       while (1) {
168         __fortio_scratch_name(filename, unit);
169         fd = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0666);
170         if (fd == -1) {
171           continue;
172         }
173         close(fd);
174         break;
175       }
176     }
177     namelen = strlen(filename);
178   }
179 
180   /* ******************************************************************
181       procede with opening of new file based on value of STATUS:
182       *******************************************************************/
183 
184   if (status_flag == FIO_OLD) {
185     /* if OLD and doesn't exist, then error */
186     if (__fort_access(filename, 0) != 0)
187       EXIT_OPEN(__fortio_error(FIO_ENOEXIST))
188 
189 /*  open file for readonly or read/write:  */
190 
191     perms = "r+";
192     if ((action_flag == FIO_READ) ||
193         (lcl_fp = __io_fopen(filename, perms)) == NULL) {
194       perms = "r";
195       if ((lcl_fp = (__io_fopen(filename, perms))) == NULL)
196         EXIT_OPEN(__fortio_error(__io_errno()))
197     }
198   } else if (status_flag == FIO_NEW) {
199     /* if NEW and exists then error */
200     if (__fort_access(filename, 0) == 0)
201       EXIT_OPEN(__fortio_error(FIO_EEXIST))
202 
203     perms = "w+";
204     if ((lcl_fp = __io_fopen(filename, perms)) == NULL)
205       EXIT_OPEN(__fortio_error(__io_errno()))
206   } else if (status_flag == FIO_REPLACE) {
207 /* if file does not exist, create a file;
208  * if file exists, delete the file and create a new file.
209  */
210     perms = "w+";
211     if ((lcl_fp = __io_fopen(filename, perms)) == NULL)
212       EXIT_OPEN(__fortio_error(__io_errno()))
213   } else if (status_flag == FIO_UNKNOWN) {
214     i = 0;
215     if (__fort_access(filename, 0) == 0) { /* file exists */
216       perms = "r+";
217       i = 1;
218     } else /* file does not exist */
219       perms = "w+";
220 
221     if ((lcl_fp = __io_fopen(filename, perms)) == NULL) {
222       if (i == 0) /* file does not exist */
223         EXIT_OPEN(__fortio_error(__io_errno()))
224 /*  try again with different mode:  */
225       perms = "r";
226       if ((lcl_fp = __io_fopen(filename, perms)) == NULL)
227         EXIT_OPEN(__fortio_error(__io_errno()))
228     }
229   } else {
230     assert(status_flag == FIO_SCRATCH);
231     perms = "w+";
232     if ((lcl_fp = __io_fopen(filename, perms)) == NULL) {
233       EXIT_OPEN(__fortio_error(__io_errno()))
234     }
235     __fort_unlink(filename);
236   }
237 
238   /* ****************************************************************
239       allocate entry for file just opened and assign the
240       characteristics to the file:
241       ***************************************************************/
242 
243   f = __fortio_alloc_fcb();
244 
245   f->fp = lcl_fp;
246   assert(lcl_fp != NULL);
247   f->unit = unit;
248   f->action = action_flag;
249   f->status = FIO_OLD;
250   if (status_flag == FIO_SCRATCH)
251     f->status = FIO_SCRATCH;
252   f->delim = delim_flag;
253   f->dispose = dispose_flag;
254   f->blank = blank_flag;
255   f->form = form_flag;
256   f->pad = pad_flag;
257   f->pos = pos_flag;
258   f->wordlen = 1; /* default */
259   if (f->form == FIO_UNFORMATTED) {
260     if (envar_fortranopt != NULL && strstr(envar_fortranopt, "vaxio") != NULL)
261       f->wordlen = 4; /* WHAT */
262   }
263   f->reclen = reclen * f->wordlen;
264   f->nextrec = 1;
265   f->truncflag = FALSE;
266   f->skip = 0;
267   f->ispipe = FALSE;
268   f->nonadvance = FALSE;
269   f->pread = 0;
270   f->pback = 0;
271 
272   if (acc_flag == FIO_DIRECT) {
273     /*  compute number of records in direct access file:  */
274     f->acc = FIO_DIRECT;
275     f->maxrec = 0;
276     if (status_flag == FIO_OLD || status_flag == FIO_UNKNOWN) {
277       seekoffx_t len;
278       if (__io_fseekx(lcl_fp, (seekoffx_t)0L, SEEK_END) != 0)
279         goto free_fcb_err;
280       len = (seekoffx_t)__io_ftellx(lcl_fp);
281       f->maxrec = len / f->reclen;
282       __io_fseek(lcl_fp, (seekoffx_t)0L,
283                   SEEK_SET); /* re-position to beginning */
284     }
285   } else {
286     if (acc_flag == FIO_STREAM)
287       f->acc = FIO_STREAM;
288     else
289       f->acc = FIO_SEQUENTIAL;
290     if ((status_flag == FIO_OLD || status_flag == FIO_UNKNOWN) &&
291         pos_flag != FIO_APPEND)
292       f->truncflag = TRUE;
293     if (status_flag != FIO_SCRATCH && __fortio_ispipe(f->fp)) {
294       f->truncflag = FALSE;
295       f->ispipe = TRUE;
296     } else if (pos_flag == FIO_APPEND) /* position file at end of file */
297       if (__io_fseek(lcl_fp, (seekoffx_t)0L, SEEK_END) != 0)
298         goto free_fcb_err;
299   }
300 
301   if (status_flag != FIO_SCRATCH)
302     f->named = TRUE;
303   else
304     f->named = FALSE;
305   f->name = STASH(filename);
306   f->coherent = 0;
307   f->eof_flag = FALSE;
308   f->eor_flag = FALSE;
309   f->stdunit = FALSE;
310   f->byte_swap = FALSE;
311   f->native = FALSE;
312   f->binary = FALSE;
313   f->asy_rw = 0; /* init async flags */
314   f->asyptr = (void *)0;
315   f->decimal = FIO_POINT;
316   f->encoding = FIO_DEFAULT;
317   f->round = FIO_COMPATIBLE;
318   f->sign = FIO_PROCESSOR_DEFINED;
319   Fcb = f; /* save pointer to the fcb for any augmented opens */
320 
321   EXIT_OPEN(0) /* no error occurred */
322 
323 free_fcb_err:
324   __fortio_free_fcb(f); /*  free up FCB for later use  */
325   EXIT_OPEN(__fortio_error(__io_errno()))
326 }
327 
328 /* --------------------------------------------------------------------- */
329 /* internal open */
330 
331 static int
f90_open(__INT_T * unit,__INT_T * bitv,char * acc_ptr,char * action_ptr,char * blank_ptr,char * delim_ptr,char * name_ptr,char * form_ptr,__INT_T * iostat,char * pad_ptr,char * pos_ptr,__INT8_T * reclen,char * status_ptr,char * dispose_ptr,__CLEN_T acc_siz,__CLEN_T action_siz,__CLEN_T blank_siz,__CLEN_T delim_siz,__CLEN_T name_siz,__CLEN_T form_siz,__CLEN_T pad_siz,__CLEN_T pos_siz,__CLEN_T status_siz,__CLEN_T dispose_siz)332 f90_open(__INT_T *unit, __INT_T *bitv, char *acc_ptr, char *action_ptr,
333          char *blank_ptr, char *delim_ptr, char *name_ptr, char *form_ptr,
334          __INT_T *iostat, char *pad_ptr, char *pos_ptr, __INT8_T *reclen,
335          char *status_ptr, char *dispose_ptr, __CLEN_T acc_siz, __CLEN_T action_siz,
336          __CLEN_T blank_siz, __CLEN_T delim_siz, __CLEN_T name_siz, __CLEN_T form_siz, __CLEN_T pad_siz,
337          __CLEN_T pos_siz, __CLEN_T status_siz, __CLEN_T dispose_siz)
338 {
339   int acc_flag, action_flag, delim_flag, form_flag, blank_flag;
340   int pad_flag, pos_flag, status_flag, dispose_flag;
341   __INT8_T tmpreclen;
342   int retv;
343   bool binary;
344 
345   __fortio_errinit03(*unit, *bitv, iostat, "OPEN");
346 
347   if (name_ptr != NULL) {
348     fioFcbTbls.fname = name_ptr;
349     fioFcbTbls.fnamelen = name_siz;
350   } else {
351     fioFcbTbls.fname = NULL;
352     fioFcbTbls.fnamelen = 0;
353   }
354   binary = FALSE;
355 
356   /* -------- check specifiers and set flags appropriately:  */
357 
358   /* ACCESS: */
359 
360   pos_flag = FIO_ASIS;       /* default to handle "APPEND" */
361   acc_flag = FIO_SEQUENTIAL; /*  default value  */
362   if (acc_ptr != NULL) {
363     if (__fortio_eq_str(acc_ptr, acc_siz, "DIRECT")) {
364       acc_flag = FIO_DIRECT;
365     } else if (__fortio_eq_str(acc_ptr, acc_siz, "STREAM")) {
366       acc_flag = FIO_STREAM;
367     } else if (__fortio_eq_str(acc_ptr, acc_siz, "SEQUENTIAL")) {
368       acc_flag = FIO_SEQUENTIAL;
369     } else if (__fortio_eq_str(acc_ptr, acc_siz, "APPEND")) {
370       pos_flag = FIO_APPEND;
371     } else {
372       return __fortio_error(FIO_ESPEC);
373     }
374   }
375 
376   /* ACTION: */
377 
378   action_flag = FIO_READWRITE; /*  default value  */
379   if (action_ptr != NULL) {
380     if (__fortio_eq_str(action_ptr, action_siz, "READ"))
381       action_flag = FIO_READ;
382     else if (__fortio_eq_str(action_ptr, action_siz, "WRITE"))
383       action_flag = FIO_WRITE;
384     else if (__fortio_eq_str(action_ptr, action_siz, "READWRITE"))
385       action_flag = FIO_READWRITE;
386     else
387       return __fortio_error(FIO_ESPEC);
388   }
389 
390   /* FORM: */
391 
392   if (form_ptr != NULL) {
393     if (__fortio_eq_str(form_ptr, form_siz, "FORMATTED"))
394       form_flag = FIO_FORMATTED;
395     else if (__fortio_eq_str(form_ptr, form_siz, "UNFORMATTED"))
396       form_flag = FIO_UNFORMATTED;
397     else if (__fortio_eq_str(form_ptr, form_siz, "BINARY")) {
398       form_flag = FIO_UNFORMATTED;
399       binary = TRUE;
400     } else
401       return __fortio_error(FIO_ESPEC);
402   } else if (acc_flag == FIO_DIRECT || acc_flag == FIO_STREAM)
403     form_flag = FIO_UNFORMATTED;
404   else
405     form_flag = FIO_FORMATTED;
406 
407   /* DELIM: */
408 
409   delim_flag = FIO_NONE; /*  default value  */
410   if (delim_ptr != NULL) {
411     if (form_flag != FIO_FORMATTED)
412       return __fortio_error(FIO_ECOMPAT);
413     if (__fortio_eq_str(delim_ptr, delim_siz, "APOSTROPHE"))
414       delim_flag = FIO_APOSTROPHE;
415     else if (__fortio_eq_str(delim_ptr, delim_siz, "QUOTE"))
416       delim_flag = FIO_QUOTE;
417     else if (__fortio_eq_str(delim_ptr, delim_siz, "NONE"))
418       delim_flag = FIO_NONE;
419     else
420       return __fortio_error(FIO_ESPEC);
421   }
422 
423   /* BLANK: */
424 
425   blank_flag = FIO_NULL; /*  default value */
426   if (blank_ptr != NULL) {
427     /*  file must be connected for formatted I/O:  */
428     if (form_flag != FIO_FORMATTED)
429       return __fortio_error(FIO_ECOMPAT);
430     if (__fortio_eq_str(blank_ptr, blank_siz, "ZERO"))
431       blank_flag = FIO_ZERO;
432     else if (!__fortio_eq_str(blank_ptr, blank_siz, "NULL"))
433       return __fortio_error(FIO_ESPEC);
434   }
435 
436   /* PAD: */
437 
438   pad_flag = FIO_YES; /* default */
439   if (pad_ptr != NULL) {
440     if (form_flag != FIO_FORMATTED)
441       return __fortio_error(FIO_ECOMPAT);
442     if (__fortio_eq_str(pad_ptr, pad_siz, "YES"))
443       pad_flag = FIO_YES;
444     else if (__fortio_eq_str(pad_ptr, pad_siz, "NO"))
445       pad_flag = FIO_NO;
446     else
447       return __fortio_error(FIO_ESPEC);
448   }
449 
450   /* POSITION: */
451 
452   /* moved to ACCESS to handle ACCESS=APPEND
453       pos_flag = FIO_ASIS;
454   */
455   if (pos_ptr != NULL) {
456     if (acc_flag != FIO_SEQUENTIAL && acc_flag != FIO_STREAM)
457       return __fortio_error(FIO_ECOMPAT);
458     if (__fortio_eq_str(pos_ptr, pos_siz, "ASIS"))
459       pos_flag = FIO_ASIS;
460     else if (__fortio_eq_str(pos_ptr, pos_siz, "REWIND"))
461       pos_flag = FIO_REWIND;
462     else if (__fortio_eq_str(pos_ptr, pos_siz, "APPEND"))
463       pos_flag = FIO_APPEND;
464     else
465       return __fortio_error(FIO_ESPEC);
466   }
467 
468   /* STATUS: */
469 
470   status_flag = FIO_UNKNOWN; /* default */
471   if (status_ptr != NULL) {
472     if (__fortio_eq_str(status_ptr, status_siz, "OLD"))
473       status_flag = FIO_OLD;
474     else if (__fortio_eq_str(status_ptr, status_siz, "NEW"))
475       status_flag = FIO_NEW;
476     else if (__fortio_eq_str(status_ptr, status_siz, "REPLACE"))
477       status_flag = FIO_REPLACE;
478     else if (__fortio_eq_str(status_ptr, status_siz, "UNKNOWN"))
479       status_flag = FIO_UNKNOWN;
480     else if (__fortio_eq_str(status_ptr, status_siz, "SCRATCH"))
481       status_flag = FIO_SCRATCH;
482     else
483       return __fortio_error(FIO_ESPEC);
484   }
485 
486   /* DISPOSE: */
487 
488   if (dispose_ptr != NULL) {
489     if (__fortio_eq_str(dispose_ptr, dispose_siz, "KEEP"))
490       dispose_flag = FIO_KEEP;
491     else if (__fortio_eq_str(dispose_ptr, dispose_siz, "SAVE"))
492       dispose_flag = FIO_KEEP;
493     else if (__fortio_eq_str(dispose_ptr, dispose_siz, "DELETE"))
494       dispose_flag = FIO_DELETE;
495     else
496       return __fortio_error(FIO_ESPEC);
497   } else if (status_flag == FIO_SCRATCH)
498     dispose_flag = FIO_DELETE;
499   else
500     dispose_flag = FIO_KEEP;
501 
502   /* ------------- Check for compatibility between specifiers:  */
503 
504   if (get_gbl_newunit() && name_ptr == NULL && status_flag != FIO_SCRATCH) {
505     return __fortio_error(FIO_ENEWUNIT);
506   }
507 
508   if (acc_flag == FIO_DIRECT) {
509     tmpreclen = 0;
510     if (reclen)
511       tmpreclen = *reclen;
512     if (tmpreclen < 1)
513       return __fortio_error(FIO_ERECLEN);
514   } else if (acc_flag == FIO_SEQUENTIAL && reclen) {
515     tmpreclen = *reclen;
516     if (tmpreclen < 1)
517       return __fortio_error(FIO_ERECLEN);
518   } else {
519     /*  VMS allows RECL with non-DIRECT access.  Just ignore reclen.  */
520     tmpreclen = 0;
521     if (reclen) {
522       if (acc_flag == FIO_STREAM)
523         return __fortio_error(FIO_ERECL);
524     }
525   }
526 
527   if (status_flag == FIO_SCRATCH) {
528     if (dispose_flag == FIO_KEEP)
529       return __fortio_error(FIO_EDISPOSE);
530     if (fioFcbTbls.fname != NULL)
531       return __fortio_error(FIO_ESCRATCH);
532   }
533 
534   if (action_flag == FIO_READ) {
535     if (status_flag == FIO_SCRATCH || status_flag == FIO_REPLACE ||
536         dispose_flag == FIO_DELETE)
537       return __fortio_error(FIO_EREADONLY);
538   }
539 
540   if ((acc_flag == FIO_STREAM) && (form_flag == FIO_UNFORMATTED))
541     binary = TRUE;
542 
543   /* ---------  call __fortio_open to complete process of opening file:   */
544 
545   retv = __fortio_open(*unit, action_flag, status_flag, dispose_flag, acc_flag,
546                       blank_flag, form_flag, delim_flag, pos_flag, pad_flag,
547                       tmpreclen, fioFcbTbls.fname, fioFcbTbls.fnamelen);
548   if (!retv && binary) {
549     if (acc_flag == FIO_DIRECT)
550       retv = __fortio_error(FIO_ESPEC);
551     else
552       Fcb->binary = TRUE;
553   }
554 
555   return retv;
556 }
557 
558 /* --------------------------------------------------------------------- */
559 
560 /** \brief Called from user program; implements Fortran OPEN statement.
561  */
562 __INT_T
ENTF90IO(OPENA,opena)563 ENTF90IO(OPENA, opena) (
564   __INT_T *unit,   /* unit number */
565   __INT_T *bitv,   /* determines action if error occurs */
566   DCHAR(acc),      /* DIRECT, SEQUENTIAL, or NULL */
567   DCHAR(action),   /* READ, WRITE, READWRITE, or NULL */
568   DCHAR(blank),    /* ZERO or NULL */
569   DCHAR(delim),    /* APOSTROPHE, QUOTE, NONE, or NULL */
570   DCHAR(name),     /* file name */
571   DCHAR(form),     /* FORMATTED, UNFORMATTED, or NULL */
572   __INT_T *iostat, /* IOSTAT variable */
573   DCHAR(pad),      /* YES, NO, or NULL */
574   DCHAR(pos),      /* ASIS, REWIND, APPEND, or NULL */
575   __INT_T *reclen, /* record length in bytes or words */
576   DCHAR(status),   /* OLD, NEW, SCRATCH, REPLACE, or NULL */
577   DCHAR(dispose)   /* KEEP, DELETE, SAVE, or NULL */
578   DCLEN64(acc)       /* length of acc */
579   DCLEN64(action)    /* length of action */
580   DCLEN64(blank)     /* length of blank */
581   DCLEN64(delim)     /* length of delim */
582   DCLEN64(name)      /* length of name */
583   DCLEN64(form)      /* length of form */
584   DCLEN64(pad)       /* length of pad */
585   DCLEN64(pos)       /* length of pos */
586   DCLEN64(status)    /* length of status */
587   DCLEN64(dispose))  /* length of dispose */
588 {
589   char *acc_ptr;
590   char *action_ptr;
591   char *blank_ptr;
592   char *delim_ptr;
593   char *name_ptr;
594   char *form_ptr;
595   char *pad_ptr;
596   char *pos_ptr;
597   char *status_ptr;
598   char *dispose_ptr;
599   __CLEN_T acc_siz;
600   __CLEN_T action_siz;
601   __CLEN_T blank_siz;
602   __CLEN_T delim_siz;
603   __CLEN_T name_siz;
604   __CLEN_T form_siz;
605   __CLEN_T pad_siz;
606   __CLEN_T pos_siz;
607   __CLEN_T status_siz;
608   __CLEN_T dispose_siz;
609   __INT8_T newreclen;
610 
611   int s = 0;
612 
613   acc_ptr = (ISPRESENTC(acc) ? CADR(acc) : NULL);
614   action_ptr = (ISPRESENTC(action) ? CADR(action) : NULL);
615   blank_ptr = (ISPRESENTC(blank) ? CADR(blank) : NULL);
616   delim_ptr = (ISPRESENTC(delim) ? CADR(delim) : NULL);
617   name_ptr = (ISPRESENTC(name) ? CADR(name) : NULL);
618   form_ptr = (ISPRESENTC(form) ? CADR(form) : NULL);
619   pad_ptr = (ISPRESENTC(pad) ? CADR(pad) : NULL);
620   pos_ptr = (ISPRESENTC(pos) ? CADR(pos) : NULL);
621   status_ptr = (ISPRESENTC(status) ? CADR(status) : NULL);
622   dispose_ptr = (ISPRESENTC(dispose) ? CADR(dispose) : NULL);
623   acc_siz = CLEN(acc);
624   action_siz = CLEN(action);
625   blank_siz = CLEN(blank);
626   delim_siz = CLEN(delim);
627   name_siz = CLEN(name);
628   form_siz = CLEN(form);
629   pad_siz = CLEN(pad);
630   pos_siz = CLEN(pos);
631   status_siz = CLEN(status);
632   dispose_siz = CLEN(dispose);
633 
634   __fort_status_init(bitv, iostat);
635   newreclen = (__INT8_T)*reclen;
636   if (LOCAL_MODE || GET_DIST_LCPU == GET_DIST_IOPROC)
637     s = f90_open(unit, /* do real open (finally) */
638                  bitv, acc_ptr, action_ptr, blank_ptr, delim_ptr, name_ptr,
639                  form_ptr, iostat, pad_ptr, pos_ptr, &newreclen, status_ptr,
640                  dispose_ptr, acc_siz, action_siz, blank_siz, delim_siz,
641                  name_siz, form_siz, pad_siz, pos_siz, status_siz, dispose_siz);
642   *reclen = (int)newreclen;
643   __fortio_errend03();
644   return DIST_STATUS_BCST(s);
645 }
646 /* 32 bit CLEN version */
647 __INT_T
ENTF90IO(OPEN,open)648 ENTF90IO(OPEN, open) (
649   __INT_T *unit,   /* unit number */
650   __INT_T *bitv,   /* determines action if error occurs */
651   DCHAR(acc),      /* DIRECT, SEQUENTIAL, or NULL */
652   DCHAR(action),   /* READ, WRITE, READWRITE, or NULL */
653   DCHAR(blank),    /* ZERO or NULL */
654   DCHAR(delim),    /* APOSTROPHE, QUOTE, NONE, or NULL */
655   DCHAR(name),     /* file name */
656   DCHAR(form),     /* FORMATTED, UNFORMATTED, or NULL */
657   __INT_T *iostat, /* IOSTAT variable */
658   DCHAR(pad),      /* YES, NO, or NULL */
659   DCHAR(pos),      /* ASIS, REWIND, APPEND, or NULL */
660   __INT_T *reclen, /* record length in bytes or words */
661   DCHAR(status),   /* OLD, NEW, SCRATCH, REPLACE, or NULL */
662   DCHAR(dispose)   /* KEEP, DELETE, SAVE, or NULL */
663   DCLEN(acc)       /* length of acc */
664   DCLEN(action)    /* length of action */
665   DCLEN(blank)     /* length of blank */
666   DCLEN(delim)     /* length of delim */
667   DCLEN(name)      /* length of name */
668   DCLEN(form)      /* length of form */
669   DCLEN(pad)       /* length of pad */
670   DCLEN(pos)       /* length of pos */
671   DCLEN(status)    /* length of status */
672   DCLEN(dispose))  /* length of dispose */
673 {
674   return ENTF90IO(OPEN, open) (unit, bitv, CADR(acc), CADR(action),
675 		  CADR(blank), CADR(delim), CADR(name), CADR(form), iostat,
676 		  CADR(pad), CADR(pos), reclen, CADR(status), CADR(dispose),
677 		  (__CLEN_T)CLEN(acc), (__CLEN_T)CLEN(action),
678 		  (__CLEN_T)CLEN(blank), (__CLEN_T)CLEN(delim),
679 		  (__CLEN_T)CLEN(name), (__CLEN_T)CLEN(form),
680 		  (__CLEN_T)CLEN(pad), (__CLEN_T)CLEN(pos),
681 		  (__CLEN_T)CLEN(status), (__CLEN_T)CLEN(dispose));
682 }
683 
684 /* --------------------------------------------------------------------- */
685 
686 __INT_T
ENTF90IO(OPEN2003A,open2003a)687 ENTF90IO(OPEN2003A, open2003a)(
688   __INT_T *unit,    /* unit number */
689   __INT_T *bitv,    /* determines action if error occurs */
690   DCHAR(acc),       /* DIRECT, SEQUENTIAL, or NULL */
691   DCHAR(action),    /* READ, WRITE, READWRITE, or NULL */
692   DCHAR(blank),     /* ZERO or NULL */
693   DCHAR(delim),     /* APOSTROPHE, QUOTE, NONE, or NULL */
694   DCHAR(name),      /* file name */
695   DCHAR(form),      /* FORMATTED, UNFORMATTED, or NULL */
696   __INT_T *iostat,  /* IOSTAT variable */
697   DCHAR(pad),       /* YES, NO, or NULL */
698   DCHAR(pos),       /* ASIS, REWIND, APPEND, or NULL */
699   __INT8_T *reclen, /* record length in bytes or words */
700   DCHAR(status),    /* OLD, NEW, SCRATCH, REPLACE, or NULL */
701   DCHAR(dispose)    /* KEEP, DELETE, SAVE, or NULL */
702   DCLEN64(acc)        /* length of acc */
703   DCLEN64(action)     /* length of action */
704   DCLEN64(blank)      /* length of blank */
705   DCLEN64(delim)      /* length of delim */
706   DCLEN64(name)       /* length of name */
707   DCLEN64(form)       /* length of form */
708   DCLEN64(pad)        /* length of pad */
709   DCLEN64(pos)        /* length of pos */
710   DCLEN64(status)     /* length of status */
711   DCLEN64(dispose))   /* length of dispose */
712 {
713   char *acc_ptr;
714   char *action_ptr;
715   char *blank_ptr;
716   char *delim_ptr;
717   char *name_ptr;
718   char *form_ptr;
719   char *pad_ptr;
720   char *pos_ptr;
721   char *status_ptr;
722   char *dispose_ptr;
723   __CLEN_T acc_siz;
724   __CLEN_T action_siz;
725   __CLEN_T blank_siz;
726   __CLEN_T delim_siz;
727   __CLEN_T name_siz;
728   __CLEN_T form_siz;
729   __CLEN_T pad_siz;
730   __CLEN_T pos_siz;
731   __CLEN_T status_siz;
732   __CLEN_T dispose_siz;
733 
734   int s = 0;
735 
736   acc_ptr = (ISPRESENTC(acc) ? CADR(acc) : NULL);
737   action_ptr = (ISPRESENTC(action) ? CADR(action) : NULL);
738   blank_ptr = (ISPRESENTC(blank) ? CADR(blank) : NULL);
739   delim_ptr = (ISPRESENTC(delim) ? CADR(delim) : NULL);
740   name_ptr = (ISPRESENTC(name) ? CADR(name) : NULL);
741   form_ptr = (ISPRESENTC(form) ? CADR(form) : NULL);
742   pad_ptr = (ISPRESENTC(pad) ? CADR(pad) : NULL);
743   pos_ptr = (ISPRESENTC(pos) ? CADR(pos) : NULL);
744   status_ptr = (ISPRESENTC(status) ? CADR(status) : NULL);
745   dispose_ptr = (ISPRESENTC(dispose) ? CADR(dispose) : NULL);
746   acc_siz = CLEN(acc);
747   action_siz = CLEN(action);
748   blank_siz = CLEN(blank);
749   delim_siz = CLEN(delim);
750   name_siz = CLEN(name);
751   form_siz = CLEN(form);
752   pad_siz = CLEN(pad);
753   pos_siz = CLEN(pos);
754   status_siz = CLEN(status);
755   dispose_siz = CLEN(dispose);
756   if (!ISPRESENT(reclen)) {
757     reclen = NULL;
758   }
759 
760   __fort_status_init(bitv, iostat);
761   if (LOCAL_MODE || GET_DIST_LCPU == GET_DIST_IOPROC)
762     s = f90_open(unit, /* do real open (finally) */
763                  bitv, acc_ptr, action_ptr, blank_ptr, delim_ptr, name_ptr,
764                  form_ptr, iostat, pad_ptr, pos_ptr, reclen, status_ptr,
765                  dispose_ptr, acc_siz, action_siz, blank_siz, delim_siz,
766                  name_siz, form_siz, pad_siz, pos_siz, status_siz, dispose_siz);
767   __fortio_errend03();
768   return DIST_STATUS_BCST(s);
769 }
770 /* 32 bit CLEN version */
771 __INT_T
ENTF90IO(OPEN2003,open2003)772 ENTF90IO(OPEN2003, open2003)(
773   __INT_T *unit,    /* unit number */
774   __INT_T *bitv,    /* determines action if error occurs */
775   DCHAR(acc),       /* DIRECT, SEQUENTIAL, or NULL */
776   DCHAR(action),    /* READ, WRITE, READWRITE, or NULL */
777   DCHAR(blank),     /* ZERO or NULL */
778   DCHAR(delim),     /* APOSTROPHE, QUOTE, NONE, or NULL */
779   DCHAR(name),      /* file name */
780   DCHAR(form),      /* FORMATTED, UNFORMATTED, or NULL */
781   __INT_T *iostat,  /* IOSTAT variable */
782   DCHAR(pad),       /* YES, NO, or NULL */
783   DCHAR(pos),       /* ASIS, REWIND, APPEND, or NULL */
784   __INT8_T *reclen, /* record length in bytes or words */
785   DCHAR(status),    /* OLD, NEW, SCRATCH, REPLACE, or NULL */
786   DCHAR(dispose)    /* KEEP, DELETE, SAVE, or NULL */
787   DCLEN(acc)        /* length of acc */
788   DCLEN(action)     /* length of action */
789   DCLEN(blank)      /* length of blank */
790   DCLEN(delim)      /* length of delim */
791   DCLEN(name)       /* length of name */
792   DCLEN(form)       /* length of form */
793   DCLEN(pad)        /* length of pad */
794   DCLEN(pos)        /* length of pos */
795   DCLEN(status)     /* length of status */
796   DCLEN(dispose))   /* length of dispose */
797 {
798   return ENTF90IO(OPEN2003A, open2003a)(unit, bitv, CADR(acc), CADR(action),
799 		  CADR(blank), CADR(delim), CADR(name), CADR(form), iostat,
800 		  CADR(pad), CADR(pos), reclen, CADR(status), CADR(dispose),
801 		  (__CLEN_T)CLEN(acc), (__CLEN_T)CLEN(action),
802 		  (__CLEN_T)CLEN(blank), (__CLEN_T)CLEN(delim),
803 		  (__CLEN_T)CLEN(name), (__CLEN_T)CLEN(form),
804 		  (__CLEN_T)CLEN(pad), (__CLEN_T)CLEN(pos),
805 		  (__CLEN_T)CLEN(status), (__CLEN_T)CLEN(dispose));
806 }
807 
808 /** \brief Called from user program; augments the OPEN with CONVERT specifier.
809  */
810 __INT_T
ENTF90IO(OPEN_CVTA,open_cvta)811 ENTF90IO(OPEN_CVTA, open_cvta)
812 (__INT_T *istat, /* status of OPEN */
813  DCHAR(endian)   /* BIG_ENDIAN or LITTLE_ENDIAN */
814  DCLEN64(endian))  /* length of endian */
815 {
816   int s = *istat;
817 
818   if (s)
819     return DIST_STATUS_BCST(s);
820 
821   if (LOCAL_MODE || GET_DIST_LCPU == GET_DIST_IOPROC) {
822 
823     if (Fcb->form != FIO_UNFORMATTED)
824       s = __fortio_error(FIO_ECOMPAT);
825     else if (__fortio_eq_str(CADR(endian), CLEN(endian), "BIG_ENDIAN")) {
826       Fcb->byte_swap = TRUE;
827     } else if (__fortio_eq_str(CADR(endian), CLEN(endian), "LITTLE_ENDIAN")) {
828       Fcb->native = TRUE;
829     } else if (__fortio_eq_str(CADR(endian), CLEN(endian), "NATIVE")) {
830       Fcb->native = TRUE;
831     } else
832       s = __fortio_error(FIO_ESPEC);
833   }
834   __fortio_errend03();
835   return DIST_STATUS_BCST(s);
836 }
837 /* 32 bit CLEN version */
838 __INT_T
ENTF90IO(OPEN_CVT,open_cvt)839 ENTF90IO(OPEN_CVT, open_cvt)
840 (__INT_T *istat, /* status of OPEN */
841  DCHAR(endian)   /* BIG_ENDIAN or LITTLE_ENDIAN */
842  DCLEN(endian))  /* length of endian */
843 {
844   return ENTF90IO(OPEN_CVTA, open_cvta) (istat, CADR(endian), (__CLEN_T)CLEN(endian));
845 }
846 
847 __INT_T
ENTF90IO(OPEN_SHAREA,open_sharea)848 ENTF90IO(OPEN_SHAREA, open_sharea)
849 (__INT_T *istat, /* status of OPEN */
850  DCHAR(shv)      /* BIG_ENDIAN or LITTLE_ENDIAN */
851  DCLEN64(shv))     /* length */
852 {
853   int s = *istat;
854 
855   if (s)
856     return DIST_STATUS_BCST(s);
857 
858   if (LOCAL_MODE || GET_DIST_LCPU == GET_DIST_IOPROC) {
859     if (__fortio_eq_str(CADR(shv), CLEN(shv), "SHARED")) {
860       ;
861     }
862   }
863   return DIST_STATUS_BCST(s);
864 }
865 /* 32 bit CLEN version */
866 __INT_T
ENTF90IO(OPEN_SHARE,open_share)867 ENTF90IO(OPEN_SHARE, open_share)
868 (__INT_T *istat, /* status of OPEN */
869  DCHAR(shv)      /* BIG_ENDIAN or LITTLE_ENDIAN */
870  DCLEN(shv))     /* length */
871 {
872   return ENTF90IO(OPEN_SHAREA, open_sharea) (istat, CADR(shv), (__CLEN_T)CLEN(shv));
873 }
874 
875 __INT_T
ENTCRF90IO(OPENA,opena)876 ENTCRF90IO(OPENA, opena)(
877   __INT_T *unit,   /* unit number */
878   __INT_T *bitv,   /* determines action if error occurs */
879   DCHAR(acc),      /* DIRECT, SEQUENTIAL, or NULL */
880   DCHAR(action),   /* READ, WRITE, READWRITE, or NULL */
881   DCHAR(blank),    /* ZERO or NULL */
882   DCHAR(delim),    /* APOSTROPHE, QUOTE, NONE, or NULL */
883   DCHAR(name),     /* file name */
884   DCHAR(form),     /* FORMATTED, UNFORMATTED, or NULL */
885   __INT_T *iostat, /* IOSTAT variable */
886   DCHAR(pad),      /* YES, NO, or NULL */
887   DCHAR(pos),      /* ASIS, REWIND, APPEND, or NULL */
888   __INT_T *reclen, /* record length in bytes or words */
889   DCHAR(status),   /* OLD, NEW, SCRATCH, REPLACE, or NULL */
890   DCHAR(dispose)   /* KEEP, DELETE, SAVE, or NULL */
891   DCLEN64(acc)       /* length of acc */
892   DCLEN64(action)    /* length of action */
893   DCLEN64(blank)     /* length of blank */
894   DCLEN64(delim)     /* length of delim */
895   DCLEN64(name)      /* length of name */
896   DCLEN64(form)      /* length of form */
897   DCLEN64(pad)       /* length of pad */
898   DCLEN64(pos)       /* length of pos */
899   DCLEN64(status)    /* length of status */
900   DCLEN64(dispose))  /* length of dispose */
901 {
902   char *acc_ptr;
903   char *action_ptr;
904   char *blank_ptr;
905   char *delim_ptr;
906   char *name_ptr;
907   char *form_ptr;
908   char *pad_ptr;
909   char *pos_ptr;
910   char *status_ptr;
911   char *dispose_ptr;
912   __CLEN_T acc_siz;
913   __CLEN_T action_siz;
914   __CLEN_T blank_siz;
915   __CLEN_T delim_siz;
916   __CLEN_T name_siz;
917   __CLEN_T form_siz;
918   __CLEN_T pad_siz;
919   __CLEN_T pos_siz;
920   __CLEN_T status_siz;
921   __CLEN_T dispose_siz;
922   int s = 0;
923   __INT8_T newreclen;
924 
925   acc_ptr = (ISPRESENTC(acc) ? CADR(acc) : NULL);
926   action_ptr = (ISPRESENTC(action) ? CADR(action) : NULL);
927   blank_ptr = (ISPRESENTC(blank) ? CADR(blank) : NULL);
928   delim_ptr = (ISPRESENTC(delim) ? CADR(delim) : NULL);
929   name_ptr = (ISPRESENTC(name) ? CADR(name) : NULL);
930   form_ptr = (ISPRESENTC(form) ? CADR(form) : NULL);
931   pad_ptr = (ISPRESENTC(pad) ? CADR(pad) : NULL);
932   pos_ptr = (ISPRESENTC(pos) ? CADR(pos) : NULL);
933   status_ptr = (ISPRESENTC(status) ? CADR(status) : NULL);
934   dispose_ptr = (ISPRESENTC(dispose) ? CADR(dispose) : NULL);
935   acc_siz = CLEN(acc);
936   action_siz = CLEN(action);
937   blank_siz = CLEN(blank);
938   delim_siz = CLEN(delim);
939   name_siz = CLEN(name);
940   form_siz = CLEN(form);
941   pad_siz = CLEN(pad);
942   pos_siz = CLEN(pos);
943   status_siz = CLEN(status);
944   dispose_siz = CLEN(dispose);
945 
946   newreclen = (__INT8_T)*reclen;
947   s = f90_open(unit, /* do real open (finally) */
948                bitv, acc_ptr, action_ptr, blank_ptr, delim_ptr, name_ptr,
949                form_ptr, iostat, pad_ptr, pos_ptr, &newreclen, status_ptr,
950                dispose_ptr, acc_siz, action_siz, blank_siz, delim_siz, name_siz,
951                form_siz, pad_siz, pos_siz, status_siz, dispose_siz);
952   __fortio_errend03();
953   return s;
954 }
955 /* 32 bit CLEN version */
956 __INT_T
ENTCRF90IO(OPEN,open)957 ENTCRF90IO(OPEN, open)(
958   __INT_T *unit,   /* unit number */
959   __INT_T *bitv,   /* determines action if error occurs */
960   DCHAR(acc),      /* DIRECT, SEQUENTIAL, or NULL */
961   DCHAR(action),   /* READ, WRITE, READWRITE, or NULL */
962   DCHAR(blank),    /* ZERO or NULL */
963   DCHAR(delim),    /* APOSTROPHE, QUOTE, NONE, or NULL */
964   DCHAR(name),     /* file name */
965   DCHAR(form),     /* FORMATTED, UNFORMATTED, or NULL */
966   __INT_T *iostat, /* IOSTAT variable */
967   DCHAR(pad),      /* YES, NO, or NULL */
968   DCHAR(pos),      /* ASIS, REWIND, APPEND, or NULL */
969   __INT_T *reclen, /* record length in bytes or words */
970   DCHAR(status),   /* OLD, NEW, SCRATCH, REPLACE, or NULL */
971   DCHAR(dispose)   /* KEEP, DELETE, SAVE, or NULL */
972   DCLEN(acc)       /* length of acc */
973   DCLEN(action)    /* length of action */
974   DCLEN(blank)     /* length of blank */
975   DCLEN(delim)     /* length of delim */
976   DCLEN(name)      /* length of name */
977   DCLEN(form)      /* length of form */
978   DCLEN(pad)       /* length of pad */
979   DCLEN(pos)       /* length of pos */
980   DCLEN(status)    /* length of status */
981   DCLEN(dispose))  /* length of dispose */
982 {
983   return ENTCRF90IO(OPENA, opena)(unit, bitv, CADR(acc), CADR(action),
984 		    CADR(blank), CADR(delim), CADR(name), CADR(form), iostat,
985 		    CADR(pad), CADR(pos), reclen, CADR(status), CADR(dispose),
986 		    (__CLEN_T)CLEN(acc), (__CLEN_T)CLEN(action),
987 		    (__CLEN_T)CLEN(blank), (__CLEN_T)CLEN(delim),
988 		    (__CLEN_T)CLEN(name), (__CLEN_T)CLEN(form),
989 		    (__CLEN_T)CLEN(pad), (__CLEN_T)CLEN(pos),
990 		    (__CLEN_T)CLEN(status), (__CLEN_T)CLEN(dispose));
991 }
992 
993 __INT_T
ENTCRF90IO(OPEN_CVTA,open_cvta)994 ENTCRF90IO(OPEN_CVTA, open_cvta)(
995   __INT_T *istat, /* status of OPEN */
996   DCHAR(endian)   /* BIG_ENDIAN or LITTLE_ENDIAN */
997   DCLEN64(endian))  /* length of endian */
998 {
999   if (*istat)
1000     return *istat;
1001 
1002   if (Fcb->form != FIO_UNFORMATTED)
1003     return __fortio_error(FIO_ECOMPAT);
1004 
1005   if (__fortio_eq_str(CADR(endian), CLEN(endian), "BIG_ENDIAN")) {
1006     Fcb->byte_swap = TRUE;
1007   } else if (__fortio_eq_str(CADR(endian), CLEN(endian), "LITTLE_ENDIAN")) {
1008     Fcb->native = TRUE;
1009   } else if (__fortio_eq_str(CADR(endian), CLEN(endian), "NATIVE")) {
1010     Fcb->native = TRUE;
1011   } else
1012     return __fortio_error(FIO_ESPEC);
1013 
1014   return 0;
1015 }
1016 /* 32 bit CLEN version */
1017 __INT_T
ENTCRF90IO(OPEN_CVT,open_cvt)1018 ENTCRF90IO(OPEN_CVT, open_cvt)(
1019   __INT_T *istat, /* status of OPEN */
1020   DCHAR(endian)   /* BIG_ENDIAN or LITTLE_ENDIAN */
1021   DCLEN(endian))  /* length of endian */
1022 {
1023   return ENTCRF90IO(OPEN_CVTA, open_cvta)(istat, CADR(endian), (__CLEN_T)CLEN(endian));
1024 }
1025 
1026 __INT_T
ENTCRF90IO(OPEN_SHAREA,open_sharea)1027 ENTCRF90IO(OPEN_SHAREA, open_sharea)(
1028   __INT_T *istat, /* status of OPEN */
1029   DCHAR(shv)      /* BIG_ENDIAN or LITTLE_ENDIAN */
1030   DCLEN64(shv))     /* length */
1031 {
1032   int s = *istat;
1033 
1034   if (s)
1035     return DIST_STATUS_BCST(s);
1036 
1037   if (LOCAL_MODE || GET_DIST_LCPU == GET_DIST_IOPROC) {
1038     if (__fortio_eq_str(CADR(shv), CLEN(shv), "SHARED")) {
1039       ;
1040     }
1041   }
1042   return DIST_STATUS_BCST(s);
1043 }
1044 /* 32 bit CLEN version */
1045 __INT_T
ENTCRF90IO(OPEN_SHARE,open_share)1046 ENTCRF90IO(OPEN_SHARE, open_share)(
1047   __INT_T *istat, /* status of OPEN */
1048   DCHAR(shv)      /* BIG_ENDIAN or LITTLE_ENDIAN */
1049   DCLEN(shv))     /* length */
1050 {
1051   return ENTCRF90IO(OPEN_SHAREA, open_sharea)(istat, CADR(shv), (__CLEN_T)CLEN(shv));
1052 }
1053 
1054 /* handle asyncronous open parameter, called after open */
1055 
1056 int
ENTF90IO(OPEN_ASYNCA,open_asynca)1057 ENTF90IO(OPEN_ASYNCA, open_asynca)(__INT_T *istat, DCHAR(asy) DCLEN64(asy))
1058 {
1059   int retval;
1060 
1061   if (*istat)
1062     return *istat;
1063 
1064   if (!ISPRESENTC(asy)) {
1065     return 0;
1066   }
1067   if (__fortio_eq_str(CADR(asy), CLEN(asy), "YES")) {
1068     /* do nothing */
1069   } else if (__fortio_eq_str(CADR(asy), CLEN(asy), "NO")) {
1070     return 0;
1071   } else {
1072     return FIO_ESPEC;
1073   }
1074 
1075   /* enable asynchronous i/o */
1076 
1077   retval = 0;
1078 #if !defined(TARGET_WIN_X8632) && !defined(TARGET_OSX)
1079   if ((Fcb->acc == FIO_STREAM || Fcb->acc == FIO_SEQUENTIAL
1080        || Fcb->acc == FIO_DIRECT)
1081       &&
1082       (!Fcb->byte_swap)) {
1083     if (Fio_asy_open(Fcb->fp, &Fcb->asyptr) == -1) {
1084       retval = __fortio_error(__io_errno());
1085     }
1086   }
1087 #endif
1088   return (retval);
1089 }
1090 /* 32 bit CLEN version */
1091 int
ENTF90IO(OPEN_ASYNC,open_async)1092 ENTF90IO(OPEN_ASYNC, open_async)(__INT_T *istat, DCHAR(asy) DCLEN(asy))
1093 {
1094   return ENTF90IO(OPEN_ASYNCA, open_asynca)(istat, CADR(asy), (__CLEN_T)CLEN(asy));
1095 }
1096 
1097 __INT_T
ENTF90IO(OPEN03A,open03a)1098 ENTF90IO(OPEN03A, open03a)(
1099   __INT_T *istat, DCHAR(decimal), /* POINT, COMMA, or NULL */
1100   DCHAR(round),                   /* UP, DOWN, ZERO, NEAREST, COMPATIBLE,
1101                                      PROCESSOR_DEFINED,or NULL */
1102   DCHAR(sign),     /* PLUS, SUPPRESS, PROCESSOR_DEFINED, or NULL */
1103   DCHAR(encoding)  /* UTF-8, DEFAULT, or NULL */
1104   DCLEN64(decimal)   /* length of decimal */
1105   DCLEN64(round)     /* length of round */
1106   DCLEN64(sign)      /* length of sign */
1107   DCLEN64(encoding)) /* length of encoding */
1108 {
1109   /*
1110    *  N O T E  --  For any 'Fcb' members which are defined in this routine,
1111    *  make sure that they are also initialized in __fortio_open().
1112    *  ENTF90IO(open)() is always called for OPEN, but ENTF90IO(open03) is
1113    *  called only if any of the selected '03' specifiers are present.
1114    */
1115   if (*istat)
1116     return *istat;
1117 
1118   if (Fcb->form != FIO_FORMATTED)
1119     return __fortio_error(FIO_ECOMPAT);
1120 
1121   Fcb->encoding = FIO_DEFAULT;
1122   if (ISPRESENTC(encoding)) {
1123     if (__fortio_eq_str(CADR(encoding), CLEN(encoding), "UTF-8"))
1124       Fcb->encoding = FIO_UTF_8;
1125     else if (__fortio_eq_str(CADR(encoding), CLEN(encoding), "DEFAULT"))
1126       Fcb->encoding = FIO_DEFAULT;
1127     else
1128       return __fortio_error(FIO_ESPEC);
1129   }
1130 
1131   Fcb->decimal = FIO_POINT;
1132   if (ISPRESENTC(decimal)) {
1133     if (__fortio_eq_str(CADR(decimal), CLEN(decimal), "COMMA"))
1134       Fcb->decimal = FIO_COMMA;
1135     else if (__fortio_eq_str(CADR(decimal), CLEN(decimal), "POINT"))
1136       Fcb->decimal = FIO_POINT;
1137     else
1138       return __fortio_error(FIO_ESPEC);
1139   }
1140 
1141   Fcb->round = FIO_COMPATIBLE; /* This must be default mode.
1142                                   What is our default mode?
1143                                   On 10/14/10 we think it is compatible */
1144   if (ISPRESENTC(round)) {
1145     if (__fortio_eq_str(CADR(round), CLEN(round), "UP"))
1146       Fcb->round = FIO_UP;
1147     else if (__fortio_eq_str(CADR(round), CLEN(round), "DOWN"))
1148       Fcb->round = FIO_DOWN;
1149     else if (__fortio_eq_str(CADR(round), CLEN(round), "ZERO"))
1150       Fcb->round = FIO_ZERO;
1151     else if (__fortio_eq_str(CADR(round), CLEN(round), "NEAREST"))
1152       Fcb->round = FIO_NEAREST;
1153     else if (__fortio_eq_str(CADR(round), CLEN(round), "COMPATIBLE"))
1154       Fcb->round = FIO_COMPATIBLE;
1155     else if (__fortio_eq_str(CADR(round), CLEN(round), "PROCESSOR_DEFINED"))
1156       Fcb->round = FIO_PROCESSOR_DEFINED;
1157     else
1158       return __fortio_error(FIO_ESPEC);
1159   }
1160 
1161   Fcb->sign = FIO_PROCESSOR_DEFINED;
1162   if (ISPRESENTC(sign)) {
1163     if (__fortio_eq_str(CADR(sign), CLEN(sign), "PLUS"))
1164       Fcb->sign = FIO_PLUS;
1165     else if (__fortio_eq_str(CADR(sign), CLEN(sign), "SUPPRESS"))
1166       Fcb->sign = FIO_SUPPRESS;
1167     else if (__fortio_eq_str(CADR(sign), CLEN(sign), "PROCESOR_DEFINED"))
1168       Fcb->sign = FIO_PROCESSOR_DEFINED;
1169     else
1170       return __fortio_error(FIO_ESPEC);
1171   }
1172 
1173   return 0;
1174 }
1175 /* 32 bit CLEN version */
1176 __INT_T
ENTF90IO(OPEN03,open03)1177 ENTF90IO(OPEN03, open03)(
1178   __INT_T *istat, DCHAR(decimal), /* POINT, COMMA, or NULL */
1179   DCHAR(round),                   /* UP, DOWN, ZERO, NEAREST, COMPATIBLE,
1180                                      PROCESSOR_DEFINED,or NULL */
1181   DCHAR(sign),     /* PLUS, SUPPRESS, PROCESSOR_DEFINED, or NULL */
1182   DCHAR(encoding)  /* UTF-8, DEFAULT, or NULL */
1183   DCLEN(decimal)   /* length of decimal */
1184   DCLEN(round)     /* length of round */
1185   DCLEN(sign)      /* length of sign */
1186   DCLEN(encoding)) /* length of encoding */
1187 {
1188 
1189   return ENTF90IO(OPEN03A, open03a)(istat, CADR(decimal), CADR(round),
1190 		  CADR(sign), CADR(encoding), (__CLEN_T)CLEN(decimal),
1191 		  (__CLEN_T)CLEN(round), (__CLEN_T)CLEN(sign),
1192 		  (__CLEN_T)CLEN(encoding));
1193 }
1194