Ticket #187: cwd.note

File cwd.note, 5.2 KB (added by Shmuel (Seymour J.) Metz, 4 years ago)

Implementation notes on suggested fix - somewhat dated, but the OS/2 API hasn't changed

Line 
1Issue: Cwd->abs_path('F:testpl.cmd') generates the message
2  sys_is_absolute2 = Cwd
3  LF
4  sys_is_relative2 = Cwd
5
6The string appears in perlE147.dll but I couldn't find an associated source file.
7
8Issue: Cwd->abs_path('F:testpl.cmd') returns F:/ecs/testpl.cmd/Cwd instead of F:/ecs/testpl.cmd
9
10Query: is it legal to do
11CD \\server\netname\directoru
12for directories on a LAN drive. Should getdcwd support that?
13
14Q:\programs\perl\lib\5.10.0\os2\Cwd.pm
15H:\vendors\cpan\PathTools-3.39_01\Cwd.pm
16H:\vendors\cpan\PathTools-3.39_01\Cwd.xs
17H:\vendors\cpan\PathTools-3.39_01\lib\File\Spec\OS2.pm
18H:\vendors\cpan\PathTools-3.39_01\lib\File\Spec\Win32.pm
19
20EMX
21
22char *getcwd (char *buffer, size_t size);
23
24int _getcwd1 (char *buffer, char drive);
25Does not check size!
26
27char *_getcwd2 (char *buffer, int size);
28
29char _getdrive (void);
30
31OS/2
32
33
34Q:\OS2TK45\h\os2.h
35
36
37Gets the current default drive for the requesting process.
38
39
40#define INCL_DOSFILEMGR
41#include <os2.h>
42
43PULONG    pdisknum;  /*  Address of the number of the default drive. */
44PULONG    plogical;  /*  Address of the bit map where the system returns the mapping of the logical drives. */
45APIRET    ulrc;      /*  Return Code. */
46
47ulrc = DosQueryCurrentDisk(pdisknum, plogical);
48
49pdisknum (PULONG) - output
50Address of the number of the default drive.
51
52The value 1 means drive A, 2 means drive B, 3 means drive C, and so on. The maximum possible value is 26, which corresponds to drive Z.
53
54plogical (PULONG) - output
55Address of the bit map where the system returns the mapping of the logical drives.
56
57This bit map is stored in the low-order portion of the 32-bit area.
58
59Logical drives A to Z have one-to-one mapping with bit positions 0 to 25 of the map; for example, bit 0 represents drive A, bit 1 represents drive B, and so on. The settings of these bits indicate which drives exist, as follows:
60
610The logical drive does not exist.
621The logical drive exists.
63
64ulrc (APIRET) - returns
65Return Code.
66
67DosQueryCurrentDisk returns the following value:
68
690 NO_ERROR
70
71For a full list of error codes, see Errors.
72
73Gets the full path of the current directory for the requesting process on the specified drive.
74
75
76#define INCL_DOSFILEMGR
77#include <os2.h>
78
79ULONG     disknum;  /*  The drive number. */
80PBYTE     pBuf;     /*  Address of the full path of the current directory. */
81PULONG    pcbBuf;   /*  Address of the length, in bytes, of the pBuf buffer. */
82APIRET    ulrc;     /*  Return Code. */
83
84ulrc = DosQueryCurrentDir(disknum, pBuf, pcbBuf);
85
86disknum (ULONG) - input
87The drive number.
88
89The value 0 means the current drive, 1 means drive A, 2 means drive B, 3 means drive C, and so on. The maximum possible value is 26, which corresponds to drive Z.
90
91pBuf (PBYTE) - output
92Address of the full path of the current directory.
93
94pcbBuf (PULONG) - in/out
95Address of the length, in bytes, of the pBuf buffer.
96
97
98Input This field contains the length, in bytes, of the directory path buffer.
99
100Output If an error is returned because the buffer is too small, this field contains the required length, in bytes, of the buffer.
101
102ulrc (APIRET) - returns
103Return Code.
104
105DosQueryCurrentDir returns one of the following values:
106
1070 NO_ERROR
10815 ERROR_INVALID_DRIVE
10926 ERROR_NOT_DOS_DISK
110108 ERROR_DRIVE_LOCKED
111111 ERROR_BUFFER_OVERFLOW
112
113For a full list of error codes, see Errors.
114
115
116
117
118
119For Cwd.pm
120
121sub _os2_cwd {
122    my $drive = shift;
123    $ENV{'PWD'} = `cmd /c cd $drive\:`;
124    chomp $ENV{'PWD'};
125    $ENV{'PWD'} =~ s:\\:/:g ;
126    return $ENV{'PWD'};
127}
128
129
130
131For Cwd.xs, assuming EMX
132
133#if defined(OS2)
134void
135getdcwd(...)
136PROTOTYPE: ENABLE
137PPCODE:
138{
139    dXSTARG;
140    char drive;
141    char *dir;
142
143    /* Drive 0 is the current drive, A-Z are A-Z. */
144    if ( items == 0 ||
145        (items == 1 && (!SvOK(ST(0)) || (SvPOK(ST(0)) && !SvCUR(ST(0))))))
146        drive = 0;
147    else if (items == 1 && SvPOK(ST(0)) && SvCUR(ST(0)) &&
148             isALPHA(SvPVX(ST(0))[0]))
149        drive = SvPVX(ST(0))[0];
150    else
151        croak("Usage: getdcwd(DRIVE)");
152
153    New(0,dir,MAXPATHLEN,char);
154    if (_getcwd1(dir, drive)) {
155        sv_setpv_mg(TARG, dir);
156        SvPOK_only(TARG);
157    }
158    else
159        sv_setsv(TARG, &PL_sv_undef);
160
161    Safefree(dir);
162
163    XSprePUSH; PUSHs(TARG);
164#ifndef INCOMPLETE_TAINTS
165    SvTAINTED_on(TARG);
166#endif
167}
168
169#endif
170
171
172
173
174For Cwd.xs, if not using EMX,
175
176#if defined(OS2)
177
178#define INCL_DOSFILEMGR
179#include <os2.h>
180
181void
182getdcwd(...)
183PROTOTYPE: ENABLE
184PPCODE:
185{
186    dXSTARG;
187    ULONG drive;
188    PULONG *dir;
189
190    /* Drive 0 is the current drive, 1 is A:, 2 is B:, 3 is C: and so on. */
191    if ( items == 0 ||
192        (items == 1 && (!SvOK(ST(0)) || (SvPOK(ST(0)) && !SvCUR(ST(0))))))
193        drive = 0;
194    else if (items == 1 && SvPOK(ST(0)) && SvCUR(ST(0)) &&
195             isALPHA(SvPVX(ST(0))[0]))
196        drive = toUPPER(SvPVX(ST(0))[0]) - 'A' + 1;
197    else
198        croak("Usage: getdcwd(DRIVE)");
199
200    New(0,dir,MAXPATHLEN,char);
201    if (_getdcwd(drive, dir, MAXPATHLEN)) {
202        sv_setpv_mg(TARG, dir);
203        SvPOK_only(TARG);
204    }
205    else
206        sv_setsv(TARG, &PL_sv_undef);
207
208    Safefree(dir);
209
210    XSprePUSH; PUSHs(TARG);
211    SvTAINTED_on(TARG);
212}
213
214#endif