44
44
* If the container file name has more than DAT__SZNAM (15) characters,
45
45
* the name stored in the handle associated with the top level object
46
46
* will be truncated and so will not equal the name of the container
47
- * file. So only use the first DAT__SZNAM characters when comparing
47
+ * file. So only use the first DAT__SZNAM characters when comparing
48
48
* the handle name with the container file name.
49
+ * 7-MAY-2020 (DSB):
50
+ * The name associated with the top-level handle may include a directory
51
+ * path. This needs to be removed before comparing it with the name from
52
+ * the supplied handle, which will never include a path.
49
53
* {enter_further_changes_here}
50
54
51
55
* Copyright:
89
93
*-
90
94
*/
91
95
#include <strings.h>
96
+ #include <string.h>
92
97
#include <pthread.h>
93
98
94
99
#include "ems.h"
95
100
#include "sae_par.h"
96
101
#include "dat1.h"
97
102
#include "dat_err.h"
98
103
104
+ #if __MINGW32__
105
+ /* Use Windows separator */
106
+ #define DIRSEP '\\'
107
+ #else
108
+ #define DIRSEP '/'
109
+ #endif
110
+
99
111
int dat1IsTopLevel ( const HDSLoc * loc , int * status ){
100
112
101
113
/* Local Variables; */
114
+ const char * pname ;
102
115
int result ;
103
116
Handle * parent ;
104
117
@@ -118,7 +131,18 @@ int dat1IsTopLevel( const HDSLoc *loc, int *status ){
118
131
truncation of the object name to DAT__SZNAM characters), it is a
119
132
top level locator. */
120
133
} else if ( !parent -> parent && loc -> handle -> name && parent -> name ) {
121
- result = !strncasecmp ( loc -> handle -> name , parent -> name , DAT__SZNAM );
134
+
135
+ /* If the parent name contains a directory path, get a pointer to the
136
+ first character in the file name. */
137
+ pname = strrchr ( parent -> name , DIRSEP );
138
+ if ( pname ) {
139
+ pname ++ ;
140
+ } else {
141
+ pname = parent -> name ;
142
+ }
143
+
144
+ /* Do the comparison, case-insensitive. */
145
+ result = !strncasecmp ( loc -> handle -> name , pname , DAT__SZNAM );
122
146
}
123
147
124
148
/* Return the result. */
0 commit comments