X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fpc%2B-file-reader.c;h=4d08f27465407bff935163af10525bea0237e653;hb=64c3106b6b4900aa3515fb3ebc930ce80b59bb1e;hp=0aa4587d38ca3ebe81fe2b3edd10f1edd2272be1;hpb=197c17c92ac8124ae389434afa105bee90b96ad8;p=pspp diff --git a/src/data/pc+-file-reader.c b/src/data/pc+-file-reader.c index 0aa4587d38..4d08f27465 100644 --- a/src/data/pc+-file-reader.c +++ b/src/data/pc+-file-reader.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-2000, 2006-2007, 2009-2014 Free Software Foundation, Inc. + Copyright (C) 1997-2000, 2006-2007, 2009-2015 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -209,7 +209,7 @@ pcp_open (struct file_handle *fh) goto error; /* Open file. */ - r->file = fn_open (fh_get_file_name (fh), "rb"); + r->file = fn_open (fh, "rb"); if (r->file == NULL) { msg (ME, _("Error opening `%s' for reading as an SPSS/PC+ " @@ -478,7 +478,7 @@ pcp_close (struct any_reader *r_) if (r->file) { - if (fn_close (fh_get_file_name (r->fh), r->file) == EOF) + if (fn_close (r->fh, r->file) == EOF) { msg (ME, _("Error closing system file `%s': %s."), fh_get_file_name (r->fh), strerror (errno)); @@ -505,18 +505,20 @@ pcp_file_casereader_destroy (struct casereader *reader UNUSED, void *r_) pcp_close (&r->any_reader); } -/* Returns true if FILE is an SPSS/PC+ system file, - false otherwise. */ +/* Detects whether FILE is an SPSS/PC+ system file. Returns 1 if so, 0 if + not, and a negative errno value if there is an error reading FILE. */ static int pcp_detect (FILE *file) { static const char signature[4] = "SPSS"; char buf[sizeof signature]; - if (fseek (file, 0x104, SEEK_SET) - || (fread (buf, sizeof buf, 1, file) != 1 && !feof (file))) + if (fseek (file, 0x104, SEEK_SET)) return -errno; + if (fread (buf, sizeof buf, 1, file) != 1) + return ferror (file) ? -errno : 0; + return !memcmp (buf, signature, sizeof buf); }