#include <fcntl.h>
#include "RPM.h"
-static char * const rcsid = "$Id: Database.xs,v 1.6 2000/08/06 08:57:09 rjray Exp $";
+static char * const rcsid = "$Id: Database.xs,v 1.7 2000/08/11 08:17:42 rjray Exp $";
/*
Use this define for deriving the saved rpmdb struct, rather than coding
/* With that all processed, attempt to open the actual RPM DB */
if (rpmdbOpen(root, &dbstruct->dbp, mode, perms) != 0)
/* rpm lib will have set the error already */
- return (Null(RPM__Database));
+ return ((RPM__Database)0);
else
{
dbstruct->current_rec = 0;
RPM_Database* dbstruct; /* This is the struct used to hold C-level data */
/* Any successful operation will re-assign this */
- FETCH = (RPM__Header)newSVsv(&PL_sv_undef);
+ FETCH = (RPM__Header)0;
dbstruct_from_object_ret(svp, dbstruct, self, FETCH);
/* De-reference key, if it is a reference */
#include "RPM.h"
-static char * const rcsid = "$Id: Header.xs,v 1.12 2000/08/06 08:57:09 rjray Exp $";
+static char * const rcsid = "$Id: Header.xs,v 1.13 2000/08/11 08:17:42 rjray Exp $";
static int scalar_tag(pTHX_ SV *, int);
/*
return(new_from_fd_t(FD, new_hdr));
}
-static int new_from_fname(const char* source, RPM_Header* new_hdr)
+static int new_from_fname(pTHX_ const char* source, RPM_Header* new_hdr)
{
FD_t fd;
if (! (fd = Fopen(source, "r+")))
+ {
+ char errmsg[256];
+
+ snprintf(errmsg, 256, "Unable to open file %s", source);
+ rpm_error(aTHX_ RPMERR_BADFILENAME, errmsg);
return 0;
+ }
return(new_from_fd_t(fd, new_hdr));
}
hdr_struct = safemalloc(sizeof(RPM_Header));
Zero(hdr_struct, 1, RPM_Header);
- TIEHASH = (RPM__Header)newSVsv(&PL_sv_undef);
+ TIEHASH = (RPM__Header)0;
if (! source)
hdr_struct->hdr = headerNew();
if (SvPOK(source))
{
fname = SvPV(source, fname_len);
- if (! new_from_fname(fname, hdr_struct))
+ if (! new_from_fname(aTHX_ fname, hdr_struct))
{
return TIEHASH;
}
$SIG{__WARN__} = sub { $@ = shift; };
$SIG{__DIE__} = sub { $@ = shift; };
-print "1..11\n";
+print "1..12\n";
tie %DB, "RPM::Database" or print "not ";
print "ok 1\n";
# Verify that STORE, DELETE and CLEAR operations are blocked
# STORE
-eval { $DB{foo_package} = 'baz'; print "not " if ($DB{foo_package} == 'baz') };
+eval { $DB{foo_package} = 'baz'; print "not " if ($DB{foo_package} eq 'baz') };
print "ok 3\n";
# DELETE
print "not " unless (grep 'rpm-devel', @matches);
print "ok 10\n";
-undef $rpm;
+# Try to fetch a bogus package
+$hdr = $rpm->{i_hope_no_one_makes_a_package_by_this_name};
+print "not " if $hdr;
print "ok 11\n";
+undef $rpm;
+print "ok 12\n";
+
exit 0;
chomp($rpmstr = qx{rpm -q rpm});
-print "1..17\n";
+print "1..18\n";
tie %DB, "RPM::Database" or die "$RPM::err";
}
print "ok 17\n";
+# Test an attempt to open a non-existant RPM file
+$hdr = new RPM::Header "this_file_not_here.rpm";
+print "not " if $hdr;
+print "ok 18\n";
+
exit 0;
OUTPUT
O_RPM_Database
- if ($var != Null(RPM__Database))
+ if ($var)
{
$arg = sv_bless(newRV_noinc((SV*)$var),
gv_stashpv("RPM::Database", TRUE));
}
O_RPM_Header
- if ($var != Null(RPM__Header))
+ if ($var)
{
$arg = sv_bless(newRV_noinc((SV*)$var),
gv_stashpv("RPM::Header", TRUE));