Author: ambs
Date: Sun Jan 8 07:53:34 2006
New Revision: 10990
Modified:
trunk/languages/tcl/lib/builtins/cd.pir
trunk/src/builtin.c
trunk/src/classes/os.pmc
trunk/t/pmc/os.t
Log:
os.pmc - added lstat and chroot, renamed cd to chdir
buildin.c - added lstat, chroot and renamed cd to chdir
os.t - changed cd to chdir
tcl/.../cd.pir - changed pir code to use chdir
Modified: trunk/languages/tcl/lib/builtins/cd.pir
==============================================================================
--- trunk/languages/tcl/lib/builtins/cd.pir (original)
+++ trunk/languages/tcl/lib/builtins/cd.pir Sun Jan 8 07:53:34 2006
@@ -50,7 +50,7 @@ cd_it:
pir_code .= $S2
pir_code .= " = $P"
pir_code .= $S1
- pir_code .= '."cd"($P'
+ pir_code .= '."chdir"($P'
$S2 = directory_num
pir_code .= $S2
pir_code .= ")\n"
Modified: trunk/src/builtin.c
==============================================================================
--- trunk/src/builtin.c (original)
+++ trunk/src/builtin.c Sun Jan 8 07:53:34 2006
@@ -39,7 +39,8 @@ static Builtins builtins[] = {
{ "atan2", "PJOP", "Float", 0, 0 },
{ "cos", "PJO", "Float", 0, 0 },
{ "cosh", "PJO", "Float", 0, 0 },
- { "cd", "vJOS", "OS", 0, 0 },
+ { "chdir", "vJOS", "OS", 0, 0 },
+ { "chroot", "vJOS", "OS", 0, 0 },
{ "cwd", "SJO", "OS", 0, 0 },
{ "exp", "PJO", "Float", 0, 0 },
{ "mkdir", "vJOSI", "OS", 0, 0 },
@@ -56,6 +57,7 @@ static Builtins builtins[] = {
{ "is_integer","IJS", "String", 0, 0 },
{ "link", "vJOSS", "OS", 0, 0 },
{ "lower", "PJO", "String", 0, 0 },
+ { "lstat", "PJOS", "OS", 0, 0 },
{ "open", "PJS.S", "ParrotIO", 0, 0 },
{ "puts", "IJOS", "ParrotIO", 0, 0 },
{ "reverse","vJS", "String", 0, 0 },
Modified: trunk/src/classes/os.pmc
==============================================================================
--- trunk/src/classes/os.pmc (original)
+++ trunk/src/classes/os.pmc Sun Jan 8 07:53:34 2006
@@ -1,5 +1,5 @@
/*
-Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
+Copyright: 2001-2006 The Perl Foundation. All Rights Reserved.
$Id$
=head1 NAME
@@ -85,7 +85,7 @@ Returns the current working directory.
/*
-=item C<void cd(STRING *path)>
+=item C<void chdir(STRING *path)>
Changes the current working directory to the one specified by C<path>.
@@ -93,7 +93,7 @@ Changes the current working directory to
*/
- METHOD void cd(STRING *path) {
+ METHOD void chdir(STRING *path) {
#ifndef _MSC_VER
int error;
char *cpath = string_to_cstring(interpreter, path);
@@ -108,7 +108,6 @@ Changes the current working directory to
#endif
}
-
/*
=item C<void rm(STRING* path)>
@@ -120,7 +119,6 @@ C<path>.
*/
-
METHOD void rm(STRING *path) {
int error;
char *cpath = string_to_cstring(interpreter, path);
@@ -132,7 +130,6 @@ C<path>.
}
}
-
/*
=item C<void mkdir(STRING* path, STRING* mode)>
@@ -163,7 +160,6 @@ Creates a directory specified by C<path>
#endif
}
-
/*
=item C<fixedpmcarray* stat(STRING* path)>
@@ -184,6 +180,8 @@ Stats a file, and returns a 13 position
11 blksize preferred block size for file system I/O
12 blocks actual number of blocks allocated
+11 and 12 are not available under Windows.
+
=cut
*/
@@ -242,6 +240,85 @@ Stats a file, and returns a 13 position
#endif
}
+/*
+
+=item C<fixedpmcarray* stat(STRING* path)>
+
+Stats a file, and returns a 13 position array as in Perl:
+
+ 0 dev device number of filesystem
+ 1 ino inode number
+ 2 mode file mode (type and permissions)
+ 3 nlink number of (hard) links to the file
+ 4 uid numeric user ID of file's owner
+ 5 gid numeric group ID of file's owner
+ 6 rdev the device identifier (special files only)
+ 7 size total size of file, in bytes
+ 8 atime last access time in seconds since the epoch
+ 9 mtime last modify time in seconds since the epoch
+ 10 ctime inode change time in seconds since the epoch (*)
+ 11 blksize preferred block size for file system I/O
+ 12 blocks actual number of blocks allocated
+
+11 and 12 are not available under Windows.
+
+=cut
+
+*/
+
+ METHOD PMC* lstat(STRING *path) {
+#ifndef _MSC_VER
+ struct stat info;
+ PMC *array;
+
+ char *cpath = string_to_cstring(interpreter, path);
+ int error = lstat(cpath, &info);
+ string_cstring_free(cpath);
+
+ if (error) {
+ char *errmsg = strerror(errno);
+ real_exception(interpreter, NULL, E_SystemError, errmsg);
+ return NULL;
+ }
+ else {
+ array = pmc_new(interpreter, enum_class_FixedPMCArray);
+ VTABLE_set_integer_native(interpreter, array, 13);
+
+ VTABLE_set_integer_keyed_int(interpreter, array, 0,
+ info.st_dev);
+ VTABLE_set_integer_keyed_int(interpreter, array, 1,
+ info.st_ino);
+ VTABLE_set_integer_keyed_int(interpreter, array, 2,
+ info.st_mode);
+ VTABLE_set_integer_keyed_int(interpreter, array, 3,
+ info.st_nlink);
+ VTABLE_set_integer_keyed_int(interpreter, array, 4,
+ info.st_uid);
+ VTABLE_set_integer_keyed_int(interpreter, array, 5,
+ info.st_gid);
+ VTABLE_set_integer_keyed_int(interpreter, array, 6,
+ info.st_rdev);
+ VTABLE_set_integer_keyed_int(interpreter, array, 7,
+ info.st_size);
+ VTABLE_set_integer_keyed_int(interpreter, array, 8,
+ info.st_atime);
+ VTABLE_set_integer_keyed_int(interpreter, array, 9,
+ info.st_mtime);
+ VTABLE_set_integer_keyed_int(interpreter, array,10,
+ info.st_ctime);
+#ifndef WIN32
+ VTABLE_set_integer_keyed_int(interpreter, array,11,
+ info.st_blksize);
+ VTABLE_set_integer_keyed_int(interpreter, array,12,
+ info.st_blocks);
+#endif
+ return array;
+ }
+#else
+ internal_exception(UNIMPLEMENTED, "Win32 is not POSIX. Need win32
developer!");
+ return NULL;
+#endif
+ }
/*
@@ -269,7 +346,6 @@ Creates a symlink, where available
#endif
}
-
/*
=item C<void link(STRING* from, STRING *to)>
@@ -317,15 +393,41 @@ previous one).
#endif
}
+/*
+
+=item C<INTVAL chroot(STRING* path)>
+
+it makes the named directory the new root directory for all further
+pathnames that begin with a "/" by your process and all its children.
+
+=cut
+
+*/
+
+ METHOD void chroot(STRING* path) {
+#ifndef _MSC_VER
+ char *cpath = string_to_cstring(interpreter, path);
+ int error = chroot(cpath);
+ string_cstring_free(cpath);
+ if (error) {
+ char *errmsg = strerror(errno);
+ real_exception(interpreter, NULL, E_SystemError, errmsg);
+ }
+#else
+ internal_exception(UNIMPLEMENTED, "Win32 is not POSIX. Need win32
developer!");
+#endif
+ }
+
}
+
/*
=back
=head1 SEE ALS0
- chdir(2), getcwd(3), unlink(2), mkdir(2), stat(2), symlink(2),
- link(2), umask(2)
+ chdir(2), getcwd(3), unlink(2), mkdir(2), stat(2), lstat(2),
+ symlink(2), link(2), umask(2), chroot(2)
=cut
Modified: trunk/t/pmc/os.t
==============================================================================
--- trunk/t/pmc/os.t (original)
+++ trunk/t/pmc/os.t Sun Jan 8 07:53:34 2006
@@ -52,24 +52,24 @@ OUT
-# TEST cd
+# TEST chdir
chdir "src";
my $upcwd = getcwd;
chdir "..";
-pir_output_is(<<'CODE', <<"OUT", "Test cd");
+pir_output_is(<<'CODE', <<"OUT", "Test chdir");
.sub main :main
$P1 = new .OS
$S1 = "src"
- $P1."cd"($S1)
+ $P1."chdir"($S1)
$S1 = $P1."cwd"()
print $S1
print "\n"
$S1 = ".."
- $P1."cd"($S1)
+ $P1."chdir"($S1)
$S1 = $P1."cwd"()
print $S1
@@ -95,14 +95,14 @@ pir_output_is(<<'CODE', <<"OUT", "Test m
$S1 = "xpto"
$I1 = 0o555
$P1."mkdir"($S1,$I1)
- $P1."cd"($S1)
+ $P1."chdir"($S1)
$S1 = $P1."cwd"()
print $S1
print "\n"
$S1 = ".."
- $P1."cd"($S1)
+ $P1."chdir"($S1)
$S1 = $P1."cwd"()
print $S1