[svn:parrot] r49402 - in trunk: config/auto config/auto/stat config/gen/platform/generic config/gen/platform/win32 lib/Parrot/Configure/Step
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Fri Oct 1 22:34:12 UTC 2010
Author: plobsing
Date: Fri Oct 1 22:34:11 2010
New Revision: 49402
URL: https://trac.parrot.org/parrot/changeset/49402
Log:
detect if a platform has the BSD stat extensions
Added:
trunk/config/auto/stat/
trunk/config/auto/stat.pm
trunk/config/auto/stat/test_c.in
Deleted:
trunk/config/gen/platform/win32/stat.c
Modified:
trunk/config/gen/platform/generic/stat.c
trunk/lib/Parrot/Configure/Step/List.pm
Added: trunk/config/auto/stat.pm
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/config/auto/stat.pm Fri Oct 1 22:34:11 2010 (r49402)
@@ -0,0 +1,66 @@
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+config/auto/stat.pm - stat extension detection
+
+=head1 DESCRIPTION
+
+Determining if the system has BSD stat extensions.
+
+=cut
+
+package auto::stat;
+
+use strict;
+use warnings;
+
+use base qw(Parrot::Configure::Step);
+
+use Parrot::Configure::Utils ':auto';
+
+sub _init {
+ my $self = shift;
+ my %data;
+ $data{description} = q{Detect stat type};
+ $data{result} = q{};
+ return \%data;
+}
+
+sub runstep {
+ my ( $self, $conf ) = @_;
+
+ my $bsd_stat = 0;
+
+ $conf->cc_gen('config/auto/stat/test_c.in');
+ eval { $conf->cc_build(); };
+ if (!$@) {
+ my $output = eval { $conf->cc_run() };
+ if (!$@ && $output =~ /OK/) {
+ $bsd_stat = 1;
+ }
+ }
+ $conf->cc_clean();
+
+ if ($bsd_stat) {
+ $conf->data->set( HAS_BSD_STAT_EXTN => 1 );
+ $self->set_result('bsd');
+ }
+ else {
+ $conf->data->set( HAS_BSD_STAT_EXTN => 0 );
+ $self->set_result('posix');
+ }
+
+ return 1;
+}
+
+1;
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
+
Added: trunk/config/auto/stat/test_c.in
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/config/auto/stat/test_c.in Fri Oct 1 22:34:11 2010 (r49402)
@@ -0,0 +1,28 @@
+/*
+Copyright (C) 2010, Parrot Foundation.
+$Id$
+
+seeing if struct stat has BSD extensions
+
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+
+int
+main()
+{
+ struct stat st;
+ st.st_blocks = 22;
+ st.st_blksize = 500;
+ printf("OK: %d %d", st.st_blocks, st.st_blksize);
+ return EXIT_SUCCESS;
+}
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
Modified: trunk/config/gen/platform/generic/stat.c
==============================================================================
--- trunk/config/gen/platform/generic/stat.c Fri Oct 1 21:08:48 2010 (r49401)
+++ trunk/config/gen/platform/generic/stat.c Fri Oct 1 22:34:11 2010 (r49402)
@@ -177,10 +177,20 @@
result = statbuf->st_rdev;
break;
case STAT_PLATFORM_BLOCKSIZE:
+#if PARROT_HAS_BSD_STAT_EXTN
result = statbuf->st_blksize;
+#else
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "STAT_PLATFORM_BLOCKSIZE not supported");
+#endif
break;
case STAT_PLATFORM_BLOCKS:
+#if PARROT_HAS_BSD_STAT_EXTN
result = statbuf->st_blocks;
+#else
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "STAT_PLATFORM_BLOCKS not supported");
+#endif
break;
default:
break;
Deleted: trunk/config/gen/platform/win32/stat.c
==============================================================================
--- trunk/config/gen/platform/win32/stat.c Fri Oct 1 22:34:11 2010 (r49401)
+++ /dev/null 00:00:00 1970 (deleted)
@@ -1,253 +0,0 @@
-/*
- * $Id$
- * Copyright (C) 2007-2008, Parrot Foundation.
- */
-
-/*
-
-=head1 NAME
-
-config/gen/platform/win32/stat.c
-
-=head1 DESCRIPTION
-
-File stat stuff
-
-=head2 Functions
-
-=over 4
-
-=cut
-
-*/
-
-
-/*
-
-=item C<PMC * Parrot_stat_file(PARROT_INTERP, STRING *filename)>
-
-Stat a file. On Win32 this is not yet implemented, so we return a
-C<NULL> PMC, not C<PMCNULL>.
-
-=cut
-
-*/
-
-PMC *
-Parrot_stat_file(PARROT_INTERP, STRING *filename)
-{
- return NULL;
-}
-
-/*
-
-=item C<PMC * Parrot_stat_info_pmc(PARROT_INTERP, STRING *filename, INTVAL
-thing)>
-
-Return stat info on a file as a PMC. Not implemented on Win32, so we
-return C<NULL>, not C<PMCNULL>.
-
-=cut
-
-*/
-
-PMC *
-Parrot_stat_info_pmc(PARROT_INTERP, STRING *filename, INTVAL thing)
-{
- return NULL;
-}
-
-/*
-
-=item C<static INTVAL stat_common(PARROT_INTERP, struct stat *statbuf, INTVAL
-thing, int status)>
-
-Stats the file, and returns the information specified by C<thing>. C<thing> can
-be one of: C<STAT_EXISTS>, C<STAT_FILESIZE>, C<STAT_ISDIR>, C<STAT_ISDEV>,
-C<STAT_ACCESSTIME>, C<STAT_MODIFYTIME>, C<STAT_CHANGETIME>, C<STAT_UID>,
-C<STAT_GID>, C<STAT_PLATFORM_DEV>, C<STAT_PLATFORM_INODE>,
-C<STAT_PLATFORM_NLINKS>, C<STAT_PLATFORM_DEVTYPE>.
-
-C<STAT_BACKUPTIME> and C<STAT_CREATETIME> are not supported on Win32, so will
-return -1.
-
-C<STAT_PLATFORM_BLOCKS> and C<STAT_PLATFORM_BLOCKSIZE> are not supported by
-Win32 and will throw an exception.
-
-=cut
-
-*/
-
-static INTVAL
-stat_common(PARROT_INTERP, struct stat *statbuf, INTVAL thing, int status)
-{
- INTVAL result = -1;
-
- if (thing == STAT_EXISTS)
- return status == 0;
-
- if (status == -1) {
- const char *err = strerror(errno);
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_PIO_ERROR,
- "stat failed: %s", err);
- }
-
- switch (thing) {
- case STAT_FILESIZE:
- result = statbuf->st_size;
- break;
- case STAT_ISDIR:
- result = S_ISDIR(statbuf->st_mode);
- break;
- case STAT_ISREG:
- result = S_ISREG(statbuf->st_mode);
- break;
- case STAT_ISDEV:
- result = S_ISCHR(statbuf->st_mode) || S_ISBLK(statbuf->st_mode);
- break;
- case STAT_CREATETIME:
- result = -1;
- break;
- case STAT_ACCESSTIME:
- result = statbuf->st_atime;
- break;
- case STAT_MODIFYTIME:
- result = statbuf->st_mtime;
- break;
- case STAT_CHANGETIME:
- result = statbuf->st_ctime;
- break;
- case STAT_BACKUPTIME:
- result = -1;
- break;
- case STAT_UID:
- result = statbuf->st_uid;
- break;
- case STAT_GID:
- result = statbuf->st_gid;
- break;
- case STAT_PLATFORM_DEV:
- result = statbuf->st_dev;
- break;
- case STAT_PLATFORM_INODE:
- result = statbuf->st_ino;
- break;
- case STAT_PLATFORM_MODE:
- result = statbuf->st_mode;
- break;
- case STAT_PLATFORM_NLINKS:
- result = statbuf->st_nlink;
- break;
- case STAT_PLATFORM_DEVTYPE:
- result = statbuf->st_rdev;
- break;
- case STAT_PLATFORM_BLOCKSIZE:
- Parrot_ex_throw_from_c_args(interp, NULL, 1,
- "STAT_PLATFORM_BLOCKSIZE not supported");
- break;
- case STAT_PLATFORM_BLOCKS:
- Parrot_ex_throw_from_c_args(interp, NULL, 1,
- "STAT_PLATFORM_BLOCKS not supported");
- break;
- default:
- break;
- }
-
- return result;
-}
-
-/*
-
-=item C<INTVAL Parrot_stat_info_intval(PARROT_INTERP, STRING *file, INTVAL
-thing)>
-
-Returns the stat field given by C<thing> of file C<file>.
-
-=cut
-
-*/
-
-INTVAL
-Parrot_stat_info_intval(PARROT_INTERP, STRING *file, INTVAL thing)
-{
- struct stat statbuf;
-
- /* Get the name of the file as something we can use */
- char * const filename = Parrot_str_to_cstring(interp, file);
-
- /* Everything needs the result of stat, so just go do it */
- const int status = stat(filename, &statbuf);
- Parrot_str_free_cstring(filename);
- return stat_common(interp, &statbuf, thing, status);
-}
-
-/*
-
-=item C<INTVAL Parrot_fstat_info_intval(PARROT_INTERP, INTVAL file, INTVAL
-thing)>
-
-Returns the fstat field given by C<thing> from file identifier C<file>.
-
-=cut
-
-*/
-
-INTVAL
-Parrot_fstat_info_intval(PARROT_INTERP, INTVAL file, INTVAL thing)
-{
- struct stat statbuf;
- int status;
-
- /* Everything needs the result of stat, so just go do it */
- status = fstat(file, &statbuf);
- return stat_common(interp, &statbuf, thing, status);
-}
-
-/*
-
-=item C<FLOATVAL Parrot_stat_info_floatval(PARROT_INTERP, STRING *filename,
-INTVAL thing)>
-
-Currently returns C<-1.0> and has no side effects.
-
-=cut
-
-*/
-
-FLOATVAL
-Parrot_stat_info_floatval(PARROT_INTERP, STRING *filename, INTVAL thing)
-{
- return (FLOATVAL)-1;
-}
-
-/*
-
-=item C<STRING * Parrot_stat_info_string(PARROT_INTERP, STRING *filename, INTVAL
-thing)>
-
-Not implemented. Returns C<NULL>.
-
-=cut
-
-*/
-
-STRING *
-Parrot_stat_info_string(PARROT_INTERP, STRING *filename, INTVAL thing)
-{
- return NULL;
-}
-
-/*
-
-=back
-
-=cut
-
-*/
-
-/*
- * Local variables:
- * c-file-style: "parrot"
- * End:
- * vim: expandtab shiftwidth=4:
- */
Modified: trunk/lib/Parrot/Configure/Step/List.pm
==============================================================================
--- trunk/lib/Parrot/Configure/Step/List.pm Fri Oct 1 21:08:48 2010 (r49401)
+++ trunk/lib/Parrot/Configure/Step/List.pm Fri Oct 1 22:34:11 2010 (r49402)
@@ -45,6 +45,7 @@
auto::memalign
auto::signal
auto::socklen_t
+ auto::stat
auto::neg_0
auto::env
auto::timespec
More information about the parrot-commits
mailing list