Subject: | Cwd-> |
Cwd->abs_path and File::Spec->rel2abs produce incorrect results in OS/2.
[g:\bin]perl -v
This is perl, v5.10.0 built for os2
Q:\programs\perl\lib\5.10.0\os2\Cwd.pm has $VERSION = '3.2501';
Q:\programs\perl\lib\5.10.0\File\Spec.pm has $VERSION = '3.2501'.
Running under eComStation 2.0 GA (rebranded OS/2 4.52).
Cwd->abs_path() is appending '/Cwd' to file names.
File::Spec->rel2abs()is using the current drive instead of the drive
specified in the call when the parameter specifies a drive but not a
root directory; it is converting the double \ before a Universal Naming
Convention (UNC) specification into a single / instead of a double /.
To reproduce the problem, adjust the drive letters and directories in
testrel2abs.cmd as needed and adjust the path in the perl invocation to
point to wherever you have stored testrel2abs.pl.
[g:\bin]testrel2abs
F:
CD \ecs
G:
CD \BIN
Should output Cwd->abs_path(F:testpl.cmd) = F:/ecs/testpl.cmd
Cwd->abs_path(G:testpl.cmd) = G:/bin/testpl.cmd
Cwd->abs_path(testpl.cmd) = G:/bin/testpl.cmd
Cwd->abs_path(\testpl.cmd) = G:/testpl.cmd
Cwd->abs_path(\\server\testpl.cmd) =
//server/bin/testpl.cmd
File::Spec->rel2abs(F:testpl.cmd) = F:/ecs/testpl.cmd
File::Spec->rel2abs(G:testpl.cmd) = G:/bin/testpl.cmd
File::Spec->rel2abs(testpl.cmd) = G:/bin/testpl.cmd
File::Spec->rel2abs(\testpl.cmd) = G:/testpl.cmd
File::Spec->rel2abs(\\server\testpl.cmd) =
//server/bin/testpl.cmd
PERL h:\utility\testrel2abs.pl
Cwd->abs_path(F:testpl.cmd) = F:/ecs/testpl.cmd/Cwd
Cwd->abs_path(G:testpl.cmd) = G:/BIN/testpl.cmd/Cwd
Cwd->abs_path(H:testpl.cmd) = H:/testpl.cmd/Cwd
Cwd->abs_path(testpl.cmd) = G:/BIN/testpl.cmd/Cwd
Cwd->abs_path(\testpl.cmd) = G:/testpl.cmd/Cwd
Cwd->abs_path(\\server\testpl.cmd) = G:/server/testpl.cmd/Cwd
File::Spec->rel2abs(F:testpl.cmd) = G:/BIN/testpl.cmd
File::Spec->rel2abs(G:testpl.cmd) = G:/BIN/testpl.cmd
File::Spec->rel2abs(H:testpl.cmd) = G:/BIN/testpl.cmd
File::Spec->rel2abs(testpl.cmd) = G:/BIN/testpl.cmd
File::Spec->rel2abs(\testpl.cmd) = /testpl.cmd
File::Spec->rel2abs(\\server\testpl.cmd) = /server/testpl.cmd
Note: while EMX has a _getcwd1 routine for returning the current
directory of a specified drive, I recommend that you use the native API
instead, as _getcwd1 does not check the buffer size. The relevant native
OS/2 routines are documented as
Show quoted text
--- Start of fair use quote from manual ---
Gets the current default drive for the requesting process.
#define INCL_DOSFILEMGR
#include <os2.h>
PULONG pdisknum; /* Address of the number of the default drive. */
PULONG plogical; /* Address of the bit map where the system returns
the mapping of the logical drives. */
APIRET ulrc; /* Return Code. */
ulrc = DosQueryCurrentDisk(pdisknum, plogical);
pdisknum (PULONG) - output
Address of the number of the default drive.
The 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.
plogical (PULONG) - output
Address of the bit map where the system returns the mapping of the
logical drives.
This bit map is stored in the low-order portion of the 32-bit area.
Logical 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:
0The logical drive does not exist.
1The logical drive exists.
ulrc (APIRET) - returns
Return Code.
DosQueryCurrentDisk returns the following value:
0 NO_ERROR
For a full list of error codes, see Errors.
Gets the full path of the current directory for the requesting process
on the specified drive.
#define INCL_DOSFILEMGR
#include <os2.h>
ULONG disknum; /* The drive number. */
PBYTE pBuf; /* Address of the full path of the current
directory. */
PULONG pcbBuf; /* Address of the length, in bytes, of the pBuf
buffer. */
APIRET ulrc; /* Return Code. */
ulrc = DosQueryCurrentDir(disknum, pBuf, pcbBuf);
disknum (ULONG) - input
The drive number.
The 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.
pBuf (PBYTE) - output
Address of the full path of the current directory.
pcbBuf (PULONG) - in/out
Address of the length, in bytes, of the pBuf buffer.
Input This field contains the length, in bytes, of the directory path
buffer.
Output If an error is returned because the buffer is too small, this
field contains the required length, in bytes, of the buffer.
ulrc (APIRET) - returns
Return Code.
DosQueryCurrentDir returns one of the following values:
0 NO_ERROR
15 ERROR_INVALID_DRIVE
26 ERROR_NOT_DOS_DISK
108 ERROR_DRIVE_LOCKED
111 ERROR_BUFFER_OVERFLOW
For a full list of error codes, see Errors.
--------- end of quote --------
Subject: | testrel2abs.pl |
#! perl
use Cwd 'abs_path';
use File::Spec;
print "\nCwd->abs_path(F:testpl.cmd) = ", Cwd->abs_path('F:testpl.cmd');
print "\nCwd->abs_path(G:testpl.cmd) = ", Cwd->abs_path('G:testpl.cmd');
print "\nCwd->abs_path(H:testpl.cmd) = ", Cwd->abs_path('H:testpl.cmd');
print "\nCwd->abs_path(testpl.cmd) = ", Cwd->abs_path('testpl.cmd');
print "\nCwd->abs_path(\\testpl.cmd) = ", Cwd->abs_path('\testpl.cmd');
print "\nCwd->abs_path(\\\\server\\testpl.cmd) = ", Cwd->abs_path('\\server\testpl.cmd');
print "\n";
print "\nFile::Spec->rel2abs(F:testpl.cmd) = ", File::Spec->rel2abs('F:testpl.cmd');
print "\nFile::Spec->rel2abs(G:testpl.cmd) = ", File::Spec->rel2abs('G:testpl.cmd');
print "\nFile::Spec->rel2abs(H:testpl.cmd) = ", File::Spec->rel2abs('H:testpl.cmd');
print "\nFile::Spec->rel2abs(testpl.cmd) = ", File::Spec->rel2abs('testpl.cmd');
print "\nFile::Spec->rel2abs(\\testpl.cmd) = ", File::Spec->rel2abs('\testpl.cmd');
print "\nFile::Spec->rel2abs(\\\\server\\testpl.cmd) = ", File::Spec->rel2abs('\\server\testpl.cmd');
Subject: | testrel2abs.cmd |
Message body not shown because it is not plain text.