[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::decc

Title:DECC
Notice:General DEC C discussions
Moderator:TLE::D_SMITHNTE
Created:Fri Nov 13 1992
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2212
Total number of notes:11045

2202.0. "VMS DECC ?? open file version #" by CSC32::I_WALDO () Wed May 28 1997 15:15

    The following is from a customer:
    
    
      System SEA is a VAXstation 4000-90 running VMS V6.2 in a VAXcluster.
      (HW Ver=017800000000000013000202, SID=13000202, XSID=04010002,DSN=V1.2)
    
    DEC C V5.5-002 on OpenVMS VAX V6.2
    DEC C V5.5-002 on OpenVMS Alpha V6.2-1H2
    
    Question 1 -
    
    When a file which does not exist is opened for write using
    fopen ("foo.bar", "w") then version one is created.  If one or
    more version(s) of the file already exist then a new version
    is created.
    
    The question is can the version number of the open file be
    determined using DEC C run time library calls?  I know how to
    obtain the information using SYS$PARSE but it is desirable to
    use DEC C RTL calls where possible in the application I am
    writing.
    
    Question 2 -
    
    Can the DEC C RTL system function be used in an exit handler
    which has been established with the DEC C RTL atexit function
    call?
    
                                             
T.RTitleUserPersonal
Name
DateLines
2202.1Options...XDELTA::HOFFMANSteve, OpenVMS EngineeringWed May 28 1997 16:0428
:...
:    The question is can the version number of the open file be
:    determined using DEC C run time library calls?  I know how to
:    obtain the information using SYS$PARSE but it is desirable to
:    use DEC C RTL calls where possible in the application I am
:    writing.

   Not in a portable program -- the run-time library provides a portable
   interface, and version numbers are a feature specific to the file
   structures used by OpenVMS and a few other operating systems.
   Most (all?) UNIX file systems lack a version number construct.

   There are non-portable ways, however...  One can use the "acc"
   keyword on the open() call to gain access to the FAB and RAB,
   and from there one can gain access to all manner of information
   on the file.

   There are also ways to open an existing file, or -- if a file
   is not found -- create a new version, if that is the goal...
    
:    Can the DEC C RTL system function be used in an exit handler
:    which has been established with the DEC C RTL atexit function
:    call?

   I would see no reason not -- I assume there is a question or a
   problem seen here, as it would take ten minutes to create a test
   program to verify this...
    
2202.2getname(file_descr) or getname(fileno(file_pointer))TLE::BORISBoris Gubenko, DEC C RTLWed May 28 1997 17:5948
>     
>     The question is can the version number of the open file be
>     determined using DEC C run time library calls?  I know how to
>     obtain the information using SYS$PARSE but it is desirable to
>     use DEC C RTL calls where possible in the application I am
>     writing.

  getname() function is, probably, what you're looking for:


CC

  Run-time_functions

    getname

       Returns the file specification associated with a file descriptor.

       Syntax:

            #include <unixio.h>

            char *getname(int file_descriptor, char *buffer,...);

       where the ...  is an optional argument that can be either 1 or 0.
       If you specify 1, getname returns the directory specification in
       OpenVMS format.  If you specify 0, getname returns the directory
       specification (path name) in UNIX style format.  If you do not
       specify this argument, getname returns the file name according to
       your current command-language interpreter.

>     
>     Can the DEC C RTL system function be used in an exit handler
>     which has been established with the DEC C RTL atexit function
>     call?
>     

  As Steve mentioned in .1, there is no obvious reason not. The system()
  routine is based on LIB$SPAWN(WAIT) call and utilities structures
  maintained by the CRTL to describe processes created by vfork(), exec*()
  and system() routines.

  The exit handler established by CRTL itself analyzes these structures
  and kills all child processes found. Because this handler will be invoked
  *after* the handler established by the atexit() function, there shouldn't
  be any problem.

  Boris
2202.3also strchr(), sorryTLE::BORISBoris Gubenko, DEC C RTLWed May 28 1997 18:1926
  I forgot to mention in my previous reply, that you need to locate a ';'
  character in the string returned by getname() if you're interested only
  in file's version. Try example below.

  Boris

x.c
===

#include <stdio.h>
#include <string.h>
#include <unixio.h>

main()
{
        char s[256], *p;
        FILE *fp = fopen( __FILE__ , "r");

        if ( fp ) {
                if ( getname(fileno(fp), s, 1) ) {
                        puts(s);
                        if ( (p = strchr(s,';')) )
                                puts(++p);
                }
        }
}
2202.4Beware Of Home-Grown File Parsing...XDELTA::HOFFMANSteve, OpenVMS EngineeringThu May 29 1997 10:4714
:  I forgot to mention in my previous reply, that you need to locate a ';'
:  character in the string returned by getname() if you're interested only
:  in file's version. Try example below.

   I would recommend using the FAB and RAB mechanism and sys$parse.
   (We (OpenVMS) really need to implement this in an RTL somewhere.)
   I would tend to avoid parsing the file specification when possible,
   and would prefer to pass it to RMS for parsing.

   (Among other reasons: we are extending the character set permitted
   in certain file naming sitations.  We already allow the use of "."
   as a version seperator -- though getname() might prefer to return
   ";" over "." as the seperator.)
2202.5thanks!CSC32::I_WALDOThu May 29 1997 13:011
    Thanks for the answers!  I learn stuff everyday.