home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZOO21E.EXE / VMSTIME.C < prev    next >
C/C++ Source or Header  |  1991-07-11  |  7KB  |  203 lines

  1. /* vmstime.c */
  2. #ifndef LINT
  3. static char sccsid[]="$Source: /usr/home/dhesi/zoo/RCS/vmstime.c,v $\n\
  4. $Id: vmstime.c,v 1.6 91/07/06 12:20:26 dhesi Exp $";
  5. #endif
  6. /*
  7. This file was graciously supplied by Randal Barnes to support preservation
  8. of file timestamps under VAX/VMS.  I claim no copyright on the contents of
  9. this file.  I assume that neither do its authors.  However, if you adapt
  10. this code for your own use, I recommend preserving author attributions.
  11.  
  12.                                 -- Rahul Dhesi  1991/07/04
  13. */
  14.  
  15. /*
  16. *  This module sets a VAX/VMS file's creation and revision date/time to a
  17. *  specified date/time.
  18. *
  19. *  Inputs       Type            Description
  20. *  ------       ----            -----------
  21. *  path         char *          Name of file to be modified
  22. *  date         int             Binary formatted date to be applied to the file
  23. *  time         int             Binary formatted time to be applied to the file
  24. *
  25. *  Outputs      Type            Description
  26. *  -------      ----            -----------
  27. *  Modified file
  28. *
  29. *  Randy Magnuson - (612) 542-5052
  30. *  Randal Barnes  - (612) 542-5021
  31. *  Honeywell Inc. - Military Avionics Division
  32. *  April 12, 1990
  33. */
  34.  
  35. #include <stdio.h>
  36. #include <rms.h>
  37. #include <fibdef.h>
  38. #include <atrdef.h>
  39. #include <descrip.h>
  40. #include <iodef.h>
  41. #include <libdtdef.h>
  42.  
  43. int setutime (char *path, unsigned int date, unsigned int time)
  44. {
  45.    char EName [NAM$C_MAXRSS],   /*  Expanded String Area                */
  46.         RName [NAM$C_MAXRSS],   /*  Resultant String Area               */
  47.         date_str [50];          /*  Holds intermediate ASCII date/time  */
  48.  
  49.    short iosb [4];              /*  I/O status block for sys calls      */
  50.  
  51.    int  status,                 /*  Condition code for sys calls, etc.  */
  52.         i,                      /*  Temp index for looping thru arrays  */
  53.         chan,                   /*  Channel to device containing file   */
  54.         Cdate [2],              /*  VMS binary time - creation date     */
  55.         Rdate [2],              /*  VMS binary time - revision date     */
  56.         datetimecontext = 0,    /*  Context for time conv. lib calls    */
  57.         intime = LIB$K_INPUT_FORMAT,  /*  Constant for time lib calls   */
  58.         intdate [2];            /*  VMS binary time - temp              */
  59.  
  60.    struct FAB Fab;              /*  RMS File Access Block               */
  61.    struct NAM Nam;              /*  RMS Name Block                      */
  62.    static struct fibdef Fib;    /*  RMS File Information Block          */
  63.    struct atrdef Atr [] =       /*  File attribute struct               */
  64.       {
  65.          { sizeof (Cdate), ATR$C_CREDATE, &Cdate [0] }, /*  Creation date  */
  66.          { sizeof (Rdate), ATR$C_REVDATE, &Rdate [0] }, /*  Revision date  */
  67.          {              0,             0,         0 }
  68.       };
  69.    struct dsc$descriptor devnam =       /*  Device name descriptor      */
  70.       { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi [1] };
  71.    struct dsc$descriptor FibDesc =      /*  File ID descriptor          */
  72.       { sizeof (Fib), 0, 0, &Fib };
  73.    struct dsc$descriptor_s FileName =   /*  File name descriptor        */
  74.       { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
  75.  
  76.    /*  Time conversion format specification  */
  77.    $DESCRIPTOR (datetimeformat, "|!Y4!MN0!D0|!H04!M0!S0!C2|");
  78.  
  79.    /*  String descriptor for intermediate date/time string  */
  80.    $DESCRIPTOR (date_desc, date_str);
  81.  
  82.  
  83. /*
  84. *  Fill out our File Access Block, Name Block, and Extended Attribute Block so
  85. *  we can parse the file name.
  86. */
  87.    Fab = cc$rms_fab;
  88.    Nam = cc$rms_nam;
  89.  
  90.    Fab.fab$l_fna = path;
  91.    Fab.fab$b_fns = strlen (path);
  92.    Fab.fab$l_nam = &Nam;
  93.  
  94.    Nam.nam$l_esa = &EName;
  95.    Nam.nam$b_ess = sizeof (EName);
  96.    Nam.nam$l_rsa = &RName;
  97.    Nam.nam$b_rss = sizeof (RName);
  98.  
  99.  
  100. /*
  101. *  Do a parse and search to fill out the NAM block.
  102. */
  103.    status = sys$parse(&Fab);
  104.    if (!(status & 1))
  105.       return 0;
  106.    status = sys$search(&Fab);
  107.    if (!(status & 1))
  108.       return 0;
  109.  
  110.  
  111. /*
  112. *  Open a channel to the device that the file resides on.
  113. */
  114.    devnam.dsc$w_length = Nam.nam$t_dvi [0];
  115.    status = SYS$ASSIGN (&devnam, &chan, 0, 0);
  116.    if (!(status & 1))
  117.       return 0;
  118.  
  119.  
  120. /*
  121. *  Initialize the FIB
  122. */
  123.    Fib.fib$r_acctl_overlay.fib$l_acctl = FIB$M_NORECORD;
  124.    for (i = 0; i < 3; i++)
  125.    {
  126.       Fib.fib$r_fid_overlay.fib$w_fid [i] = Nam.nam$w_fid [i];
  127.       Fib.fib$r_did_overlay.fib$w_did [i] = Nam.nam$w_did [i];
  128.    }
  129.  
  130.  
  131. /*
  132. *  Set up the file name descriptor for the QIO
  133. */
  134.    FileName.dsc$a_pointer = Nam.nam$l_name;
  135.    FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver;
  136.  
  137.  
  138. /*
  139. *  Use the IO$_ACCESS function to return info about the file.
  140. */
  141.    status = SYS$QIOW (0, chan, IO$_ACCESS, &iosb, 0, 0,
  142.                       &FibDesc, &FileName, 0, 0, 0, 0);
  143.    if (!(status & 1))
  144.       return 0;
  145.    status = iosb [0];
  146.    if (!(status & 1))
  147.       return 0;
  148.  
  149.  
  150. /*
  151. *  Set up a date/time format that we can easily convert to - "YYMMDD HHMMSS"
  152. */
  153.    status = LIB$INIT_DATE_TIME_CONTEXT (&datetimecontext, &intime,
  154.                                         &datetimeformat);
  155.    if (!(status & 1))
  156.       return 0;
  157.  
  158.  
  159. /*
  160. *  Convert the MS-DOS time ints to our ASCII format.
  161. */
  162.    date_desc.dsc$w_length = sprintf (date_str, "%04d%02d%02d %02d%02d%02d00",
  163.                                       ((date >> 9) & 0x7f) + 1980, /* year */
  164.                                       (date >> 5) & 0x0f,          /* month */
  165.                                       date & 0x1f,                 /* day */
  166.                                       (time >> 11)& 0x1f,          /* hour */
  167.                                       (time >> 5) & 0x3f,          /* min */
  168.                                       (time & 0x1f) * 2);          /* sec */
  169.  
  170.  
  171. /*
  172. *  Convert our ASCII formatted date/time to VMS internal time format
  173. */
  174.    status = LIB$CONVERT_DATE_STRING (&date_desc, &intdate, &datetimecontext);
  175.    if (!(status & 1))
  176.       return 0;
  177.  
  178.  
  179. /*
  180. *  Fill in the creation date and revision date fields in the Extended Attribute
  181. *  Block with the date and time from the zoo file.
  182. */
  183.    Cdate [0] = Rdate [0] = intdate [0];
  184.    Cdate [1] = Rdate [1] = intdate [1];
  185.  
  186. /*
  187. *  Modify the file
  188. */
  189.    status = SYS$QIOW (0, chan, IO$_MODIFY, &iosb, 0, 0,
  190.                       &FibDesc, &FileName, 0, 0, &Atr, 0);
  191.    if (!(status & 1))
  192.       return 0;
  193.    status = iosb [0];
  194.    if (!(status & 1))
  195.       return 0;
  196.  
  197.  
  198. /*
  199. *  Okee dokee.
  200. */
  201.    return 1;
  202. }
  203.