Author: ambs
Date: Wed Jan 11 12:14:55 2006
New Revision: 11099
Added:
trunk/src/classes/file.pmc (contents, props changed)
trunk/t/pmc/file.t (contents, props changed)
Modified:
trunk/MANIFEST
trunk/src/classes/os.pmc
trunk/src/classes/pmc.num
trunk/t/pmc/os.t
Log:
Added File pmc with is_dir and is_link
Removed is_dir and is_link from OS pmc
Added is_dir test to file.t
Removes is_dir test from os.t
Added file.pmc and file.t into MANIFEST file
Added file.pm into pmc.num list
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Wed Jan 11 12:14:55 2006
@@ -1589,6 +1589,7 @@ src/classes/env.pmc
src/classes/eval.pmc []
src/classes/exception.pmc []
src/classes/exception_handler.pmc []
+src/classes/file.pmc []
src/classes/fixedbooleanarray.pmc []
src/classes/fixedfloatarray.pmc []
src/classes/fixedintegerarray.pmc []
@@ -1978,6 +1979,7 @@ t/pmc/delegate.t
t/pmc/env.t []
t/pmc/eval.t []
t/pmc/exception.t []
+t/pmc/file.t []
t/pmc/fixedbooleanarray.t []
t/pmc/fixedfloatarray.t []
t/pmc/fixedintegerarray.t []
Added: trunk/src/classes/file.pmc
==============================================================================
--- (empty file)
+++ trunk/src/classes/file.pmc Wed Jan 11 12:14:55 2006
@@ -0,0 +1,128 @@
+/*
+Copyright: 2001-2006 The Perl Foundation. All Rights Reserved.
+$Id$
+
+=head1 NAME
+
+src/classes/file.pmc - File PMC
+
+=head1 DESCRIPTION
+
+C<File> is a singleton class which provides access to File functions.
+
+=head2 Methods
+
+=over 4
+
+=cut
+
+*/
+
+#ifdef WIN32
+#include <direct.h>
+#endif
+
+#include "parrot/parrot.h"
+
+/* XXX Check if we need to deallocate strerror strings */
+/* XXX apparently, strerror_r is thread-safe and should be used instead.*/
+
+static PMC * File_PMC;
+pmclass File singleton {
+
+/*
+
+=item C<void* get_pointer()>
+
+=item C<void set_pointer(void *ptr)>
+
+These two functions are part of the singleton creation interface. For more
+information see F<src/pmc.c>.
+
+=cut
+
+*/
+
+ void* get_pointer() {
+ return File_PMC;
+ }
+
+ void set_pointer(void* ptr) {
+ File_PMC = (PMC*) ptr;
+ }
+
+/*
+
+=item C<INTVAL is_dir(STRING* path)>
+
+Returns a true value (1) if the supplied path is a directory.
+
+=cut
+
+*/
+
+ METHOD INTVAL is_dir(STRING *path) {
+ struct stat info;
+ char *cpath = string_to_cstring(interpreter, path);
+ int error = stat(cpath, &info);
+ if (error) {
+ char *errmsg = strerror(errno);
+ real_exception(interpreter, NULL, E_SystemError, errmsg);
+ }
+
+ if (S_ISDIR(info.st_mode)) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+/*
+
+=item C<INTVAL is_link(STRING* path)>
+
+Returns a true value (1) if the supplied path is a link.
+
+=cut
+
+*/
+
+ METHOD INTVAL is_link(STRING *path) {
+ struct stat info;
+ char *cpath = string_to_cstring(interpreter, path);
+ int error = stat(cpath, &info);
+ if (error) {
+ char *errmsg = strerror(errno);
+ real_exception(interpreter, NULL, E_SystemError, errmsg);
+ }
+
+ if (S_ISLNK(info.st_mode)) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+}
+
+/*
+
+=back
+
+=head1 SEE ALS0
+
+ stat(2)
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vim: expandtab shiftwidth=4:
+*/
Modified: trunk/src/classes/os.pmc
==============================================================================
--- trunk/src/classes/os.pmc (original)
+++ trunk/src/classes/os.pmc Wed Jan 11 12:14:55 2006
@@ -429,63 +429,6 @@ idea to do the same with parrot.
#endif
}
-
-
-/*
-
-=item C<INTVAL is_dir(STRING* path)>
-
-Returns a true value (1) if the supplied path is a directory.
-
-=cut
-
-*/
-
- METHOD INTVAL is_dir(STRING *path) {
- struct stat info;
- char *cpath = string_to_cstring(interpreter, path);
- int error = stat(cpath, &info);
- if (error) {
- char *errmsg = strerror(errno);
- real_exception(interpreter, NULL, E_SystemError, errmsg);
- }
-
- if (S_ISDIR(info.st_mode)) {
- return 1;
- } else {
- return 0;
- }
- }
-
-
-
-
-/*
-
-=item C<INTVAL is_link(STRING* path)>
-
-Returns a true value (1) if the supplied path is a link.
-
-=cut
-
-*/
-
- METHOD INTVAL is_link(STRING *path) {
- struct stat info;
- char *cpath = string_to_cstring(interpreter, path);
- int error = stat(cpath, &info);
- if (error) {
- char *errmsg = strerror(errno);
- real_exception(interpreter, NULL, E_SystemError, errmsg);
- }
-
- if (S_ISLNK(info.st_mode)) {
- return 1;
- } else {
- return 0;
- }
- }
-
}
/*
Modified: trunk/src/classes/pmc.num
==============================================================================
--- trunk/src/classes/pmc.num (original)
+++ trunk/src/classes/pmc.num Wed Jan 11 12:14:55 2006
@@ -88,4 +88,5 @@ tqueue.pmc 55
parrotclass.pmc 56
parrotobject.pmc 57
-os.pmc 58
\ No newline at end of file
+os.pmc 58
+file.pmc 59
\ No newline at end of file
Added: trunk/t/pmc/file.t
==============================================================================
--- (empty file)
+++ trunk/t/pmc/file.t Wed Jan 11 12:14:55 2006
@@ -0,0 +1,57 @@
+#! perl
+# Copyright: 2001-2006 The Perl Foundation. All Rights Reserved.
+# $Id$
+
+use strict;
+use warnings;
+use lib qw( . lib ../lib ../../lib );
+use Test::More;
+use Parrot::Test tests => 1;
+use Parrot::Config;
+use Cwd;
+use File::Spec;
+
+our ($MSWin32, $cygwin);
+$MSWin32 = 1 if $^O =~ m!MSWin32!;
+$cygwin = 1 if $^O =~ m!cygwin!;
+
+=head1 NAME
+
+t/pmc/file.t - Files functions
+
+=head1 SYNOPSIS
+
+ % prove t/pmc/file.t
+
+=head1 DESCRIPTION
+
+Tests the C<File> PMC.
+
+=cut
+
+END {
+ # Clean up environment on exit
+ rmdir "xpto" if -d "xpto";
+ unlink "xpto" if -f "xpto";
+}
+
+# test is_dir
+mkdir "xpto" unless -d "xpto";
+pir_output_is(<<'CODE', <<"OUT", "Test is_dir in a directory");
+.sub main :main
+ $P1 = new .File
+
+ $S1 = "xpto"
+ $I1 = $P1."is_dir"($S1)
+
+ if $I1 goto ok
+ print "not "
+
+ok:
+ print "ok\n"
+ end
+.end
+CODE
+ok
+OUT
+
Modified: trunk/t/pmc/os.t
==============================================================================
--- trunk/t/pmc/os.t (original)
+++ trunk/t/pmc/os.t Wed Jan 11 12:14:55 2006
@@ -6,7 +6,7 @@ use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 9;
use Parrot::Config;
use Cwd;
use File::Spec;
@@ -114,26 +114,6 @@ $xpto
$cwd
OUT
-# test is_dir
-mkdir "xpto" unless -d "xpto";
-pir_output_is(<<'CODE', <<"OUT", "Test rm call in a directory");
-.sub main :main
- $P1 = new .OS
-
- $S1 = "xpto"
- $I1 = $P1."is_dir"($S1)
-
- if $I1 goto ok
- print "not "
-
-ok:
- print "ok\n"
- end
-.end
-CODE
-ok
-OUT
-
# Test remove on a directory
mkdir "xpto" unless -d "xpto";