summaryrefslogtreecommitdiffstats
path: root/scripts/msg2notice.pl
diff options
context:
space:
mode:
authorfimojoha2015-04-29 16:03:35 +0200
committerfimojoha2015-04-29 16:03:35 +0200
commit5ee9e0b72ab4c78de1ccc54b0bf982a91b915a11 (patch)
tree19ff851c2fe945e4311e8f27804d19b449d8bf17 /scripts/msg2notice.pl
parentbb24818ba7a8d5e6909d31f9e608bf497fc7dfb0 (diff)
downloadscripts.irssi.org-5ee9e0b72ab4c78de1ccc54b0bf982a91b915a11.tar.bz2
Use 3-arg open, and check return values
Diffstat (limited to 'scripts/msg2notice.pl')
-rw-r--r--scripts/msg2notice.pl38
1 files changed, 22 insertions, 16 deletions
diff --git a/scripts/msg2notice.pl b/scripts/msg2notice.pl
index 33ddf3c..5dc3ba9 100644
--- a/scripts/msg2notice.pl
+++ b/scripts/msg2notice.pl
@@ -72,15 +72,18 @@ sub load_nicks {
my($mask,$net,$channel,$flags,$flag);
local(*FILE);
- %nicks = ();
- open FILE, "< $file";
- while (<FILE>) {
- add_nick($_);
- }
- close FILE;
- $count = keys %nicks;
+ %nicks = ();
+ if (open FILE, "<", $file) {
+ while (<FILE>) {
+ add_nick($_);
+ }
+ close FILE;
+ $count = keys %nicks;
- crap("Loaded $count nicks");
+ crap("Loaded $count nicks");
+ } else {
+ crap("Unable to open $file for loading: $!");
+ }
}
# --------[ save_nicks ]------------------------------------------------
@@ -93,15 +96,18 @@ sub save_nicks {
return if $auto && !Irssi::settings_get_bool('msg2notice_autosave');
- open FILE, "> $file";
- for my $nick (keys %nicks) {
- $count++;
- print FILE "$nick\n";
- }
- close FILE;
+ if (open FILE, ">", $file) {
+ for my $nick (keys %nicks) {
+ $count++;
+ print FILE "$nick\n";
+ }
+ close FILE;
- crap("Saved $count nicks to $file")
- unless $auto;
+ crap("Saved $count nicks to $file")
+ unless $auto;
+ } else {
+ crap("Unable to open $file for saving: $!");
+ }
}
# ======[ Hooks ]=======================================================