OLD | NEW |
1 /* $LP: LPlib/source/LPdir_vms.c,v 1.20 2004/08/26 13:36:05 _cvs_levitte Exp $ *
/ | 1 /* $LP: LPlib/source/LPdir_vms.c,v 1.20 2004/08/26 13:36:05 _cvs_levitte Exp $ *
/ |
2 /* | 2 /* |
3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org> | 3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org> |
4 * All rights reserved. | 4 * All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include <namdef.h> | 33 #include <namdef.h> |
34 #include <rmsdef.h> | 34 #include <rmsdef.h> |
35 #include <libfildef.h> | 35 #include <libfildef.h> |
36 #include <lib$routines.h> | 36 #include <lib$routines.h> |
37 #include <strdef.h> | 37 #include <strdef.h> |
38 #include <str$routines.h> | 38 #include <str$routines.h> |
39 #include <stsdef.h> | 39 #include <stsdef.h> |
40 #ifndef LPDIR_H | 40 #ifndef LPDIR_H |
41 #include "LPdir.h" | 41 #include "LPdir.h" |
42 #endif | 42 #endif |
| 43 #include "vms_rms.h" |
43 | 44 |
44 /* Because some compiler options hide this macor */ | 45 /* Some compiler options hide EVMSERR. */ |
45 #ifndef EVMSERR | 46 #ifndef EVMSERR |
46 #define EVMSERR»» 65535 /* error for non-translatable VMS errors */ | 47 # define EVMSERR» 65535 /* error for non-translatable VMS errors */ |
47 #endif | 48 #endif |
48 | 49 |
49 struct LP_dir_context_st | 50 struct LP_dir_context_st |
50 { | 51 { |
51 unsigned long VMS_context; | 52 unsigned long VMS_context; |
52 #ifdef NAML$C_MAXRSS | 53 char filespec[ NAMX_MAXRSS+ 1]; |
53 char filespec[NAML$C_MAXRSS+1]; | 54 char result[ NAMX_MAXRSS+ 1]; |
54 char result[NAML$C_MAXRSS+1]; | |
55 #else | |
56 char filespec[256]; | |
57 char result[256]; | |
58 #endif | |
59 struct dsc$descriptor_d filespec_dsc; | 55 struct dsc$descriptor_d filespec_dsc; |
60 struct dsc$descriptor_d result_dsc; | 56 struct dsc$descriptor_d result_dsc; |
61 }; | 57 }; |
62 | 58 |
63 const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) | 59 const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory) |
64 { | 60 { |
65 int status; | 61 int status; |
66 char *p, *r; | 62 char *p, *r; |
67 size_t l; | 63 size_t l; |
68 unsigned long flags = 0; | 64 unsigned long flags = 0; |
| 65 |
| 66 /* Arrange 32-bit pointer to (copied) string storage, if needed. */ |
| 67 #if __INITIAL_POINTER_SIZE == 64 |
| 68 # pragma pointer_size save |
| 69 # pragma pointer_size 32 |
| 70 char *ctx_filespec_32p; |
| 71 # pragma pointer_size restore |
| 72 char ctx_filespec_32[ NAMX_MAXRSS+ 1]; |
| 73 #endif /* __INITIAL_POINTER_SIZE == 64 */ |
| 74 |
69 #ifdef NAML$C_MAXRSS | 75 #ifdef NAML$C_MAXRSS |
70 flags |= LIB$M_FIL_LONG_NAMES; | 76 flags |= LIB$M_FIL_LONG_NAMES; |
71 #endif | 77 #endif |
72 | 78 |
73 if (ctx == NULL || directory == NULL) | 79 if (ctx == NULL || directory == NULL) |
74 { | 80 { |
75 errno = EINVAL; | 81 errno = EINVAL; |
76 return 0; | 82 return 0; |
77 } | 83 } |
78 | 84 |
79 errno = 0; | 85 errno = 0; |
80 if (*ctx == NULL) | 86 if (*ctx == NULL) |
81 { | 87 { |
82 size_t filespeclen = strlen(directory); | 88 size_t filespeclen = strlen(directory); |
83 char *filespec = NULL; | 89 char *filespec = NULL; |
84 | 90 |
85 /* MUST be a VMS directory specification! Let's estimate if it is. */ | 91 /* MUST be a VMS directory specification! Let's estimate if it is. */ |
86 if (directory[filespeclen-1] != ']' | 92 if (directory[filespeclen-1] != ']' |
87 && directory[filespeclen-1] != '>' | 93 && directory[filespeclen-1] != '>' |
88 && directory[filespeclen-1] != ':') | 94 && directory[filespeclen-1] != ':') |
89 { | 95 { |
90 errno = EINVAL; | 96 errno = EINVAL; |
91 return 0; | 97 return 0; |
92 } | 98 } |
93 | 99 |
94 filespeclen += 4; /* "*.*;" */ | 100 filespeclen += 4; /* "*.*;" */ |
95 | 101 |
96 if (filespeclen > | 102 if (filespeclen > NAMX_MAXRSS) |
97 #ifdef NAML$C_MAXRSS | |
98 » NAML$C_MAXRSS | |
99 #else | |
100 » 255 | |
101 #endif | |
102 » ) | |
103 { | 103 { |
104 errno = ENAMETOOLONG; | 104 errno = ENAMETOOLONG; |
105 return 0; | 105 return 0; |
106 } | 106 } |
107 | 107 |
108 *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX)); | 108 *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX)); |
109 if (*ctx == NULL) | 109 if (*ctx == NULL) |
110 { | 110 { |
111 errno = ENOMEM; | 111 errno = ENOMEM; |
112 return 0; | 112 return 0; |
113 } | 113 } |
114 memset(*ctx, '\0', sizeof(LP_DIR_CTX)); | 114 memset(*ctx, '\0', sizeof(LP_DIR_CTX)); |
115 | 115 |
116 strcpy((*ctx)->filespec,directory); | 116 strcpy((*ctx)->filespec,directory); |
117 strcat((*ctx)->filespec,"*.*;"); | 117 strcat((*ctx)->filespec,"*.*;"); |
| 118 |
| 119 /* Arrange 32-bit pointer to (copied) string storage, if needed. */ |
| 120 #if __INITIAL_POINTER_SIZE == 64 |
| 121 # define CTX_FILESPEC ctx_filespec_32p |
| 122 /* Copy the file name to storage with a 32-bit pointer. */ |
| 123 ctx_filespec_32p = ctx_filespec_32; |
| 124 strcpy( ctx_filespec_32p, (*ctx)->filespec); |
| 125 #else /* __INITIAL_POINTER_SIZE == 64 */ |
| 126 # define CTX_FILESPEC (*ctx)->filespec |
| 127 #endif /* __INITIAL_POINTER_SIZE == 64 [else] */ |
| 128 |
118 (*ctx)->filespec_dsc.dsc$w_length = filespeclen; | 129 (*ctx)->filespec_dsc.dsc$w_length = filespeclen; |
119 (*ctx)->filespec_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | 130 (*ctx)->filespec_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
120 (*ctx)->filespec_dsc.dsc$b_class = DSC$K_CLASS_S; | 131 (*ctx)->filespec_dsc.dsc$b_class = DSC$K_CLASS_S; |
121 (*ctx)->filespec_dsc.dsc$a_pointer = (*ctx)->filespec; | 132 (*ctx)->filespec_dsc.dsc$a_pointer = CTX_FILESPEC; |
122 (*ctx)->result_dsc.dsc$w_length = 0; | |
123 (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | |
124 (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D; | |
125 (*ctx)->result_dsc.dsc$a_pointer = 0; | |
126 } | 133 } |
127 | 134 |
128 (*ctx)->result_dsc.dsc$w_length = 0; | 135 (*ctx)->result_dsc.dsc$w_length = 0; |
129 (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T; | 136 (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T; |
130 (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D; | 137 (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D; |
131 (*ctx)->result_dsc.dsc$a_pointer = 0; | 138 (*ctx)->result_dsc.dsc$a_pointer = 0; |
132 | 139 |
133 status = lib$find_file(&(*ctx)->filespec_dsc, &(*ctx)->result_dsc, | 140 status = lib$find_file(&(*ctx)->filespec_dsc, &(*ctx)->result_dsc, |
134 &(*ctx)->VMS_context, 0, 0, 0, &flags); | 141 &(*ctx)->VMS_context, 0, 0, 0, &flags); |
135 | 142 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 errno = EVMSERR; | 197 errno = EVMSERR; |
191 vaxc$errno = status; | 198 vaxc$errno = status; |
192 return 0; | 199 return 0; |
193 } | 200 } |
194 return 1; | 201 return 1; |
195 } | 202 } |
196 errno = EINVAL; | 203 errno = EINVAL; |
197 return 0; | 204 return 0; |
198 } | 205 } |
199 | 206 |
OLD | NEW |