Пример #1
1
int
idxread (unit *ftnunit)
{
   register int    i;
   register char  *keyval, *field;
   int             newkeyid = 0, mode = ftnunit->f77idxlist.cimatch;

   keys = ftnunit->ukeys;
   ftnunit->f77recend = i = ftnunit->url;
   if (ftnunit->url > ftnunit->f77fio_size)
      check_buflen (ftnunit, ftnunit->url);
   while (i-- > 0)
      ftnunit->f77fio_buf[i] = '\0';
   if (ftnunit->f77idxlist.cikeyid >= 0 && ftnunit->ukeyid != ftnunit->f77idxlist.cikeyid) {
      ftnunit->ukeyid = ftnunit->f77idxlist.cikeyid;
      newkeyid = 1;
   }
/* 8/23/89 fix bug 4847 */
   else if (ftnunit->ukeyid < 0) {
      ftnunit->ukeyid = ftnunit->f77idxlist.cikeyid >= 0 ? ftnunit->f77idxlist.cikeyid : 0;
      newkeyid = 1;
   }
   if (mode) {
      field = ftnunit->f77fio_buf + KEYOFF (ftnunit->ukeyid);
      if (KEYTYPE (ftnunit->ukeyid) != ftnunit->f77idxlist.cikeytype)
	 err (ftnunit->f77errlist.cierr, 154, "indexed read");
      if (KEYTYPE (ftnunit->ukeyid) == CHARTYPE) {
	 keyval = ftnunit->f77idxlist.cikeyval.cicharval;
/* fix bug 4779 */
	 if ((i = ftnunit->f77idxlist.cikeyvallen) > KEYLEN (ftnunit->ukeyid))
	    err (ftnunit->f77errlist.cierr, 155, "indexed read");
	 /* For Fortran, there's no such thing as null terminators for
	 the string values, so use the string len value only 
	 while (*keyval && i-- > 0)
	    *field++ = *keyval++;
	 while (i-- > 0)
	    *field++ = ' ';
	*/
	 while (i-- > 0)
	    *field++ = *keyval++;
      } else
	 stlong (ftnunit->f77idxlist.cikeyval.ciintval, field);
   } else
      /* If the last read operation was locked try readign the same record
      again
      mode = (newkeyid ? ISFIRST : ISNEXT);
      */
      mode = (newkeyid ? ISFIRST : ftnunit->uerror == F_ERLOCKED ? ISCURR : ISNEXT);
      ftnunit->uerror = 0;	/* clear error for new operation */
   if (newkeyid) {
      dokey (ftnunit->ukeyid, ONEKEY);
      if (isstart (ftnunit->isfd, &onekey, ftnunit->url, ftnunit->f77fio_buf, mode)
	  < SUCCESS)
	 ierr (ftnunit->f77errlist.cierr, iserrno, "indexed read");
   }
   if (isread (ftnunit->isfd, ftnunit->f77fio_buf, mode) < SUCCESS)
      if (iserrno == EENDFILE) {
	 ftnunit->uend = 1;
	 err (ftnunit->f77errlist.ciend, EOF, "indexed read");
      } else
	 ierr (ftnunit->f77errlist.cierr, iserrno, "indexed read");
   /* When the read is successful, make sure the EOF flag is not set */
   ftnunit->uend = 0;
   return SUCCESS;
}
Пример #2
0
int parse_ei_scn(struct opal_ei_scn **r_ei,
                 struct opal_v6_hdr *hdr,
                 const char *buf, int buflen)
{
	struct opal_ei_scn *ei;
	struct opal_ei_scn *eibuf = (struct opal_ei_scn *)buf;

	if (check_buflen(buflen, sizeof(struct opal_ei_scn), __func__) < 0 ||
		 check_buflen(hdr->length, sizeof(struct opal_ei_scn), __func__) < 0)
		return -EINVAL;

	*r_ei = malloc(hdr->length);
	if (!*r_ei)
		return -ENOMEM;

	ei = *r_ei;

	ei->v6hdr = *hdr;
	ei->g_timestamp = be64toh(eibuf->g_timestamp);
	ei->genesis.corrosion = be32toh(eibuf->genesis.corrosion);
	ei->genesis.temperature = be16toh(eibuf->genesis.temperature);
	ei->genesis.rate = be16toh(eibuf->genesis.rate);
	ei->status = eibuf->status;
	ei->user_data_scn = eibuf->user_data_scn;
	ei->read_count = be16toh(eibuf->read_count);
	if (check_buflen(hdr->length, sizeof(struct opal_ei_scn) +
		 (ei->read_count * sizeof(struct opal_ei_env_scn)),
		 __func__) < 0 ||
		 check_buflen(buflen, sizeof(struct opal_ei_scn) +
		 (ei->read_count * sizeof(struct opal_ei_env_scn)),
		 __func__)) {
		free(ei);
		return -EINVAL;
	}

	int i;
	for (i = 0; i < ei->read_count; i++) {
		ei->readings[i].corrosion = be32toh(eibuf->readings[i].corrosion);
		ei->readings[i].temperature = be16toh(eibuf->readings[i].temperature);
		ei->readings[i].rate = be16toh(eibuf->readings[i].rate);
	}

	return 0;
}
Пример #3
0
int32 wsfe (cilist *a, unit **fu, int f90sw)
#endif
{
   int32             n;
   unit             *ftnunit;

   if (!f77init)
      f_init ();

   if (n = c_sfe (a, fu))
      return n;

   ftnunit = *fu;
   if (ftnunit->uacc == DIRECT)
      errret(a->cierr, 171, "sequential write");

   ftnunit->f77cursor = ftnunit->f77recpos = ftnunit->f77recend = 0;
   ftnunit->f77cplus = 0;
   ftnunit->f77scale = 0;
#ifdef I90
   ftnunit->f90sw = f90sw;
   if (!f90sw) ftnunit->f77recpos = ftnunit->f77recend = 0;
   /* in f90 mode we initialize f77recpos and f77recend in the caller, dont
      know why. */
#else
   ftnunit->f77recpos = ftnunit->f77recend = 0;
#endif
   ftnunit->f77errlist.cierr = a->cierr;
   ftnunit->f77errlist.ciend = a->ciend;
   ftnunit->f77errlist.cieor = a->cieor;
   ftnunit->f77errlist.cisize = a->cisize;
   ftnunit->f77errlist.iciunit = 0; 
   ftnunit->f77fmtbuf = a->cifmt;
   if (ftnunit->uacc == KEYED) {
      ftnunit->f77idxlist.cimatch = a->cimatch;
      ftnunit->f77idxlist.cikeytype = a->cikeytype;
      ftnunit->f77idxlist.cikeyval.cicharval = a->cikeyval.cicharval;
      ftnunit->f77idxlist.cikeyid = a->cikeyid;
      ftnunit->f77idxlist.cinml = a->cinml;
      ftnunit->f77idxlist.cikeyvallen = a->cikeyvallen;
   }
   if (pars_f (ftnunit, ftnunit->f77fmtbuf) < 0)
      errret(a->cierr, 100, "startio");
   ftnunit->f77putn = x_putc;
   ftnunit->f77ungetn = x_ungetc;
   ftnunit->f77doed = w_ed;
   ftnunit->f77doned = w_ned;
   ftnunit->f77doend = xw_end;
   ftnunit->f77dorevert = xw_rev;
   ftnunit->f77donewrec = x_wSL;
   fmt_bg (ftnunit);
   ftnunit->f77cblank = ftnunit->ublnk;
   if (ftnunit->url > ftnunit->f77fio_size)
       check_buflen( ftnunit, ftnunit->url > FIO_ALLOC ? ftnunit->url : FIO_ALLOC );
   return 0;
}
Пример #4
0
int
xrd_SL (unit *ftnunit)
{
   int             n;


   if (ftnunit->uacc == KEYED) {
      if (n = idxread(ftnunit))
	 return n;
   } else {
      if (ftnunit->ufmt == 2) {
         if (fread ((char *) &ftnunit->f77recend, sizeof (int), 1, ftnunit->ufd) != 1) {
	    clearerr(ftnunit->ufd);
	    return (errno);
         }
         /* make sure there is enough buffer space */
         check_buflen (ftnunit, ftnunit->f77recend + (int) sizeof(int));
         if (fread (ftnunit->f77fio_buf, ftnunit->f77recend + sizeof (int), 1, ftnunit->ufd) != 1) {
	    clearerr(ftnunit->ufd);
	    return (errno);
         }
         ftnunit->f77cursor = ftnunit->f77recpos = 0;
         return (0);
      }
         /* For regular formatted file */
#ifdef I90
  /* f77recpos cannot be used as a flag for all f77donewrec functions
  ** since it could point to y_rdXL to skip to the end of the
  ** current record and destroying the current f77recpos by
  ** resetting it to 0 would amke that impossible.  My guess
  ** is that the whole reason for this setting of f77recpos to 0
  ** in the first place is simply to deal with the NOADVACE
  ** feature in F90 when reaching the end of a FORMAT specification
  ** (and the function x_rev is called.  
  */
  if (ftnunit->f90nadv != NOADVANCE_AT_REV) {
#endif
      ftnunit->f77recend = 0;
      while ((n = getc (ftnunit->ufd)) != EOF && n != '\n') {
         ftnunit->f77fio_buf[ftnunit->f77recend] = (char) n;
         if (++ftnunit->f77recend == ftnunit->f77fio_size)
	 ftnunit->f77fio_buf = realloc (ftnunit->f77fio_buf, ftnunit->f77fio_size += FIO_ALLOC);
      }
#ifdef I90
    }
#endif
      ftnunit->f77fio_buf[ftnunit->f77recend] = '\0';/* replace '\n' with null */
      if (n == EOF && ftnunit->f77recend == 0) {
         ftnunit->uend = 1;
         return (EOF);
      }
   }
   ftnunit->f77cursor = ftnunit->f77recpos = 0;
   return (0);
}
Пример #5
0
void
s_idxwrite (unit *ftnunit)
{
/* Fix BN 10498.
 * Check to ensure that the f77fio_buf is equal to the record length
 * ftnunit->url. Since this was not being done previously, f77fio_buf
 * was getting written with more characters then malloced which inturn
 * caused svr4 realloc and malloc to fail becuase these routines keep
 * size info in the first word of the block. The next  block was getting over
 * written.
 * ---ravi---1/15/92
 */
   check_buflen (ftnunit, ftnunit->url);
   if (ftnunit->ufmt)
      while (ftnunit->f77recpos++ < ftnunit->url)
	 ftnunit->f77fio_buf[ftnunit->f77recpos] = ' ';
   else
      while (ftnunit->f77reclen++ < ftnunit->url)
	 ftnunit->f77fio_buf[ftnunit->f77reclen] = '\0';
   ftnunit->f77fio_buf[ftnunit->url] = '\0';
}
Пример #6
0
int
do_ui(unit *ftnunit, XINT *number, register char *ptr, ftnlen len)
{
    register char  *recp;
    register XINT    i = *number * len;

    if (!(ftnunit->uwrt & WR_OP)) {
        recp = ftnunit->f77fio_buf + ftnunit->f77recpos;
        if ((ftnunit->f77recpos += i) > ftnunit->url)
            err(ftnunit->f77errlist.cierr, 147, "indexed read");
        while (i-- > 0)
            *ptr++ = *recp++;
    } else {
        if (ftnunit->url > ftnunit->f77fio_size)
            check_buflen (ftnunit, ftnunit->url);
        recp = ftnunit->f77fio_buf + ftnunit->f77reclen;
        if ((ftnunit->f77reclen += i) > ftnunit->url)
            err(ftnunit->f77errlist.cierr, 148, "indexed write");
        while (i-- > 0)
            *recp++ = *ptr++;
    }
    return 0;
}
Пример #7
0
int
x_putc (register unit *ftnunit, register XINT count, char con, char *buf)
{
   register char  *iobuf;
   XINT    new_size;

   /*
   It is very expensive to declare irrelevant symbols as 'register'
   in this routine
   */
   if (((new_size = ftnunit->f77recpos + count)) > ftnunit->f77fio_size)
      check_buflen( ftnunit, new_size + FIO_ALLOC );

   iobuf = ftnunit->f77fio_buf + ftnunit->f77recpos;
   ftnunit->f77recpos = new_size;

   /* LHL 4/27/89 change it back to use memcpy for performance
    * reason. if ( buf ) for ( ; count--; iobuf++, buf++ ) *iobuf =
    * *buf; */
   if (buf)
      memcpy (iobuf, buf, count);
   else {
      if (con)
	 while (count--)
	    *(iobuf++) = con;
      else if ((count = ftnunit->f77recpos - ftnunit->f77recend) > 0) {
	 iobuf = ftnunit->f77fio_buf + ftnunit->f77recend;
	 while (count--)
	    *(iobuf++) = ' ';
      }
   }

   if (ftnunit->f77recpos > ftnunit->f77recend)
      ftnunit->f77recend = ftnunit->f77recpos;
   return (0);
}
Пример #8
0
Файл: uio.c Проект: xyuan/Path64
int
do_us (unit *ftnunit, XINT *number, char *ptr, ftnlen len)
{
   if (!(ftnunit->uwrt & WR_OP)) {
      XINT             nread = *number * len;

      ftnunit->f77recpos += nread;
      if (ftnunit->f77reclen == 1 && f77vms_flag_[VMS_EF]) {
	 /* VMS endfile record */
	 (void) fread (ptr, 1, 1, ftnunit->ufd);
	 if (*ptr == '\032') {
	    (void) fseek (ftnunit->ufd, sizeof (int), 1);
	    return( EOF );	/* Endfile record */
	 } else if (ftnunit->f77recpos > 1)
	    errret(ftnunit->f77errlist.cierr, 110, "eof/uio");
	 return (0);
      }
      if (ftnunit->f77recpos > ftnunit->f77reclen) {
	 ftnunit->f77recpos -= nread;
	 (void) fread (ptr, (int) ftnunit->f77reclen - ftnunit->f77recpos, 1, ftnunit->ufd);
	 errret(ftnunit->f77errlist.cierr, 110, "eof/uio");
      }
      (void) fread (ptr, (int) nread, 1, ftnunit->ufd);
      return (0);
   } else {

/* 7/18/90 MNH  REPLACE FWRITE WITH MEMCPY -- FWRITE BEGAN AT BYTE #5 TO */
/* ALLOW SPACE FOR EVENTUAL FRWITE OF "f77reclen" TO BEGINNING OF FILE */
      XINT             n = *number * len;
      int             seekdone = 0;

      if (ftnunit->f77recpos + n > ftnunit->f77fio_size || n >= BUFSIZ || est_reclen) {
	 if (!ftnunit->overflowed) {
	    ftnunit->overflowed = 1;
	    if (!est_reclen) {
	       if (ftnunit->f77recpos == 4) {
		  fseek (ftnunit->ufd, 4, 1);
		  seekdone = 1;
		  ftnunit->f77recpos = 0;
	       }
	    } else
	       *(int *) ftnunit->f77fio_buf = est_reclen;
	 }
	 if (ftnunit->f77recpos) {
	    if (fwrite (ftnunit->f77fio_buf, ftnunit->f77recpos, 1, ftnunit->ufd) != 1)
	       errret(ftnunit->f77errlist.cierr, errno, "system write error");
	    ftnunit->f77recpos = 0;
	 }
	 if (n >= BUFSIZ) {
	    /* for large user data it's preferable to flush the
	     * system buffer to disk so that it won't have to copy
	     * the user array, which could be several megs, to the
	     * system buffer before writing it out */
	    if (!seekdone)
	       fseek (ftnunit->ufd, 0, 1);
	    if (fwrite (ptr, n, 1, ftnunit->ufd) != 1)
	       errret(ftnunit->f77errlist.cierr, errno, "system write error");
	    ftnunit->f77reclen += n;
	    return (0);
	 }
      }
      if (!est_reclen) {
	 if (ftnunit->f77recpos + n > ftnunit->f77fio_size)
             check_buflen( ftnunit, ftnunit->f77recpos + n );
	 memcpy (ftnunit->f77fio_buf + ftnunit->f77recpos, ptr, n);
	 ftnunit->f77recpos += n;
      } else if (fwrite (ptr, n, 1, ftnunit->ufd) != 1) {
	 ftnunit->f77recpos = 0;
	 errret(ftnunit->f77errlist.cierr, errno, "system write error");
      }
      ftnunit->f77reclen += n;
      return (0);
   }
}
Пример #9
0
int s_rsfe_com (cilist *a, unit **fu)
#endif
{
   int             n;
   unit           *ftnunit;

   if (!f77init)
      f_init ();
   if (n = c_sfe (a, fu))
      return (n);
   ftnunit = *fu;

/* Fix BN 9768.
 * If user tries to read from stdout  then cause startio to abort with an
 * error. This is particularly importrant if a user is tries to read from
 * fortran unit 6 , which by default is connected to stdout. Even though
 * the standard says nothing about the way unit 5 and unit 6 should be
 * handled, I generally think that it is a good idea to distinguish 
 * between these and not allow users to read from stdout.
 * ---ravi---1/7/92
 */
   /* Fix 12308: Read error from stdout should occur for only files
    * connected to terminal. The change is taken from the 'fix'
    * section of the bug description - Bhaskar 08/14/92 */
   if (ftnunit->ufd == stdout && isatty (fileno (ftnunit->ufd)))
      errret(a->cierr, 173, "startio");
   ftnunit->f77errlist.cierr = a->cierr;
   ftnunit->f77errlist.ciend = a->ciend;
   ftnunit->f77errlist.cieor = a->cieor;
   ftnunit->f77errlist.cisize = a->cisize;
   ftnunit->f77errlist.iciunit = 0; 
   ftnunit->f77scale = 0;
   ftnunit->f77fmtbuf = a->cifmt;
   if (ftnunit->uacc == KEYED) {
      ftnunit->f77idxlist.cimatch = a->cimatch;
      ftnunit->f77idxlist.cikeytype = a->cikeytype;
      ftnunit->f77idxlist.cikeyval.cicharval = a->cikeyval.cicharval;
      ftnunit->f77idxlist.cikeyid = a->cikeyid;
      ftnunit->f77idxlist.cinml = a->cinml;
      ftnunit->f77idxlist.cikeyvallen = a->cikeyvallen;
   }
   else {
      if (ftnunit->uacc == DIRECT)
	 errret(a->cierr, 171, "sequential read");
      if (ftnunit->ualias->ucc == CC_FORTRAN &&
	  ftnunit->ualias->ucchar) {
	 putc (ftnunit->ualias->ucchar, ftnunit->ualias->ufd);
	 ftnunit->ualias->ucchar = '\0';
      } else if (ftnunit->ucc == CC_FORTRAN && ftnunit->ucchar) {
	 putc (ftnunit->ucchar, ftnunit->ufd);
	 ftnunit->ucchar = '\0';
      }
   }
#ifdef I90
   ftnunit->f90sw = 0;
   ftnunit->f90nadv = 0;
#endif
   if (pars_f (ftnunit, ftnunit->f77fmtbuf) < 0)
      errret(a->cierr, 100, "startio");
   ftnunit->f77getn = x_getc;
   ftnunit->f77gets = x_gets;
   ftnunit->f77ungetn = x_ungetc;
   ftnunit->f77doed = rd_ed;
   ftnunit->f77doned = rd_ned;
   fmt_bg (ftnunit);
   ftnunit->f77doend = x_endp;
   ftnunit->f77donewrec = xrd_SL;
   ftnunit->f77dorevert = x_rev;
   ftnunit->f77cblank = ftnunit->ublnk;
   ftnunit->f77cplus = 0;

   if (ftnunit->ufd == stdin && feof (ftnunit->ufd) && f77vms_flag_[VMS_IN])
      clearerr(ftnunit->ufd);
   (void) f77nowreading (ftnunit);
   check_buflen( ftnunit, ftnunit->url > FIO_ALLOC ? ftnunit->url : FIO_ALLOC );

#ifdef I90
   if (ftnunit->uaction == WRITEONLY ) 
       errret(ftnunit->f77errlist.cierr,180,"startread");
   ftnunit->f77recpos = 0;
   ftnunit->f77recend = 0;
#endif

   n = xrd_SL (ftnunit);
   if (n > 0) {
     errret(a->cierr, n, "s_rsfe");
   } else if (n < 0) {
     errret(a->ciend, n, "s_rsfe");
   } else 
     return(0);
}
Пример #10
0
f_open_com (olist *a, ftnint *mask, char **mode_, char **buf_, unit **fu)
#endif
{
   unit           *b;
   ino_t           inod;
   int             n, org;
   char           *mode = "r";
   char           *abuf, c, *cbuf, errstr[80];
   char    	  buf[PATH_MAX];		/* temp buffer */
   char    	  ubuf[PATH_MAX];		/* temp buffer */
   unsigned int   need;
#if 00
   cllist64          x;
#else
   cllist          x;
#endif
   struct stat     sbuf;
   static char     seed[] = "aa";
   char		   *q = seed;
   char            ch;
   unit		  *dupunit;
   int 	  	   dupopen;
   int             istty = 0;	/* Flag to indicate whether file
				 * being opened is /dev/tty */

   /*
   extern	FILE *debugfile;
   */
   struct stat     stat_struct;
   unit           *ftnunit;

   /* bug fix 12787 : need to initialize to zero */

   /* sjc #1827: The cretin who coded this originally assumed that an
    * 80-byte temporary string would always be enough. We dynamically
    * allocate it to be 80 bytes plus whatever we can easily find out
    * about the length of the filename being passed to us. That may
    * not be enough (the string gets passed all over creation, so
    * it's hard to know) but it's better than before. Note that this
    * relies on f_open continuing not to be recursive. */

   if (a->ofnm)
      istty = !strncmp ("/dev/tty", a->ofnm, 8);
   need = a->odfnm ? a->odfnmlen : 0;
   need += a->ofnm ? a->ofnmlen : 0;
   need += 40;
   if ((*fu = ftnunit = b = map_luno (a->ounit)) == NULL)
      err(a->oerr, 101, "open");
   while (fu != &f77curunit && test_and_set( &ftnunit->lock_unit, 1L )) {
      sginap(0);
   }
   /* obtain exclusive lock for special I/O operation, this should always
   be done after the lock onthe unit has been done to avoid deadlock */
   while (test_and_set( &io_lock, 1L ))
      sginap(0);
   * buf_ = buf;

/* Fix BN 9310 . If the the terminal is being opened do not test to see if this
 * file is already connected to a fortran unit since the terminal should be
 * able to be connected to various fortran units simultaneously
 * ---ravi---1/7/91
 */

 /* From the ANSI standard: to make this clear once and for all:
 ** 	If a unit is connnected to a file that exists, execution of an OPEN
 ** statement for that unit is permitted.   If the FILE= specifier is not
 ** included in the OPEN statement, the file to be connected to the unit is
 ** the same as the file to which the unit is connected.
 ** 	If the file to be connected to the unit does not exist, but is the
 ** same as the file to which the unit is preconnected, the properties
 ** specifies by the OPEN statement become a part of the connection.
 **	If the file to be connected to the unit is not the same as the
 ** file to which the unit is conencted, the effect is as if a CLOSE
 ** statement without a STATUS= specifier had been executed for the unit
 ** immediately to the execution of the OPEN statement.
 **	If the file to be connected to the unit is the same as the file
 ** to which the unit is connected, only the BLANK= specifier may have a
 ** value different from the one currently in effect.  The position of
 ** the file is unaffected.
 **	If a file is connected to a unit, execution of an OPEN statement
 ** on that file and a different unit is not permitted
 */

   if (!istty) {
      if (dupopen = f_duped (a, ftnunit, &dupunit))
         if (!a->oshared)
            return(dupopen);
   }
   else
       dupopen = 0;

   if (a->odfnm) {
      g_char (a->odfnm, a->odfnmlen, buf);
      abuf = &buf[strlen(buf)];
   } else
      abuf = buf;
   if (b->uconn > 0 && (!a->osta || up_low (*a->osta) != 's')) {
      if (a->ofnm == 0) {
same:if (a->oblnk != 0)
	 b->ublnk = up_low (*a->oblnk) == 'z' ? 1 : 0;
	 /* Ignore this open statement if it is not a preconnected unit
	 ** otherwise redefine the unit characteristics
	 */
	 if ((b->ufd == stdin || b->ufd == stdout || b->ufd == stderr)
	   && b->ufnm == NULL)
	   dupopen = 1;
	 else
           return (0);
      }
      if (a->ofnm) {
         g_char (a->ofnm, a->ofnmlen, abuf);
         if (b->uacc == KEYED)
            mkidxname (buf, buf);
         f77inode (buf, &inod);
         if ((inod == b->uinode) && inod)
            goto same;
         buf[a->ofnmlen] = '\0';
      }
      x.cunit = a->ounit;
      x.csta = 0;
      x.cerr = a->oerr;
/* fix bug 6084 */
   /* BN-8077 */
   /* Leave the stdin, stdout, stderr alone without closing them,
    * since if that is done a normal file will be opened which will
    * have the ufd value of stdin, stdout, or stderr and mess up all
    * the conditional testing for stdin, stdout, and stderr */
      if (b->ufd == stdin || b->ufd == stdout || b->ufd == stderr) {
	 if (!dupopen) {
            b->uconn = 0;
            b->ufd = NULL;
	 }
#if 00
#define NAMEf_clos	f_clos64
#else
#define NAMEf_clos	f_clos
#endif
      } else if ((n = NAMEf_clos (&x)) != 0)
         return (n);
      b->luno = a->ounit;
#undef NAMEf_clos
   }

   org = a->oorg ? up_low (*a->oorg) : 0;
   b->umask = *mask;
   if (a->oacc == 0)
      switch (org) {
      case 'r':
	 b->uacc = DIRECT;
	 break;
      case 'i':
         if (dupopen)
           err(a->oerr, 186, "open")
	 b->uacc = KEYED;
	 break;
      default:
	 b->uacc = SEQUENTIAL;
      }
   else
      switch (up_low (*a->oacc)) {
      case 'd':
	 b->uacc = DIRECT;
	 if (org == 'i')
	    err(a->oerr, 149, "open")
	       break;
      case 'k':
	 b->uacc = KEYED;
	 if (org == 's')
	    err(a->oerr, 150, "open")
	       if (org == 'r')
	       err(a->oerr, 151, "open")
		  break;
      case 'a':
	 b->uacc = APPEND;
	 if (org == 'i')
	    err(a->oerr, 152, "open")
	       break;
/* Fix BN 11769 
 * Currently if the access parameter is not a keywords, it
 * sets it to the default ,sequential. Generate error instead.
 * ---ravi---2/21/92
 *
	      case 's':
	      default:  b->uacc = org == 'i' ? KEYED : SEQUENTIAL;
*/
      case 's':
	 b->uacc = org == 'i' ? KEYED : SEQUENTIAL;
	 break;
      default:
	 err(a->oerr, 130, "open");
      }
   if (a->oassocv && b->uacc == DIRECT)
      set_var ((ftnintu *)(b->uassocv = a->oassocv), b->umask, ASSOCV, 1);
   else
      b->uassocv = NULL;
   if (a->omaxrec && b->uacc == DIRECT)
      b->umaxrec = a->omaxrec;
   else
      b->umaxrec = 0;
   if (cbuf = a->odisp)
      switch (up_low (*cbuf++)) {
      case 'd':
	 b->udisp = DELETE;
	 break;
      case 'p':
	 b->udisp = PRINT;
	 goto checkdelete;
      case 's':
	 if (up_low (*cbuf) == 'a')
	    goto keep;
	 b->udisp = SUBMIT;
   checkdelete:
	 while (c = (*cbuf++))
	    if ((c == '/') && (c = (*cbuf)) && (up_low (c) == 'd'))
	       b->udisp |= DELETE;
	 break;
   keep:
      default:
	 b->udisp = KEEP;
      }
   else
      b->udisp = KEEP;

   b->ushared = a->oshared;
   b->ureadonly = a->oreadonly;
   if (a->oblnk && up_low (*a->oblnk) == 'z')
      b->ublnk = 1;
   else
      b->ublnk = 0;
#ifdef I90
	b->uaction = b->ureadonly ? READONLY : READWRITE;
	b->unpad = 0;
	b->udelim = DELIM_NONE;
#endif
   b->url = a->orl;
   if (a->ofm == 0) {
      if (b->uacc == DIRECT || b->uacc == KEYED) {
	 b->ufmt = 0;
	 if (!f77vms_flag_[OLD_RL])
	    b->url *= sizeof (int);
      } else
	 b->ufmt = 1;
   } else if (up_low (*a->ofm) == 'f')
      b->ufmt = 1;
   else if (up_low (*a->ofm) == 'b')
      b->ufmt = 2;
   else if (up_low (*a->ofm) == 's') {
      /* system file = direct unformatted file with record length = 1 */
      b->ufmt = 0;
      b->url = 1;
      b->uacc = DIRECT;
   } else {
      b->ufmt = 0;
      if (!f77vms_flag_[OLD_RL])
	 b->url *= sizeof (int);
      /* all sequential unformatted must need a minimum of 1K buffer to
	 avoid fseek() operations when reading which causes data to be
	 read from the disk each time and cause a 12X performance loss.
      */ 
      check_buflen( b, 1024 );
   }
   if (a->orectype)
      switch (up_low (*a->orectype)) {
      case 'f':
	 if (b->uacc != DIRECT && b->uacc != KEYED)
	    err(a->oerr, 156, "open")
	       break;
      case 'v':
	 if (b->uacc == DIRECT || b->uacc == KEYED ||
	     b->ufmt == 1)
	    err(a->oerr, 157, "open")
	       break;
      case 's':
	 if (b->uacc == DIRECT || b->uacc == KEYED ||
	     b->ufmt != 1)
	    err(a->oerr, 158, "open")
      default:
	    break;
      }
   if (a->occ == 0)
	b->ucc = (char) (b->ufmt ? ((b->luno == 6 && f77vms_flag_[VMS_CC]) ?
		CC_FORTRAN : CC_LIST) : CC_NONE);
   else
   switch (up_low (*a->occ)) {
   case 'l':
      b->ucc = CC_LIST;
      break;
   case 'f':
      b->ucc = CC_FORTRAN;
      b->ucchar = '\0';
      break;
   case 'n':
      b->ucc = CC_NONE;
      break;
   default:
      b->ucc = (char) (b->ufmt ? ((b->luno == 6 && f77vms_flag_[VMS_CC]) ?
			  CC_FORTRAN : CC_LIST) : CC_NONE);
   }

   if (!b->ufmt && b->ucc != CC_NONE)
      err(a->oerr, 162, "open");

   if (a->ofnm == 0)
#ifdef SIZEOF_LUNO_IS_64
      (void) sprintf (abuf, "fort.%lld", a->ounit);
#else
      (void) sprintf (abuf, "fort.%d", a->ounit);
#endif
   else
Пример #11
0
int parse_src_scn(struct opal_src_scn **r_src,
                  const struct opal_v6_hdr *hdr,
                  const char *buf, int buflen)
{
	struct opal_src_scn *bufsrc = (struct opal_src_scn*)buf;
	struct opal_src_scn *src;

	int offset = OPAL_SRC_SCN_STATIC_SIZE;

	int error = check_buflen(buflen, offset, __func__);
	if (error)
		return error;

/* header length can be > sizeof() as is variable sized section
 * subtract the size of the optional section
 */
	if (hdr->length < offset) {
		fprintf(stderr, "%s: section header length less than min size "
		        ". section header length %u, min size: %u\n",
		        __func__, hdr->length, offset);
		return -EINVAL;
	}

	*r_src = malloc(sizeof(struct opal_src_scn));
	if(!*r_src)
		return -ENOMEM;
	src = *r_src;

	src->v6hdr = *hdr;
	src->version = bufsrc->version;
	src->flags = bufsrc->flags;
	src->wordcount = bufsrc->wordcount;
	src->srclength = be16toh(bufsrc->srclength);
	src->ext_refcode2 = be32toh(bufsrc->ext_refcode2);
	src->ext_refcode3 = be32toh(bufsrc->ext_refcode3);
	src->ext_refcode4 = be32toh(bufsrc->ext_refcode4);
	src->ext_refcode5 = be32toh(bufsrc->ext_refcode5);
	src->ext_refcode6 = be32toh(bufsrc->ext_refcode6);
	src->ext_refcode7 = be32toh(bufsrc->ext_refcode7);
	src->ext_refcode8 = be32toh(bufsrc->ext_refcode8);
	src->ext_refcode9 = be32toh(bufsrc->ext_refcode9);

	memcpy(src->primary_refcode, bufsrc->primary_refcode,
	       OPAL_SRC_SCN_PRIMARY_REFCODE_LEN);

	src->fru_count = 0;
	if (src->flags & OPAL_SRC_ADD_SCN) {
		error = check_buflen(buflen, offset + sizeof(struct opal_src_add_scn_hdr), __func__);
		if (error) {
			free(src);
			return error;
		}

		src->addhdr.flags = bufsrc->addhdr.flags;
		src->addhdr.id = bufsrc->addhdr.id;
		if (src->addhdr.id != OPAL_FRU_SCN_ID) {
			fprintf(stderr, "%s: invalid section id, expecting 0x%x but found"
			        " 0x%x", __func__, OPAL_FRU_SCN_ID, src->addhdr.id);
			free(src);
			return -EINVAL;
		}
		src->addhdr.length = be16toh(bufsrc->addhdr.length);
		offset += sizeof(struct opal_src_add_scn_hdr);

		while(offset < src->srclength && src->fru_count < OPAL_SRC_FRU_MAX) {
			error = parse_fru_scn(&(src->fru[src->fru_count]), buf + offset, buflen - offset);
			if (error < 0) {
				free(src);
				return error;
			}
			offset += error;
			src->fru_count++;
		}
	}

	return 0;
}