1 /*
  2 
  3 
  4 
  5    COPYRIGHT 1973
  6    MASSACHUSETTS INSTITUTE OF TECHNOLOGY
  7    CAMBRIDGE, MASSACHUSETTS  02139
  8    (ALL RIGHTS RESERVED)
  9 
 10 
 11 
 12    Module Name:     compare_paths_
 13 
 14    Type of Program:           subroutine
 15 
 16    External Name:   compare_paths_
 17 
 18    Entry Point:     compare_paths_
 19 
 20    Purpose:                   Performs an expand_path_ followed by an hcs_$status_long to check if the UID's of two
 21    (possibly relative) pathnames indicate the same entity.
 22 
 23    Original Author: Andrew H. Mason
 24 
 25    Maintained by:   RDMS Staff
 26 
 27    Notes:           dcl compare_paths_ ext entry(char(*), char(*), fixed bin(17), fixed bin(35));
 28 
 29    call compare_paths_(PATH1,PATH2,SAME,CODE);
 30    PATH1 is the first (relative) pathname.
 31    PATH2 is the second (relative) pathname.
 32    if code=0 then SAME=1 => paths mean the same entity, SAME=0 => paths do not mean the same entity.
 33    if code^=0 then code is a file system error code and SAME = 1 or 2 to indicate which pathname
 34    caused the error.  This program will chase through links.
 35 */
 36 ^L
 37 compare_paths_: proc (PATH1, PATH2, SAME, CODE);
 38 
 39 dcl  PATH1 char (*);
 40 dcl  PATH2 char (*);
 41 dcl  SAME fixed bin (17);
 42 dcl  CODE fixed bin (35);
 43 
 44 dcl  uid1 bit (36) aligned;
 45 dcl  uid2 bit (36) aligned;
 46 
 47 dcl  dirname char (168) aligned;
 48 dcl  entryname char (32) aligned;
 49 
 50 dcl  chase fixed bin (1) init (1);
 51 dcl  code fixed bin (35);
 52 dcl  pname_len fixed bin (17);
 53 
 54 dcl  area_ptr ptr init (null ());
 55 
 56 dcl 1 branch aligned,
 57     2 (type bit (2),
 58      nnames bit (16),
 59      nrp bit (18),
 60      dtm bit (36),
 61      dtu bit (36),
 62      mode bit (5),
 63      padding bit (13),
 64      records bit (18),
 65      dtd bit (36),
 66      dtem bit (36),
 67      acct bit (36),
 68      curlen bit (12),
 69      bitcnt bit (24),
 70      did bit (4),
 71      mdid bit (4),
 72      copysw bit (1),
 73      pad2 bit (9),
 74      rbs (0:2) bit (6),
 75      uid bit (36)) unaligned;
 76 
 77 dcl  addr builtin;
 78 dcl  length builtin;
 79 dcl  null builtin;
 80 
 81 dcl  expand_path_ ext entry (ptr, fixed bin (17), ptr, ptr, fixed bin (35));
 82 dcl  hcs_$status_long ext entry (char (*) aligned, char (*) aligned, fixed bin (1), ptr, ptr, fixed bin (35));
 83 dcl  error_table_$no_s_permission ext fixed bin (35);
 84 ^L
 85           if PATH1 = PATH2 then do;                         /* if strings are identical then paths are */
 86                SAME = 1;
 87                code = 0;
 88                goto finish;
 89           end;
 90 
 91 /*        strings aren't the same, have to look more closely */
 92 
 93           SAME = 1;
 94 
 95           begin;
 96 
 97 dcl  dirname_ptr ptr init (addr (dirname));
 98 dcl  entryname_ptr ptr init (addr (entryname));
 99 dcl  eptr ptr init (addr (branch));
100 
101           call expand_path_ (addr (PATH1), length (PATH1), dirname_ptr, entryname_ptr, code);
102           if code ^= 0 then go to finish;
103           call hcs_$status_long (dirname, entryname, chase, eptr, area_ptr, code);
104           if code = error_table_$no_s_permission then goto no_status;
105           if code ^= 0 then go to finish;
106           uid1 = uid;
107           SAME = 2;
108           call expand_path_ (addr (PATH2), length (PATH2), dirname_ptr, entryname_ptr, code);
109           if code ^= 0 then go to finish;
110           call hcs_$status_long (dirname, entryname, chase, eptr, area_ptr, code);
111           if code = error_table_$no_s_permission then goto no_status;
112           if code ^= 0 then go to finish;
113           uid2 = uid;
114           if uid1 = uid2
115           then SAME = 1;
116           else SAME = 0;
117           end;
118 finish:
119           CODE = code;
120           return;
121 
122 no_status:                                                  /* can't get id */
123           goto finish;
124 
125      end compare_paths_;